Detalhes do pacote

transformers

ForbesLindesay640.2kMITdepreciado3.1.0

Deprecated, use jstransformer

String/Data transformations for use in templating libraries, static site generators and web frameworks

readme (leia-me)

Build Status

transformers

String/Data transformations for use in templating libraries, static site generators and web frameworks. This gathers the most useful transformations you can apply to text or data into one library with a consistent API. Transformations can be pretty much anything but most are either compilers or templating engines.

Supported transforms

To use each of these transforms you will also need to install the associated npm module for that transformer.

Template engines

Stylesheet Languages

  • less (website) - LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions.
  • stylus (website) - revolutionary CSS generator making braces optional
  • sass (website) - Sassy CSS

Minifiers

  • uglify-js - No need to install anything, just minifies/beautifies JavaScript
  • uglify-css - No need to install anything, just minifies/beautifies CSS
  • ugilify-json - No need to install anything, just minifies/beautifies JSON

Other

  • cdata - No need to install anything, just wraps input as <![CDATA[${INPUT_STRING]]> with the standard escape for ]]> (]]]]><![CDATA[>).
  • cdata-js - as cdata, but with surrounding comments suitable for inclusion into a HTML/JavaScript <script> block: //<![CDATA[\n${INPUT_STRING\n//]]>.
  • cdata-css - as cdata, but with surrounding comments suitable for inclusion into a HTML/CSS <style> block: /*<![CDATA[*/\n${INPUT_STRING\n/*]]>*/.
  • verbatim - No need to install anything, acts as a verbatim passthrough ${INPUT_STRING}
  • escape-html - No need to install anything, just replaces special characters to sanitize input for html/xml
  • coffee-script - npm install coffee-script
  • cson - coffee-script based JSON format
  • markdown - You can use marked, supermarked, markdown-js or markdown

Pull requests to add more transforms will always be accepted providing they are open-source, come with unit tests, and don't cause any of the tests to fail.

API

The exported object transformers is a collection of named transformers. To access an individual transformer just do:

  var transformer = require('transformers')['transformer-name']

Transformer

The following options are given special meaning by transformers:

  • filename is set by transformers automatically if using the renderFile APIs. It is used if cache is enabled.
  • cache if true, the template function will be cached where possible (templates are still updated if you provide new options, so this can be used in most live applications).
  • sudoSync used internally to put some asyncronous transformers into "sudo syncronous" mode. Don't touch this.
  • minify if set to true on a transformer that isn't a minifier, it will cause the output to be minified. e.g. coffeeScript.renderSync(str, {minify: true}) will result in minified JavaScript.

Transformer.engines

Returns an array of engines that can be used to power this transformer. The first of these that's installed will be used for the transformation.

To enable a transformation just take [engine] = Transformer.engines[0] and then do npm install [engine]. If [engine] is . there is no need to install an engine from npm to use the transformer.

Transformer.render(str, options, cb)

Tranform the string str using the Transformer with the provided options and call the callback cb(err, res).

If no cb is provided, this method returns a promises/A+ promise.

Transformer.renderSync(str, options)

Synchronous version of Transformer.render

Transformer.renderFile(filename, options, cb)

Reads the file at filename into str and sets options.filename = filename then calls Transform.render(str, options, cb).

If no cb is provided, this method returns a promises/A+ promise.

Tranformer.renderFileSync(filename, options)

Synchronous version of Tranformer.renderFile

Transformer.outputFormat

A string, one of:

  • 'xml'
  • 'css'
  • 'js'
  • 'json'
  • 'text'

Adding to this list will not result in a major version change, so you should handle unexpected types gracefully (I'd suggest default to assuming 'text').

Transformer.sync

true if the transformer can be used syncronously, false otherwise.

Libraries that don't work synchronously

The following transformations will always throw an exception if you attempt to run them synchronously:

  1. dust
  2. qejs
  3. html2jade

The following transformations sometimes throw an exception if run syncronously, typically they only throw an exception if you are doing something like including another file. If you are not doing the things that cause them to fail then they are consistently safe to use syncronously.

  • jade (only when using then-jade instead of jade)
  • less (when @import is used with a url instead of a filename)
  • jazz (When one of the functions passed as locals is asyncronous)

The following libraries look like they might sometimes throw exceptions when used syncronously (if you read the source) but they never actually do so:

  • just
  • ect
  • stylus

changelog (log de mudanças)

3.0.0 - 2014-02-12

  • escape-html
  • remove html2jade (it was all round problematic and not kept up to date with recent changes to jade)
  • remove component-js and component-css (I don't think they are very useful to have here, browserify is better)
  • improve stylus support
  • fix mustache (it no longer supports caching properly)

2.1.0 - 2013-07-13

  • verbatim
  • cdata-js
  • cdata-css
  • fix escaping in cdata
  • fix less errors

2.0.1 - 2013-04-22

  • Fix global leak of exportscoffeeScript (test still fails because jade requires an out of date version of transformers)

2.0.0 - 2013-03-31

  • Add minify support to all transformers
  • Bundle minifiers in package

1.8.3 - 2013-03-19

  • Update promise dependency

1.8.2 - 2013-02-10

  • Support sourceURLs in component

1.8.1 - 2013-02-10

  • Add travis-ci
  • FIX toffee support which was broken by their latest update
  • FIX lookup paths for component weren't set so you couldn't build components with dependancies

1.8.0 - 2013-01-30

  • highlight (needs tests)

1.7.0 - 2013-01-30

  • component-js
  • component-css
  • html2jade - must be v0.0.7 because of a bug in later versions
  • Much more extensive tests

1.6.0 - 2013-01-29

  • uglify-css
  • uglify-json
  • Rename uglify to uglify-js

1.5.0 - 2013-01-27

  • dot

1.4.0 - 2013-01-25

  • Support sync @import statements in less
  • Report real errors from less (rather than objects)

1.3.0 - 2013-01-25

  • templayed
  • plates

1.2.1 - 2013-01-09

  • make markdown work when using markdown as the engine (marked is the recommended engine).

1.2.0 - 2013-01-09

  • js (pass through)
  • css (pass through)
  • rename coffee-script from coffee to coffee-script and add coffee as an alias

1.1.0 - 2013-01-08

  • coffeecup
  • cson
  • FIX: disabling dust cache