This repository was archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
118 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright (c) 2012, Alexander Solovyov <[email protected]> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose | ||
with or without fee is hereby granted, provided that the above copyright notice | ||
and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Leco: Le Embedded CoffeeScript templates | ||
|
||
Leco is reimplementation of [Eco](https://github.com/sstephenson/eco), partly | ||
because of NIH, partly because I wanted to play with writing template compiler, | ||
partly because I was not satisfied with how original implementation was | ||
structured and in here I was responsible for everything. | ||
|
||
It works largely as Eco, but supports custom tag types, so you can add your own | ||
tags, i.e. `<%_ ... %>` for i18n and whatnot. | ||
|
||
Proper description will follow. I guess. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
console.log(require('../lib/command').run()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
fs = require 'fs' | ||
argumentum = require 'argumentum' | ||
helpers = require './helpers' | ||
compiler = require './compiler' | ||
|
||
|
||
optConfig = | ||
script: 'leco' | ||
commandRequired: no | ||
options: | ||
'no-include-helpers': | ||
abbr: 'n' | ||
flag: true | ||
help: 'do not include helpers in template' | ||
'wrap': | ||
abbr: 'w' | ||
default: 'amd' | ||
help: 'wrapper type (AMD, CommonJS, global)' | ||
'helpers-name': | ||
help: 'name of object containing helper functions' | ||
default: 'helpers' | ||
'helpers': | ||
flag: true | ||
help: 'only output helpers' | ||
|
||
|
||
wrappers = | ||
amd: | ||
begin: 'define(function() { return ' | ||
end: '});' | ||
commonjs: | ||
begin: 'module.exports = ' | ||
end: '' | ||
global: | ||
begin: '''(function() { | ||
(this.templates || (this.templates = {}))["%name%"] = ''' | ||
end: '}).call(this);' | ||
|
||
|
||
wrap = (name, template, path) -> | ||
wrapper = wrappers[name.toLowerCase()] | ||
if not wrapper | ||
return "Unknown wrapper: #{wrapper}" | ||
|
||
begin = wrapper.begin | ||
if begin.indexOf('%name%') != -1 | ||
tname = path.slice(path.lastIndexOf('/') + 1, path.lastIndexOf('.')) | ||
begin = begin.replace('%name%', name) | ||
|
||
return begin + template.trim() + wrapper.end | ||
|
||
|
||
run = -> | ||
parser = argumentum.load(optConfig) | ||
options = parser.parse() | ||
|
||
if options.helpers | ||
return compiler.printHelpers(helpers, options['helpers-name']) | ||
|
||
if not options[0] | ||
return parser.getUsage() | ||
|
||
replaceName = (s) -> | ||
|
||
source = fs.readFileSync(options[0]).toString() | ||
|
||
if options['no-include-helpers'] | ||
template = compiler.compile(source) | ||
else | ||
template = compiler.compile(source, helpers, options['helpers-name']) | ||
|
||
return wrap(options.wrap, template, options[0]) | ||
|
||
|
||
exports.run = run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,5 @@ | ||
fs = require 'fs' | ||
argumentum = require 'argumentum' | ||
helpers = require './helpers' | ||
compiler = require './compiler' | ||
{compile, printHelpers} = require './compiler' | ||
{tokenize} = require './tokenizer' | ||
{transform} = require './transformer' | ||
|
||
|
||
optConfig = | ||
script: 'leco' | ||
commandRequired: no | ||
options: | ||
'no-include-helpers': | ||
abbr: 'n' | ||
flag: true | ||
help: 'do not include helpers in template' | ||
'wrap': | ||
abbr: 'w' | ||
default: 'amd' | ||
help: 'wrapper type (AMD, CommonJS, global)' | ||
'helpers-name': | ||
help: 'name of object containing helper functions' | ||
default: 'helpers' | ||
'helpers': | ||
flag: true | ||
help: 'only output helpers' | ||
|
||
|
||
wrappers = | ||
amd: | ||
begin: 'define(function() { return ' | ||
end: '});' | ||
commonjs: | ||
begin: 'module.exports = ' | ||
end: '' | ||
global: | ||
begin: '''(function() { | ||
(this.templates || (this.templates = {}))["%name%"] = ''' | ||
end: '}).call(this);' | ||
|
||
|
||
wrap = (name, template, path) -> | ||
wrapper = wrappers[name.toLowerCase()] | ||
if not wrapper | ||
return "Unknown wrapper: #{wrapper}" | ||
|
||
begin = wrapper.begin | ||
if begin.indexOf('%name%') != -1 | ||
tname = path.slice(path.lastIndexOf('/') + 1, path.lastIndexOf('.')) | ||
begin = begin.replace('%name%', name) | ||
|
||
return begin + template.trim() + wrapper.end | ||
|
||
|
||
run = -> | ||
parser = argumentum.load(optConfig) | ||
options = parser.parse() | ||
|
||
if options.helpers | ||
return compiler.printHelpers(helpers, options['helpers-name']) | ||
|
||
if not options[0] | ||
return parser.getUsage() | ||
|
||
replaceName = (s) -> | ||
|
||
source = fs.readFileSync(options[0]).toString() | ||
|
||
if options['no-include-helpers'] | ||
template = compiler.compile(source) | ||
else | ||
template = compiler.compile(source, helpers, options['helpers-name']) | ||
|
||
return wrap(options.wrap, template, options[0]) | ||
|
||
|
||
console.log(run()) | ||
module.exports = {compile, printHelpers, tokenize, transform} |