Ind.ie is now Small Technology Foundation.
Commit 9efe54f4 authored by Aral Balkan's avatar Aral Balkan

Upgraded to the latest JSDOM. Upgraded to latest CoffeeScript. Upgraded to run on Node 4.2.1.

parent ca0d03d8
......@@ -43,10 +43,13 @@ exports.__express = (path, data, callback) ->
callback null, html
render = (template, data) ->
# Create the DOM.
document = jsdom.jsdom(template)
window = document.parentWindow
# The non-standard document.parentWindow was removed, in favor of the standard document.defaultView. Our apologies for encouraging use of parentWindow in our README, tests, and examples. (https://github.com/tmpvar/jsdom/blob/98e412228cdf8edcd364a3fe5acd91b752370a71/Changelog.md#400)
window = document.defaultView
window.console = console
# Create a private member in the data to communicate with the Tally engine in the DOM.
......@@ -56,10 +59,12 @@ render = (template, data) ->
# and will remove nodes that don’t satisfy conditionals
# (data-qif) instead of setting them to display: none
# like it does when running on the client.
data.__set['server'] = yes;
data.__set['server'] = yes
# Create Tally in the DOM.
window.run set
# window.run set
# (window.run support was removed from JSDOM after v3; simply eval it instead.)
window.eval(set)
#
# Copy over formatters and hooks (if any) from the special __set namespace
......@@ -117,15 +122,15 @@ render = (template, data) ->
# === although window.document.innerHTML works. window.document.documentElement
# also works. I’ll be darned if I know why or where the problem is.
try
window.run ('set(window.document.documentElement, window.data);')
window.eval 'set(window.document.documentElement, window.data);'
catch e
throw e
html = window.document.documentElement.outerHTML;
html = window.document.documentElement.outerHTML
# Note: .outerHTML does not return the doctype, get it manually.
# (Adapted from http://stackoverflow.com/a/10162353/253485 by Rob W)
doctype = window.document.doctype;
doctype = window.document.doctype
if doctype != null
doctypeName = doctype.name
doctypePublicID = (doctype.publicId ? ' PUBLIC "' + doctype.publicId + '"' : '')
......
// Generated by CoffeeScript 1.8.0
// Generated by CoffeeScript 1.10.0
/*
Copyright 2013-2014 Aral Balkan <aral@ind.ie>
......@@ -24,7 +24,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/)
set = function(root, obj) {
"use strict";
var TAL, altAttr, attr, attr2, attributeWillChange, doc, formInputHasBody, format, getProp, html, i, innerText, isRunningOnServer, len, list, listStack, name, node, obj2, objList, pos, posStack, prefix, qattr, qdef, qdup, qif, qrepeat, qtext, querySelectorAll, resolve, shouldRenderStatic, textWillChange, tmpNode, value, wrapper, _results;
var TAL, altAttr, attr, attr2, attributeWillChange, doc, formInputHasBody, format, getProp, html, i, innerText, isRunningOnServer, len, list, listStack, name, node, obj2, objList, pos, posStack, prefix, qattr, qdef, qdup, qif, qrepeat, qtext, querySelectorAll, resolve, results, shouldRenderStatic, textWillChange, tmpNode, value, wrapper;
wrapper = function() {};
wrapper.prototype = obj;
obj = new wrapper();
......@@ -97,7 +97,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/)
}
listStack = [(querySelectorAll ? root.querySelectorAll(TAL) : root.getElementsByTagName("*"))];
list = [root];
_results = [];
results = [];
while (true) {
node = list[pos++];
while (!node && (list = listStack.pop())) {
......@@ -374,15 +374,15 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/)
attr2 = attr(attr2);
}
if (html) {
_results.push(node.innerHTML = attr2);
results.push(node.innerHTML = attr2);
} else {
_results.push(node[("form" in node && !formInputHasBody[node.tagName] ? "value" : innerText)] = attr2);
results.push(node[("form" in node && !formInputHasBody[node.tagName] ? "value" : innerText)] = attr2);
}
} else {
_results.push(void 0);
results.push(void 0);
}
}
return _results;
return results;
};
set.resolve = function(obj, seq, x, lastObj) {
......
{
"name": "indie-set",
"description": "Set is an unobtrusive and DRY template engine for Node.js and browsers.",
"version": "1.0.1",
"version": "1.1.0",
"author": "Aral Balkan <aral@ind.ie>",
"repository": {
"type": "git",
......@@ -13,11 +13,11 @@
"test": "node_modules/.bin/mocha test/*.coffee --require coffee-script/register --require should --reporter spec --compilers coffee:coffee-script/register"
},
"dependencies": {
"coffee-script": "1.8.0",
"coffee-script": "1.10.0",
"express": "4.9.7",
"forever": "0.11.1",
"ghm": "1.0.0-3",
"jsdom": "3.1.2",
"jsdom": "7.0.2",
"superagent": "0.12.4"
},
"devDependencies": {
......@@ -45,6 +45,6 @@
},
"subdomain": "set",
"engines": {
"node": "0.10.38"
"node": "4.2.1"
}
}
################################################################################
#
# Set tests.
# Set tests.
#
# Copyright © Aral Balkan.
# Released with ♥ by Ind.ie under the MIT License.
# Copyright © Aral Balkan.
# Released with ♥ by Ind.ie under the MIT License.
# Portions released under the Apache License.
#
################################################################################
......@@ -15,7 +15,6 @@ set = (require '../lib/set-express').render
colors = require('mocha/lib/reporters/base').colors
colors['pass'] = colors['error stack'] = colors['light'] = colors['diff gutter'] = '92'
describe 'Set', ->
#
......@@ -68,32 +67,32 @@ describe 'Set', ->
it 'should repeat nodes with data-set-repeat', ->
template = '<html><ul><li data-set-repeat="person people"><span data-set-text="person.name"></span></li></ul></html>'
data = { people:[ {name: 'Aral'}, {name: 'Laura'}, {name: 'Natalie'}, {name: 'Osky'} ] }
result = '<html><head></head><body><ul><li data-set-repeat="person people" style=""><span data-set-text="person.name">Aral</span></li><li style="" data-set-alias="person people 1" data-set-dummy="1"><span data-set-text="person.name">Laura</span></li><li style="" data-set-alias="person people 2" data-set-dummy="1"><span data-set-text="person.name">Natalie</span></li><li style="" data-set-alias="person people 3" data-set-dummy="1"><span data-set-text="person.name">Osky</span></li></ul></body></html>'
result = '<html><head></head><body><ul><li data-set-repeat="person people"><span data-set-text="person.name">Aral</span></li><li data-set-alias="person people 1" data-set-dummy="1"><span data-set-text="person.name">Laura</span></li><li data-set-alias="person people 2" data-set-dummy="1"><span data-set-text="person.name">Natalie</span></li><li data-set-alias="person people 3" data-set-dummy="1"><span data-set-text="person.name">Osky</span></li></ul></body></html>'
set(template, data).should.equal(result)
it 'should display elements with truthy conditionals', ->
set('<html><p data-set-if="truthy"></p></html>', {truthy: yes}).should.equal('<html><head></head><body><p data-set-if="truthy" style=""></p></body></html>')
set('<html><p data-set-if="truthy"></p></html>', {truthy: yes}).should.equal('<html><head></head><body><p data-set-if="truthy"></p></body></html>')
it 'should hide elements with falsey conditionals', ->
set('<html><p data-set-if="truthy"></p></html>', {truthy: no}).should.equal('<html><head></head><body><p data-set-if="truthy" style="display: none;"></p></body></html>')
it 'should handle "not:" conditionals correctly', ->
set('<html><p data-set-if="not:dog">Want dog</p></html>', {dog: no}).should.equal('<html><head></head><body><p data-set-if="not:dog" style="">Want dog</p></body></html>')
set('<html><p data-set-if="not:dog">Want dog</p></html>', {dog: no}).should.equal('<html><head></head><body><p data-set-if="not:dog">Want dog</p></body></html>')
it 'should handle "is" conditionals correctly', ->
set('<html><p data-set-if="dog is Osky"></p></html>', {dog: 'Osky'}).should.equal('<html><head></head><body><p data-set-if="dog is Osky" style=""></p></body></html>')
set('<html><p data-set-if="dog is Osky"></p></html>', {dog: 'Osky'}).should.equal('<html><head></head><body><p data-set-if="dog is Osky"></p></body></html>')
it 'should handle "isNot" conditionals correctly', ->
set('<html><p data-set-if="dog isNot Osky"></p></html>', {dog: 'Osky'}).should.equal('<html><head></head><body><p data-set-if="dog isNot Osky" style="display: none;"></p></body></html>')
it 'should handle "isGreaterThan" conditionals correctly', ->
set('<html><p data-set-if="age isGreaterThan 18">You can drive.</p></html>', {age: 21}).should.equal('<html><head></head><body><p data-set-if="age isGreaterThan 18" style="">You can drive.</p></body></html>')
set('<html><p data-set-if="age isGreaterThan 18">You can drive.</p></html>', {age: 21}).should.equal('<html><head></head><body><p data-set-if="age isGreaterThan 18">You can drive.</p></body></html>')
it 'should handle "isLessThan" conditionals correctly', ->
set('<html><p data-set-if="age isLessThan 18">You can’t drive.</p></html>', {age: 21}).should.equal('<html><head></head><body><p data-set-if="age isLessThan 18" style="display: none;">You can’t drive.</p></body></html>')
it 'should handle "contains" conditionals correctly', ->
set('<html><p data-set-if="statement contains sarcasm">I was being sarcastic</p></html>', {statement: 'This statement contains sarcasm. Literally.'}).should.equal('<html><head></head><body><p data-set-if="statement contains sarcasm" style="">I was being sarcastic</p></body></html>')
set('<html><p data-set-if="statement contains sarcasm">I was being sarcastic</p></html>', {statement: 'This statement contains sarcasm. Literally.'}).should.equal('<html><head></head><body><p data-set-if="statement contains sarcasm">I was being sarcastic</p></body></html>')
it 'should handle "doesNotContain" conditionals correctly', ->
set('<html><p data-set-if="statement doesNotContain sarcasm">I’m serious</p></html>', {statement: 'This statement contains sarcasm. Literally.'}).should.equal('<html><head></head><body><p data-set-if="statement doesNotContain sarcasm" style="display: none;">I’m serious</p></body></html>')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment