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
21 changed files
with
224 additions
and
5 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,17 @@ | ||
COFFEE = ./node_modules/.bin/coffee | ||
|
||
SRC = $(wildcard src/*.coffee) | ||
DST = $(SRC:src/%.coffee=lib/%.js) | ||
|
||
|
||
all: compile | ||
|
||
|
||
compile: $(DST) | ||
|
||
test: compile | ||
node_modules/.bin/nodeunit test | ||
|
||
lib/%.js: src/%.coffee | ||
@mkdir -p $(@D) | ||
$(COFFEE) -bpc $< > $@ |
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
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,10 @@ | ||
<% renderItem = (item) -> %> | ||
<div class="item"> | ||
<span class="name"><%= item.name %></span> | ||
<span class="price">$<%= item.price %></span> | ||
</div> | ||
<% end %> | ||
|
||
<% for item in @items: %> | ||
<%= renderItem item %> | ||
<% end %> |
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,17 @@ | ||
|
||
|
||
|
||
|
||
<div class="item"> | ||
<span class="name">Caprese</span> | ||
<span class="price">$5.25</span> | ||
</div> | ||
|
||
|
||
|
||
<div class="item"> | ||
<span class="name">Artichoke</span> | ||
<span class="price">$6.25</span> | ||
</div> | ||
|
||
|
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,8 @@ | ||
(ctx) -> | ||
((out) -> | ||
out.push "Hello, " | ||
out.push helpers.escape @name | ||
out.push ".\nI'M SHOUTING AT YOU, " | ||
out.push helpers.escape @name.toUpperCase() | ||
out.push "!\n" | ||
out).call(ctx, []).join("") |
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 @@ | ||
Hello, <%= @name %>. | ||
I'M SHOUTING AT YOU, <%= @name.toUpperCase() %>! |
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 @@ | ||
Hello, Sam. | ||
I'M SHOUTING AT YOU, SAM! |
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 @@ | ||
[["literal","Hello, "],["escape"," @name "],["literal",".\nI'M SHOUTING AT YOU, "],["escape"," @name.toUpperCase() "],["literal","!\n"]] |
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,19 @@ | ||
(ctx) -> | ||
((out) -> | ||
for item in @items | ||
out.push "\n " | ||
out.push helpers.escape @contentTag "div", class: "item", => ((out) => | ||
out.push "\n " | ||
out.push helpers.escape @contentTag "span", class: "price", -> ((out) -> | ||
out.push "$" | ||
out.push helpers.escape item.price | ||
out)([]).join("") | ||
out.push "\n " | ||
out.push helpers.escape @contentTag "span", class: "name", -> ((out) -> | ||
out.push helpers.escape item.name | ||
out)([]).join("") | ||
out.push "\n " | ||
out)([]).join("") | ||
out.push "\n" | ||
out.push "\n" | ||
out).call(ctx, []).join("") |
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,6 @@ | ||
<% for item in @items: %> | ||
<%= @contentTag "div", class: "item", => %> | ||
<%= @contentTag "span", class: "price", -> %>$<%= item.price %><% end %> | ||
<%= @contentTag "span", class: "name", -> %><%= item.name %><% end %> | ||
<% end %> | ||
<% end %> |
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 @@ | ||
|
||
<div class="item"> | ||
<span class="price">$5.25</span> | ||
<span class="name">Caprese</span> | ||
</div> | ||
|
||
<div class="item"> | ||
<span class="price">$6.25</span> | ||
<span class="name">Artichoke</span> | ||
</div> | ||
|
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 @@ | ||
[["literal",""],["code"," for item in @items: "],["literal","\n "],["escape"," @contentTag \"div\", class: \"item\", => "],["literal","\n "],["escape"," @contentTag \"span\", class: \"price\", -> "],["literal","$"],["escape"," item.price "],["literal",""],["code"," end "],["literal","\n "],["escape"," @contentTag \"span\", class: \"name\", -> "],["literal",""],["escape"," item.name "],["literal",""],["code"," end "],["literal","\n "],["code"," end "],["literal","\n"],["code"," end "],["literal","\n"]] |
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,17 @@ | ||
(ctx) -> | ||
((out) -> | ||
if @projects.length | ||
out.push "\n " | ||
for project in @projects | ||
out.push "\n <a href=\"" | ||
out.push helpers.escape project.url | ||
out.push "\">" | ||
out.push helpers.escape project.name | ||
out.push "</a>\n " | ||
out.push project.description | ||
out.push "\n " | ||
out.push "\n" | ||
else | ||
out.push "\n No projects\n" | ||
out.push "\n" | ||
out).call(ctx, []).join("") |
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,8 @@ | ||
<% if @projects.length: %> | ||
<% for project in @projects: %> | ||
<a href="<%= project.url %>"><%= project.name %></a> | ||
<%- project.description %> | ||
<% end %> | ||
<% else: %> | ||
No projects | ||
<% end %> |
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,12 @@ | ||
|
||
|
||
<a href="/projects/1">PowerTMS Active Shipments Page Redesign</a> | ||
|
||
|
||
<a href="/projects/2">SCU Intranet</a> | ||
<p><em>On hold</em></p> | ||
|
||
<a href="/projects/3">Sales Template</a> | ||
|
||
|
||
|
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 @@ | ||
[["literal",""],["code"," if @projects.length: "],["literal","\n "],["code"," for project in @projects: "],["literal","\n <a href=\""],["escape"," project.url "],["literal","\">"],["escape"," project.name "],["literal","</a>\n "],["out"," project.description "],["literal","\n "],["code"," end "],["literal","\n"],["code"," else: "],["literal","\n No projects\n"],["code"," end "],["literal","\n"]] |
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,39 @@ | ||
{tokenize, transform, helpers} = require '../lib/leco' | ||
fs = require 'fs' | ||
CoffeeScript = require 'coffee-script' | ||
|
||
|
||
read = (x) -> fs.readFileSync(__dirname + '/fixtures/' + x).toString() | ||
f = (x) -> read(x + '.out') | ||
t = (x, ctx) -> | ||
tokens = tokenize(read(x + '.eco')) | ||
tpl = transform(tokens, {}, helpers) | ||
CoffeeScript.eval(tpl)(ctx) | ||
|
||
|
||
module.exports = | ||
'transforming fixtures/hello.eco': (test) -> | ||
test.deepEqual f('hello'), t('hello', name: 'Sam') | ||
test.done() | ||
|
||
'transforming fixtures/projects.eco': (test) -> | ||
result = t('projects', projects: [ | ||
{ name: "PowerTMS Active Shipments Page Redesign", url: "/projects/1" }, | ||
{ name: "SCU Intranet", url: "/projects/2", description: "<p><em>On hold</em></p>" }, | ||
{ name: "Sales Template", url: "/projects/3" } | ||
]) | ||
test.deepEqual f('projects'), result | ||
test.done() | ||
|
||
'transforming fixtures/helpers.eco': (test) -> | ||
result = t('helpers', | ||
items: [ | ||
{ name: "Caprese", price: "5.25"}, | ||
{ name: "Artichoke", price: "6.25" } | ||
] | ||
contentTag: (tagName, attributes, callback) -> | ||
attrs = (" #{name}=\"#{value}\"" for name, value of attributes) | ||
helpers.safe "<#{tagName}#{attrs.join("")}>#{callback()}</#{tagName}>" | ||
) | ||
test.deepEqual f('helpers'), result | ||
test.done() |
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,19 @@ | ||
{tokenize} = require '../lib/leco' | ||
fs = require 'fs' | ||
|
||
read = (x) -> fs.readFileSync(__dirname + '/fixtures/' + x).toString() | ||
f = (x) -> JSON.parse(read(x + '.tok')) | ||
t = (x) -> tokenize(read(x + '.eco')) | ||
|
||
module.exports = | ||
'tokenizing fixtures/hello.eco': (test) -> | ||
test.deepEqual f('hello'), t('hello') | ||
test.done() | ||
|
||
'tokenizing fixtures/projects.eco': (test) -> | ||
test.deepEqual f('projects'), t('projects') | ||
test.done() | ||
|
||
'tokenizing fixtures/helpers.eco': (test) -> | ||
test.deepEqual f('helpers'), t('helpers') | ||
test.done() |
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,19 @@ | ||
{tokenize, transform} = require '../lib/leco' | ||
fs = require 'fs' | ||
|
||
read = (x) -> fs.readFileSync(__dirname + '/fixtures/' + x).toString() | ||
f = (x) -> read(x + '.coffee') | ||
t = (x) -> transform(tokenize(read(x + '.eco'))) | ||
|
||
module.exports = | ||
'transforming fixtures/hello.eco': (test) -> | ||
test.deepEqual f('hello'), t('hello') | ||
test.done() | ||
|
||
'transforming fixtures/projects.eco': (test) -> | ||
test.deepEqual f('projects'), t('projects') | ||
test.done() | ||
|
||
'transforming fixtures/helpers.eco': (test) -> | ||
test.deepEqual f('helpers'), t('helpers') | ||
test.done() |