Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and additions #33

Merged
merged 9 commits into from
Jul 18, 2012
Merged

Fixes and additions #33

merged 9 commits into from
Jul 18, 2012

Conversation

panosru
Copy link

@panosru panosru commented Jun 9, 2012

  • Fix related to typo mentioned on issue let instead of set? typo? #31
  • Fix float filter so it return 0.0 instead of NaN
  • improved reverse filter supports number, string and array
  • Added outputUndefinedVariable flag
  • Added outputUndefinedVariableWithBrackets flag
  • Added options method on engine initialization

@panosru panosru closed this Jul 18, 2012
@panosru panosru reopened this Jul 18, 2012
@panosru
Copy link
Author

panosru commented Jul 18, 2012

Example of outputUndefinedVariable and outputUndefinedVariableWithBrackets

JinJS Template (test.tpl):

Hi, {{name}}!

Initialize the engine: (jin.js):

var jinjs = require("jinjs");
    jinjs.registerExtension(".tpl");

var my_template = require("./test");
var context = { };
var result = my_template.render(context);

console.log(result);

Will output:

Hi, !

Since the name variable is undefined, we could use jinjs.outputUndefinedVariable() in order to output the variable name, so if we alter our jin.js file into this:

var jinjs = require("jinjs");
    jinjs.registerExtension(".tpl");
    jinjs.outputUndefinedVariable();

var my_template = require("./test");
var context = { };
var result = my_template.render(context);

console.log(result);

Then it will output:

Hi, name!

In case we want to output the variable name with brackets then all we have to do is this:

var jinjs = require("jinjs");
    jinjs.registerExtension(".tpl");
    jinjs.outputUndefinedVariable(true,true);

var my_template = require("./test");
var context = { };
var result = my_template.render(context);

console.log(result);

And now it will output:

Hi, {{name}}!

outputUndefinedVariable method takes two parameters, both are boolean parameters, first param is for outputUndefinedVariable and second parameter is for outputUndefinedVariableWithBrackets.

@panosru
Copy link
Author

panosru commented Jul 18, 2012

Options method added


Now instead of having multiple methods when initializing jinjs engine you have only options method which handles the rest.

For instance instead of this:

require("jinjs");
    jinjs.registerExtension(".tpl", function (txt) {
      return my_transformation_module.transform_text(txt);
    });
    jinjs.outputUndefinedVariable(true, true);

you can have this:

require("jinjs").options({
  ext : '.tpl',
  outputUndefinedVariable : true,
  outputUndefinedVariableWithBrackets : true,
  filter : function (txt) {
    return my_transformation_module.transform_text(txt);
  }
});

@ceymard ceymard merged this pull request into ravelsoft:master Jul 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants