Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Liquid, customError, util; |
4 | ||
5 | 1 | Liquid = require("./liquid"); |
6 | ||
7 | 1 | util = require("util"); |
8 | ||
9 | 1 | customError = function(name, inherit) { |
10 | 9 | var error; |
11 | if (inherit == null) { | |
12 | 1 | inherit = global.Error; |
13 | } | |
14 | 9 | error = function(message) { |
15 | 19 | this.name = name; |
16 | 19 | this.message = message; |
17 | if (global.Error.captureStackTrace) { | |
18 | 19 | return global.Error.captureStackTrace(this, arguments.callee); |
19 | } | |
20 | }; | |
21 | 9 | util.inherits(error, inherit); |
22 | 9 | return error; |
23 | }; | |
24 | ||
25 | 1 | Liquid.Error = customError("Error"); |
26 | ||
27 | 1 | ["ArgumentError", "ContextError", "FilterNotFound", "FilterNotFound", "FileSystemError", "StandardError", "StackLevelError", "SyntaxError"].forEach(function(className) { |
28 | 8 | return Liquid[className] = customError("Liquid." + className, Liquid.Error); |
29 | }); | |
30 | ||
31 | 1 | Liquid.Engine = require("./liquid/engine"); |
32 | ||
33 | 1 | Liquid.Helpers = require("./liquid/helpers"); |
34 | ||
35 | 1 | Liquid.Range = require("./liquid/range"); |
36 | ||
37 | 1 | Liquid.Iterable = require("./liquid/iterable"); |
38 | ||
39 | 1 | Liquid.Drop = require("./liquid/drop"); |
40 | ||
41 | 1 | Liquid.Context = require("./liquid/context"); |
42 | ||
43 | 1 | Liquid.Tag = require("./liquid/tag"); |
44 | ||
45 | 1 | Liquid.Block = require("./liquid/block"); |
46 | ||
47 | 1 | Liquid.Document = require("./liquid/document"); |
48 | ||
49 | 1 | Liquid.Variable = require("./liquid/variable"); |
50 | ||
51 | 1 | Liquid.Template = require("./liquid/template"); |
52 | ||
53 | 1 | Liquid.StandardFilters = require("./liquid/standard_filters"); |
54 | ||
55 | 1 | Liquid.Condition = require("./liquid/condition"); |
56 | ||
57 | 1 | Liquid.ElseCondition = require("./liquid/else_condition"); |
58 | ||
59 | 1 | Liquid.Assign = require("./liquid/tags/assign"); |
60 | ||
61 | 1 | Liquid.Capture = require("./liquid/tags/capture"); |
62 | ||
63 | 1 | Liquid.Comment = require("./liquid/tags/comment"); |
64 | ||
65 | 1 | Liquid.Decrement = require("./liquid/tags/decrement"); |
66 | ||
67 | 1 | Liquid.For = require("./liquid/tags/for"); |
68 | ||
69 | 1 | Liquid.If = require("./liquid/tags/if"); |
70 | ||
71 | 1 | Liquid.Ifchanged = require("./liquid/tags/ifchanged"); |
72 | ||
73 | 1 | Liquid.Increment = require("./liquid/tags/increment"); |
74 | ||
75 | 1 | Liquid.Raw = require("./liquid/tags/raw"); |
76 | ||
77 | 1 | Liquid.Unless = require("./liquid/tags/unless"); |
78 | ||
79 | 1 | module.exports = Liquid; |
80 | ||
81 | }).call(this); | |
82 | ||
83 | //# sourceMappingURL=index.map | |
84 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Liquid; |
4 | ||
5 | 1 | module.exports = Liquid = (function() { |
6 | function Liquid() {} | |
7 | ||
8 | 1 | Liquid.FilterSeparator = /\|/; |
9 | ||
10 | 1 | Liquid.ArgumentSeparator = /,/; |
11 | ||
12 | 1 | Liquid.FilterArgumentSeparator = /\:/; |
13 | ||
14 | 1 | Liquid.VariableAttributeSeparator = /\./; |
15 | ||
16 | 1 | Liquid.TagStart = /\{\%/; |
17 | ||
18 | 1 | Liquid.TagEnd = /\%\}/; |
19 | ||
20 | 1 | Liquid.VariableSignature = /\(?[\w\-\.\[\]]\)?/; |
21 | ||
22 | 1 | Liquid.VariableSegment = /[\w\-]/; |
23 | ||
24 | 1 | Liquid.VariableStart = /\{\{/; |
25 | ||
26 | 1 | Liquid.VariableEnd = /\}\}/; |
27 | ||
28 | 1 | Liquid.VariableIncompleteEnd = /\}\}?/; |
29 | ||
30 | 1 | Liquid.QuotedString = /"[^"]*"|'[^']*'/; |
31 | ||
32 | 1 | Liquid.QuotedFragment = RegExp("" + Liquid.QuotedString.source + "|(?:[^\\s,\\|'\"]|" + Liquid.QuotedString.source + ")+"); |
33 | ||
34 | 1 | Liquid.StrictQuotedFragment = /"[^"]+"|'[^']+'|[^\s|:,]+/; |
35 | ||
36 | 1 | Liquid.FirstFilterArgument = RegExp("" + Liquid.FilterArgumentSeparator.source + "(?:" + Liquid.StrictQuotedFragment.source + ")"); |
37 | ||
38 | 1 | Liquid.OtherFilterArgument = RegExp("" + Liquid.ArgumentSeparator.source + "(?:" + Liquid.StrictQuotedFragment.source + ")"); |
39 | ||
40 | 1 | Liquid.SpacelessFilter = RegExp("^(?:'[^']+'|\"[^\"]+\"|[^'\"])*" + Liquid.FilterSeparator.source + "(?:" + Liquid.StrictQuotedFragment.source + ")(?:" + Liquid.FirstFilterArgument.source + "(?:" + Liquid.OtherFilterArgument.source + ")*)?"); |
41 | ||
42 | 1 | Liquid.Expression = RegExp("(?:" + Liquid.QuotedFragment.source + "(?:" + Liquid.SpacelessFilter.source + ")*)"); |
43 | ||
44 | 1 | Liquid.TagAttributes = RegExp("(\\w+)\\s*\\:\\s*(" + Liquid.QuotedFragment.source + ")"); |
45 | ||
46 | 1 | Liquid.AnyStartingTag = /\{\{|\{\%/; |
47 | ||
48 | 1 | Liquid.PartialTemplateParser = RegExp("" + Liquid.TagStart.source + ".*?" + Liquid.TagEnd.source + "|" + Liquid.VariableStart.source + ".*?" + Liquid.VariableIncompleteEnd.source); |
49 | ||
50 | 1 | Liquid.TemplateParser = RegExp("(" + Liquid.PartialTemplateParser.source + "|" + Liquid.AnyStartingTag.source + ")"); |
51 | ||
52 | 1 | Liquid.VariableParser = RegExp("\\[[^\\]]+\\]|" + Liquid.VariableSegment.source + "+\\??"); |
53 | ||
54 | 1 | return Liquid; |
55 | ||
56 | })(); | |
57 | ||
58 | }).call(this); | |
59 | ||
60 | //# sourceMappingURL=liquid.map | |
61 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Block, Liquid, Promise, util, |
4 | __hasProp = {}.hasOwnProperty, | |
5 | 5 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
6 | ||
7 | 1 | Liquid = require("../liquid"); |
8 | ||
9 | 1 | util = require("util"); |
10 | ||
11 | 1 | Promise = require("bluebird"); |
12 | ||
13 | 1 | module.exports = Block = (function(_super) { |
14 | 1 | __extends(Block, _super); |
15 | ||
16 | function Block() { | |
17 | 85 | return Block.__super__.constructor.apply(this, arguments); |
18 | } | |
19 | ||
20 | 1 | Block.IsTag = RegExp("^" + Liquid.TagStart.source); |
21 | ||
22 | 1 | Block.IsVariable = RegExp("^" + Liquid.VariableStart.source); |
23 | ||
24 | 1 | Block.FullToken = RegExp("^" + Liquid.TagStart.source + "\\s*(\\w+)\\s*(.*)?" + Liquid.TagEnd.source + "$"); |
25 | ||
26 | 1 | Block.ContentOfVariable = RegExp("^" + Liquid.VariableStart.source + "(.*)" + Liquid.VariableEnd.source + "$"); |
27 | ||
28 | 1 | Block.prototype.beforeParse = function() { |
29 | if (this.nodelist == null) { | |
30 | 122 | this.nodelist = []; |
31 | } | |
32 | 196 | return this.nodelist.length = 0; |
33 | }; | |
34 | ||
35 | 1 | Block.prototype.afterParse = function() { |
36 | 186 | return this.assertMissingDelimitation(); |
37 | }; | |
38 | ||
39 | 1 | Block.prototype.parse = function(tokens) { |
40 | 497 | var token; |
41 | if (tokens.length === 0 || this.ended) { | |
42 | 184 | return Promise.cast(); |
43 | } | |
44 | 313 | token = tokens.shift(); |
45 | 313 | return Promise["try"]((function(_this) { |
46 | 313 | return function() { |
47 | 313 | return _this.parseToken(token, tokens); |
48 | }; | |
49 | })(this))["catch"](function(e) { | |
50 | 10 | e.message = "" + e.message + "\n at " + token.value + " (" + token.filename + ":" + token.line + ":" + token.col + ")"; |
51 | if (e.location == null) { | |
52 | 8 | e.location = { |
53 | col: token.col, | |
54 | line: token.line, | |
55 | filename: token.filename | |
56 | }; | |
57 | } | |
58 | 10 | throw e; |
59 | }).then((function(_this) { | |
60 | 313 | return function() { |
61 | 303 | return _this.parse(tokens); |
62 | }; | |
63 | })(this)); | |
64 | }; | |
65 | ||
66 | 1 | Block.prototype.parseToken = function(token, tokens) { |
67 | 313 | var Tag, match, tag; |
68 | if (Block.IsTag.test(token.value)) { | |
69 | 185 | match = Block.FullToken.exec(token.value); |
70 | if (!match) { | |
71 | 1 | throw new Liquid.SyntaxError("Tag '" + token.value + "' was not properly terminated with regexp: " + Liquid.TagEnd.inspect); |
72 | } | |
73 | if (this.blockDelimiter() === match[1]) { | |
74 | 80 | return this.endTag(); |
75 | } | |
76 | 104 | Tag = this.template.tags[match[1]]; |
77 | if (!Tag) { | |
78 | 11 | return this.unknownTag(match[1], match[2], tokens); |
79 | } | |
80 | 93 | tag = new Tag(this.template, match[1], match[2]); |
81 | 93 | this.nodelist.push(tag); |
82 | 93 | return tag.parseWithCallbacks(tokens); |
83 | } else if (Block.IsVariable.test(token.value)) { | |
84 | 53 | return this.nodelist.push(this.createVariable(token)); |
85 | } else if (token.value.length === 0) { | |
86 | ||
87 | } else { | |
88 | 75 | return this.nodelist.push(token.value); |
89 | } | |
90 | }; | |
91 | ||
92 | 1 | Block.prototype.endTag = function() { |
93 | 82 | return this.ended = true; |
94 | }; | |
95 | ||
96 | 1 | Block.prototype.unknownTag = function(tag, params, tokens) { |
97 | if (tag === 'else') { | |
98 | 1 | throw new Liquid.SyntaxError("" + (this.blockName()) + " tag does not expect else tag"); |
99 | } else if (tag === 'end') { | |
100 | 1 | throw new Liquid.SyntaxError("'end' is not a valid delimiter for " + (this.blockName()) + " tags. use " + (this.blockDelimiter())); |
101 | } else { | |
102 | 3 | throw new Liquid.SyntaxError("Unknown tag '" + tag + "'"); |
103 | } | |
104 | }; | |
105 | ||
106 | 1 | Block.prototype.blockDelimiter = function() { |
107 | 100 | return "end" + (this.blockName()); |
108 | }; | |
109 | ||
110 | 1 | Block.prototype.blockName = function() { |
111 | 103 | return this.tagName; |
112 | }; | |
113 | ||
114 | 1 | Block.prototype.createVariable = function(token) { |
115 | 53 | var match, _ref; |
116 | 53 | match = (_ref = Liquid.Block.ContentOfVariable.exec(token.value)) != null ? _ref[1] : void 0; |
117 | if (match) { | |
118 | 52 | return new Liquid.Variable(match); |
119 | } | |
120 | 1 | throw new Liquid.SyntaxError("Variable '" + token.value + "' was not properly terminated with regexp: " + Liquid.VariableEnd.inspect); |
121 | }; | |
122 | ||
123 | 1 | Block.prototype.render = function(context) { |
124 | 98 | return this.renderAll(this.nodelist, context); |
125 | }; | |
126 | ||
127 | 1 | Block.prototype.assertMissingDelimitation = function() { |
128 | if (!this.ended) { | |
129 | 1 | throw new Liquid.SyntaxError("" + (this.blockName()) + " tag was never closed"); |
130 | } | |
131 | }; | |
132 | ||
133 | 1 | Block.prototype.renderAll = function(list, context) { |
134 | 226 | return Promise.map(list, function(token) { |
135 | if (typeof (token != null ? token.render : void 0) !== "function") { | |
136 | 73 | return token; |
137 | } | |
138 | 202 | return Promise["try"](function() { |
139 | 202 | return token.render(context); |
140 | })["catch"](function(e) { | |
141 | 1 | return context.handleError(e); |
142 | }); | |
143 | }, { | |
144 | concurrency: 1 | |
145 | }); | |
146 | }; | |
147 | ||
148 | 1 | return Block; |
149 | ||
150 | })(Liquid.Tag); | |
151 | ||
152 | }).call(this); | |
153 | ||
154 | //# sourceMappingURL=block.map | |
155 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Condition, Liquid, Promise; |
4 | ||
5 | 1 | Liquid = require("../liquid"); |
6 | ||
7 | 1 | Promise = require("bluebird"); |
8 | ||
9 | 1 | module.exports = Condition = (function() { |
10 | 1 | var LITERALS; |
11 | ||
12 | 1 | Condition.operators = { |
13 | '==': function(cond, left, right) { | |
14 | 14 | return cond.equalVariables(left, right); |
15 | }, | |
16 | 'is': function(cond, left, right) { | |
17 | 1 | return cond.equalVariables(left, right); |
18 | }, | |
19 | '!=': function(cond, left, right) { | |
20 | 3 | return !cond.equalVariables(left, right); |
21 | }, | |
22 | '<>': function(cond, left, right) { | |
23 | 1 | return !cond.equalVariables(left, right); |
24 | }, | |
25 | 'isnt': function(cond, left, right) { | |
26 | 1 | return !cond.equalVariables(left, right); |
27 | }, | |
28 | '<': function(cond, left, right) { | |
29 | 1 | return left < right; |
30 | }, | |
31 | '>': function(cond, left, right) { | |
32 | 1 | return left > right; |
33 | }, | |
34 | '<=': function(cond, left, right) { | |
35 | 2 | return left <= right; |
36 | }, | |
37 | '>=': function(cond, left, right) { | |
38 | 2 | return left >= right; |
39 | }, | |
40 | 'contains': function(cond, left, right) { | |
41 | 4 | return (left != null ? typeof left.indexOf === "function" ? left.indexOf(right) : void 0 : void 0) >= 0; |
42 | } | |
43 | }; | |
44 | ||
45 | function Condition(left, operator, right) { | |
46 | 62 | this.left = left; |
47 | 62 | this.operator = operator; |
48 | 62 | this.right = right; |
49 | 62 | this.childRelation = null; |
50 | 62 | this.childCondition = null; |
51 | } | |
52 | ||
53 | 1 | Condition.prototype.evaluate = function(context) { |
54 | 59 | var result; |
55 | if (context == null) { | |
56 | 1 | context = new Liquid.Context(); |
57 | } | |
58 | 59 | result = this.interpretCondition(this.left, this.right, this.operator, context); |
59 | switch (this.childRelation) { | |
60 | case "or": | |
61 | 4 | return Promise.cast(result).then((function(_this) { |
62 | 4 | return function(result) { |
63 | 4 | return result || _this.childCondition.evaluate(context); |
64 | }; | |
65 | })(this)); | |
66 | case "and": | |
67 | 6 | return Promise.cast(result).then((function(_this) { |
68 | 6 | return function(result) { |
69 | 6 | return result && _this.childCondition.evaluate(context); |
70 | }; | |
71 | })(this)); | |
72 | default: | |
73 | 48 | return result; |
74 | } | |
75 | }; | |
76 | ||
77 | 1 | Condition.prototype.or = function(childCondition) { |
78 | 4 | this.childCondition = childCondition; |
79 | 4 | return this.childRelation = "or"; |
80 | }; | |
81 | ||
82 | 1 | Condition.prototype.and = function(childCondition) { |
83 | 6 | this.childCondition = childCondition; |
84 | 6 | return this.childRelation = "and"; |
85 | }; | |
86 | ||
87 | 1 | Condition.prototype.attach = function(attachment) { |
88 | 51 | return this.attachment = attachment; |
89 | }; | |
90 | ||
91 | 1 | Condition.prototype.equalVariables = function(left, right) { |
92 | if (typeof left === "function") { | |
93 | 2 | return left(right); |
94 | } else if (typeof right === "function") { | |
95 | 4 | return right(left); |
96 | } else { | |
97 | 14 | return left === right; |
98 | } | |
99 | }; | |
100 | ||
101 | 1 | LITERALS = { |
102 | empty: function(v) { | |
103 | 3 | return !((v != null ? v.length : void 0) > 0); |
104 | }, | |
105 | blank: function(v) { | |
106 | 3 | return !v || v.toString().length === 0; |
107 | } | |
108 | }; | |
109 | ||
110 | 1 | Condition.prototype.resolveVariable = function(v, context) { |
111 | if (v in LITERALS) { | |
112 | 6 | return Promise.cast(LITERALS[v]); |
113 | } else { | |
114 | 82 | return context.get(v); |
115 | } | |
116 | }; | |
117 | ||
118 | 1 | Condition.prototype.interpretCondition = function(left, right, op, context) { |
119 | 59 | var operation; |
120 | if (op == null) { | |
121 | 28 | return this.resolveVariable(left, context); |
122 | } | |
123 | 31 | operation = Condition.operators[op]; |
124 | if (operation == null) { | |
125 | 1 | throw new Error("Unknown operator " + op); |
126 | } | |
127 | 30 | left = this.resolveVariable(left, context); |
128 | 30 | right = this.resolveVariable(right, context); |
129 | 30 | return Promise.join(left, right).spread((function(_this) { |
130 | 30 | return function(left, right) { |
131 | 30 | return operation(_this, left, right); |
132 | }; | |
133 | })(this)); | |
134 | }; | |
135 | ||
136 | 1 | return Condition; |
137 | ||
138 | })(); | |
139 | ||
140 | }).call(this); | |
141 | ||
142 | //# sourceMappingURL=condition.map | |
143 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Context, Liquid, Promise, |
4 | __slice = [].slice, | |
5 | __hasProp = {}.hasOwnProperty; | |
6 | ||
7 | 1 | Liquid = require("../liquid"); |
8 | ||
9 | 1 | Promise = require("bluebird"); |
10 | ||
11 | 1 | module.exports = Context = (function() { |
12 | function Context(engine, environments, outerScope, registers, rethrowErrors) { | |
13 | 113 | var _ref; |
14 | if (environments == null) { | |
15 | 19 | environments = {}; |
16 | } | |
17 | if (outerScope == null) { | |
18 | 19 | outerScope = {}; |
19 | } | |
20 | if (registers == null) { | |
21 | 19 | registers = {}; |
22 | } | |
23 | if (rethrowErrors == null) { | |
24 | 19 | rethrowErrors = false; |
25 | } | |
26 | 113 | this.environments = Liquid.Helpers.flatten([environments]); |
27 | 113 | this.scopes = [outerScope]; |
28 | 113 | this.registers = registers; |
29 | 113 | this.errors = []; |
30 | 113 | this.rethrowErrors = rethrowErrors; |
31 | 113 | this.strainer = (_ref = engine != null ? new engine.Strainer(this) : void 0) != null ? _ref : {}; |
32 | 113 | this.squashInstanceAssignsWithEnvironments(); |
33 | } | |
34 | ||
35 | 1 | Context.prototype.registerFilters = function() { |
36 | 2 | var filter, filters, k, v, _i, _len; |
37 | 2 | filters = 1 <= arguments.length ? __slice.call(arguments, 0) : []; |
38 | for (_i = 0, _len = filters.length; _i < _len; _i++) { | |
39 | 1 | filter = filters[_i]; |
40 | for (k in filter) { | |
41 | if (!__hasProp.call(filter, k)) continue; | |
42 | 2 | v = filter[k]; |
43 | if (v instanceof Function) { | |
44 | 2 | this.strainer[k] = v; |
45 | } | |
46 | } | |
47 | } | |
48 | }; | |
49 | ||
50 | 1 | Context.prototype.handleError = function(e) { |
51 | 5 | this.errors.push(e); |
52 | if (this.rethrowErrors) { | |
53 | 1 | throw e; |
54 | } | |
55 | if (e instanceof Liquid.SyntaxError) { | |
56 | 1 | return "Liquid syntax error: " + e.message; |
57 | } else { | |
58 | 3 | return "Liquid error: " + e.message; |
59 | } | |
60 | }; | |
61 | ||
62 | 1 | Context.prototype.invoke = function() { |
63 | 8 | var args, available, method, methodName; |
64 | 8 | methodName = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; |
65 | 8 | method = this.strainer[methodName]; |
66 | if (method instanceof Function) { | |
67 | 7 | return method.apply(this.strainer, args); |
68 | } else { | |
69 | 1 | available = Object.keys(this.strainer); |
70 | 1 | throw new Liquid.FilterNotFound("Unknown filter `" + methodName + "`, available: [" + (available.join(', ')) + "]"); |
71 | } | |
72 | }; | |
73 | ||
74 | 1 | Context.prototype.push = function(newScope) { |
75 | if (newScope == null) { | |
76 | 101 | newScope = {}; |
77 | } | |
78 | 196 | this.scopes.unshift(newScope); |
79 | if (this.scopes.length > 100) { | |
80 | 1 | throw new Error("Nesting too deep"); |
81 | } | |
82 | }; | |
83 | ||
84 | 1 | Context.prototype.merge = function(newScope) { |
85 | 2 | var k, v, _results; |
86 | if (newScope == null) { | |
87 | 1 | newScope = {}; |
88 | } | |
89 | 2 | _results = []; |
90 | for (k in newScope) { | |
91 | if (!__hasProp.call(newScope, k)) continue; | |
92 | 2 | v = newScope[k]; |
93 | 2 | _results.push(this.scopes[0][k] = v); |
94 | } | |
95 | 2 | return _results; |
96 | }; | |
97 | ||
98 | 1 | Context.prototype.pop = function() { |
99 | if (this.scopes.length <= 1) { | |
100 | 1 | throw new Error("ContextError"); |
101 | } | |
102 | 92 | return this.scopes.shift(); |
103 | }; | |
104 | ||
105 | 1 | Context.prototype.lastScope = function() { |
106 | 119 | return this.scopes[this.scopes.length - 1]; |
107 | }; | |
108 | ||
109 | 1 | Context.prototype.stack = function(newScope, f) { |
110 | 87 | var popLater, result; |
111 | if (newScope == null) { | |
112 | 1 | newScope = {}; |
113 | } | |
114 | 87 | popLater = false; |
115 | try { | |
116 | if (arguments.length < 2) { | |
117 | 86 | f = newScope; |
118 | 86 | newScope = {}; |
119 | } | |
120 | 87 | this.push(newScope); |
121 | 87 | result = f(); |
122 | if ((result != null ? result.nodeify : void 0) != null) { | |
123 | 86 | popLater = true; |
124 | 86 | result.nodeify((function(_this) { |
125 | 86 | return function() { |
126 | 86 | return _this.pop(); |
127 | }; | |
128 | })(this)); | |
129 | } | |
130 | 87 | return result; |
131 | } finally { | |
132 | if (!popLater) { | |
133 | 1 | this.pop(); |
134 | } | |
135 | } | |
136 | }; | |
137 | ||
138 | 1 | Context.prototype.clearInstanceAssigns = function() { |
139 | 1 | return this.scopes[0] = {}; |
140 | }; | |
141 | ||
142 | 1 | Context.prototype.set = function(key, value) { |
143 | 157 | return this.scopes[0][key] = value; |
144 | }; | |
145 | ||
146 | 1 | Context.prototype.get = function(key) { |
147 | 218 | return this.resolve(key); |
148 | }; | |
149 | ||
150 | 1 | Context.prototype.hasKey = function(key) { |
151 | 4 | return Promise.cast(this.resolve(key)).then(function(v) { |
152 | 4 | return v != null; |
153 | }); | |
154 | }; | |
155 | ||
156 | 1 | Context.Literals = { |
157 | 'null': null, | |
158 | 'nil': null, | |
159 | '': null, | |
160 | 'true': true, | |
161 | 'false': false | |
162 | }; | |
163 | ||
164 | 1 | Context.prototype.resolve = function(key) { |
165 | 236 | var hi, lo, match; |
166 | if (Liquid.Context.Literals.hasOwnProperty(key)) { | |
167 | 4 | return Liquid.Context.Literals[key]; |
168 | } else if (match = /^'(.*)'$/.exec(key)) { | |
169 | 6 | return match[1]; |
170 | } else if (match = /^"(.*)"$/.exec(key)) { | |
171 | 5 | return match[1]; |
172 | } else if (match = /^(\d+)$/.exec(key)) { | |
173 | 28 | return Number(match[1]); |
174 | } else if (match = /^\((\S+)\.\.(\S+)\)$/.exec(key)) { | |
175 | 3 | lo = this.resolve(match[1]); |
176 | 3 | hi = this.resolve(match[2]); |
177 | 3 | return Promise.join(lo, hi).spread(function(lo, hi) { |
178 | 3 | lo = Number(lo); |
179 | 3 | hi = Number(hi); |
180 | if (isNaN(lo) || isNaN(hi)) { | |
181 | 1 | return []; |
182 | } | |
183 | 2 | return new Liquid.Range(lo, hi + 1); |
184 | }); | |
185 | } else if (match = /^(\d[\d\.]+)$/.exec(key)) { | |
186 | 1 | return Number(match[1]); |
187 | } else { | |
188 | 189 | return this.variable(key); |
189 | } | |
190 | }; | |
191 | ||
192 | 1 | Context.prototype.findVariable = function(key) { |
193 | 192 | var variable, variableScope; |
194 | 192 | variableScope = void 0; |
195 | 192 | variable = void 0; |
196 | 192 | this.scopes.some(function(scope) { |
197 | if (scope.hasOwnProperty(key)) { | |
198 | 98 | variableScope = scope; |
199 | 98 | return true; |
200 | } | |
201 | }); | |
202 | if (variableScope == null) { | |
203 | 94 | this.environments.some((function(_this) { |
204 | 94 | return function(env) { |
205 | 96 | variable = _this.lookupAndEvaluate(env, key); |
206 | if (variable != null) { | |
207 | 84 | return variableScope = env; |
208 | } | |
209 | }; | |
210 | })(this)); | |
211 | } | |
212 | if (variableScope == null) { | |
213 | if (this.environments.length > 0) { | |
214 | 10 | variableScope = this.environments[this.environments.length - 1]; |
215 | } else if (this.scopes.length > 0) { | |
216 | 0 | variableScope = this.scopes[this.scopes.length - 1]; |
217 | } else { | |
218 | 0 | throw new Error("No scopes to find variable in."); |
219 | } | |
220 | } | |
221 | if (variable == null) { | |
222 | 108 | variable = this.lookupAndEvaluate(variableScope, key); |
223 | } | |
224 | 192 | return Promise.cast(variable).then((function(_this) { |
225 | 192 | return function(v) { |
226 | 192 | return _this.liquify(v); |
227 | }; | |
228 | })(this)); | |
229 | }; | |
230 | ||
231 | 1 | Context.prototype.variable = function(markup) { |
232 | 192 | return Promise["try"]((function(_this) { |
233 | 192 | return function() { |
234 | 192 | var firstPart, iterator, mapper, match, object, parts, squareBracketed; |
235 | 192 | parts = Liquid.Helpers.scan(markup, Liquid.VariableParser); |
236 | 192 | squareBracketed = /^\[(.*)\]$/; |
237 | 192 | firstPart = parts.shift(); |
238 | if (match = squareBracketed.exec(firstPart)) { | |
239 | 0 | firstPart = match[1]; |
240 | } | |
241 | 192 | object = _this.findVariable(firstPart); |
242 | if (parts.length === 0) { | |
243 | 134 | return object; |
244 | } | |
245 | 58 | mapper = function(part, object) { |
246 | if (object == null) { | |
247 | 0 | return Promise.cast(object); |
248 | } | |
249 | 58 | return Promise.cast(object).then(_this.liquify.bind(_this)).then(function(object) { |
250 | 58 | var bracketMatch; |
251 | if (object == null) { | |
252 | 0 | return object; |
253 | } | |
254 | 58 | bracketMatch = squareBracketed.exec(part); |
255 | if (bracketMatch) { | |
256 | 3 | part = _this.resolve(bracketMatch[1]); |
257 | } | |
258 | 58 | return Promise.cast(part).then(function(part) { |
259 | 58 | var isArrayAccess, isObjectAccess, isSpecialAccess; |
260 | 58 | isArrayAccess = Array.isArray(object) && isFinite(part); |
261 | 58 | isObjectAccess = object instanceof Object && ((typeof object.hasKey === "function" ? object.hasKey(part) : void 0) || part in object); |
262 | 58 | isSpecialAccess = !bracketMatch && object && (Array.isArray(object) || Object.prototype.toString.call(object) === "[object String]") && ["size", "first", "last"].indexOf(part) >= 0; |
263 | if (isArrayAccess || isObjectAccess) { | |
264 | 55 | return Promise.cast(_this.lookupAndEvaluate(object, part)).then(_this.liquify.bind(_this)); |
265 | } else if (isSpecialAccess) { | |
266 | switch (part) { | |
267 | case "size": | |
268 | 1 | return _this.liquify(object.length); |
269 | case "first": | |
270 | 1 | return _this.liquify(object[0]); |
271 | case "last": | |
272 | 1 | return _this.liquify(object[object.length - 1]); |
273 | default: | |
274 | ||
275 | /* @covignore */ | |
276 | throw new Error("Unknown special accessor: " + part); | |
277 | } | |
278 | } else { | |
279 | ||
280 | /* @covignore */ | |
281 | throw new Error("Unknown access: " + part); | |
282 | } | |
283 | }); | |
284 | }); | |
285 | }; | |
286 | 58 | iterator = function(object, index) { |
287 | if (index < parts.length) { | |
288 | 58 | return mapper(parts[index], object).then(function(object) { |
289 | 58 | return iterator(object, index + 1); |
290 | }); | |
291 | } else { | |
292 | 58 | return Promise.cast(object); |
293 | } | |
294 | }; | |
295 | 58 | return iterator(object, 0).then(null, function(err) { |
296 | 0 | throw new Error("Couldn't walk variable: " + markup + ": " + err); |
297 | }); | |
298 | }; | |
299 | })(this)); | |
300 | }; | |
301 | ||
302 | 1 | Context.prototype.lookupAndEvaluate = function(obj, key) { |
303 | if (obj instanceof Liquid.Drop) { | |
304 | 4 | return obj.get(key); |
305 | } else { | |
306 | 255 | return obj != null ? obj[key] : void 0; |
307 | } | |
308 | }; | |
309 | ||
310 | 1 | Context.prototype.squashInstanceAssignsWithEnvironments = function() { |
311 | 113 | var lastScope; |
312 | 113 | lastScope = this.lastScope(); |
313 | 113 | return Object.keys(lastScope).forEach((function(_this) { |
314 | 113 | return function(key) { |
315 | 0 | return _this.environments.some(function(env) { |
316 | if (env.hasOwnProperty(key)) { | |
317 | 0 | lastScope[key] = _this.lookupAndEvaluate(env, key); |
318 | 0 | return true; |
319 | } | |
320 | }); | |
321 | }; | |
322 | })(this)); | |
323 | }; | |
324 | ||
325 | 1 | Context.prototype.liquify = function(object) { |
326 | 308 | return Promise.cast(object).then((function(_this) { |
327 | 308 | return function(object) { |
328 | if (object == null) { | |
329 | 11 | return object; |
330 | } else if (typeof object.toLiquid === "function") { | |
331 | 9 | object = object.toLiquid(); |
332 | } else if (typeof object === "object") { | |
333 | 139 | true; |
334 | } else if (typeof object === "function") { | |
335 | 1 | object = ""; |
336 | } else { | |
337 | 148 | Object.prototype.toString.call(object); |
338 | } | |
339 | if (object instanceof Liquid.Drop) { | |
340 | 9 | object.context = _this; |
341 | } | |
342 | 297 | return object; |
343 | }; | |
344 | })(this)); | |
345 | }; | |
346 | ||
347 | 1 | return Context; |
348 | ||
349 | })(); | |
350 | ||
351 | }).call(this); | |
352 | ||
353 | //# sourceMappingURL=context.map | |
354 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Liquid, |
4 | __hasProp = {}.hasOwnProperty, | |
5 | 5 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
6 | ||
7 | 1 | Liquid = require("../liquid"); |
8 | ||
9 | 1 | module.exports = Liquid.Document = (function(_super) { |
10 | 1 | __extends(Document, _super); |
11 | ||
12 | function Document(template) { | |
13 | 111 | this.template = template; |
14 | } | |
15 | ||
16 | 1 | Document.prototype.blockDelimiter = function() { |
17 | 91 | return []; |
18 | }; | |
19 | ||
20 | 1 | Document.prototype.assertMissingDelimitation = function() {}; |
21 | ||
22 | 1 | return Document; |
23 | ||
24 | })(Liquid.Block); | |
25 | ||
26 | }).call(this); | |
27 | ||
28 | //# sourceMappingURL=document.map | |
29 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Drop; |
4 | ||
5 | 1 | module.exports = Drop = (function() { |
6 | function Drop() {} | |
7 | ||
8 | 1 | Drop.prototype.context = null; |
9 | ||
10 | 1 | Drop.prototype.hasKey = function(key) { |
11 | 4 | return true; |
12 | }; | |
13 | ||
14 | 1 | Drop.prototype.invokeDrop = function(methodOrKey) { |
15 | 4 | var value; |
16 | if (this.constructor.isInvokable(methodOrKey)) { | |
17 | 2 | value = this[methodOrKey]; |
18 | if (typeof value === "function") { | |
19 | 1 | return value.call(this); |
20 | } else { | |
21 | 1 | return value; |
22 | } | |
23 | } else { | |
24 | 2 | return this.beforeMethod(methodOrKey); |
25 | } | |
26 | }; | |
27 | ||
28 | 1 | Drop.prototype.beforeMethod = function(method) {}; |
29 | ||
30 | 1 | Drop.isInvokable = function(method) { |
31 | if (this.invokableMethods == null) { | |
32 | 3 | this.invokableMethods = (function(_this) { |
33 | 3 | return function() { |
34 | 3 | var blacklist, whitelist; |
35 | 3 | blacklist = Object.keys(Drop.prototype); |
36 | 3 | whitelist = ["toLiquid"]; |
37 | 3 | Object.keys(_this.prototype).forEach(function(k) { |
38 | if (!(blacklist.indexOf(k) >= 0)) { | |
39 | 9 | return whitelist.push(k); |
40 | } | |
41 | }); | |
42 | 3 | return whitelist; |
43 | }; | |
44 | })(this)(); | |
45 | } | |
46 | 11 | return this.invokableMethods.indexOf(method) >= 0; |
47 | }; | |
48 | ||
49 | 1 | Drop.prototype.get = function(methodOrKey) { |
50 | 4 | return this.invokeDrop(methodOrKey); |
51 | }; | |
52 | ||
53 | 1 | Drop.prototype.toLiquid = function() { |
54 | 9 | return this; |
55 | }; | |
56 | ||
57 | 1 | Drop.prototype.toString = function() { |
58 | 1 | return "[Liquid.Drop " + this.constructor.name + "]"; |
59 | }; | |
60 | ||
61 | 1 | return Drop; |
62 | ||
63 | })(); | |
64 | ||
65 | }).call(this); | |
66 | ||
67 | //# sourceMappingURL=drop.map | |
68 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var ElseCondition, Liquid, |
4 | __hasProp = {}.hasOwnProperty, | |
5 | 5 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
6 | ||
7 | 1 | Liquid = require("../liquid"); |
8 | ||
9 | 1 | module.exports = ElseCondition = (function(_super) { |
10 | 1 | __extends(ElseCondition, _super); |
11 | ||
12 | function ElseCondition() { | |
13 | 5 | return ElseCondition.__super__.constructor.apply(this, arguments); |
14 | } | |
15 | ||
16 | 1 | ElseCondition.prototype.evaluate = function() { |
17 | 2 | return true; |
18 | }; | |
19 | ||
20 | 1 | return ElseCondition; |
21 | ||
22 | })(Liquid.Condition); | |
23 | ||
24 | }).call(this); | |
25 | ||
26 | //# sourceMappingURL=else_condition.map | |
27 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Liquid, Promise, |
4 | __hasProp = {}.hasOwnProperty, | |
5 | __slice = [].slice; | |
6 | ||
7 | 1 | Liquid = require("../liquid"); |
8 | ||
9 | 1 | Promise = require("bluebird"); |
10 | ||
11 | 1 | module.exports = Liquid.Engine = (function() { |
12 | function Engine() { | |
13 | 115 | var isBlockOrTagBaseClass, isSubclassOf, tag, tagName; |
14 | 115 | this.tags = {}; |
15 | 115 | this.Strainer = function(context) { |
16 | 97 | this.context = context; |
17 | }; | |
18 | 115 | this.registerFilters(Liquid.StandardFilters); |
19 | 115 | isSubclassOf = function(klass, ofKlass) { |
20 | 10925 | var _ref; |
21 | if (typeof klass !== 'function') { | |
22 | 4830 | return false; |
23 | } else if (klass === ofKlass) { | |
24 | 1495 | return true; |
25 | } else { | |
26 | 4600 | return isSubclassOf((_ref = klass.__super__) != null ? _ref.constructor : void 0, ofKlass); |
27 | } | |
28 | }; | |
29 | for (tagName in Liquid) { | |
30 | if (!__hasProp.call(Liquid, tagName)) continue; | |
31 | 6325 | tag = Liquid[tagName]; |
32 | if (!isSubclassOf(tag, Liquid.Tag)) { | |
33 | 4830 | continue; |
34 | } | |
35 | 1495 | isBlockOrTagBaseClass = [Liquid.Tag, Liquid.Block].indexOf(tag.constructor) >= 0; |
36 | if (!isBlockOrTagBaseClass) { | |
37 | 1495 | this.registerTag(tagName.toLowerCase(), tag); |
38 | } | |
39 | } | |
40 | } | |
41 | ||
42 | 1 | Engine.prototype.registerTag = function(name, tag) { |
43 | 1495 | return this.tags[name] = tag; |
44 | }; | |
45 | ||
46 | 1 | Engine.prototype.registerFilters = function() { |
47 | 117 | var filters; |
48 | 117 | filters = 1 <= arguments.length ? __slice.call(arguments, 0) : []; |
49 | 117 | return filters.forEach((function(_this) { |
50 | 117 | return function(filter) { |
51 | 117 | var k, v, _results; |
52 | 117 | _results = []; |
53 | for (k in filter) { | |
54 | if (!__hasProp.call(filter, k)) continue; | |
55 | 3682 | v = filter[k]; |
56 | if (v instanceof Function) { | |
57 | 3682 | _results.push(_this.Strainer.prototype[k] = v); |
58 | } else { | |
59 | 0 | _results.push(void 0); |
60 | } | |
61 | } | |
62 | 117 | return _results; |
63 | }; | |
64 | })(this)); | |
65 | }; | |
66 | ||
67 | 1 | Engine.prototype.parse = function(source) { |
68 | 111 | var template; |
69 | 111 | template = new Liquid.Template; |
70 | 111 | return template.parse(this, source); |
71 | }; | |
72 | ||
73 | 1 | Engine.prototype.parseAndRender = function() { |
74 | 1 | var args, source; |
75 | 1 | source = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; |
76 | 1 | return this.parse(source).then(function(template) { |
77 | 1 | return template.render.apply(template, args); |
78 | }); | |
79 | }; | |
80 | ||
81 | 1 | return Engine; |
82 | ||
83 | })(); | |
84 | ||
85 | }).call(this); | |
86 | ||
87 | //# sourceMappingURL=engine.map | |
88 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | module.exports = { |
4 | flatten: function(array) { | |
5 | 252 | var output, _flatten; |
6 | 252 | output = []; |
7 | 252 | _flatten = function(array) { |
8 | 489 | return array.forEach(function(item) { |
9 | if (Array.isArray(item)) { | |
10 | 237 | return _flatten(item); |
11 | } else { | |
12 | 445 | return output.push(item); |
13 | } | |
14 | }); | |
15 | }; | |
16 | 252 | _flatten(array); |
17 | 252 | return output; |
18 | }, | |
19 | toFlatString: function(array) { | |
20 | 110 | return this.flatten(array).join(""); |
21 | }, | |
22 | scan: function(string, regexp, globalMatch) { | |
23 | 305 | var result, _scan; |
24 | if (globalMatch == null) { | |
25 | 305 | globalMatch = false; |
26 | } | |
27 | 305 | result = []; |
28 | 305 | _scan = function(s) { |
29 | 402 | var l, match; |
30 | 402 | match = regexp.exec(s); |
31 | if (match) { | |
32 | if (match.length === 1) { | |
33 | 340 | result.push(match[0]); |
34 | } else { | |
35 | 23 | result.push(match.slice(1)); |
36 | } | |
37 | 363 | l = match[0].length; |
38 | if (globalMatch) { | |
39 | 0 | l = 1; |
40 | } | |
41 | if (match.index + l < s.length) { | |
42 | 97 | return _scan(s.substring(match.index + l)); |
43 | } | |
44 | } | |
45 | }; | |
46 | 305 | _scan(string); |
47 | 305 | return result; |
48 | } | |
49 | }; | |
50 | ||
51 | }).call(this); | |
52 | ||
53 | //# sourceMappingURL=helpers.map | |
54 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Iterable, IterableForArray, Promise, Range, isString, |
4 | __hasProp = {}.hasOwnProperty, | |
5 | 5 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
6 | ||
7 | 1 | Range = require("./range"); |
8 | ||
9 | 1 | Promise = require("bluebird"); |
10 | ||
11 | 1 | isString = function(input) { |
12 | 6 | return Object.prototype.toString.call(input) === "[object String]"; |
13 | }; | |
14 | ||
15 | 1 | module.exports = Iterable = (function() { |
16 | function Iterable() {} | |
17 | ||
18 | 1 | Iterable.prototype.first = function() { |
19 | 5 | return this.slice(0, 1).then(function(a) { |
20 | 5 | return a[0]; |
21 | }); | |
22 | }; | |
23 | ||
24 | 1 | Iterable.prototype.map = function() { |
25 | 3 | var _ref; |
26 | 3 | return (_ref = this.toArray()).map.apply(_ref, arguments); |
27 | }; | |
28 | ||
29 | 1 | Iterable.prototype.sort = function() { |
30 | 2 | var args; |
31 | 2 | args = arguments; |
32 | 2 | return this.toArray().then(function(a) { |
33 | 2 | return a.sort.apply(a, args); |
34 | }); | |
35 | }; | |
36 | ||
37 | 1 | Iterable.prototype.toArray = function() { |
38 | 14 | return this.slice(0); |
39 | }; | |
40 | ||
41 | 1 | Iterable.prototype.slice = function() { |
42 | 1 | throw new Error("" + this.constructor.name + ".slice() not implemented"); |
43 | }; | |
44 | ||
45 | 1 | Iterable.prototype.last = function() { |
46 | 1 | throw new Error("" + this.constructor.name + ".last() not implemented"); |
47 | }; | |
48 | ||
49 | 1 | Iterable.cast = function(v) { |
50 | if (v instanceof Iterable) { | |
51 | 1 | return v; |
52 | } else if (v instanceof Range) { | |
53 | 5 | return new IterableForArray(v.toArray()); |
54 | } else if (Array.isArray(v) || isString(v)) { | |
55 | 39 | return new IterableForArray(v); |
56 | } else if (v != null) { | |
57 | 3 | return new IterableForArray([v]); |
58 | } else { | |
59 | 1 | return new IterableForArray([]); |
60 | } | |
61 | }; | |
62 | ||
63 | 1 | return Iterable; |
64 | ||
65 | })(); | |
66 | ||
67 | 1 | IterableForArray = (function(_super) { |
68 | 1 | __extends(IterableForArray, _super); |
69 | ||
70 | function IterableForArray(array) { | |
71 | 48 | this.array = array; |
72 | } | |
73 | ||
74 | 1 | IterableForArray.prototype.slice = function() { |
75 | 43 | var _ref; |
76 | 43 | return Promise.cast((_ref = this.array).slice.apply(_ref, arguments)); |
77 | }; | |
78 | ||
79 | 1 | IterableForArray.prototype.last = function() { |
80 | 5 | return Promise.cast(this.array[this.array.length - 1]); |
81 | }; | |
82 | ||
83 | 1 | return IterableForArray; |
84 | ||
85 | })(Iterable); | |
86 | ||
87 | }).call(this); | |
88 | ||
89 | //# sourceMappingURL=iterable.map | |
90 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var Range; |
4 | ||
5 | 1 | module.exports = Range = (function() { |
6 | function Range(start, end, step) { | |
7 | 19 | this.start = start; |
8 | 19 | this.end = end; |
9 | 19 | this.step = step != null ? step : 0; |
10 | if (this.step === 0) { | |
11 | if (this.end < this.start) { | |
12 | 3 | this.step = -1; |
13 | } else { | |
14 | 13 | this.step = 1; |
15 | } | |
16 | } | |
17 | 19 | Object.seal(this); |
18 | } | |
19 | ||
20 | 1 | Range.prototype.some = function(f) { |
21 | 16 | var current, end, step; |
22 | 16 | current = this.start; |
23 | 16 | end = this.end; |
24 | 16 | step = this.step; |
25 | if (step > 0) { | |
26 | while (current < end) { | |
27 | if (f(current)) { | |
28 | 1 | return true; |
29 | } | |
30 | 2026 | current += step; |
31 | } | |
32 | } else { | |
33 | while (current > end) { | |
34 | if (f(current)) { | |
35 | 1 | return true; |
36 | } | |
37 | 11 | current += step; |
38 | } | |
39 | } | |
40 | 14 | return false; |
41 | }; | |
42 | ||
43 | 1 | Range.prototype.forEach = function(f) { |
44 | 12 | return this.some(function(e) { |
45 | 2025 | f(e); |
46 | 2025 | return false; |
47 | }); | |
48 | }; | |
49 | ||
50 | 1 | Range.prototype.toArray = function() { |
51 | 12 | var array; |
52 | 12 | array = []; |
53 | 12 | this.forEach(function(e) { |
54 | 2025 | return array.push(e); |
55 | }); | |
56 | 12 | return array; |
57 | }; | |
58 | ||
59 | 1 | return Range; |
60 | ||
61 | })(); | |
62 | ||
63 | 1 | Object.defineProperty(Range.prototype, "length", { |
64 | get: function() { | |
65 | 3 | return Math.floor((this.end - this.start) / this.step); |
66 | } | |
67 | }); | |
68 | ||
69 | }).call(this); | |
70 | ||
71 | //# sourceMappingURL=range.map | |
72 |
Line | Hits | Source |
---|---|---|
1 | // Generated by CoffeeScript 1.7.1 | |
2 | 1 | (function() { |
3 | 1 | var HTML_ESCAPE, HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE_REGEXP, Iterable, Promise, isNumber, isString, strftime, toDate, toIterable, toNumber, toObjectString, toString; |
4 | ||
5 | 1 | strftime = require("strftime"); |
6 | ||
7 | 1 | Promise = require("bluebird"); |
8 | ||
9 | 1 | Iterable = require("./iterable"); |
10 | ||
11 | 1 | toNumber = function(input) { |
12 | 22 | return Number(input); |
13 | }; | |
14 | ||
15 | 1 | toObjectString = Object.prototype.toString; |
16 | ||
17 | 1 | isString = function(input) { |
18 | 356 | return toObjectString.call(input) === "[object String]"; |
19 | }; | |
20 | ||
21 | 1 | isNumber = function(input) { |
22 | 203 | return !Array.isArray(input) && (input - parseFloat(input)) >= 0; |
23 | }; | |
24 | ||
25 | 1 | toString = function(input) { |
26 | if (input == null) { | |
27 | 163 | return ""; |
28 | } else if (isString(input)) { | |
29 | 223 | return input; |
30 | } else if (typeof input.toString === "function") { | |
31 | 132 | return toString(input.toString()); |
32 | } else { | |
33 | 1 | return toObjectString.call(input); |
34 | } | |
35 | }; | |
36 | ||
37 | 1 | toIterable = function(input) { |
38 | 23 | return Iterable.cast(input); |
39 | }; | |
40 | ||
41 | 1 | toDate = function(input) { |
42 | if (input == null) { | |
43 | 66 | return; |
44 | } | |
45 | if (input instanceof Date) { | |
46 | 3 | return input; |
47 | } | |
48 | if (isNumber(input)) { | |
49 | 34 | input = parseInt(input); |
50 | } else { | |
51 | 169 | input = toString(input); |
52 | if (input.length === 0) { | |
53 | 32 | return; |
54 | } | |
55 | 137 | input = Date.parse(input); |
56 | } | |
57 | if (input != null) { | |
58 | 171 | return new Date(input); |
59 | } | |
60 | }; | |
61 | ||
62 | 1 | HTML_ESCAPE = function(chr) { |
63 | switch (chr) { | |
64 | case "&": | |
65 | 0 | return '&'; |
66 | case ">": | |
67 | 2 | return '>'; |
68 | case "<": | |
69 | 2 | return '<'; |
70 | case '"': | |
71 | 0 | return '"'; |
72 | case "'": | |
73 | 0 | return '''; |
74 | } | |
75 | }; | |
76 | ||
77 | 1 | HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/g; |
78 | ||
79 | 1 | HTML_ESCAPE_REGEXP = /([&><"'])/g; |
80 | ||
81 | 1 | module.exports = { |
82 | size: function(input) { | |
83 | 8 | var _ref; |
84 | 8 | return (_ref = input != null ? input.length : void 0) != null ? _ref : 0; |
85 | }, | |
86 | downcase: function(input) { | |
87 | 2 | return toString(input).toLowerCase(); |
88 | }, | |
89 | upcase: function(input) { | |
90 | 5 | return toString(input).toUpperCase(); |
91 | }, | |
92 | append: function(input, suffix) { | |
93 | 1 | return toString(input) + toString(suffix); |
94 | }, | |
95 | prepend: function(input, prefix) { | |
96 | 1 | return toString(prefix) + toString(input); |
97 | }, | |
98 | empty: function(input) { | |
99 | if (!input) { | |
100 | 0 | return true; |
101 | } | |
102 | if (input.length == null) { | |
103 | 0 | return false; |
104 | } | |
105 | 0 | return true; |
106 | }, | |
107 | capitalize: function(input) { | |
108 | 1 | return toString(input).replace(/^([a-z])/, function(m, chr) { |
109 | 1 | return chr.toUpperCase(); |
110 | }); | |
111 | }, | |
112 | sort: function(input, property) { | |
113 | if (property == null) { | |
114 | 2 | return toIterable(input).sort(); |
115 | } | |
116 | 2 | return toIterable(input).map(function(item) { |
117 | 6 | return Promise.cast(item != null ? item[property] : void 0).then(function(key) { |
118 | 6 | return { |
119 | key: key, | |
120 | item: item | |
121 | }; | |
122 | }); | |
123 | }).then(function(array) { | |
124 | 2 | return array.sort(function(a, b) { |
125 | 5 | var _ref, _ref1; |
126 | 5 | return (_ref = a.key > b.key) != null ? _ref : { |
127 | 1: (_ref1 = a.key === b.key) != null ? _ref1 : { | |
128 | 0: -1 | |
129 | } | |
130 | }; | |
131 | }).map(function(a) { | |
132 | 6 | return a.item; |
133 | }); | |
134 | }); | |
135 | }, | |
136 | map: function(input, property) { | |
137 | if (property == null) { | |
138 | 1 | return input; |
139 | } | |
140 | 1 | return toIterable(input).map(function(e) { |
141 | 3 | return e != null ? e[property] : void 0; |
142 | }); | |
143 | }, | |
144 | escape: function(input) { | |
145 | 1 | return toString(input).replace(HTML_ESCAPE_REGEXP, HTML_ESCAPE); |
146 | }, | |
147 | escape_once: function(input) { | |
148 | 1 | return toString(input).replace(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE); |
149 | }, | |
150 | strip_html: function(input) { | |
151 | 5 | return toString(input).replace(/ |