pug-ruby 1.0.2 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rubocop.yml +81 -0
- data/.travis.yml +17 -8
- data/.yardopts +4 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +32 -0
- data/LICENSE +21 -0
- data/README.md +256 -24
- data/Rakefile +74 -8
- data/lib/jade-pug/base.rb +178 -0
- data/lib/jade-pug/compiler.rb +166 -0
- data/lib/jade-pug/config.rb +60 -0
- data/lib/jade-pug/errors/compilation-error.rb +14 -0
- data/lib/jade-pug/errors/compiler-error.rb +13 -0
- data/lib/jade-pug/shipped-compiler.rb +80 -0
- data/lib/jade-pug/system-compiler.rb +139 -0
- data/lib/jade-ruby/compilation-essentials.rb +24 -0
- data/lib/jade-ruby/config.rb +17 -44
- data/lib/jade-ruby/errors/compilation-error.rb +14 -0
- data/lib/jade-ruby/errors/compiler-error.rb +13 -0
- data/lib/jade-ruby/shipped-compiler.rb +15 -0
- data/lib/jade-ruby/system-compiler.rb +15 -0
- data/lib/pug-ruby.rb +46 -5
- data/lib/pug-ruby/compilation-essentials.rb +29 -0
- data/lib/pug-ruby/config.rb +11 -37
- data/lib/pug-ruby/errors/compilation-error.rb +14 -0
- data/lib/pug-ruby/errors/compiler-error.rb +13 -0
- data/lib/pug-ruby/shipped-compiler.rb +15 -0
- data/lib/pug-ruby/system-compiler.rb +15 -0
- data/lib/pug-ruby/version.rb +7 -0
- data/package.json +11 -0
- data/pug-ruby.gemspec +19 -12
- data/support/browserify-jade-runtime.js +19 -0
- data/support/browserify-jade.js +17 -0
- data/support/browserify-pug-runtime.js +19 -0
- data/support/browserify-pug.js +23 -0
- data/support/minify-jade.js +11 -0
- data/support/minify-pug.js +11 -0
- data/test/helper.rb +202 -0
- data/test/jade/includes/includes/footer.jade +1 -1
- data/test/manual.html +21 -0
- data/test/manual.rb +25 -0
- data/test/pug/includes/includes/footer.pug +1 -1
- data/test/pug/index.pug +3 -3
- data/test/test-jade.rb +3 -67
- data/test/test-pug.rb +3 -67
- data/vendor/jade-1.0.0.min.js +1 -0
- data/vendor/jade-1.0.1.min.js +1 -0
- data/vendor/jade-1.0.2.min.js +1 -0
- data/vendor/jade-1.1.0.min.js +1 -0
- data/vendor/jade-1.1.1.min.js +1 -0
- data/vendor/jade-1.1.2.min.js +1 -0
- data/vendor/jade-1.1.3.min.js +1 -0
- data/vendor/jade-1.1.4.min.js +1 -0
- data/vendor/jade-1.1.5.min.js +1 -0
- data/vendor/jade-1.10.0.min.js +1 -0
- data/vendor/jade-1.11.0.min.js +1 -0
- data/vendor/jade-1.2.0.min.js +1 -0
- data/vendor/jade-1.3.0.min.js +1 -0
- data/vendor/jade-1.3.1.min.js +1 -0
- data/vendor/jade-1.4.0.min.js +1 -0
- data/vendor/jade-1.4.1.min.js +1 -0
- data/vendor/jade-1.4.2.min.js +1 -0
- data/vendor/jade-1.5.0.min.js +1 -0
- data/vendor/jade-1.6.0.min.js +1 -0
- data/vendor/jade-1.7.0.min.js +1 -0
- data/vendor/jade-1.8.0.min.js +1 -0
- data/vendor/jade-1.8.1.min.js +1 -0
- data/vendor/jade-1.8.2.min.js +1 -0
- data/vendor/jade-1.9.0.min.js +1 -0
- data/vendor/jade-1.9.1.min.js +1 -0
- data/vendor/jade-1.9.2.min.js +1 -0
- data/vendor/jade-runtime-1.0.0-license +22 -0
- data/vendor/jade-runtime-1.0.0.js +199 -0
- data/vendor/jade-runtime-1.0.1-license +22 -0
- data/vendor/jade-runtime-1.0.1.js +199 -0
- data/vendor/jade-runtime-1.0.2-license +22 -0
- data/vendor/jade-runtime-1.0.2.js +199 -0
- data/vendor/jade-runtime-1.1.0-license +22 -0
- data/vendor/jade-runtime-1.1.0.js +199 -0
- data/vendor/jade-runtime-1.1.1-license +22 -0
- data/vendor/jade-runtime-1.1.1.js +199 -0
- data/vendor/jade-runtime-1.1.2-license +22 -0
- data/vendor/jade-runtime-1.1.2.js +200 -0
- data/vendor/jade-runtime-1.1.3-license +22 -0
- data/vendor/jade-runtime-1.1.3.js +200 -0
- data/vendor/jade-runtime-1.1.4-license +22 -0
- data/vendor/jade-runtime-1.1.4.js +200 -0
- data/vendor/jade-runtime-1.1.5-license +22 -0
- data/vendor/jade-runtime-1.1.5.js +200 -0
- data/vendor/jade-runtime-1.10.0-license +22 -0
- data/vendor/jade-runtime-1.10.0.js +233 -0
- data/vendor/jade-runtime-1.11.0-license +22 -0
- data/vendor/jade-runtime-1.11.0.js +246 -0
- data/vendor/jade-runtime-1.2.0-license +22 -0
- data/vendor/jade-runtime-1.2.0.js +200 -0
- data/vendor/jade-runtime-1.3.0-license +22 -0
- data/vendor/jade-runtime-1.3.0.js +200 -0
- data/vendor/jade-runtime-1.3.1-license +22 -0
- data/vendor/jade-runtime-1.3.1.js +200 -0
- data/vendor/jade-runtime-1.4.0-license +22 -0
- data/vendor/jade-runtime-1.4.0.js +200 -0
- data/vendor/jade-runtime-1.4.1-license +22 -0
- data/vendor/jade-runtime-1.4.1.js +200 -0
- data/vendor/jade-runtime-1.4.2-license +22 -0
- data/vendor/jade-runtime-1.4.2.js +200 -0
- data/vendor/jade-runtime-1.5.0-license +22 -0
- data/vendor/jade-runtime-1.5.0.js +200 -0
- data/vendor/jade-runtime-1.6.0-license +22 -0
- data/vendor/jade-runtime-1.6.0.js +200 -0
- data/vendor/jade-runtime-1.7.0-license +22 -0
- data/vendor/jade-runtime-1.7.0.js +200 -0
- data/vendor/jade-runtime-1.8.0-license +22 -0
- data/vendor/jade-runtime-1.8.0.js +228 -0
- data/vendor/jade-runtime-1.8.1-license +22 -0
- data/vendor/jade-runtime-1.8.1.js +228 -0
- data/vendor/jade-runtime-1.8.2-license +22 -0
- data/vendor/jade-runtime-1.8.2.js +228 -0
- data/vendor/jade-runtime-1.9.0-license +22 -0
- data/vendor/jade-runtime-1.9.0.js +228 -0
- data/vendor/jade-runtime-1.9.1-license +22 -0
- data/vendor/jade-runtime-1.9.1.js +228 -0
- data/vendor/jade-runtime-1.9.2-license +22 -0
- data/vendor/jade-runtime-1.9.2.js +228 -0
- data/vendor/pug-2.0.0-beta.12-license +22 -0
- data/vendor/pug-2.0.0-beta.12.min.js +1 -0
- data/vendor/pug-2.0.0-beta1-license +22 -0
- data/vendor/pug-2.0.0-beta1.min.js +1 -0
- data/vendor/pug-2.0.0-beta10-license +22 -0
- data/vendor/pug-2.0.0-beta10.min.js +1 -0
- data/vendor/pug-2.0.0-beta11-license +22 -0
- data/vendor/pug-2.0.0-beta11.min.js +1 -0
- data/vendor/pug-2.0.0-beta2-license +22 -0
- data/vendor/pug-2.0.0-beta2.min.js +1 -0
- data/vendor/pug-2.0.0-beta3-license +22 -0
- data/vendor/pug-2.0.0-beta3.min.js +1 -0
- data/vendor/pug-2.0.0-beta4-license +22 -0
- data/vendor/pug-2.0.0-beta4.min.js +1 -0
- data/vendor/pug-2.0.0-beta5-license +22 -0
- data/vendor/pug-2.0.0-beta5.min.js +1 -0
- data/vendor/pug-2.0.0-beta6-license +22 -0
- data/vendor/pug-2.0.0-beta6.min.js +1 -0
- data/vendor/pug-2.0.0-beta7-license +22 -0
- data/vendor/pug-2.0.0-beta7.min.js +1 -0
- data/vendor/pug-2.0.0-beta8-license +22 -0
- data/vendor/pug-2.0.0-beta8.min.js +1 -0
- data/vendor/pug-2.0.0-beta9-license +22 -0
- data/vendor/pug-2.0.0-beta9.min.js +1 -0
- data/vendor/pug-2.0.0-rc.1-license +22 -0
- data/vendor/pug-2.0.0-rc.1.min.js +1 -0
- data/vendor/pug-2.0.0-rc.2-license +22 -0
- data/vendor/pug-2.0.0-rc.2.min.js +1 -0
- data/vendor/pug-2.0.0-rc.3-license +22 -0
- data/vendor/pug-2.0.0-rc.3.min.js +1 -0
- data/vendor/pug-runtime-2.0.0-license +19 -0
- data/vendor/pug-runtime-2.0.0.js +266 -0
- data/vendor/pug-runtime-2.0.1-license +19 -0
- data/vendor/pug-runtime-2.0.1.js +266 -0
- data/vendor/pug-runtime-2.0.2-license +19 -0
- data/vendor/pug-runtime-2.0.2.js +267 -0
- metadata +242 -13
- data/lib/jade-ruby/compile.rb +0 -79
- data/lib/pug-ruby/compile.rb +0 -88
@@ -0,0 +1,200 @@
|
|
1
|
+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jade = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2
|
+
|
3
|
+
},{}],2:[function(require,module,exports){
|
4
|
+
'use strict';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Merge two attribute objects giving precedence
|
8
|
+
* to values in object `b`. Classes are special-cased
|
9
|
+
* allowing for arrays and merging/joining appropriately
|
10
|
+
* resulting in a string.
|
11
|
+
*
|
12
|
+
* @param {Object} a
|
13
|
+
* @param {Object} b
|
14
|
+
* @return {Object} a
|
15
|
+
* @api private
|
16
|
+
*/
|
17
|
+
|
18
|
+
exports.merge = function merge(a, b) {
|
19
|
+
if (arguments.length === 1) {
|
20
|
+
var attrs = a[0];
|
21
|
+
for (var i = 1; i < a.length; i++) {
|
22
|
+
attrs = merge(attrs, a[i]);
|
23
|
+
}
|
24
|
+
return attrs;
|
25
|
+
}
|
26
|
+
var ac = a['class'];
|
27
|
+
var bc = b['class'];
|
28
|
+
|
29
|
+
if (ac || bc) {
|
30
|
+
ac = ac || [];
|
31
|
+
bc = bc || [];
|
32
|
+
if (!Array.isArray(ac)) ac = [ac];
|
33
|
+
if (!Array.isArray(bc)) bc = [bc];
|
34
|
+
a['class'] = ac.concat(bc).filter(nulls);
|
35
|
+
}
|
36
|
+
|
37
|
+
for (var key in b) {
|
38
|
+
if (key != 'class') {
|
39
|
+
a[key] = b[key];
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
return a;
|
44
|
+
};
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Filter null `val`s.
|
48
|
+
*
|
49
|
+
* @param {*} val
|
50
|
+
* @return {Boolean}
|
51
|
+
* @api private
|
52
|
+
*/
|
53
|
+
|
54
|
+
function nulls(val) {
|
55
|
+
return val != null && val !== '';
|
56
|
+
}
|
57
|
+
|
58
|
+
/**
|
59
|
+
* join array as classes.
|
60
|
+
*
|
61
|
+
* @param {*} val
|
62
|
+
* @return {String}
|
63
|
+
*/
|
64
|
+
exports.joinClasses = joinClasses;
|
65
|
+
function joinClasses(val) {
|
66
|
+
return Array.isArray(val) ? val.map(joinClasses).filter(nulls).join(' ') : val;
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Render the given classes.
|
71
|
+
*
|
72
|
+
* @param {Array} classes
|
73
|
+
* @param {Array.<Boolean>} escaped
|
74
|
+
* @return {String}
|
75
|
+
*/
|
76
|
+
exports.cls = function cls(classes, escaped) {
|
77
|
+
var buf = [];
|
78
|
+
for (var i = 0; i < classes.length; i++) {
|
79
|
+
if (escaped && escaped[i]) {
|
80
|
+
buf.push(exports.escape(joinClasses([classes[i]])));
|
81
|
+
} else {
|
82
|
+
buf.push(joinClasses(classes[i]));
|
83
|
+
}
|
84
|
+
}
|
85
|
+
var text = joinClasses(buf);
|
86
|
+
if (text.length) {
|
87
|
+
return ' class="' + text + '"';
|
88
|
+
} else {
|
89
|
+
return '';
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Render the given attribute.
|
95
|
+
*
|
96
|
+
* @param {String} key
|
97
|
+
* @param {String} val
|
98
|
+
* @param {Boolean} escaped
|
99
|
+
* @param {Boolean} terse
|
100
|
+
* @return {String}
|
101
|
+
*/
|
102
|
+
exports.attr = function attr(key, val, escaped, terse) {
|
103
|
+
if ('boolean' == typeof val || null == val) {
|
104
|
+
if (val) {
|
105
|
+
return ' ' + (terse ? key : key + '="' + key + '"');
|
106
|
+
} else {
|
107
|
+
return '';
|
108
|
+
}
|
109
|
+
} else if (0 == key.indexOf('data') && 'string' != typeof val) {
|
110
|
+
return ' ' + key + "='" + JSON.stringify(val).replace(/'/g, ''') + "'";
|
111
|
+
} else if (escaped) {
|
112
|
+
return ' ' + key + '="' + exports.escape(val) + '"';
|
113
|
+
} else {
|
114
|
+
return ' ' + key + '="' + val + '"';
|
115
|
+
}
|
116
|
+
};
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Render the given attributes object.
|
120
|
+
*
|
121
|
+
* @param {Object} obj
|
122
|
+
* @param {Object} escaped
|
123
|
+
* @return {String}
|
124
|
+
*/
|
125
|
+
exports.attrs = function attrs(obj, terse) {
|
126
|
+
var buf = [];
|
127
|
+
|
128
|
+
var keys = Object.keys(obj);
|
129
|
+
|
130
|
+
if (keys.length) {
|
131
|
+
for (var i = 0; i < keys.length; ++i) {
|
132
|
+
var key = keys[i],
|
133
|
+
val = obj[key];
|
134
|
+
|
135
|
+
if ('class' == key) {
|
136
|
+
if (val = joinClasses(val)) {
|
137
|
+
buf.push(' ' + key + '="' + val + '"');
|
138
|
+
}
|
139
|
+
} else {
|
140
|
+
buf.push(exports.attr(key, val, false, terse));
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
return buf.join('');
|
146
|
+
};
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Escape the given string of `html`.
|
150
|
+
*
|
151
|
+
* @param {String} html
|
152
|
+
* @return {String}
|
153
|
+
* @api private
|
154
|
+
*/
|
155
|
+
|
156
|
+
exports.escape = function escape(html) {
|
157
|
+
var result = String(html).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
158
|
+
if (result === '' + html) return html;else return result;
|
159
|
+
};
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Re-throw the given `err` in context to the
|
163
|
+
* the jade in `filename` at the given `lineno`.
|
164
|
+
*
|
165
|
+
* @param {Error} err
|
166
|
+
* @param {String} filename
|
167
|
+
* @param {String} lineno
|
168
|
+
* @api private
|
169
|
+
*/
|
170
|
+
|
171
|
+
exports.rethrow = function rethrow(err, filename, lineno, str) {
|
172
|
+
if (!(err instanceof Error)) throw err;
|
173
|
+
if ((typeof window != 'undefined' || !filename) && !str) {
|
174
|
+
err.message += ' on line ' + lineno;
|
175
|
+
throw err;
|
176
|
+
}
|
177
|
+
try {
|
178
|
+
str = str || require('fs').readFileSync(filename, 'utf8');
|
179
|
+
} catch (ex) {
|
180
|
+
rethrow(err, null, lineno);
|
181
|
+
}
|
182
|
+
var context = 3,
|
183
|
+
lines = str.split('\n'),
|
184
|
+
start = Math.max(lineno - context, 0),
|
185
|
+
end = Math.min(lines.length, lineno + context);
|
186
|
+
|
187
|
+
// Error context
|
188
|
+
var context = lines.slice(start, end).map(function (line, i) {
|
189
|
+
var curr = i + start + 1;
|
190
|
+
return (curr == lineno ? ' > ' : ' ') + curr + '| ' + line;
|
191
|
+
}).join('\n');
|
192
|
+
|
193
|
+
// Alter exception message
|
194
|
+
err.path = filename;
|
195
|
+
err.message = (filename || 'Jade') + ':' + lineno + '\n' + context + '\n\n' + err.message;
|
196
|
+
throw err;
|
197
|
+
};
|
198
|
+
|
199
|
+
},{"fs":1}]},{},[2])(2)
|
200
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,228 @@
|
|
1
|
+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jade = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2
|
+
|
3
|
+
},{}],2:[function(require,module,exports){
|
4
|
+
'use strict';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Merge two attribute objects giving precedence
|
8
|
+
* to values in object `b`. Classes are special-cased
|
9
|
+
* allowing for arrays and merging/joining appropriately
|
10
|
+
* resulting in a string.
|
11
|
+
*
|
12
|
+
* @param {Object} a
|
13
|
+
* @param {Object} b
|
14
|
+
* @return {Object} a
|
15
|
+
* @api private
|
16
|
+
*/
|
17
|
+
|
18
|
+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
19
|
+
|
20
|
+
exports.merge = function merge(a, b) {
|
21
|
+
if (arguments.length === 1) {
|
22
|
+
var attrs = a[0];
|
23
|
+
for (var i = 1; i < a.length; i++) {
|
24
|
+
attrs = merge(attrs, a[i]);
|
25
|
+
}
|
26
|
+
return attrs;
|
27
|
+
}
|
28
|
+
var ac = a['class'];
|
29
|
+
var bc = b['class'];
|
30
|
+
|
31
|
+
if (ac || bc) {
|
32
|
+
ac = ac || [];
|
33
|
+
bc = bc || [];
|
34
|
+
if (!Array.isArray(ac)) ac = [ac];
|
35
|
+
if (!Array.isArray(bc)) bc = [bc];
|
36
|
+
a['class'] = ac.concat(bc).filter(nulls);
|
37
|
+
}
|
38
|
+
|
39
|
+
for (var key in b) {
|
40
|
+
if (key != 'class') {
|
41
|
+
a[key] = b[key];
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
return a;
|
46
|
+
};
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Filter null `val`s.
|
50
|
+
*
|
51
|
+
* @param {*} val
|
52
|
+
* @return {Boolean}
|
53
|
+
* @api private
|
54
|
+
*/
|
55
|
+
|
56
|
+
function nulls(val) {
|
57
|
+
return val != null && val !== '';
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* join array as classes.
|
62
|
+
*
|
63
|
+
* @param {*} val
|
64
|
+
* @return {String}
|
65
|
+
*/
|
66
|
+
exports.joinClasses = joinClasses;
|
67
|
+
function joinClasses(val) {
|
68
|
+
return (Array.isArray(val) ? val.map(joinClasses) : val && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' ? Object.keys(val).filter(function (key) {
|
69
|
+
return val[key];
|
70
|
+
}) : [val]).filter(nulls).join(' ');
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Render the given classes.
|
75
|
+
*
|
76
|
+
* @param {Array} classes
|
77
|
+
* @param {Array.<Boolean>} escaped
|
78
|
+
* @return {String}
|
79
|
+
*/
|
80
|
+
exports.cls = function cls(classes, escaped) {
|
81
|
+
var buf = [];
|
82
|
+
for (var i = 0; i < classes.length; i++) {
|
83
|
+
if (escaped && escaped[i]) {
|
84
|
+
buf.push(exports.escape(joinClasses([classes[i]])));
|
85
|
+
} else {
|
86
|
+
buf.push(joinClasses(classes[i]));
|
87
|
+
}
|
88
|
+
}
|
89
|
+
var text = joinClasses(buf);
|
90
|
+
if (text.length) {
|
91
|
+
return ' class="' + text + '"';
|
92
|
+
} else {
|
93
|
+
return '';
|
94
|
+
}
|
95
|
+
};
|
96
|
+
|
97
|
+
exports.style = function (val) {
|
98
|
+
if (val && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object') {
|
99
|
+
return Object.keys(val).map(function (style) {
|
100
|
+
return style + ':' + val[style];
|
101
|
+
}).join(';');
|
102
|
+
} else {
|
103
|
+
return val;
|
104
|
+
}
|
105
|
+
};
|
106
|
+
/**
|
107
|
+
* Render the given attribute.
|
108
|
+
*
|
109
|
+
* @param {String} key
|
110
|
+
* @param {String} val
|
111
|
+
* @param {Boolean} escaped
|
112
|
+
* @param {Boolean} terse
|
113
|
+
* @return {String}
|
114
|
+
*/
|
115
|
+
exports.attr = function attr(key, val, escaped, terse) {
|
116
|
+
if (key === 'style') {
|
117
|
+
val = exports.style(val);
|
118
|
+
}
|
119
|
+
if ('boolean' == typeof val || null == val) {
|
120
|
+
if (val) {
|
121
|
+
return ' ' + (terse ? key : key + '="' + key + '"');
|
122
|
+
} else {
|
123
|
+
return '';
|
124
|
+
}
|
125
|
+
} else if (0 == key.indexOf('data') && 'string' != typeof val) {
|
126
|
+
if (JSON.stringify(val).indexOf('&') !== -1) {
|
127
|
+
console.warn('Since Jade 2.0.0, ampersands (`&`) in data attributes ' + 'will be escaped to `&`');
|
128
|
+
};
|
129
|
+
if (val && typeof val.toISOString === 'function') {
|
130
|
+
console.warn('Jade will eliminate the double quotes around dates in ' + 'ISO form after 2.0.0');
|
131
|
+
}
|
132
|
+
return ' ' + key + "='" + JSON.stringify(val).replace(/'/g, ''') + "'";
|
133
|
+
} else if (escaped) {
|
134
|
+
if (val && typeof val.toISOString === 'function') {
|
135
|
+
console.warn('Jade will stringify dates in ISO form after 2.0.0');
|
136
|
+
}
|
137
|
+
return ' ' + key + '="' + exports.escape(val) + '"';
|
138
|
+
} else {
|
139
|
+
if (val && typeof val.toISOString === 'function') {
|
140
|
+
console.warn('Jade will stringify dates in ISO form after 2.0.0');
|
141
|
+
}
|
142
|
+
return ' ' + key + '="' + val + '"';
|
143
|
+
}
|
144
|
+
};
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Render the given attributes object.
|
148
|
+
*
|
149
|
+
* @param {Object} obj
|
150
|
+
* @param {Object} escaped
|
151
|
+
* @return {String}
|
152
|
+
*/
|
153
|
+
exports.attrs = function attrs(obj, terse) {
|
154
|
+
var buf = [];
|
155
|
+
|
156
|
+
var keys = Object.keys(obj);
|
157
|
+
|
158
|
+
if (keys.length) {
|
159
|
+
for (var i = 0; i < keys.length; ++i) {
|
160
|
+
var key = keys[i],
|
161
|
+
val = obj[key];
|
162
|
+
|
163
|
+
if ('class' == key) {
|
164
|
+
if (val = joinClasses(val)) {
|
165
|
+
buf.push(' ' + key + '="' + val + '"');
|
166
|
+
}
|
167
|
+
} else {
|
168
|
+
buf.push(exports.attr(key, val, false, terse));
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
return buf.join('');
|
174
|
+
};
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Escape the given string of `html`.
|
178
|
+
*
|
179
|
+
* @param {String} html
|
180
|
+
* @return {String}
|
181
|
+
* @api private
|
182
|
+
*/
|
183
|
+
|
184
|
+
exports.escape = function escape(html) {
|
185
|
+
var result = String(html).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
186
|
+
if (result === '' + html) return html;else return result;
|
187
|
+
};
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Re-throw the given `err` in context to the
|
191
|
+
* the jade in `filename` at the given `lineno`.
|
192
|
+
*
|
193
|
+
* @param {Error} err
|
194
|
+
* @param {String} filename
|
195
|
+
* @param {String} lineno
|
196
|
+
* @api private
|
197
|
+
*/
|
198
|
+
|
199
|
+
exports.rethrow = function rethrow(err, filename, lineno, str) {
|
200
|
+
if (!(err instanceof Error)) throw err;
|
201
|
+
if ((typeof window != 'undefined' || !filename) && !str) {
|
202
|
+
err.message += ' on line ' + lineno;
|
203
|
+
throw err;
|
204
|
+
}
|
205
|
+
try {
|
206
|
+
str = str || require('fs').readFileSync(filename, 'utf8');
|
207
|
+
} catch (ex) {
|
208
|
+
rethrow(err, null, lineno);
|
209
|
+
}
|
210
|
+
var context = 3,
|
211
|
+
lines = str.split('\n'),
|
212
|
+
start = Math.max(lineno - context, 0),
|
213
|
+
end = Math.min(lines.length, lineno + context);
|
214
|
+
|
215
|
+
// Error context
|
216
|
+
var context = lines.slice(start, end).map(function (line, i) {
|
217
|
+
var curr = i + start + 1;
|
218
|
+
return (curr == lineno ? ' > ' : ' ') + curr + '| ' + line;
|
219
|
+
}).join('\n');
|
220
|
+
|
221
|
+
// Alter exception message
|
222
|
+
err.path = filename;
|
223
|
+
err.message = (filename || 'Jade') + ':' + lineno + '\n' + context + '\n\n' + err.message;
|
224
|
+
throw err;
|
225
|
+
};
|
226
|
+
|
227
|
+
},{"fs":1}]},{},[2])(2)
|
228
|
+
});
|