{"id":16254301,"url":"https://github.com/celer/fire-ts","last_synced_at":"2025-03-19T21:30:27.776Z","repository":{"id":7921982,"uuid":"9308402","full_name":"celer/fire-ts","owner":"celer","description":"Fire TS is a templating library for NodeJS which specializes in generating non HTML templates (c, c++, Java, JavaScript, Ruby, Perl, etc)","archived":false,"fork":false,"pushed_at":"2014-03-18T05:49:38.000Z","size":224,"stargazers_count":7,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T21:05:56.793Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/celer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-08T22:42:11.000Z","updated_at":"2022-04-20T07:09:19.000Z","dependencies_parsed_at":"2022-09-26T17:00:57.527Z","dependency_job_id":null,"html_url":"https://github.com/celer/fire-ts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Ffire-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Ffire-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Ffire-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Ffire-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/celer","download_url":"https://codeload.github.com/celer/fire-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244021751,"owners_count":20385122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T15:21:02.023Z","updated_at":"2025-03-19T21:30:27.340Z","avatar_url":"https://github.com/celer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Fire TS\n=======\n\nBuild Status: [![Build Status](https://travis-ci.org/celer/fire-ts.png)](https://travis-ci.org/celer/fire-ts)\n\n# Introduction\n\nFire TS is a template engine for generating code. \n\n * Designed to generate C, C++, Java, JavaScript, Ruby, Perl, and HTML\n * Tries to generate well formatted code, you can properly indent your templates and fire-ts will remove your extra indention\n * Can update existing generated files with out overwriting everything\n * Designed to be compatible with the combustion template system  \n\nIf you want to generate HTML templates you should consider other template engines\n\n## The basics\n\nThe syntax for Fire TS looks a lot like JSP, except the base language is JavaScript\n\n```c\n\u003c%\n\tvar colors=[ \"red\",\"blue\",\"green\"];\n\tvar numbers=[1,2,3,5];\n%\u003e\n\n#include\u003cstdio.h\u003e\n\n/*%{header}\n\t\n\tThe text in this 'header' block can be overridden by what is found in the file that wil be overwritten when this file is generated. Allowing the user to edit this bit of comment or code safely without having to worry about loosing his/her changes.\n\n}%*/\n\n//%{prefix}  \n\n//This code will be preserved, even when the template is re-generated!!!\nconst char *prefix=\"\u003e\";\n\n//}%\n\nchar *colors[]={\n\t\u003c% for(var i in colors){ \n\t\t\tvar color = colors[i];\n\t%\u003e\n\t\t\u003c%# color %\u003e,\n\t\u003c% } %\u003e\n\tNULL \n};\n\nint *numbers[]={ \n\t\u003c% numbers.map(function(number){ %\u003e\n\t\t\u003c%= number %\u003e,\n\t\u003c% }); %\u003e\n\tNULL \n};\n\nvoid main(){\n\tint i,j;\n\tfor(i=0;colors[i];i++){\n\t\tfor(j=0;numbers[j];j++){\n\t\t\tprintf(\"%s %s %d\\n\",prefix,colors[i],numbers[j]);\n\t\t}\n\t}\n}\n\n```\n\nAnd will generate this:\n\n```c\n#include\u003cstdio.h\u003e\n\n/*%{header}\n\tThis text was pulled from the file that was gonna be over written.\t\n}%*/\n\n//%{prefix}\nconst char *prefix=\"\u003c\";\n//}%\n\nchar *colors[]={\n\t\"red\",\n\t\"blue\",\n\t\"green\",\n\tNULL \n};\n\nint *numbers[]={ \n\t1,\n\t2,\n\t3,\n\t5,\n\tNULL \n};\n\nvoid main(){\n\tint i,j;\n\tfor(i=0;colors[i];i++){\n\t\tfor(j=0;numbers[j];j++){\n\t\t\tprintf(\"%s %s %d\\n\",prefix,colors[i],numbers[j]);\n\t\t}\n\t}\n}\n\n\n```\n# Writing templates!\n\n## Well formated templates! \n\nOne of the neat things that Fire TS does is it tries to allow you to both have well formated templates and well formatted output. \nThis means that Fire-TS will count the number of opening and closing braces and then remove the appropriates spacing. By default Fire-TS\nwill look for tabs, although you can set the 'indent' property in the options to change it to spaces, etc. \n\nHere are some examples:\n\n```c\n\u003c% for(var i in items){ %\u003e //tabDepth++\n\t// This will automatically remove 1 tab from the generated output since we're one set of of braces deep\n\tint \u003c%= items[i].name %\u003e;\n\u003c% } %\u003e //tabDepth--;\n// Would generate\nint foo;\n```\n\n```c\n\u003c% for(var i in items){ %\u003e  \n\t\t// This will automatically remove 1 tab from the generated output since we're one set of of braces deep,\n\t\tint \u003c%= items[i].name %\u003e;\n\u003c% } %\u003e\n//Would generate\n\tint foo;\n```\n\n```javascript\n\t//Tell Fire-TS to remove two spaces for each level of indention found\n\tFire.parseSync(\"input.fts\",{ indent:\"  \" });\n``\n\n## Evaluating code\n\nAnything in: \n\n```jsp\n\u003c% CODE %\u003e \n```\nwill be evaluated as JavaScript, and it can even be multi-line\n\n```jsp\nLet's do some looping\n\u003c%\n\tfor(var i=0;i\u003c3;i++){\n\t\tif(i==2){\n%\u003e\n\t\t\ti is 2\n\u003c%\t\n\t\t}\n\t}\n%\u003e\n```\nWhich would even track the number of opening and closing braces to properly add and remove tab characters from the output - So your templates and your generated code will look good!\n\n```\nLet's do some looping\ni is 2\n```\n\nIf you want to actually indent \"i is 2\" simply add more tabs to it. \n\n## Expressions\n\nThere are multiple types of expressions\n\n**Raw**\n\n\nThis will just output the value of the variable or expression with no formatting\n```jsp\n\t\u003c!-- Output the raw variable or expression --\u003e\n\t\u003c%=variable%\u003e\n```\n\n**JSON Encoded**\n\nThis will output the JSON encoded variable or expression\n```jsp\n\t\u003c!-- Output a JSON encoded value - which works well for 'c' escaped strings  --\u003e\n\t\u003c%#variable%\u003e\n```\n\n**URL Encoded**\n\nThis will output a URL escaped string\n```jsp\n\t\u003c!-- Output a URL encoded value  --\u003e\n\t\u003c%%variable%\u003e\n```\n\n## Capturing and modifying the template itself\n\n```jsp\n\n//Will replace Their with There\n\u003c%(%\u003eHello Their \u003c%=name%\u003e\u003c%).replace(/Their/,\"There\")%\u003e \n\n//Will convert this to lower case \n\u003c%(%\u003eMiXeDcAsE\u003c%).toLowerCase()%\u003e\n\n\n``` \n\nUsing '\u003c%(%\u003e' and '\u003c%)%\u003e' allows you to capture and modify result of that part of the template as a String and modify it. Here are a few examples:\n\n\n\n## Including sub-templates\n\nIf you want to nest templates you an do this:\n\n```jsp\n\t\u003c%@ header.fts %\u003e\n```\n\nAll the inputs and options pasted to the top template will be passed to the nested templates. If you need to capture variables from one template to the nested templates:\n\n```jsp\n\t\u003c%@ header.fts (variableA,variableB) %\u003e\n```\n\nwill capture local variableA and variableB and pass them into the nested template. Fire-TS will call opts.render to resolve the template, so you can back it with something that returns a file or a named snippet\n\n## Blocks\n\nOne of the more advanced features of Fire-TS is that it can preserve the contents of the file it is going to over-write. Let's say for example you want to have a SQL file:\n\n```sql\n\u003c%\n\tvar colors=[ \"red\",\"blue\",\"green\"];\n\tvar numbers=[1,2,3,5];\n%\u003e\n\n\n-- %{schema} \n\ncreate table colors (\n\tid bigint auto_increment,\n\tcolor varchar(20) not null,\n\tnumber bigint not null,\n);\n\n-- }%\n\n\u003c% colors.map(function(color){ %\u003e\n\t\u003c% numbers.map(function(number){ %\u003e\n\t\tinsert into colors (name) values(\u003c%#color%\u003e,\u003c%=number%\u003e);\n\t\u003c% }); %\u003e\n\u003c% }); %\u003e\n\n```\n\nFire-TS will see if the file it is about to over-write exists, and look for blocks ( starting with '%{[A-Za-z0-9]+}' and ending with '}%' ) and read them from the old file, and then insert them into the newly written output. Allowing you to preserve certain parts of older files. In the example above it would let you safely modify the schema and have the inserts regenerated each time!\n\n\n# Embedding\n\nTake a look at bin/fire-ts to get an idea how to use the templating engine, you can install it globally using\n\n```shell\n\tnpm install fire-ts -g\n```\n\nYou can see embedding examples here: https://github.com/celer/fire-ts/tree/master/examples/embed\n\n# Command line\n\n```shell\n./fire-ts\nOptions:\n  --output    File to write (will reload blocks)            \n  --template  The template to use                           \n  --compile   The template to compile                       \n  --input     The input to use to run the template (as JSON)\n  --blocks    The blocks to use (as a JSON hash)            \n  --compare   Compare the output file to the specified file \n  --uglify    Uglify the compiled template                  \n  --debug     Debug   \n```\n\nLet's run a template\n\n```shell\n./bin/fire-ts --template test/1.fts\n```\n\nLet's compile a template\n\n```shell\n./bin/fire-ts --compile test/1.fts\n```\nResults in \n\n```javascript\nfunction template(_$_i,_$_o,_$_oc){_$_o=_$_o||{},_$_o.b=_$_o.blocks||{};var _$_s=\"\",_$_e=_$_o.e||function(_){_$_s+=_};with(_$_o.j||JSON.stringify,_$_o.render,_$_i)_$_e(\"Hello\\n  1\\n  2 \\n  3\\n  4\\n  5\\n6\\n   6\\n 7 8\\n   A\\n     B\\n\");return _$_s}\n```\n\n## License\n\n  MIT\n\n# API\n\n\n```js\n/**\n\tFire Template System\n\n\t@module FireTS\n\t@class Fire\n*/\n\n\n/**\n\n\tRead blocks from a given string\n\n\tBlocks are primarly used as a way to keep modifications from various files. So typically FireTS will read the blocks from the file that is\n\tabout to be overwritten and make sure they aren't modified when the template is rewritten.\n\n\t@param {String} input template or generated file containing one or more named blocks\n\t@returns {Object} hash of blocks\n\n\tExample of a block\n\t\n\t@example\n\t\t//%{header}\n\t\t\tThis is a block\n\t\t//}%\n\n\tReading the above example would return:\n\n\t@example\n\t\t{ header:\"\\n  This is a block\\n//\"}\n\t\n\t@method Fire.readBlocks\n\n*/\n\n\n/**\n\n\tRead blocks from a file asynchronously\n\n\t@param {String} file The file to read blocks from\n\t@param {Function} onComplete\n\t\t@param {String} onComplete.err The error string\n\t\t@param {Object} onComplete.blocks The hash of blocks from file\n\n\t@method Fire.readFileBlocks\n\t@see Fire.readBlocks\n\n*/\n\n\n/**\n\n\tRead blocks from a file synchronously\n\n\t@param {String} file The file to read blocks from\n\t@return {Object} The hash of blocks from file\n\n\t@method Fire.readFileBlocksSync\n\t@see Fire.readBlocks\n\n*/\n\n\n/**\n\n\tCompile a string into a template\n\n\t@param {String} input The template to compile\n\t@param {Object} opts\n\t\t@param {Boolean} opts.source Return the source for the template, not the compiled function\n\t\t@param {Boolean} opts.uglify Uglify the source (true by default)\n\t\t@param {Boolean} opts.async Generate a template which can load files/snippets asynchronously\n\t@returns {Function or String} String or compiled template \n\n\t@method Fire.compile\n\n*/\n\n\n/**\n\n\tSynchronous template function\n\n\t@param {Object} input Input for the template\n\t@param {Object} opts Options for the template\n\t\t@param {Object} opts.blocks The blocks to insert into the file\n\t\t@param {Function} opts.render The function to call to render the template (When run synchronously)\n\t\t\t@param {String} opts.render.template The name of the template or snippet to render\n\t\t\t@param {String} opts.render.input The inputs to use for the template\n\t\t\t@param {String} opts.render.opts The options for the template\n\n\t@returns {String} The result of running the template\n\t\n\t@example\n\t\tvar result = template({ name:\"George\" },{ \n\t\t\trender: function(template,input,opts){\n\t\t\t\treturn Fire.compile(\"\u003c%=xi%\u003e\")(input)\t\n\t\t\t}\t\n\t\t});\n\n\t@method template (synchronous)\n\n*/\n\n\n/**\n\n\tAsynchronous template function\n\n\t@param {Object} input Input for the template\n\t@param {Object} opts Options for the template\n\t\t@param {Object} opts.blocks The blocks to insert into the file\n\t\t@param {Function} opts.fetch The function to call to fetch a snippet or template asynchrounsly\n\t\t\t@param {String} opts.fetch.template The name of the template or snippet to render\n\t\t\t@param {Function} opts.fetch.onComplete\tThe lambda to call when the snippet/template has been loaded\n\t\t\t@param {String} opts.fetch.onComplete.err The returned as a result of loading the template\n\t\t\t@param {Function} opts.fetch.onComplete.template The template function\n\t@param {Function} onComplete The callback for when the template has been rendered\n\t\t\t@param {String} opts.onComplete.err The returned as a result of loading the template\n\t\t\t@param {String} opts.onComplete.result The result of running the template\n\t\t\t\n\t@example\n\t\ttemplate({name:\"hello\"},{ \n\t\t\tfetch: function(template,onComplete){\n\t\t\t\tFire.parse(template,{async:true},onComplete);\n\t\t\t}\n\t\t},function(err,template){\n\t\t\tconsole.log(\"Result\",template);\n\t\t});\n\n\t@method template (asynchronous)\n\n*/\n\n\n/**\n\n\tSimulate the combustion template interface\n\n\tThe returned functions has the following parameters\n\n\t@param {Object} input The input template\n\t@param {Object} opts The options for the template \n\t\n\t@returns {Function} Function to use for compiling templates\n\n\t@example\n\t\tvar template = Fire.combustion().compile(\"\u003c%=x%\u003e\");\n\t\ttemplate({x:5});\n\n\t@method Fire.combustion\t\n\n*/\n\n\n/**\n\n\tGenerate a file from a template\n\n\tThis function will:\n\t\n\t* Read the blocks from outFile if it exists\n\t* Generate a new output file, reusing the blocks from the prior outFile\n\n\t@param {String} template the template file\n\t@param {String} outFile the output file\n\t@param {Object} input the inputs to the template\n\t@param {Object} options options for the template (see template)\n\t\n\t@returns {String} The result of running the template\n\t\n\t@method Fire.generateSync\n\n*/\n\n\n/**\n\n\tParse a template file synchronously and return a compiled template\n\n\t@param {String} file the template file\n\t@param {Object} opts the options for the compiler\n\n\t@return {Function} The compiled template\n\t\n\t@method Fire.parseSync\n\n*/\n\n\n/**\n\n\tParse a template file and return a compiled template\n\n\t@param {String} file the template file\n\t@param {Object} opts the options for the compiler\n\t@param {Function} onComplete The lambda to be called upon completion\n\t\t@param {String} onComplete.err The error\t\n\t\t@param {Function} onComplete.template  compiled template\n\t\n\t@method Fire.parse\n\n*/\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceler%2Ffire-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceler%2Ffire-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceler%2Ffire-ts/lists"}