Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

erb

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

erb

Compile a given Embedded RuBy (ERB) template using variables and functions defined in given a JavaScript object

  • 1.3.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

erb

JavaScript Style Guide Build Status

Compile a given Embedded RuBy (ERB) template using variables and functions defined in given a JavaScript object.

Installation

npm install --save erb

Usage

Executing

const erb = require('erb');

const data = {
  "fields": {
    "first": "Morty",
    "second": "Rick"
  },
  "values": {
    "additions": "with pattie, breaded and fried"
  },
  "functions": {
    "title": [
      [
        1,
        "One Chicken Fried Steak"
      ],
      [
        2,
        3,
        "Two or Three Chicken Fried Steaks"
      ]
    ]
  }
}

erb({
  timeout: 5000,
  data: data,
  template: '<%= @first %> had <%= title(1) %> <%= additions %>.\n<%= @second %> had <%= title(2, 3) %> <%= additions %>.'
}).then(console.log, console.error);

would result in

Morty had One Chicken Fried Steak with pattie, breaded and fried.
Rick had Two or Three Chicken Fried Steaks with pattie, breaded and fried.

API

erb(opts)

opts is a simple JSON object with these properties:

  • timeout (optional, integer) - number of milliseconds (defaults to 5000) to wait for the template evaluation to finish before terminating with error
  • data (optional, object) - an object that contains these properties:
    • fields (optional, object) - the keys of this object are instance variable names to be used in the ERB template and values are the values of the instance variables
    • values (optional, object) - the keys of this object are variable names to be used in the ERB template and values are the values of the variables
    • functions (optional, object) - the keys of this object are function names to be used in the ERB template and values are special arrays - the items match the function call arguments with the last item being the value returned by the function when called with these arguments.
  • template (required, string) - the ERB template to be compiled

Building

Requires Bundler.

npm run build

Contributing

  • do not do existing API-breaking changes - the test suite should remain unchanged forever, except when you add new features
  • if you do a pull request, then it must have a precise title and exactly the change the title describes - otherwise do several pull requests

FAQs

Package last updated on 13 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc