preproc

0.1.14 • Public • Published

Preproc.js

Preproc.js is the anything preprocessor for node.js. Preprocess any file performing inclusions and conditional compilation.

Installation

npm install preproc

Usage

Include everything everywhere

//= include "mylib.coffee"
 
MyLib.doSomething();

Define delimiters for each file format and choose how to transform sources before they are included into other files

var preproc = require('preproc');
 
var builder = new preproc.Builder({
  types: {
    coffeescript: {
      delimiters: ["#="],
      extensions: ['.coffee'],
      to: {
        javascript: function(content) {
          return coffee.compile(content, {
            bare: true
          });
        }
      }
    },
    javascript: {
      delimiters: ["//="],
      extensions: ['.js'],
      to: {
        javascript: function(content) {
          return ";" + content + ";";
        },
        coffeescript: function(content) {
          return "\`" + content + "\`\n";
        },
        html: function(content) {
          return "<script>\\\\<![CDATA[\n" + content + "\n\\\\]]></script>";
        }
      }
    },
    html: {
      delimiters: ["<!--=", "-->"],
      extensions: ['.html']
    }
  }
});
 

Note: Preproc.js ships with a default configuration. See https://github.com/mcasimir/preprocjs/blob/master/src/defaults.coffee for more.

Use Path Globbing to include multiple files at once

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My App</title>
</head>
<body>
<!--= include "templates/*.hbs" -->
</body>
</html>

Require something once

//= require "mylib.js"

Skip precompilation on unknown sources

//= require "vendor/lib.js" --skip

Environment

Variables

builder.setEnv({debug: true});
var myVal = fn();
 
//= if debug
console.log("myVal is: " + myVal);
//= end

Conditional Compilation

//= if target == 'client'
 
$.get("/data", function(data){
  //...
});
 
//= else if target == 'server'
 
Db.queryData(function(data){
  //...
});
 
//= end

Operators

  • ! or not
  • & or and
  • || or or
  • < or lt
  • > or gt
  • <= or lte
  • >= or gte
  • == or eq
  • != or neq

Give it a try

npm install preproc

Read http://mcasimir.github.io/preprocjs/getting_started.html for more


Copyright (c) 2013 mcasimir

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.14
    1
    • latest

Version History

Package Sidebar

Install

npm i preproc

Weekly Downloads

20

Version

0.1.14

License

none

Last publish

Collaborators

  • mcasimir