Merge pull request #93 from yolk/spaces

Removed trailing spaces
This commit is contained in:
Leo Horie 2014-05-25 23:51:47 -04:00
commit e1090c9c90
5 changed files with 53 additions and 53 deletions

View file

@ -1,12 +1,12 @@
module.exports = function(grunt) { module.exports = function(grunt) {
var version = "0.1.14" var version = "0.1.14"
var inputFolder = "./docs" var inputFolder = "./docs"
var tempFolder = "./temp" var tempFolder = "./temp"
var archiveFolder = "./archive" var archiveFolder = "./archive"
var outputFolder = "../mithril" var outputFolder = "../mithril"
var guideLayout = "guide" var guideLayout = "guide"
var guide = [ var guide = [
"auto-redrawing", "auto-redrawing",
@ -43,9 +43,9 @@ module.exports = function(grunt) {
"mithril.withAttr", "mithril.withAttr",
"mithril.xhr" "mithril.xhr"
] ]
var md2htmlTasks = {} var md2htmlTasks = {}
var makeTasks = function(layout, pages) { var makeTasks = function(layout, pages) {
pages.map(function(name) { pages.map(function(name) {
@ -57,7 +57,7 @@ module.exports = function(grunt) {
} }
makeTasks("guide", guide) makeTasks("guide", guide)
makeTasks("api", api) makeTasks("api", api)
var currentVersionArchiveFolder = archiveFolder + "/v" + version var currentVersionArchiveFolder = archiveFolder + "/v" + version
grunt.initConfig({ grunt.initConfig({
md2html: md2htmlTasks, md2html: md2htmlTasks,
@ -111,7 +111,7 @@ module.exports = function(grunt) {
tasks: ["build"] tasks: ["build"]
} }
}); });
grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks("grunt-contrib-copy"); grunt.loadNpmTasks("grunt-contrib-copy");

View file

@ -2,7 +2,7 @@ Mithril = m = new function app(window) {
var selectorCache = {} var selectorCache = {}
var type = {}.toString var type = {}.toString
var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.+?)\2)?\]/ var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.+?)\2)?\]/
function m() { function m() {
var args = arguments var args = arguments
var hasAttrs = type.call(args[1]) == "[object Object]" && !("tag" in args[1]) && !("subtree" in args[1]) var hasAttrs = type.call(args[1]) == "[object Object]" && !("tag" in args[1]) && !("subtree" in args[1])
@ -35,14 +35,14 @@ Mithril = m = new function app(window) {
function build(parentElement, parentTag, data, cached, shouldReattach, index, editable, namespace) { function build(parentElement, parentTag, data, cached, shouldReattach, index, editable, namespace) {
if (data === null || data === undefined) data = "" if (data === null || data === undefined) data = ""
if (data.subtree === "retain") return if (data.subtree === "retain") return
var cachedType = type.call(cached), dataType = type.call(data) var cachedType = type.call(cached), dataType = type.call(data)
if (cachedType != dataType) { if (cachedType != dataType) {
if (cached !== null && cached !== undefined) clear(cached.nodes) if (cached !== null && cached !== undefined) clear(cached.nodes)
cached = new data.constructor cached = new data.constructor
cached.nodes = [] cached.nodes = []
} }
if (dataType == "[object Array]") { if (dataType == "[object Array]") {
var nodes = [], intact = cached.length === data.length, subArrayCount = 0 var nodes = [], intact = cached.length === data.length, subArrayCount = 0
for (var i = 0, cacheCount = 0; i < data.length; i++) { for (var i = 0, cacheCount = 0; i < data.length; i++) {
@ -64,7 +64,7 @@ Mithril = m = new function app(window) {
else if (dataType == "[object Object]") { else if (dataType == "[object Object]") {
if (data.tag != cached.tag || Object.keys(data.attrs).join() != Object.keys(cached.attrs).join() || data.attrs.id != cached.attrs.id) clear(cached.nodes) if (data.tag != cached.tag || Object.keys(data.attrs).join() != Object.keys(cached.attrs).join() || data.attrs.id != cached.attrs.id) clear(cached.nodes)
if (typeof data.tag != "string") return if (typeof data.tag != "string") return
var node, isNew = cached.nodes.length === 0 var node, isNew = cached.nodes.length === 0
if (data.attrs.xmlns) namespace = data.attrs.xmlns if (data.attrs.xmlns) namespace = data.attrs.xmlns
else if (data.tag === "svg") namespace = "http://www.w3.org/2000/svg" else if (data.tag === "svg") namespace = "http://www.w3.org/2000/svg"
@ -126,7 +126,7 @@ Mithril = m = new function app(window) {
} }
else cached.nodes.intact = true else cached.nodes.intact = true
} }
return cached return cached
} }
function setAttributes(node, tag, dataAttrs, cachedAttrs, namespace) { function setAttributes(node, tag, dataAttrs, cachedAttrs, namespace) {
@ -184,7 +184,7 @@ Mithril = m = new function app(window) {
finally {m.endComputation()} finally {m.endComputation()}
} }
} }
var html var html
var documentNode = { var documentNode = {
insertAdjacentHTML: function(_, data) { insertAdjacentHTML: function(_, data) {
@ -211,13 +211,13 @@ Mithril = m = new function app(window) {
var node = root == window.document || root == window.document.documentElement ? documentNode : root var node = root == window.document || root == window.document.documentElement ? documentNode : root
cellCache[id] = build(node, null, cell, cellCache[id], false, 0, null, undefined) cellCache[id] = build(node, null, cell, cellCache[id], false, 0, null, undefined)
} }
m.trust = function(value) { m.trust = function(value) {
value = new String(value) value = new String(value)
value.$trusted = true value.$trusted = true
return value return value
} }
var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0, computePostRedrawHook = null var roots = [], modules = [], controllers = [], now = 0, lastRedraw = 0, lastRedrawId = 0, computePostRedrawHook = null
m.module = function(root, module) { m.module = function(root, module) {
m.startComputation() m.startComputation()
@ -249,21 +249,21 @@ Mithril = m = new function app(window) {
} }
lastRedraw = now lastRedraw = now
} }
var pendingRequests = 0 var pendingRequests = 0
m.startComputation = function() {pendingRequests++} m.startComputation = function() {pendingRequests++}
m.endComputation = function() { m.endComputation = function() {
pendingRequests = Math.max(pendingRequests - 1, 0) pendingRequests = Math.max(pendingRequests - 1, 0)
if (pendingRequests == 0) m.redraw() if (pendingRequests == 0) m.redraw()
} }
m.withAttr = function(prop, withAttrCallback) { m.withAttr = function(prop, withAttrCallback) {
return function(e) { return function(e) {
e = e || event e = e || event
withAttrCallback(prop in e.currentTarget ? e.currentTarget[prop] : e.currentTarget.getAttribute(prop)) withAttrCallback(prop in e.currentTarget ? e.currentTarget[prop] : e.currentTarget.getAttribute(prop))
} }
} }
//routing //routing
var modes = {pathname: "", hash: "#", search: "?"} var modes = {pathname: "", hash: "#", search: "?"}
var redirect = function() {}, routeParams = {}, currentRoute var redirect = function() {}, routeParams = {}, currentRoute
@ -325,9 +325,9 @@ Mithril = m = new function app(window) {
for (var route in router) { for (var route in router) {
if (route == path) return !void m.module(root, router[route]) if (route == path) return !void m.module(root, router[route])
var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$") var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$")
if (matcher.test(path)) { if (matcher.test(path)) {
return !void path.replace(matcher, function() { return !void path.replace(matcher, function() {
var keys = route.match(/:[^\/]+/g) || [] var keys = route.match(/:[^\/]+/g) || []
@ -366,7 +366,7 @@ Mithril = m = new function app(window) {
function decodeSpace(string) { function decodeSpace(string) {
return decodeURIComponent(string.replace(/\+/g, " ")) return decodeURIComponent(string.replace(/\+/g, " "))
} }
//model //model
m.prop = function(store) { m.prop = function(store) {
var prop = function() { var prop = function() {
@ -436,7 +436,7 @@ Mithril = m = new function app(window) {
return value return value
} }
} }
var deferred = m.deferred() var deferred = m.deferred()
var results = [] var results = []
for (var i = 0; i < args.length; i++) { for (var i = 0; i < args.length; i++) {
@ -511,12 +511,12 @@ Mithril = m = new function app(window) {
ajax(xhrOptions) ajax(xhrOptions)
return deferred.promise return deferred.promise
} }
//testing API //testing API
m.deps = function(mock) {return window = mock} m.deps = function(mock) {return window = mock}
//for internal testing only, do not use `m.deps.factory` //for internal testing only, do not use `m.deps.factory`
m.deps.factory = app m.deps.factory = app
return m return m
}(this) }(this)

View file

@ -1,6 +1,6 @@
function testMithril(mock) { function testMithril(mock) {
m.deps(mock) m.deps(mock)
//m //m
test(function() {return m("div").tag === "div"}) test(function() {return m("div").tag === "div"})
test(function() {return m(".foo").tag === "div"}) test(function() {return m(".foo").tag === "div"})
@ -27,21 +27,21 @@ function testMithril(mock) {
//m.module //m.module
test(function() { test(function() {
mock.performance.$elapse(50) mock.performance.$elapse(50)
var root1 = mock.document.createElement("div") var root1 = mock.document.createElement("div")
m.module(root1, { m.module(root1, {
controller: function() {this.value = "test1"}, controller: function() {this.value = "test1"},
view: function(ctrl) {return ctrl.value} view: function(ctrl) {return ctrl.value}
}) })
var root2 = mock.document.createElement("div") var root2 = mock.document.createElement("div")
m.module(root2, { m.module(root2, {
controller: function() {this.value = "test2"}, controller: function() {this.value = "test2"},
view: function(ctrl) {return ctrl.value} view: function(ctrl) {return ctrl.value}
}) })
mock.requestAnimationFrame.$resolve() mock.requestAnimationFrame.$resolve()
return root1.childNodes[0].nodeValue === "test1" && root2.childNodes[0].nodeValue === "test2" return root1.childNodes[0].nodeValue === "test1" && root2.childNodes[0].nodeValue === "test2"
}) })
@ -168,17 +168,17 @@ function testMithril(mock) {
m.render(root, list.reverse().map(function(flag, index) { m.render(root, list.reverse().map(function(flag, index) {
return m("input[type=checkbox]", {onclick: m.withAttr("checked", function(value) {list[index] = value}), checked: flag}) return m("input[type=checkbox]", {onclick: m.withAttr("checked", function(value) {list[index] = value}), checked: flag})
})) }))
mock.document.activeElement = root.childNodes[0] mock.document.activeElement = root.childNodes[0]
root.childNodes[0].checked = true root.childNodes[0].checked = true
root.childNodes[0].onclick({currentTarget: {checked: true}}) root.childNodes[0].onclick({currentTarget: {checked: true}})
m.render(root, list.reverse().map(function(flag, index) { m.render(root, list.reverse().map(function(flag, index) {
return m("input[type=checkbox]", {onclick: m.withAttr("checked", function(value) {list[index] = value}), checked: flag}) return m("input[type=checkbox]", {onclick: m.withAttr("checked", function(value) {list[index] = value}), checked: flag})
})) }))
mock.document.activeElement = null mock.document.activeElement = null
return root.childNodes[0].checked === false && root.childNodes[1].checked === true return root.childNodes[0].checked === false && root.childNodes[1].checked === true
}) })
test(function() { test(function() {
@ -384,7 +384,7 @@ function testMithril(mock) {
return root.childNodes[0].childNodes.length == 2 return root.childNodes[0].childNodes.length == 2
}) })
//end m.render //end m.render
//m.redraw //m.redraw
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
@ -425,7 +425,7 @@ function testMithril(mock) {
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.search = "?" mock.location.search = "?"
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "search" m.route.mode = "search"
m.route(root, "/test1", { m.route(root, "/test1", {
@ -437,7 +437,7 @@ function testMithril(mock) {
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.pathname = "/" mock.location.pathname = "/"
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "pathname" m.route.mode = "pathname"
m.route(root, "/test2", { m.route(root, "/test2", {
@ -449,7 +449,7 @@ function testMithril(mock) {
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.hash = "#" mock.location.hash = "#"
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "hash" m.route.mode = "hash"
m.route(root, "/test3", { m.route(root, "/test3", {
@ -461,7 +461,7 @@ function testMithril(mock) {
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.search = "?" mock.location.search = "?"
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "search" m.route.mode = "search"
m.route(root, "/test4/foo", { m.route(root, "/test4/foo", {
@ -473,9 +473,9 @@ function testMithril(mock) {
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.search = "?" mock.location.search = "?"
var module = {controller: function() {}, view: function() {return m.route.param("test")}} var module = {controller: function() {}, view: function() {return m.route.param("test")}}
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "search" m.route.mode = "search"
m.route(root, "/test5/foo", { m.route(root, "/test5/foo", {
@ -492,9 +492,9 @@ function testMithril(mock) {
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.search = "?" mock.location.search = "?"
var module = {controller: function() {}, view: function() {return m.route.param("a1")}} var module = {controller: function() {}, view: function() {return m.route.param("a1")}}
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "search" m.route.mode = "search"
m.route(root, "/test6/foo", { m.route(root, "/test6/foo", {
@ -512,9 +512,9 @@ function testMithril(mock) {
//https://github.com/lhorie/mithril.js/issues/61 //https://github.com/lhorie/mithril.js/issues/61
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.search = "?" mock.location.search = "?"
var module = {controller: function() {}, view: function() {return m.route.param("a1")}} var module = {controller: function() {}, view: function() {return m.route.param("a1")}}
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "search" m.route.mode = "search"
m.route(root, "/test7/foo", { m.route(root, "/test7/foo", {
@ -531,7 +531,7 @@ function testMithril(mock) {
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.search = "?" mock.location.search = "?"
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "search" m.route.mode = "search"
m.route(root, "/test8/foo/SEP/bar/baz", { m.route(root, "/test8/foo/SEP/bar/baz", {
@ -548,7 +548,7 @@ function testMithril(mock) {
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.search = "?" mock.location.search = "?"
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "search" m.route.mode = "search"
m.route(root, "/test9/foo/bar/SEP/baz", { m.route(root, "/test9/foo/bar/SEP/baz", {
@ -565,7 +565,7 @@ function testMithril(mock) {
test(function() { test(function() {
mock.performance.$elapse(50) //setup mock.performance.$elapse(50) //setup
mock.location.search = "?" mock.location.search = "?"
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.route.mode = "search" m.route.mode = "search"
m.route(root, "/test10/foo%20bar", { m.route(root, "/test10/foo%20bar", {
@ -888,22 +888,22 @@ function testMithril(mock) {
//m.startComputation/m.endComputation //m.startComputation/m.endComputation
test(function() { test(function() {
mock.performance.$elapse(50) mock.performance.$elapse(50)
var controller var controller
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.module(root, { m.module(root, {
controller: function() {controller = this}, controller: function() {controller = this},
view: function(ctrl) {return ctrl.value} view: function(ctrl) {return ctrl.value}
}) })
mock.performance.$elapse(50) mock.performance.$elapse(50)
m.startComputation() m.startComputation()
controller.value = "foo" controller.value = "foo"
m.endComputation() m.endComputation()
return root.childNodes[0].nodeValue === "foo" return root.childNodes[0].nodeValue === "foo"
}) })
//console.log presence //console.log presence
test(function() { test(function() {
return m.deps.factory.toString().indexOf("console") < 0 return m.deps.factory.toString().indexOf("console") < 0

View file

@ -31,7 +31,7 @@
<li>a clock with the current time</li> <li>a clock with the current time</li>
</ul> </ul>
<p>The links should open in a new tab. All items should display title tooltips when hovered over.</p> <p>The links should open in a new tab. All items should display title tooltips when hovered over.</p>
<div id="test"></div> <div id="test"></div>
<script src="../mithril.js"></script> <script src="../mithril.js"></script>
<script> <script>

View file

@ -10,7 +10,7 @@ test.print = function(print) {
print(test.failures[i].toString()) print(test.failures[i].toString())
} }
print("tests: " + test.total + "\nfailures: " + test.failures.length) print("tests: " + test.total + "\nfailures: " + test.failures.length)
if (test.failures.length > 0) { if (test.failures.length > 0) {
throw new Error(test.failures.length + " tests did not pass") throw new Error(test.failures.length + " tests did not pass")
} }