Skip to content

Commit

Permalink
Added submodules.
Browse files Browse the repository at this point in the history
  • Loading branch information
fadrizul committed Sep 13, 2011
1 parent 0c0367f commit 46e124f
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "support/coffee-script"]
path = support/coffee-script
url = https://github.com/jashkenas/coffee-script.git
[submodule "dev/eyes"]
path = dev/eyes
url = git://github.com/cloudhead/eyes.js.git
2 changes: 1 addition & 1 deletion compiled/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Author: Fadrizul H. <fadrizul[at]gmail.com>
*/
var Compile, Compiler, exports, pr, x;
x = require("./regexes");
pr = require("eyes");
pr = require("../dev/eyes");
Compiler = (function() {
function Compiler(node) {
this.node = node || {};
Expand Down
2 changes: 1 addition & 1 deletion compiled/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Author: Fadrizul H. <fadrizul[at]gmail.com>
*/
var Parser, exports, pr, x;
x = require("./regexes");
pr = require("eyes");
pr = require("../dev/eyes");
Parser = (function() {
function Parser(str, tags) {
this.rawTokens = str ? str.trim().replace(x.Replace, "").split(x.Split) : {};
Expand Down
3 changes: 2 additions & 1 deletion compiled/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
TwigJS
Author: Fadrizul H. <fadrizul[at]gmail.com>
*/
var Compiler, check, escape, helpers;
var Compiler, check, escape, helpers, pr;
Compiler = require("./compiler");
helpers = require("./helpers");
pr = require("../dev/eyes");
check = helpers.check;
escape = helpers.escape;
exports["extends"] = {};
Expand Down
2 changes: 1 addition & 1 deletion compiled/twig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Author: Fadrizul H. <fadrizul[at]gmail.com>
*/
var Compiler, Parser, compile, fileRenderer, fs, pr, tags, widgets;
fs = require("fs");
pr = require("eyes");
pr = require("../dev/eyes");
Parser = require("./parser");
Compiler = require("./compiler");
tags = require("./tags");
Expand Down
5 changes: 2 additions & 3 deletions compiled/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
TwigJS
Author: Fadrizul H. <fadrizul[at]gmail.com>
*/
var textWidgetGenerator;
var pr, textWidgetGenerator;
pr = require("../dev/eyes");
textWidgetGenerator = function(tagname) {
return function() {
var i, output;
Expand Down Expand Up @@ -41,8 +42,6 @@ exports.renderSlot = function(slotContent, context) {
output = [];
i = 0;
j = slot.length;
i;
j;
while (i < j) {
widget = slot[i];
if (widget === void 0 || widget === null || widget === false) {
Expand Down
1 change: 1 addition & 0 deletions dev/eyes
Submodule eyes added at ab4f3e
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require('coffee-script');
module.exports = require('./lib/twig');
require('./support/coffee-script');
module.exports = require('./lib/twig');
2 changes: 1 addition & 1 deletion lib/compiler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author: Fadrizul H. <fadrizul[at]gmail.com>

# Module dependencies
x = require "./regexes"
pr = require "eyes" # Debugging purposes
pr = require "../dev/eyes" # Debugging purposes

class Compiler
constructor: (node) ->
Expand Down
2 changes: 1 addition & 1 deletion lib/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author: Fadrizul H. <fadrizul[at]gmail.com>

# Load regexes
x = require "./regexes"
pr = require "eyes" # Debugging purposes
pr = require "../dev/eyes" # Debugging purposes

class Parser
constructor: (str, tags) ->
Expand Down
18 changes: 14 additions & 4 deletions lib/tags.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ Author: Fadrizul H. <fadrizul[at]gmail.com>
###

# Load dependencies
Compiler = require("./compiler")
helpers = require("./helpers")
Compiler = require "./compiler"
helpers = require "./helpers"
pr = require "../dev/eyes" # Debugging purposes

# Declare helpers
check = helpers.check
escape = helpers.escape

# Expose
exports.extends = {}
exports.block = ends: true
exports.extends = {}
exports.block = ends: true

# Slots
exports.slot = (twig) ->
Expand Down Expand Up @@ -82,6 +83,7 @@ exports["if"] = (indent) ->
throw new Error("Invalid arguments (" + operand2 + ") passed to 'if' tag") if operator and not helpers.isLiteral(operand2) and not helpers.isValidName(operand2)

out = [ "(function () {" ]

out.push " var __op1;"
out.push " if (" + check(operand1) + ") {"
out.push " __op1 = " + escape(operand1) + ";"
Expand All @@ -91,25 +93,33 @@ exports["if"] = (indent) ->
out.push " }"

if typeof operand2 == "undefined"

out.push " if (" + (if negation then "!" else "!!") + "__op1) {"
out.push commpiler.compile()
out.push " }"

else

out.push " var __op2;"
out.push " if (" + check(operand2) + ") {"
out.push " __op2 = " + escape(operand2) + ";"
out.push " }"
out.push " else if (" + check(operand2, "__context") + ") {"
out.push " __op2 = " + escape(operand2, "__context") + ";"
out.push " }"

if operator == "in"

out.push " if ((Array.isArray(__op2) && __op2.indexOf(__op1) > -1) ||"
out.push " (typeof __op2 === \"string\" && __op2.indexOf(__op1) > -1) ||"
out.push " (!Array.isArray(__op2) && typeof __op2 === \"object\" && __op1 in __op2)) {"

else
out.push " if (__op1 " + escape(operator) + " __op2) {"

out.push compiler.compile(this, indent + " ")
out.push " }"

out.push "})();"
out.join "\n" + indent

Expand Down
2 changes: 1 addition & 1 deletion lib/twig.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author: Fadrizul H. <fadrizul[at]gmail.com>

# Module dependencies
fs = require "fs"
pr = require "eyes" # Debugging purpose
pr = require "../dev/eyes" # Debugging purpose

# Load local lib
Parser = require "./parser"
Expand Down
36 changes: 23 additions & 13 deletions lib/widgets.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,52 @@ TwigJS
Author: Fadrizul H. <fadrizul[at]gmail.com>
###

pr = require "../dev/eyes" # Debugging purposes

textWidgetGenerator = (tagname) ->
->
output = [ "<", tagname ]

for i of this
output.push " ", i, "='", this[i], "'" if @hasOwnProperty(i) and i != "content" and 1 != "tagname"

output.push ">", @content, "</", tagname, ">"
output.join ""

exports.p = textWidgetGenerator("p")
exports.h1 = textWidgetGenerator("h1")
exports.h2 = textWidgetGenerator("h2")
exports.h3 = textWidgetGenerator("h3")
exports.ol = textWidgetGenerator("ol")
exports.ul = textWidgetGenerator("ul")
exports.q = textWidgetGenerator("q")
exports.p = textWidgetGenerator "p"
exports.h1 = textWidgetGenerator "h1"
exports.h2 = textWidgetGenerator "h2"
exports.h3 = textWidgetGenerator "h3"
exports.ol = textWidgetGenerator "ol"
exports.ul = textWidgetGenerator "ul"
exports.q = textWidgetGenerator "q"

exports.list = exports.image = (context) ->
output = [ "<div" ]

for i of this
output.push " ", i, "='", this[i], "'" if @hasOwnProperty(i) and i != "content" and 1 != "tagname"

output.push " data-tagname='", @tagname, "'"
output.push ">", @content, "</div>"
output.join ""

exports.renderSlot = (slotContent, context) ->
slot = slotContent or []
slot = slotContent or []
output = []
i = 0
j = slot.length
i
j
i = 0
j = slot.length

while i < j
widget = slot[i]

continue if widget == undefined or widget == null or widget == false

if typeof widget == "string"

output.push widget
else output.push exports[widget.tagname].call(widget, context) if widget.tagname and typeof exports[widget.tagname] == "function"
else output.push exports[widget.tagname].call(widget, context) if widget.tagname and typeof exports[widget.tagname] == "function"

i += 1

output.join ""
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"author": "Fadrizul H. <fadrizul@gmail.com> (github.com/fadrizul)",
"name": "TwigJS",
"description": "A port of PHP template engine (www.twig-project.org) to Javascript",
"version": "0.0.1",
"homepage": "twigjs.org",
"repository": {
"type": "git",
"url": "git://github.com/fadrizul/twigjs.git"
},
"main": "index.js",
"engines": {
"node": "~v0.4.11"
},
"dependencies": {
"coffee-script"
},
"devDependencies": {
"eyes"
}
}
1 change: 1 addition & 0 deletions support/coffee-script
Submodule coffee-script added at c5dbb1

0 comments on commit 46e124f

Please sign in to comment.