Permalink
Browse files

test suite fixes, added index.js

  • Loading branch information...
1 parent 5ec8353 commit d7bfd445c0631adbe062661ce229ace505e1b254 @amccollum committed Oct 4, 2011
Showing with 117 additions and 23 deletions.
  1. +8 −2 Cakefile
  2. +1 −0 index.js
  3. +9 −11 lib/wings.js
  4. +2 −2 package.json
  5. +20 −0 src/test/index.html
  6. +66 −0 src/test/vows.css
  7. +1 −2 src/test/{wings.coffee → wings-test.coffee}
  8. +7 −2 src/wings/wings.coffee
  9. +3 −4 test/wings.js
View
@@ -17,8 +17,14 @@ task 'build', 'Build the library', ->
task 'test', 'Build and run the test suite', ->
execCmds [
+ 'cake build',
'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',
- 'ln -s ender-vows node_modules/vows',
- 'node_modules/.bin/vows ./test/*.js'
+ 'ln -sf ender-vows node_modules/vows',
+ 'node_modules/.bin/vows ./test/*-test.js'
]
View
@@ -0,0 +1 @@
+exports = require('lib/wings')
View
@@ -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 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;
name = section_name || tag_name;
content = section_content;
@@ -44,15 +44,13 @@
if (!(value != null)) {
throw "Invalid section: " + data + ": " + name + ": " + value;
} else if (isArray(value)) {
- return ((function() {
- var _i, _len, _results;
- _results = [];
- for (_i = 0, _len = value.length; _i < _len; _i++) {
- v = value[_i];
- _results.push(renderRawTemplate(content, v, links));
- }
- return _results;
- })()).join('');
+ parts = [];
+ for (i = 0, _len = value.length; i < _len; i++) {
+ v = value[i];
+ v['#'] = i;
+ parts.push(renderRawTemplate(content, v, links));
+ }
+ return parts.join('');
} else if (typeof value === 'object') {
return renderRawTemplate(content, value, links);
} else if (typeof value === 'function') {
View
@@ -1,14 +1,14 @@
{
"name": "wings",
- "version": "0.2.0",
+ "version": "0.3.0",
"description": "Templating library that works on the server and client closely modeled on Mustache",
"keywords": ["ender", "template", "mustache", "html"],
"author": "Andrew McCollum <amccollum@gmail.com>",
"url": "http://github.com/amccollum/wings",
"repositories": [{ "type": "git", "url": "http://github.com/amccollum/wings.git" }],
"licenses": [{ "type": "MIT", "url": "http://opensource.org/licenses/mit-license.php" }],
- "main": "lib/template.js",
+ "main": "lib/wings.js",
"ender": "lib/ender.js",
"directories": { "lib": "lib" },
"devDependencies": {
View
@@ -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>
View
@@ -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;
+}
@@ -1,8 +1,7 @@
assert = require('assert')
vows = require('vows')
-template = require('../lib/template.js')
-t = template.renderTemplate
+t = require('wings').renderTemplate
equal = assert.equal
if not vows.add
View
@@ -22,7 +22,7 @@
else return s
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\s]+? \s* \#\} # comments
///mg
@@ -40,7 +40,12 @@
throw "Invalid section: #{data}: #{name}: #{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'
return renderRawTemplate(content, value, links)
View
@@ -1,10 +1,9 @@
-var assert, equal, t, template, vows;
+var assert, equal, t, vows;
assert = require('assert');
vows = require('vows');
-template = require('../lib/template.js');
-t = template.renderTemplate;
+t = require('wings').renderTemplate;
equal = assert.equal;
-if (!(vows.add != null)) {
+if (!vows.add) {
vows.add = function(name, batch) {
return vows.describe(name).addBatch(batch)["export"](module);
};

0 comments on commit d7bfd44

Please sign in to comment.