Skip to content

Commit

Permalink
test suite fixes, added index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
amccollum committed Oct 4, 2011
1 parent 5ec8353 commit d7bfd44
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 23 deletions.
10 changes: 8 additions & 2 deletions Cakefile
Expand Up @@ -17,8 +17,14 @@ task 'build', 'Build the library', ->


task 'test', 'Build and run the test suite', -> task 'test', 'Build and run the test suite', ->
execCmds [ execCmds [
'cake build',
'coffee --bare --output ./test ./src/test/*.coffee', 'coffee --bare --output ./test ./src/test/*.coffee',
'cp ./src/test/*.html ./test',
'cp ./src/test/*.css ./test',
'pushd test',
'test -e ender.js || ender build ender-vows wings',
'popd',
'npm install --dev', 'npm install --dev',
'ln -s ender-vows node_modules/vows', 'ln -sf ender-vows node_modules/vows',
'node_modules/.bin/vows ./test/*.js' 'node_modules/.bin/vows ./test/*-test.js'
] ]
1 change: 1 addition & 0 deletions index.js
@@ -0,0 +1 @@
exports = require('lib/wings')
20 changes: 9 additions & 11 deletions lib/wings.js
Expand Up @@ -31,10 +31,10 @@
} }
}); });
}; };
parse_re = /\s*\{([!:])\s*([^}]*?)\s*\}([\S\s]+?)\s*\{\/\s*\2\s*\}|\{([@&]?)\s*([^}]*?)\s*\}|\{(\#)\s*[\S\s]+?\s*\#\}/mg; parse_re = /\s*\{([!:])\s*([^}]*?)\s*\}([\S\s]+?)\s*\{\\/\s*\2\s*\}|\{([@&]?)\s*([^}]*?)\s*\}|\{(\#)\s*[\S\s]+?\s*\#\}/mg;
return renderRawTemplate = function(template, data, links) { return renderRawTemplate = function(template, data, links) {
return template.replace(parse_re, function(match, section_op, section_name, section_content, tag_op, tag_name, comment_op) { return template.replace(parse_re, function(match, section_op, section_name, section_content, tag_op, tag_name, comment_op) {
var content, link, name, op, part, v, value, _ref2; var content, i, link, name, op, part, parts, v, value, _len, _ref2;
op = section_op || tag_op || comment_op; op = section_op || tag_op || comment_op;
name = section_name || tag_name; name = section_name || tag_name;
content = section_content; content = section_content;
Expand All @@ -44,15 +44,13 @@
if (!(value != null)) { if (!(value != null)) {
throw "Invalid section: " + data + ": " + name + ": " + value; throw "Invalid section: " + data + ": " + name + ": " + value;
} else if (isArray(value)) { } else if (isArray(value)) {
return ((function() { parts = [];
var _i, _len, _results; for (i = 0, _len = value.length; i < _len; i++) {
_results = []; v = value[i];
for (_i = 0, _len = value.length; _i < _len; _i++) { v['#'] = i;
v = value[_i]; parts.push(renderRawTemplate(content, v, links));
_results.push(renderRawTemplate(content, v, links)); }
} return parts.join('');
return _results;
})()).join('');
} else if (typeof value === 'object') { } else if (typeof value === 'object') {
return renderRawTemplate(content, value, links); return renderRawTemplate(content, value, links);
} else if (typeof value === 'function') { } else if (typeof value === 'function') {
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,14 +1,14 @@
{ {
"name": "wings", "name": "wings",
"version": "0.2.0", "version": "0.3.0",
"description": "Templating library that works on the server and client closely modeled on Mustache", "description": "Templating library that works on the server and client closely modeled on Mustache",
"keywords": ["ender", "template", "mustache", "html"], "keywords": ["ender", "template", "mustache", "html"],
"author": "Andrew McCollum <amccollum@gmail.com>", "author": "Andrew McCollum <amccollum@gmail.com>",
"url": "http://github.com/amccollum/wings", "url": "http://github.com/amccollum/wings",
"repositories": [{ "type": "git", "url": "http://github.com/amccollum/wings.git" }], "repositories": [{ "type": "git", "url": "http://github.com/amccollum/wings.git" }],
"licenses": [{ "type": "MIT", "url": "http://opensource.org/licenses/mit-license.php" }], "licenses": [{ "type": "MIT", "url": "http://opensource.org/licenses/mit-license.php" }],


"main": "lib/template.js", "main": "lib/wings.js",
"ender": "lib/ender.js", "ender": "lib/ender.js",
"directories": { "lib": "lib" }, "directories": { "lib": "lib" },
"devDependencies": { "devDependencies": {
Expand Down
20 changes: 20 additions & 0 deletions src/test/index.html
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />

<!-- Stylesheet -->
<link rel="stylesheet" href="vows.css" />

<!-- Ender -->
<script src="ender.js" type="text/javascript" charset="utf-8"></script>

<!-- Tests -->
<script src="wings.js" type="text/javascript" charset="utf-8"></script>

</head>
<body>
<!-- Test Results -->
<pre id="vows-results"></pre>
</body>
</html>
66 changes: 66 additions & 0 deletions src/test/vows.css
@@ -0,0 +1,66 @@
body {
color: #EBEFE7;
text-shadow: 0 -1px 1px #221E1C;
background-color: #272625;
font-family: 'Monaco', Courier, monospace;
font-size: 13px;
}

.results {
margin: 20px;
padding: 20px;
}

#vows-results div {
display: inline;
}

.success {
color: #99C270;
}

.error {
color: #F26B61;
}

.warning {
color: #EADD83;
}

.pending {
color: #619CBA;
}

.result {}

.message {
color: #999;
}

.result div {
display: inline
}

.label {}
.key {}
.string {
color: #B5C587;
}
.number {
color: #A33D29;
}
.boolean {
color: #C2A770;
}
.special {
color: #669199;
}
.regexp {
color: #B5C587;
}
.function {
color: #C2A770;
}
.comment {
color: #999;
}
3 changes: 1 addition & 2 deletions src/test/wings.coffee → src/test/wings-test.coffee
@@ -1,8 +1,7 @@
assert = require('assert') assert = require('assert')
vows = require('vows') vows = require('vows')
template = require('../lib/template.js')


t = template.renderTemplate t = require('wings').renderTemplate
equal = assert.equal equal = assert.equal


if not vows.add if not vows.add
Expand Down
9 changes: 7 additions & 2 deletions src/wings/wings.coffee
Expand Up @@ -22,7 +22,7 @@
else return s else return s


parse_re = /// parse_re = ///
\s* \{([!:]) \s* ([^}]*?) \s*\ } ([\S\s]+?) \s* \{/ \s* \2 \s*\} | # sections \s* \{([!:]) \s* ([^}]*?) \s* \} ([\S\s]+?) \s* \{\/ \s* \2 \s*\} | # sections
\{([@&]?) \s* ([^}]*?) \s* \} | # tags \{([@&]?) \s* ([^}]*?) \s* \} | # tags
\{(\#) \s* [\S\s]+? \s* \#\} # comments \{(\#) \s* [\S\s]+? \s* \#\} # comments
///mg ///mg
Expand All @@ -40,7 +40,12 @@
throw "Invalid section: #{data}: #{name}: #{value}" throw "Invalid section: #{data}: #{name}: #{value}"


else if isArray(value) else if isArray(value)
return (renderRawTemplate(content, v, links) for v in value).join('') parts = []
for v, i in value
v['#'] = i
parts.push(renderRawTemplate(content, v, links))

return parts.join('')


else if typeof value == 'object' else if typeof value == 'object'
return renderRawTemplate(content, value, links) return renderRawTemplate(content, value, links)
Expand Down
7 changes: 3 additions & 4 deletions test/wings.js
@@ -1,10 +1,9 @@
var assert, equal, t, template, vows; var assert, equal, t, vows;
assert = require('assert'); assert = require('assert');
vows = require('vows'); vows = require('vows');
template = require('../lib/template.js'); t = require('wings').renderTemplate;
t = template.renderTemplate;
equal = assert.equal; equal = assert.equal;
if (!(vows.add != null)) { if (!vows.add) {
vows.add = function(name, batch) { vows.add = function(name, batch) {
return vows.describe(name).addBatch(batch)["export"](module); return vows.describe(name).addBatch(batch)["export"](module);
}; };
Expand Down

0 comments on commit d7bfd44

Please sign in to comment.