runtime.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. 'use strict';
  3. /**
  4. * Merge two attribute objects giving precedence
  5. * to values in object `b`. Classes are special-cased
  6. * allowing for arrays and merging/joining appropriately
  7. * resulting in a string.
  8. *
  9. * @param {Object} a
  10. * @param {Object} b
  11. * @return {Object} a
  12. * @api private
  13. */
  14. exports.merge = function merge(a, b) {
  15. if (arguments.length === 1) {
  16. var attrs = a[0];
  17. for (var i = 1; i < a.length; i++) {
  18. attrs = merge(attrs, a[i]);
  19. }
  20. return attrs;
  21. }
  22. var ac = a['class'];
  23. var bc = b['class'];
  24. if (ac || bc) {
  25. ac = ac || [];
  26. bc = bc || [];
  27. if (!Array.isArray(ac)) ac = [ac];
  28. if (!Array.isArray(bc)) bc = [bc];
  29. a['class'] = ac.concat(bc).filter(nulls);
  30. }
  31. for (var key in b) {
  32. if (key != 'class') {
  33. a[key] = b[key];
  34. }
  35. }
  36. return a;
  37. };
  38. /**
  39. * Filter null `val`s.
  40. *
  41. * @param {*} val
  42. * @return {Boolean}
  43. * @api private
  44. */
  45. function nulls(val) {
  46. return val != null && val !== '';
  47. }
  48. /**
  49. * join array as classes.
  50. *
  51. * @param {*} val
  52. * @return {String}
  53. */
  54. exports.joinClasses = joinClasses;
  55. function joinClasses(val) {
  56. return (Array.isArray(val) ? val.map(joinClasses) :
  57. (val && typeof val === 'object') ? Object.keys(val).filter(function (key) { return val[key]; }) :
  58. [val]).filter(nulls).join(' ');
  59. }
  60. /**
  61. * Render the given classes.
  62. *
  63. * @param {Array} classes
  64. * @param {Array.<Boolean>} escaped
  65. * @return {String}
  66. */
  67. exports.cls = function cls(classes, escaped) {
  68. var buf = [];
  69. for (var i = 0; i < classes.length; i++) {
  70. if (escaped && escaped[i]) {
  71. buf.push(exports.escape(joinClasses([classes[i]])));
  72. } else {
  73. buf.push(joinClasses(classes[i]));
  74. }
  75. }
  76. var text = joinClasses(buf);
  77. if (text.length) {
  78. return ' class="' + text + '"';
  79. } else {
  80. return '';
  81. }
  82. };
  83. exports.style = function (val) {
  84. if (val && typeof val === 'object') {
  85. return Object.keys(val).map(function (style) {
  86. return style + ':' + val[style];
  87. }).join(';');
  88. } else {
  89. return val;
  90. }
  91. };
  92. /**
  93. * Render the given attribute.
  94. *
  95. * @param {String} key
  96. * @param {String} val
  97. * @param {Boolean} escaped
  98. * @param {Boolean} terse
  99. * @return {String}
  100. */
  101. exports.attr = function attr(key, val, escaped, terse) {
  102. if (key === 'style') {
  103. val = exports.style(val);
  104. }
  105. if ('boolean' == typeof val || null == val) {
  106. if (val) {
  107. return ' ' + (terse ? key : key + '="' + key + '"');
  108. } else {
  109. return '';
  110. }
  111. } else if (0 == key.indexOf('data') && 'string' != typeof val) {
  112. if (JSON.stringify(val).indexOf('&') !== -1) {
  113. console.warn('Since Jade 2.0.0, ampersands (`&`) in data attributes ' +
  114. 'will be escaped to `&amp;`');
  115. };
  116. if (val && typeof val.toISOString === 'function') {
  117. console.warn('Jade will eliminate the double quotes around dates in ' +
  118. 'ISO form after 2.0.0');
  119. }
  120. return ' ' + key + "='" + JSON.stringify(val).replace(/'/g, '&apos;') + "'";
  121. } else if (escaped) {
  122. if (val && typeof val.toISOString === 'function') {
  123. console.warn('Jade will stringify dates in ISO form after 2.0.0');
  124. }
  125. return ' ' + key + '="' + exports.escape(val) + '"';
  126. } else {
  127. if (val && typeof val.toISOString === 'function') {
  128. console.warn('Jade will stringify dates in ISO form after 2.0.0');
  129. }
  130. return ' ' + key + '="' + val + '"';
  131. }
  132. };
  133. /**
  134. * Render the given attributes object.
  135. *
  136. * @param {Object} obj
  137. * @param {Object} escaped
  138. * @return {String}
  139. */
  140. exports.attrs = function attrs(obj, terse){
  141. var buf = [];
  142. var keys = Object.keys(obj);
  143. if (keys.length) {
  144. for (var i = 0; i < keys.length; ++i) {
  145. var key = keys[i]
  146. , val = obj[key];
  147. if ('class' == key) {
  148. if (val = joinClasses(val)) {
  149. buf.push(' ' + key + '="' + val + '"');
  150. }
  151. } else {
  152. buf.push(exports.attr(key, val, false, terse));
  153. }
  154. }
  155. }
  156. return buf.join('');
  157. };
  158. /**
  159. * Escape the given string of `html`.
  160. *
  161. * @param {String} html
  162. * @return {String}
  163. * @api private
  164. */
  165. var jade_encode_html_rules = {
  166. '&': '&amp;',
  167. '<': '&lt;',
  168. '>': '&gt;',
  169. '"': '&quot;'
  170. };
  171. var jade_match_html = /[&<>"]/g;
  172. function jade_encode_char(c) {
  173. return jade_encode_html_rules[c] || c;
  174. }
  175. exports.escape = jade_escape;
  176. function jade_escape(html){
  177. var result = String(html).replace(jade_match_html, jade_encode_char);
  178. if (result === '' + html) return html;
  179. else return result;
  180. };
  181. /**
  182. * Re-throw the given `err` in context to the
  183. * the jade in `filename` at the given `lineno`.
  184. *
  185. * @param {Error} err
  186. * @param {String} filename
  187. * @param {String} lineno
  188. * @api private
  189. */
  190. exports.rethrow = function rethrow(err, filename, lineno, str){
  191. if (!(err instanceof Error)) throw err;
  192. if ((typeof window != 'undefined' || !filename) && !str) {
  193. err.message += ' on line ' + lineno;
  194. throw err;
  195. }
  196. try {
  197. str = str || require('fs').readFileSync(filename, 'utf8')
  198. } catch (ex) {
  199. rethrow(err, null, lineno)
  200. }
  201. var context = 3
  202. , lines = str.split('\n')
  203. , start = Math.max(lineno - context, 0)
  204. , end = Math.min(lines.length, lineno + context);
  205. // Error context
  206. var context = lines.slice(start, end).map(function(line, i){
  207. var curr = i + start + 1;
  208. return (curr == lineno ? ' > ' : ' ')
  209. + curr
  210. + '| '
  211. + line;
  212. }).join('\n');
  213. // Alter exception message
  214. err.path = filename;
  215. err.message = (filename || 'Jade') + ':' + lineno
  216. + '\n' + context + '\n\n' + err.message;
  217. throw err;
  218. };
  219. exports.DebugItem = function DebugItem(lineno, filename) {
  220. this.lineno = lineno;
  221. this.filename = filename;
  222. }
  223. },{"fs":2}],2:[function(require,module,exports){
  224. },{}]},{},[1])(1)
  225. });