sass-twitter-bootstrap 0.1.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. data/lib/{sass-twitter-bootstrap.rb → sass/twitter/bootstrap.rb} +1 -1
  2. data/lib/sass/twitter/bootstrap/rails.rb +1 -5
  3. data/lib/sass/twitter/bootstrap/rails/engine.rb +12 -0
  4. data/lib/sass/twitter/bootstrap/version.rb +1 -1
  5. data/vendor/assets/images/glyphicons-halflings-white.png +0 -0
  6. data/vendor/assets/images/glyphicons-halflings.png +0 -0
  7. data/vendor/assets/javascripts/twitter/bootstrap-alert.js +32 -28
  8. data/vendor/assets/javascripts/twitter/bootstrap-button.js +33 -29
  9. data/vendor/assets/javascripts/twitter/bootstrap-carousel.js +21 -33
  10. data/vendor/assets/javascripts/twitter/bootstrap-collapse.js +26 -47
  11. data/vendor/assets/javascripts/twitter/bootstrap-dropdown.js +10 -18
  12. data/vendor/assets/javascripts/twitter/bootstrap-modal.js +17 -25
  13. data/vendor/assets/javascripts/twitter/bootstrap-popover.js +10 -13
  14. data/vendor/assets/javascripts/twitter/bootstrap-scrollspy.js +18 -44
  15. data/vendor/assets/javascripts/twitter/bootstrap-tab.js +7 -12
  16. data/vendor/assets/javascripts/twitter/bootstrap-tooltip.js +35 -40
  17. data/vendor/assets/javascripts/twitter/bootstrap-transition.js +20 -30
  18. data/vendor/assets/javascripts/twitter/bootstrap-typeahead.js +15 -29
  19. data/vendor/assets/stylesheets/tests/buttons.html +139 -0
  20. data/vendor/assets/stylesheets/tests/css-tests.css +99 -1
  21. data/vendor/assets/stylesheets/tests/css-tests.html +519 -37
  22. data/vendor/assets/stylesheets/tests/forms-responsive.html +71 -0
  23. data/vendor/assets/stylesheets/tests/navbar-fixed-top.html +104 -0
  24. data/vendor/assets/stylesheets/tests/navbar-static-top.html +107 -0
  25. data/vendor/assets/stylesheets/tests/navbar.html +38 -39
  26. data/vendor/assets/stylesheets/twitter/_accordion.scss +0 -5
  27. data/vendor/assets/stylesheets/twitter/_alerts.scss +15 -3
  28. data/vendor/assets/stylesheets/twitter/_breadcrumbs.scss +0 -2
  29. data/vendor/assets/stylesheets/twitter/_button-groups.scss +32 -76
  30. data/vendor/assets/stylesheets/twitter/_buttons.scss +25 -33
  31. data/vendor/assets/stylesheets/twitter/_close.scss +1 -12
  32. data/vendor/assets/stylesheets/twitter/_code.scss +8 -8
  33. data/vendor/assets/stylesheets/twitter/_component-animations.scss +7 -9
  34. data/vendor/assets/stylesheets/twitter/_dropdowns.scss +45 -58
  35. data/vendor/assets/stylesheets/twitter/_forms.scss +146 -206
  36. data/vendor/assets/stylesheets/twitter/_grid.scss +5 -2
  37. data/vendor/assets/stylesheets/twitter/_hero-unit.scss +1 -3
  38. data/vendor/assets/stylesheets/twitter/_labels.scss +32 -0
  39. data/vendor/assets/stylesheets/twitter/_layouts.scss +2 -2
  40. data/vendor/assets/stylesheets/twitter/_mixins.scss +208 -273
  41. data/vendor/assets/stylesheets/twitter/_modals.scss +8 -14
  42. data/vendor/assets/stylesheets/twitter/_navbar.scss +73 -132
  43. data/vendor/assets/stylesheets/twitter/_navs.scss +43 -53
  44. data/vendor/assets/stylesheets/twitter/_pager.scss +0 -6
  45. data/vendor/assets/stylesheets/twitter/_pagination.scss +0 -1
  46. data/vendor/assets/stylesheets/twitter/_progress-bars.scss +6 -28
  47. data/vendor/assets/stylesheets/twitter/_reset.scss +4 -9
  48. data/vendor/assets/stylesheets/twitter/_scaffolding.scss +8 -4
  49. data/vendor/assets/stylesheets/twitter/_sprites.scss +7 -40
  50. data/vendor/assets/stylesheets/twitter/_tables.scss +33 -38
  51. data/vendor/assets/stylesheets/twitter/_thumbnails.scss +2 -14
  52. data/vendor/assets/stylesheets/twitter/_tooltip.scss +1 -1
  53. data/vendor/assets/stylesheets/twitter/_type.scss +14 -28
  54. data/vendor/assets/stylesheets/twitter/_variables.scss +19 -116
  55. data/vendor/assets/stylesheets/twitter/_wells.scss +0 -10
  56. data/vendor/assets/stylesheets/twitter/bootstrap.scss +7 -3
  57. data/vendor/assets/stylesheets/twitter/responsive.scss +301 -15
  58. metadata +25 -190
  59. data/.gitignore +0 -4
  60. data/Gemfile +0 -3
  61. data/Gemfile.lock +0 -14
  62. data/LICENSE +0 -176
  63. data/Makefile +0 -94
  64. data/README.md +0 -217
  65. data/Rakefile +0 -52
  66. data/bootstrap-2.0.4.css +0 -4661
  67. data/bootstrap-2.0.4.min.css +0 -9
  68. data/bootstrap-responsive-2.0.4.css +0 -932
  69. data/bootstrap-responsive-2.0.4.min.css +0 -9
  70. data/docs/assets/css/bootstrap-responsive.css +0 -932
  71. data/docs/assets/css/bootstrap.css +0 -4661
  72. data/docs/assets/css/docs.css +0 -846
  73. data/docs/assets/ico/apple-touch-icon-114-precomposed.png +0 -0
  74. data/docs/assets/ico/apple-touch-icon-144-precomposed.png +0 -0
  75. data/docs/assets/ico/apple-touch-icon-57-precomposed.png +0 -0
  76. data/docs/assets/ico/apple-touch-icon-72-precomposed.png +0 -0
  77. data/docs/assets/ico/favicon.ico +0 -0
  78. data/docs/assets/img/bird.png +0 -0
  79. data/docs/assets/img/bootstrap-mdo-sfmoma-01.jpg +0 -0
  80. data/docs/assets/img/bootstrap-mdo-sfmoma-02.jpg +0 -0
  81. data/docs/assets/img/bootstrap-mdo-sfmoma-03.jpg +0 -0
  82. data/docs/assets/img/browsers.png +0 -0
  83. data/docs/assets/img/example-sites/fleetio.png +0 -0
  84. data/docs/assets/img/example-sites/jshint.png +0 -0
  85. data/docs/assets/img/example-sites/kippt.png +0 -0
  86. data/docs/assets/img/example-sites/soundready.png +0 -0
  87. data/docs/assets/img/examples/bootstrap-example-fluid.jpg +0 -0
  88. data/docs/assets/img/examples/bootstrap-example-hero.jpg +0 -0
  89. data/docs/assets/img/examples/bootstrap-example-starter.jpg +0 -0
  90. data/docs/assets/img/github-16px.png +0 -0
  91. data/docs/assets/img/glyphicons-halflings-white.png +0 -0
  92. data/docs/assets/img/glyphicons-halflings.png +0 -0
  93. data/docs/assets/img/glyphicons/glyphicons_009_magic.png +0 -0
  94. data/docs/assets/img/glyphicons/glyphicons_042_group.png +0 -0
  95. data/docs/assets/img/glyphicons/glyphicons_079_podium.png +0 -0
  96. data/docs/assets/img/glyphicons/glyphicons_082_roundabout.png +0 -0
  97. data/docs/assets/img/glyphicons/glyphicons_155_show_thumbnails.png +0 -0
  98. data/docs/assets/img/glyphicons/glyphicons_163_iphone.png +0 -0
  99. data/docs/assets/img/glyphicons/glyphicons_214_resize_small.png +0 -0
  100. data/docs/assets/img/glyphicons/glyphicons_266_book_open.png +0 -0
  101. data/docs/assets/img/grid-18px-masked.png +0 -0
  102. data/docs/assets/img/icon-css3.png +0 -0
  103. data/docs/assets/img/icon-github.png +0 -0
  104. data/docs/assets/img/icon-html5.png +0 -0
  105. data/docs/assets/img/icon-twitter.png +0 -0
  106. data/docs/assets/img/less-logo-large.png +0 -0
  107. data/docs/assets/img/less-small.png +0 -0
  108. data/docs/assets/img/responsive-illustrations.png +0 -0
  109. data/docs/assets/js/README.md +0 -106
  110. data/docs/assets/js/application.js +0 -184
  111. data/docs/assets/js/bootstrap-alert.js +0 -90
  112. data/docs/assets/js/bootstrap-button.js +0 -96
  113. data/docs/assets/js/bootstrap-carousel.js +0 -169
  114. data/docs/assets/js/bootstrap-collapse.js +0 -157
  115. data/docs/assets/js/bootstrap-dropdown.js +0 -100
  116. data/docs/assets/js/bootstrap-modal.js +0 -218
  117. data/docs/assets/js/bootstrap-popover.js +0 -98
  118. data/docs/assets/js/bootstrap-scrollspy.js +0 -151
  119. data/docs/assets/js/bootstrap-tab.js +0 -135
  120. data/docs/assets/js/bootstrap-tooltip.js +0 -275
  121. data/docs/assets/js/bootstrap-transition.js +0 -61
  122. data/docs/assets/js/bootstrap-typeahead.js +0 -285
  123. data/docs/assets/js/bootstrap.js +0 -1825
  124. data/docs/assets/js/bootstrap.min.js +0 -6
  125. data/docs/assets/js/google-code-prettify/prettify.css +0 -30
  126. data/docs/assets/js/google-code-prettify/prettify.js +0 -28
  127. data/docs/assets/js/jquery.js +0 -9252
  128. data/docs/base-css.html +0 -1710
  129. data/docs/build/index.js +0 -44
  130. data/docs/build/node_modules/.bin/hulk +0 -93
  131. data/docs/build/node_modules/hogan.js/.git_ignore +0 -1
  132. data/docs/build/node_modules/hogan.js/.gitmodules +0 -3
  133. data/docs/build/node_modules/hogan.js/LICENSE +0 -177
  134. data/docs/build/node_modules/hogan.js/Makefile +0 -62
  135. data/docs/build/node_modules/hogan.js/README.md +0 -93
  136. data/docs/build/node_modules/hogan.js/bin/hulk +0 -93
  137. data/docs/build/node_modules/hogan.js/lib/compiler.js +0 -348
  138. data/docs/build/node_modules/hogan.js/lib/hogan.js +0 -20
  139. data/docs/build/node_modules/hogan.js/lib/template.js +0 -233
  140. data/docs/build/node_modules/hogan.js/package.json +0 -20
  141. data/docs/build/node_modules/hogan.js/test/html/list.html +0 -8
  142. data/docs/build/node_modules/hogan.js/test/index.html +0 -13
  143. data/docs/build/node_modules/hogan.js/test/index.js +0 -848
  144. data/docs/build/node_modules/hogan.js/test/mustache.js +0 -90
  145. data/docs/build/node_modules/hogan.js/test/spec.js +0 -77
  146. data/docs/build/node_modules/hogan.js/test/spec/Changes +0 -31
  147. data/docs/build/node_modules/hogan.js/test/spec/README.md +0 -65
  148. data/docs/build/node_modules/hogan.js/test/spec/Rakefile +0 -27
  149. data/docs/build/node_modules/hogan.js/test/spec/TESTING.md +0 -46
  150. data/docs/build/node_modules/hogan.js/test/spec/specs/comments.json +0 -1
  151. data/docs/build/node_modules/hogan.js/test/spec/specs/comments.yml +0 -103
  152. data/docs/build/node_modules/hogan.js/test/spec/specs/delimiters.json +0 -1
  153. data/docs/build/node_modules/hogan.js/test/spec/specs/delimiters.yml +0 -158
  154. data/docs/build/node_modules/hogan.js/test/spec/specs/interpolation.json +0 -1
  155. data/docs/build/node_modules/hogan.js/test/spec/specs/interpolation.yml +0 -230
  156. data/docs/build/node_modules/hogan.js/test/spec/specs/inverted.json +0 -1
  157. data/docs/build/node_modules/hogan.js/test/spec/specs/inverted.yml +0 -193
  158. data/docs/build/node_modules/hogan.js/test/spec/specs/partials.json +0 -1
  159. data/docs/build/node_modules/hogan.js/test/spec/specs/partials.yml +0 -109
  160. data/docs/build/node_modules/hogan.js/test/spec/specs/sections.json +0 -1
  161. data/docs/build/node_modules/hogan.js/test/spec/specs/sections.yml +0 -256
  162. data/docs/build/node_modules/hogan.js/test/spec/specs/~lambdas.json +0 -1
  163. data/docs/build/node_modules/hogan.js/test/spec/specs/~lambdas.yml +0 -149
  164. data/docs/build/node_modules/hogan.js/test/templates/list.mustache +0 -8
  165. data/docs/build/node_modules/hogan.js/tools/release.js +0 -74
  166. data/docs/build/node_modules/hogan.js/tools/web_templates.js +0 -32
  167. data/docs/build/node_modules/hogan.js/web/1.0.0/hogan.js +0 -500
  168. data/docs/build/node_modules/hogan.js/web/1.0.0/hogan.min.js +0 -14
  169. data/docs/build/node_modules/hogan.js/web/builds/1.0.0/hogan.js +0 -500
  170. data/docs/build/node_modules/hogan.js/web/builds/1.0.0/hogan.min.js +0 -14
  171. data/docs/build/node_modules/hogan.js/web/builds/1.0.3/hogan.js +0 -545
  172. data/docs/build/node_modules/hogan.js/web/builds/1.0.3/hogan.min.js +0 -5
  173. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/hogan-1.0.5.amd.js +0 -576
  174. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/hogan-1.0.5.common.js +0 -576
  175. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/hogan-1.0.5.js +0 -572
  176. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/hogan-1.0.5.min.amd.js +0 -5
  177. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/hogan-1.0.5.min.common.js +0 -5
  178. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/hogan-1.0.5.min.js +0 -5
  179. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/hogan-1.0.5.min.mustache.js +0 -5
  180. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/hogan-1.0.5.mustache.js +0 -619
  181. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/template-1.0.5.js +0 -233
  182. data/docs/build/node_modules/hogan.js/web/builds/1.0.5/template-1.0.5.min.js +0 -5
  183. data/docs/build/node_modules/hogan.js/web/favicon.ico +0 -0
  184. data/docs/build/node_modules/hogan.js/web/images/logo.png +0 -0
  185. data/docs/build/node_modules/hogan.js/web/images/noise.png +0 -0
  186. data/docs/build/node_modules/hogan.js/web/images/small-hogan-icon.png +0 -0
  187. data/docs/build/node_modules/hogan.js/web/images/stripes.png +0 -0
  188. data/docs/build/node_modules/hogan.js/web/index.html.mustache +0 -139
  189. data/docs/build/node_modules/hogan.js/web/stylesheets/layout.css +0 -206
  190. data/docs/build/node_modules/hogan.js/web/stylesheets/skeleton.css +0 -236
  191. data/docs/build/node_modules/hogan.js/wrappers/amd.js.mustache +0 -21
  192. data/docs/build/node_modules/hogan.js/wrappers/common.js.mustache +0 -21
  193. data/docs/build/node_modules/hogan.js/wrappers/js.mustache +0 -17
  194. data/docs/build/node_modules/hogan.js/wrappers/mustache.js.mustache +0 -64
  195. data/docs/build/package.json +0 -6
  196. data/docs/components.html +0 -1931
  197. data/docs/download.html +0 -454
  198. data/docs/examples.html +0 -147
  199. data/docs/examples/fluid.html +0 -162
  200. data/docs/examples/hero.html +0 -109
  201. data/docs/examples/starter-template.html +0 -79
  202. data/docs/index.html +0 -259
  203. data/docs/javascript.html +0 -1520
  204. data/docs/less.html +0 -1060
  205. data/docs/scaffolding.html +0 -671
  206. data/docs/templates/layout.mustache +0 -146
  207. data/docs/templates/pages/base-css.mustache +0 -1594
  208. data/docs/templates/pages/components.mustache +0 -1815
  209. data/docs/templates/pages/download.mustache +0 -338
  210. data/docs/templates/pages/examples.mustache +0 -31
  211. data/docs/templates/pages/index.mustache +0 -144
  212. data/docs/templates/pages/javascript.mustache +0 -1405
  213. data/docs/templates/pages/less.mustache +0 -944
  214. data/docs/templates/pages/scaffolding.mustache +0 -555
  215. data/docs/templates/pages/upgrading.mustache +0 -194
  216. data/docs/upgrading.html +0 -310
  217. data/js/tests/index.html +0 -54
  218. data/js/tests/phantom.js +0 -63
  219. data/js/tests/server.js +0 -14
  220. data/js/tests/unit/bootstrap-alert.js +0 -56
  221. data/js/tests/unit/bootstrap-button.js +0 -77
  222. data/js/tests/unit/bootstrap-carousel.js +0 -28
  223. data/js/tests/unit/bootstrap-collapse.js +0 -54
  224. data/js/tests/unit/bootstrap-dropdown.js +0 -87
  225. data/js/tests/unit/bootstrap-modal.js +0 -114
  226. data/js/tests/unit/bootstrap-phantom.js +0 -21
  227. data/js/tests/unit/bootstrap-popover.js +0 -93
  228. data/js/tests/unit/bootstrap-scrollspy.js +0 -31
  229. data/js/tests/unit/bootstrap-tab.js +0 -61
  230. data/js/tests/unit/bootstrap-tooltip.js +0 -155
  231. data/js/tests/unit/bootstrap-transition.js +0 -13
  232. data/js/tests/unit/bootstrap-typeahead.js +0 -148
  233. data/js/tests/vendor/jquery.js +0 -9252
  234. data/js/tests/vendor/qunit.css +0 -232
  235. data/js/tests/vendor/qunit.js +0 -1510
  236. data/package.json +0 -25
  237. data/sass-twitter-bootstrap.gemspec +0 -19
  238. data/vendor/assets/javascripts/README.md +0 -112
  239. data/vendor/assets/javascripts/twitter/bootstrap.js +0 -12
  240. data/vendor/assets/stylesheets/twitter/_labels-badges.scss +0 -52
  241. data/vendor/assets/stylesheets/twitter/_responsive-1200px-min.scss +0 -26
  242. data/vendor/assets/stylesheets/twitter/_responsive-767px-max.scss +0 -149
  243. data/vendor/assets/stylesheets/twitter/_responsive-768px-979px.scss +0 -17
  244. data/vendor/assets/stylesheets/twitter/_responsive-navbar.scss +0 -153
  245. data/vendor/assets/stylesheets/twitter/_responsive-utilities.scss +0 -41
@@ -1,233 +0,0 @@
1
- /*
2
- * Copyright 2011 Twitter, Inc.
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- var Hogan = {};
17
-
18
- (function (Hogan) {
19
- Hogan.Template = function constructor(renderFunc, text, compiler) {
20
- if (renderFunc) {
21
- this.r = renderFunc;
22
- }
23
- this.c = compiler;
24
- this.text = text || '';
25
- }
26
-
27
- Hogan.Template.prototype = {
28
- // render: replaced by generated code.
29
- r: function (context, partials, indent) { return ''; },
30
-
31
- // variable escaping
32
- v: hoganEscape,
33
-
34
- render: function render(context, partials, indent) {
35
- return this.ri([context], partials || {}, indent);
36
- },
37
-
38
- // render internal -- a hook for overrides that catches partials too
39
- ri: function (context, partials, indent) {
40
- return this.r(context, partials, indent);
41
- },
42
-
43
- // tries to find a partial in the curent scope and render it
44
- rp: function(name, context, partials, indent) {
45
- var partial = partials[name];
46
-
47
- if (!partial) {
48
- return '';
49
- }
50
-
51
- if (this.c && typeof partial == 'string') {
52
- partial = this.c.compile(partial);
53
- }
54
-
55
- return partial.ri(context, partials, indent);
56
- },
57
-
58
- // render a section
59
- rs: function(context, partials, section) {
60
- var buf = '',
61
- tail = context[context.length - 1];
62
-
63
- if (!isArray(tail)) {
64
- return buf = section(context, partials);
65
- }
66
-
67
- for (var i = 0; i < tail.length; i++) {
68
- context.push(tail[i]);
69
- buf += section(context, partials);
70
- context.pop();
71
- }
72
-
73
- return buf;
74
- },
75
-
76
- // maybe start a section
77
- s: function(val, ctx, partials, inverted, start, end, tags) {
78
- var pass;
79
-
80
- if (isArray(val) && val.length === 0) {
81
- return false;
82
- }
83
-
84
- if (typeof val == 'function') {
85
- val = this.ls(val, ctx, partials, inverted, start, end, tags);
86
- }
87
-
88
- pass = (val === '') || !!val;
89
-
90
- if (!inverted && pass && ctx) {
91
- ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]);
92
- }
93
-
94
- return pass;
95
- },
96
-
97
- // find values with dotted names
98
- d: function(key, ctx, partials, returnFound) {
99
- var names = key.split('.'),
100
- val = this.f(names[0], ctx, partials, returnFound),
101
- cx = null;
102
-
103
- if (key === '.' && isArray(ctx[ctx.length - 2])) {
104
- return ctx[ctx.length - 1];
105
- }
106
-
107
- for (var i = 1; i < names.length; i++) {
108
- if (val && typeof val == 'object' && names[i] in val) {
109
- cx = val;
110
- val = val[names[i]];
111
- } else {
112
- val = '';
113
- }
114
- }
115
-
116
- if (returnFound && !val) {
117
- return false;
118
- }
119
-
120
- if (!returnFound && typeof val == 'function') {
121
- ctx.push(cx);
122
- val = this.lv(val, ctx, partials);
123
- ctx.pop();
124
- }
125
-
126
- return val;
127
- },
128
-
129
- // find values with normal names
130
- f: function(key, ctx, partials, returnFound) {
131
- var val = false,
132
- v = null,
133
- found = false;
134
-
135
- for (var i = ctx.length - 1; i >= 0; i--) {
136
- v = ctx[i];
137
- if (v && typeof v == 'object' && key in v) {
138
- val = v[key];
139
- found = true;
140
- break;
141
- }
142
- }
143
-
144
- if (!found) {
145
- return (returnFound) ? false : "";
146
- }
147
-
148
- if (!returnFound && typeof val == 'function') {
149
- val = this.lv(val, ctx, partials);
150
- }
151
-
152
- return val;
153
- },
154
-
155
- // higher order templates
156
- ho: function(val, cx, partials, text, tags) {
157
- var compiler = this.c;
158
- var t = val.call(cx, text, function(t) {
159
- return compiler.compile(t, {delimiters: tags}).render(cx, partials);
160
- });
161
- var s = compiler.compile(t.toString(), {delimiters: tags}).render(cx, partials);
162
- this.b = s;
163
- return false;
164
- },
165
-
166
- // higher order template result buffer
167
- b: '',
168
-
169
- // lambda replace section
170
- ls: function(val, ctx, partials, inverted, start, end, tags) {
171
- var cx = ctx[ctx.length - 1],
172
- t = null;
173
-
174
- if (!inverted && this.c && val.length > 0) {
175
- return this.ho(val, cx, partials, this.text.substring(start, end), tags);
176
- }
177
-
178
- t = val.call(cx);
179
-
180
- if (typeof t == 'function') {
181
- if (inverted) {
182
- return true;
183
- } else if (this.c) {
184
- return this.ho(t, cx, partials, this.text.substring(start, end), tags);
185
- }
186
- }
187
-
188
- return t;
189
- },
190
-
191
- // lambda replace variable
192
- lv: function(val, ctx, partials) {
193
- var cx = ctx[ctx.length - 1];
194
- var result = val.call(cx);
195
- if (typeof result == 'function') {
196
- result = result.call(cx);
197
- }
198
- result = result.toString();
199
-
200
- if (this.c && ~result.indexOf("{{")) {
201
- return this.c.compile(result).render(cx, partials);
202
- }
203
-
204
- return result;
205
- }
206
-
207
- };
208
-
209
- var rAmp = /&/g,
210
- rLt = /</g,
211
- rGt = />/g,
212
- rApos =/\'/g,
213
- rQuot = /\"/g,
214
- hChars =/[&<>\"\']/;
215
-
216
- function hoganEscape(str) {
217
- str = String((str === null || str === undefined) ? '' : str);
218
- return hChars.test(str) ?
219
- str
220
- .replace(rAmp,'&amp;')
221
- .replace(rLt,'&lt;')
222
- .replace(rGt,'&gt;')
223
- .replace(rApos,'&#39;')
224
- .replace(rQuot, '&quot;') :
225
- str;
226
- }
227
-
228
- var isArray = Array.isArray || function(a) {
229
- return Object.prototype.toString.call(a) === '[object Array]';
230
- };
231
-
232
- })(typeof exports !== 'undefined' ? exports : Hogan);
233
-
@@ -1,20 +0,0 @@
1
- {
2
- "name": "hogan.js"
3
- , "description": "A mustache compiler."
4
- , "version": "1.0.5-dev"
5
- , "keywords": ["mustache", "template"]
6
- , "main": "./lib/hogan.js"
7
- , "homepage": "http://twitter.github.com/hogan.js/"
8
- , "author": "Twitter Inc."
9
- , "repository": {
10
- "type": "git"
11
- , "url": "https://github.com/twitter/hogan.js.git"
12
- }
13
- , "licenses": [
14
- { "type": "Apache-2.0"
15
- , "url": "http://www.apache.org/licenses/LICENSE-2.0"
16
- }
17
- ]
18
- , "devDependencies": { "uglify-js": "*" }
19
- , "bin" : { "hulk" : "./bin/hulk" }
20
- }
@@ -1,8 +0,0 @@
1
- <ul>
2
- <li></li>
3
- <li></li>
4
- <li></li>
5
- <li></li>
6
- <li></li>
7
- <li></li>
8
- </ul>
@@ -1,13 +0,0 @@
1
- <html>
2
- <head>
3
- <title>test</title>
4
- <script src="https://raw.github.com/douglascrockford/JSON-js/master/json2.js"></script>
5
- </head>
6
- <body>
7
- <code id="console"></code>
8
- <script>var Hogan = {};</script>
9
- <script src="../lib/template.js"></script>
10
- <script src="../lib/compiler.js"></script>
11
- <script src="./index.js"></script>
12
- </body>
13
- </html>
@@ -1,848 +0,0 @@
1
- /*
2
- * Copyright 2011 Twitter, Inc.
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- var Hogan = Hogan || require('../lib/hogan')
17
- , doc = this["document"]
18
-
19
- function testScanTextNoTags() {
20
- var text = "<h2>hi</h2>";
21
- var tokens = Hogan.scan(text);
22
- is(tokens.length, 1, "One token");
23
- is(tokens[0]+'', text, "text is equal to first token");
24
- }
25
-
26
- function testScanOneTag() {
27
- var text = "{{hmm}}";
28
- var tokens = Hogan.scan(text);
29
- is(tokens.length, 1, "One token");
30
- is(tokens[0].n, "hmm", "First token content is variable name.");
31
- }
32
-
33
- function testScanMultipleTags() {
34
- var text = "asdf{{hmm}}asdf2{{hmm2}}asdf3";
35
- var tokens = Hogan.scan(text);
36
- is(tokens.length, 5, "3 text tokens, 2 tag tokens.");
37
- is(tokens[0]+'', "asdf", "first token is text");
38
- is(tokens[1].n, "hmm", "second token is tag");
39
- is(tokens[1].tag, "_v", "second token is a variable");
40
- is(tokens[2]+'', "asdf2", "third token is text");
41
- is(tokens[3].n, "hmm2", "fourth token is tag");
42
- is(tokens[3].tag, "_v", "fourth token is a variable");
43
- is(tokens[4]+'', "asdf3", "Fifth token is text");
44
- }
45
-
46
- function testScanSectionOpen() {
47
- var text = "{{#hmm}}";
48
- var tokens = Hogan.scan(text);
49
- is(tokens.length, 1, "One token");
50
- is(tokens[0].n, "hmm", "First token content is variable name.");
51
- is(tokens[0].tag, "#", "First token is a section.");
52
- }
53
-
54
- function testScanSectionClose() {
55
- var text = "{{/hmm}}";
56
- var tokens = Hogan.scan(text);
57
- is(tokens.length, 1, "One token");
58
- is(tokens[0].n, "hmm", "First token content is variable name.");
59
- is(tokens[0].tag, "/", "First token is a section.");
60
- }
61
-
62
- function testScanSection() {
63
- var text = "{{#hmm}}{{/hmm}}";
64
- var tokens = Hogan.scan(text);
65
- is(tokens.length, 2, "One token");
66
- is(tokens[0].n, "hmm", "First token content is variable name.");
67
- is(tokens[0].tag, "#", "First token is a section.");
68
- is(tokens[1].n, "hmm", "Second token content is variable name.");
69
- is(tokens[1].tag, "/", "Second token is a section.");
70
- }
71
-
72
- function testScanSectionInContent() {
73
- var text = "abc{{#hmm}}def{{/hmm}}ghi";
74
- var tokens = Hogan.scan(text);
75
- is(tokens.length, 5, "3 text tokens, 2 tag tokens.");
76
- is(tokens[0]+'', "abc", "first token is text");
77
- is(tokens[1].n, "hmm", "second token is tag");
78
- is(tokens[1].tag, "#", "second token is a variable");
79
- is(tokens[2]+'', "def", "third token is text");
80
- is(tokens[3].n, "hmm", "fourth token is tag");
81
- is(tokens[3].tag, "/", "fourth token is a variable");
82
- is(tokens[4]+'', "ghi", "Fifth token is text");
83
- }
84
-
85
- function testScanNegativeSection() {
86
- var text = "{{^hmm}}{{/hmm}}";
87
- var tokens = Hogan.scan(text);
88
- is(tokens.length, 2, "One token");
89
- is(tokens[0].n, "hmm", "First token content is variable name.");
90
- is(tokens[0].tag, "^", "First token is a negative section.");
91
- is(tokens[1].n, "hmm", "First token content is variable name.");
92
- is(tokens[1].tag, "/", "Second token is a section.");
93
- }
94
-
95
- function testScanPartial() {
96
- var text = "{{>hmm}}";
97
- var tokens = Hogan.scan(text);
98
- is(tokens.length, 1, "One token");
99
- is(tokens[0].n, "hmm", "First token content is variable name.");
100
- is(tokens[0].tag, ">", "First token is a partial.");
101
- }
102
-
103
-
104
- function testScanBackwardPartial() {
105
- var text = "{{<hmm}}";
106
- var tokens = Hogan.scan(text);
107
- is(tokens.length, 1, "One token");
108
- is(tokens[0].n, "hmm", "First token content is variable name.");
109
- is(tokens[0].tag, "<", "First token is a backward partial.");
110
- }
111
-
112
- function testScanAmpersandNoEscapeTag() {
113
- var text = "{{&hmm}}";
114
- var tokens = Hogan.scan(text);
115
- is(tokens.length, 1, "One token");
116
- is(tokens[0].n, "hmm", "First token content is variable name.");
117
- is(tokens[0].tag, "&", "First token is an ampersand no-escape.");
118
- }
119
-
120
- function testScanTripleStache() {
121
- var text = "{{{hmm}}}";
122
- var tokens = Hogan.scan(text);
123
- is(tokens.length, 1, "One token");
124
- is(tokens[0].n, "hmm", "First token content is variable name.");
125
- is(tokens[0].tag, "{", "First token is a triple-stache.");
126
- }
127
-
128
- function testScanSectionWithTripleStacheInside() {
129
- var text = "a{{#yo}}b{{{hmm}}}c{{/yo}}d";
130
- var tokens = Hogan.scan(text);
131
- is(tokens.length, 7, "One token");
132
- is(tokens[0]+'', "a", "First token content is correct text.");
133
- is(tokens[1].n, "yo", "Second token content is correct text.");
134
- is(tokens[1].tag, "#", "Second token is a section.");
135
- is(tokens[2]+'', "b", "Third token content is correct text.");
136
- is(tokens[3].n, "hmm", "Fourth token content is correct text.");
137
- is(tokens[3].tag, "{", "Fourth token is a triple stache.");
138
- is(tokens[4]+'', "c", "Fifth token content is correct text.");
139
- is(tokens[5].n, "yo", "Sixth token content is correct text.");
140
- is(tokens[5].tag, "/", "Sixth token is a close.");
141
- is(tokens[6]+'', "d", "Seventh token content is correct text.");
142
- }
143
-
144
- function testScanSetDelimiter() {
145
- var text = "a{{=<% %>=}}b";
146
- var tokens = Hogan.scan(text);
147
- is(tokens.length, 2, "change delimiter doesn't appear as token.");
148
- is(tokens[0]+'', "a", "text before change delimiter is processed.");
149
- is(tokens[1]+'', "b", "text after change delimiter is processed.");
150
- }
151
-
152
- function testScanResetDelimiter() {
153
- var text = "a{{=<% %>=}}b<%hmm%>c<%={{ }}=%>d{{hmm}}";
154
- var tokens = Hogan.scan(text);
155
- is(tokens.length, 6, "8 tokens, delimiter changes don't count.");
156
- is(tokens[0]+'', "a", "first token is correct.");
157
- is(tokens[1]+'', "b", "third token is correct.");
158
- is(tokens[2].tag, "_v", "third token is correct tag.");
159
- is(tokens[2].n, "hmm", "third token is correct name.");
160
- is(tokens[3]+'', "c", "fifth token is correct.");
161
- is(tokens[4]+'', "d", "seventh token is correct.");
162
- is(tokens[5].tag, "_v", "eighth token is correct tag.");
163
- is(tokens[5].n, "hmm", "eighth token is correct name.");
164
- }
165
-
166
- function testSingleCharDelimiter() {
167
- var text = '({{foo}} {{=[ ]=}}[text])';
168
- var tokens = Hogan.scan(text);
169
-
170
- var t = Hogan.compile(text);
171
- s = t.render({foo: "bar", text: 'It worked!'});
172
- is(s, '(bar It worked!)', "Hogan substitution worked after custom delimiters.");
173
- }
174
-
175
- function testSetDelimiterWithWhitespace() {
176
- var text = "{{= | | =}}|foo|";
177
- var t = Hogan.compile(text);
178
- s = t.render({foo: "bar"});
179
- is(s, 'bar', "custom delimiters with whitespace works.")
180
- }
181
-
182
- function testParseBasic() {
183
- var text = "test";
184
- var tree = Hogan.parse(Hogan.scan(text));
185
- is(tree.length, 1, "one parse node");
186
- is(tree[0]+'', "test", "text is correct");
187
- }
188
-
189
- function testParseVariables() {
190
- var text = "test{{foo}}test!{{bar}}test!!{{baz}}test!!!";
191
- var tree = Hogan.parse(Hogan.scan(text));
192
- is(tree.length, 7, "one parse node");
193
- is(tree[0]+'', "test", "first text is correct");
194
- is(tree[2]+'', "test!", "second text is correct")
195
- is(tree[4]+'', "test!!", "third text is correct")
196
- is(tree[6]+'', "test!!!", "last text is correct")
197
- is(tree[1].n, "foo", "first var is correct");
198
- is(tree[3].n, "bar", "second var is correct");
199
- is(tree[5].n, "baz", "third var is correct");
200
- }
201
-
202
- function testParseSection() {
203
- var text = "a{{#foo}}b{{/foo}}c";
204
- var tree = Hogan.parse(Hogan.scan(text));
205
- is(tree.length, 3, "three nodes at base");
206
- is(tree[0]+'', "a", "correct text in first node");
207
- is(tree[1].hasOwnProperty('nodes'), true, "second node is a section");
208
- is(tree[1].tag, '#', "second node is a section");
209
- is(tree[1].n, "foo", "correct name for section");
210
- is(tree[1].nodes[0]+'', "b", "correct text in section");
211
- is(tree[2]+'', "c", "correct text in last node");
212
- }
213
-
214
- function testParseIndexes() {
215
- var text = "abc{{#foo}}asdf{{bar}}asdf{{/foo}}def";
216
- var tree = Hogan.parse(Hogan.scan(text));
217
- is(text.substring(tree[1].i, tree[1].end), "asdf{{bar}}asdf", "section text indexes are correct");
218
- }
219
-
220
- function testParseNegativeSection() {
221
- var text = "a{{^foo}}b{{/foo}}c";
222
- var tree = Hogan.parse(Hogan.scan(text));
223
-
224
- is(tree.length, 3, "three nodes at base");
225
- is(tree[0]+'', "a", "correct text in first node");
226
- is(tree[1].hasOwnProperty('nodes'), true, "second node is a section");
227
- is(tree[1].tag, '^', "second node is a negative section");
228
- is(tree[1].n, "foo", "correct name for section");
229
- is(tree[1].nodes[0]+'', "b", "correct text in section");
230
- is(tree[2]+'', "c", "correct text in last node");
231
- }
232
-
233
- function testParseNestedSections() {
234
- var text = "{{#bar}}{{#foo}}c{{/foo}}{{/bar}}"
235
- var tree = Hogan.parse(Hogan.scan(text));
236
-
237
- is(tree.length, 1, "one node at base");
238
- is(tree[0].tag, "#", "open section is first node");
239
- is(tree[0].n, "bar", "first section name is 'bar'");
240
- is(tree[0].nodes.length, 1, "first section contains one node.");
241
- is(tree[0].nodes[0].n, "foo", "correct name for nested section");
242
- is(tree[0].nodes[0].nodes[0]+'', "c", "correct text in nested section");
243
- }
244
-
245
- function testMissingClosingTag() {
246
- var text = "a{{#foo}}bc";
247
- var msg = '';
248
- try {
249
- var tree = Hogan.parse(Hogan.scan(text));
250
- } catch (e) {
251
- msg = e.message;
252
- }
253
- is(msg, "missing closing tag: foo", "Error is generated");
254
- }
255
-
256
- function testBadNesting() {
257
- var text = "a{{#foo}}{{#bar}}b{{/foo}}{{/bar}}c";
258
- var msg = '';
259
- try {
260
- var tree = Hogan.parse(Hogan.scan(text));
261
- } catch (e) {
262
- msg = e.message;
263
- }
264
- is(msg, "Nesting error: bar vs. foo", "Error is generated");
265
- }
266
-
267
- function testBasicOutput() {
268
- var text = "test";
269
- var t = Hogan.compile(text);
270
- is(t.render(), text, "template renders one text node");
271
- }
272
-
273
- function testBasicOutputAsString() {
274
- var text = "test";
275
- var textFunc = Hogan.compile(text, true);
276
- is(textFunc, "function(context, partials){this.buffer.push('test');};", "template renders correct text function.");
277
- }
278
-
279
- function testOneVariable() {
280
- var text = "test {{foo}} test";
281
- var t = Hogan.compile(text);
282
- var s = t.render({foo:'bar'});
283
- is(s, "test bar test", "basic variable substitution works.");
284
- }
285
-
286
- function testOneVariableAsString() {
287
- var text = "test {{foo}} test";
288
- var funcText = Hogan.compile(text, true);
289
- is(funcText, "function(context, partials){this.buffer.push('test ');\nthis.buffer.push(this.find('foo', context));\nthis.buffer.push(' test');};",
290
- "Function text is correct with variable substitution.");
291
- }
292
-
293
- function testRenderWithWhitespace() {
294
- var text = "{{ string }}";
295
- var t = Hogan.compile(text);
296
- is(t.render({string: "---" }), "---", "tags with whitespace render correctly.");
297
- }
298
-
299
- function testRenderWithWhitespaceAroundTripleStache() {
300
- var text = " {{{string}}}\n";
301
- var t = Hogan.compile(text);
302
- is(t.render({string: "---" }), " ---\n", "triple stache surrounded by whitespace render correctly.");
303
- }
304
-
305
- function testRenderWithWhitespaceAroundAmpersand() {
306
- var text = " {{& string }}\n";
307
- var t = Hogan.compile(text);
308
- is(t.render({string: "---" }), " ---\n", "ampersand surrounded by whitespace render correctly.");
309
- }
310
-
311
- function testMultipleVariables() {
312
- var text = "test {{foo}} test {{bar}} test {{baz}} test {{foo}} test";
313
- var t = Hogan.compile(text);
314
- var s = t.render({foo:'42', bar: '43', baz: '44'});
315
- is(s, "test 42 test 43 test 44 test 42 test", "all variables render correctly.");
316
- }
317
-
318
- function testNumberValues() {
319
- var text = "integer: {{foo}} float: {{bar}} negative: {{baz}}";
320
- var t = Hogan.compile(text);
321
- var s = t.render({foo: 42, bar: 42.42, baz: -42});
322
- is(s, "integer: 42 float: 42.42 negative: -42", "numbers render correctly");
323
- }
324
-
325
- function testObjectRender() {
326
- var text = "object: {{foo}}";
327
- var t = Hogan.compile(text);
328
- var s = t.render({foo: {}});
329
- is(s, "object: [object Object]", "objects render default toString.");
330
- }
331
-
332
- function testObjectToStringRender() {
333
- var text = "object: {{foo}}";
334
- var t = Hogan.compile(text);
335
- var s = t.render({foo: {toString: function(){ return "yo!"}}});
336
- is(s, "object: yo!", "objects render supplied toString.");
337
- }
338
-
339
- function testArrayRender() {
340
- var text = "array: {{foo}}";
341
- var t = Hogan.compile(text);
342
- var s = t.render({foo: ["a","b","c"]});
343
- is(s, "array: a,b,c", "arrays render default toString.");
344
- }
345
-
346
- function testEscaping() {
347
- var text = "{{foo}}";
348
- var t = Hogan.compile(text);
349
- var s = t.render();
350
- var s = t.render({foo: "< > <div> \' \" &"});
351
- is(s, "&lt; &gt; &lt;div&gt; &#39; &quot; &amp;", "input correctly escaped.");
352
-
353
- var ec ={ "'": "&#39;", '"': "&quot;", "<": "&lt;", ">": "&gt;", "&": "&amp;"}
354
- for (var char in ec) {
355
- var s = t.render({foo: char + " just me"});
356
- is(s, ec[char] + " just me", "input correctly escaped.");
357
- }
358
-
359
- }
360
-
361
- function testMustacheInjection() {
362
- var text = "{{foo}}";
363
- var t = Hogan.compile(text);
364
- s = t.render({foo:"{{{<42}}}"})
365
- is(s, "{{{&lt;42}}}", "Can't inject mustache");
366
- }
367
-
368
- function testTripleStache() {
369
- var text = "{{{foo}}}";
370
- var t = Hogan.compile(text);
371
- var s = t.render({foo: "< > <div> \' \" &"});
372
- is(s, "< > <div> \' \" &", "input correctly not-escaped.");
373
- }
374
-
375
- function testAmpNoEscaping() {
376
- var text = "{{&foo}}";
377
- var t = Hogan.compile(text);
378
- var s = t.render({foo: "< > <div> \' \" &"});
379
- is(s, "< > <div> \' \" &", "input correctly not-escaped.");
380
- }
381
-
382
- function testPartial() {
383
- var partialText = "this is text from the partial--the magic number {{foo}} is from a variable";
384
- var p = Hogan.compile(partialText);
385
-
386
- var text = "This template contains a partial ({{>testPartial}})."
387
- var t = Hogan.compile(text);
388
-
389
- var s = t.render({foo: 42}, {testPartial: p});
390
- is(s, "This template contains a partial (this is text from the partial--the magic number 42 is from a variable).", "partials work");
391
- }
392
-
393
- function testNestedPartials() {
394
- var partialText = "this is text from the partial--the magic number {{foo}} is from a variable";
395
- var p = Hogan.compile(partialText);
396
-
397
- var partialText2 = "This template contains a partial ({{>testPartial}})."
398
- var p2 = Hogan.compile(partialText2);
399
-
400
- var text = "This template contains a partial that contains a partial [{{>testPartial2}}]."
401
- var t = Hogan.compile(text);
402
-
403
- var s = t.render({foo: 42}, {testPartial: p, testPartial2: p2});
404
- is(s, "This template contains a partial that contains a partial [This template contains a partial (this is text from the partial--the magic number 42 is from a variable).].", "nested partials work");
405
- }
406
-
407
- function testNegativeSection() {
408
- var text = "This template {{^foo}}BOO {{/foo}}contains an inverted section."
409
- var t = Hogan.compile(text);
410
- var s = t.render();
411
- is(s, "This template BOO contains an inverted section.", "inverted sections with no context work");
412
-
413
- s = t.render({foo:[]});
414
- is(s, "This template BOO contains an inverted section.", "inverted sections with empty list context work");
415
-
416
- s = t.render({ foo:false });
417
- is(s, "This template BOO contains an inverted section.", "inverted sections with false context work");
418
-
419
- s = t.render({foo:''});
420
- is(s, "This template contains an inverted section.", "inverted sections with empty string context work");
421
-
422
- s = t.render({foo:true});
423
- is(s, "This template contains an inverted section.", "inverted sections with true context work");
424
-
425
- s = t.render({foo: function() { return false; }});
426
- is(s, "This template BOO contains an inverted section.", "inverted sections with false returning method in context work");
427
- }
428
-
429
- function testSectionElision() {
430
- var text = "This template {{#foo}}BOO {{/foo}}contains a section."
431
- var t = Hogan.compile(text);
432
- var s = t.render();
433
- is(s, "This template contains a section.", "sections with no context work");
434
-
435
- s = t.render({foo:[]});
436
- is(s, "This template contains a section.", "sections with empty list context work");
437
-
438
- s = t.render({foo:false});
439
- is(s, "This template contains a section.", "sections with false context work");
440
- }
441
-
442
- function testSectionObjectContext() {
443
- var text = "This template {{#foo}}{{bar}} {{/foo}}contains a section."
444
- var t = Hogan.compile(text);
445
- var s = t.render({foo:{bar:42}});
446
- is(s, "This template 42 contains a section.", "sections with object context work");
447
- }
448
-
449
- function testSectionArrayContext() {
450
- var text = "This template {{#foo}}{{bar}} {{/foo}}contains a section."
451
- var t = Hogan.compile(text);
452
- var s = t.render({foo:[{bar:42}, {bar:43}, {bar:44}]});
453
- is(s, "This template 42 43 44 contains a section.", "sections with object ctx and array values work");
454
- }
455
-
456
- function testFalsyVariableNoRender() {
457
- var text = "I ({{cannot}}) be seen!";
458
- var t = Hogan.compile(text);
459
- var s = t.render();
460
- is(s, "I () be seen!", "missing value doesn't render.");
461
- }
462
-
463
- function testSectionExtensions() {
464
- var text = "Test {{_//|__foo}}bar{{/foo}}";
465
- var options = {sectionTags:[{o:'_//|__foo', c:'foo'}]};
466
- var tree = Hogan.parse(Hogan.scan(text), options);
467
- is(tree[1].tag, "#", "_//|__foo node transformed to section");
468
- is(tree[1].n, "_//|__foo", "_//|__foo node transformed to section");
469
-
470
- var t = Hogan.compile(text, options );
471
- var s = t.render({'_//|__foo':true});
472
- is(s, "Test bar", "Custom sections work");
473
- }
474
-
475
- function testMisnestedSectionExtensions() {
476
- var text = "Test {{__foo}}bar{{/bar}}";
477
- var options = {sectionTags:[{o:'__foo', c:'foo'}, {o:'__bar', c:'bar'}]};
478
- var msg = '';
479
- try {
480
- var tree = Hogan.parse(Hogan.scan(text), options);
481
- } catch (e) {
482
- msg = e.message;
483
- }
484
- is(msg, "Nesting error: __foo vs. bar", "Error is generated");
485
- }
486
-
487
- function testNestedSection() {
488
- var text = "{{#foo}}{{#bar}}{{baz}}{{/bar}}{{/foo}}";
489
- var t = Hogan.compile(text);
490
- var s = t.render({foo: 42, bar: 42, baz:42});
491
- is(s, "42", "can reach up context stack");
492
- }
493
-
494
- function testDottedNames() {
495
- var text = '"{{person.name}}" == "{{#person}}{{name}}{{/person}}"';
496
- var t = Hogan.compile(text);
497
- var s = t.render({person:{name:'Joe'}});
498
- is(s, '"Joe" == "Joe"', "dotted names work");
499
- }
500
-
501
- function testImplicitIterator() {
502
- var text = '{{#stuff}} {{.}} {{/stuff}}';
503
- var t = Hogan.compile(text);
504
- var s = t.render({stuff:[42,43,44]});
505
- is(s, " 42 43 44 ", "implicit iterators work");
506
- }
507
-
508
- function testPartialsAndDelimiters() {
509
- var text = '{{>include}}*\n{{= | | =}}\n*|>include|';
510
- var partialText = ' .{{value}}. ';
511
- var partial = Hogan.compile(partialText);
512
- var t = Hogan.compile(text);
513
- var s = t.render({value:"yes"}, {'include':partial});
514
- is(s, " .yes. *\n* .yes. ", "partials work around delimiters");
515
- }
516
-
517
- function testStringPartials() {
518
- var text = "foo{{>mypartial}}baz";
519
- var partialText = " bar ";
520
- var t = Hogan.compile(text);
521
- var s = t.render({}, {'mypartial': partialText});
522
- is(s, "foo bar baz", "string partial works.");
523
- }
524
-
525
- function testMissingPartials() {
526
- var text = "foo{{>mypartial}} bar";
527
- var t = Hogan.compile(text);
528
- var s = t.render({});
529
- is(s, "foo bar", "missing partial works.");
530
- }
531
-
532
- function testIndentedStandaloneComment() {
533
- var text = 'Begin.\n {{! Indented Comment Block! }}\nEnd.';
534
- var t = Hogan.compile(text);
535
- var s = t.render();
536
- is(s, 'Begin.\nEnd.', "Standalone comment blocks are removed.");
537
- }
538
-
539
- function testNewLineBetweenDelimiterChanges() {
540
- var data = { section: true, data: 'I got interpolated.' };
541
- var text = '\n{{#section}}\n {{data}}\n |data|\n{{/section}}x\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|';
542
- var t = Hogan.compile(text);
543
- var s = t.render(data);
544
- is(s, '\n I got interpolated.\n |data|\nx\n\n {{data}}\n I got interpolated.\n', 'render correct')
545
- }
546
-
547
- function testMustacheJSApostrophe() {
548
- var text = '{{apos}}{{control}}';
549
- var t = Hogan.compile(text);
550
- var s = t.render({'apos':"'", 'control':"X"});
551
- is(s, '&#39;X', 'Apostrophe is escaped.');
552
- }
553
-
554
- function testMustacheJSArrayOfImplicitPartials() {
555
- var text = 'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}\n';
556
- var partialText = '{{.}}\n';
557
- var t = Hogan.compile(text);
558
- var s = t.render({numbers:[1,2,3,4]}, {partial: partialText});
559
- is(s, 'Here is some stuff!\n1\n2\n3\n4\n', 'Partials with implicit iterators work.');
560
- }
561
-
562
- function testMustacheJSArrayOfPartials() {
563
- var text = 'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}\n';
564
- var partialText = '{{i}}\n';
565
- var t = Hogan.compile(text);
566
- var s = t.render({numbers:[{i:1},{i:2},{i:3},{i:4}]}, {partial: partialText});
567
- is(s, 'Here is some stuff!\n1\n2\n3\n4\n', 'Partials with arrays work.');
568
- }
569
-
570
- function testMustacheJSArrayOfStrings() {
571
- var text = '{{#strings}}{{.}} {{/strings}}';
572
- var t = Hogan.compile(text);
573
- var s = t.render({strings:['foo', 'bar', 'baz']});
574
- is(s, 'foo bar baz ', 'array of strings works with implicit iterators.');
575
- }
576
-
577
- function testMustacheJSUndefinedString() {
578
- var text = 'foo{{bar}}baz';
579
- var t = Hogan.compile(text);
580
- var s = t.render({bar:undefined});
581
- is(s, 'foobaz', 'undefined value does not render.');
582
- }
583
-
584
- function testMustacheJSTripleStacheAltDelimiter() {
585
- var text = '{{=<% %>=}}<% foo %> {{foo}} <%{bar}%> {{{bar}}}';
586
- var t = Hogan.compile(text);
587
- var s = t.render({foo:'yeah', bar:'hmm'});
588
- is(s, 'yeah {{foo}} hmm {{{bar}}}', 'triple stache inside alternate delimiter works.');
589
- }
590
-
591
- /* shootout benchmark tests */
592
-
593
- function testShootOutString() {
594
- var text = "Hello World!";
595
- var expected = "Hello World!"
596
- var t = Hogan.compile(text)
597
- var s = t.render({})
598
- is(s, expected, "Shootout String compiled correctly");
599
- }
600
-
601
- function testShootOutReplace() {
602
- var text = "Hello {{name}}! You have {{count}} new messages.";
603
- var expected = "Hello Mick! You have 30 new messages.";
604
- var t = Hogan.compile(text)
605
- var s = t.render({ name: "Mick", count: 30 })
606
- is(s, expected, "Shootout Replace compiled correctly");
607
- }
608
-
609
- function testShootOutArray() {
610
- var text = "{{#names}}{{name}}{{/names}}";
611
- var expected = "MoeLarryCurlyShemp";
612
- var t = Hogan.compile(text);
613
- var s = t.render({ names: [{name: "Moe"}, {name: "Larry"}, {name: "Curly"}, {name: "Shemp"}] })
614
- is(s, expected, "Shootout Array compiled correctly");
615
- }
616
-
617
- function testShootOutObject() {
618
- var text = "{{#person}}{{name}}{{age}}{{/person}}";
619
- var expected = "Larry45";
620
- var t = Hogan.compile(text)
621
- var s = t.render({ person: { name: "Larry", age: 45 } })
622
- is(s, expected, "Shootout Object compiled correctly");
623
- }
624
-
625
- function testShootOutPartial() {
626
- var text = "{{#peeps}}{{>replace}}{{/peeps}}";
627
- var t = Hogan.compile(text);
628
- var partial = Hogan.compile(" Hello {{name}}! You have {{count}} new messages.");
629
- var s = t.render({ peeps: [{name: "Moe", count: 15}, {name: "Larry", count: 5}, {name: "Curly", count: 2}] }, { replace: partial });
630
- var expected = " Hello Moe! You have 15 new messages. Hello Larry! You have 5 new messages. Hello Curly! You have 2 new messages.";
631
- is(s, expected, "Shootout Partial compiled correctly");
632
- }
633
-
634
- function testShootOutRecurse() {
635
- var text = "{{name}}{{#kids}}{{>recursion}}{{/kids}}";
636
- var t = Hogan.compile(text);
637
- var partial = Hogan.compile("{{name}}{{#kids}}{{>recursion}}{{/kids}}");
638
- var s = t.render({
639
- name: '1',
640
- kids: [
641
- {
642
- name: '1.1',
643
- kids: [
644
- { name: '1.1.1', kids: [] }
645
- ]
646
- }
647
- ]
648
- }, { recursion: partial });
649
- var expected = "11.11.1.1";
650
- is(s, expected, "Shootout Recurse compiled correctly");
651
- }
652
-
653
- function testShootOutFilter() {
654
- var text = "{{#filter}}foo {{bar}}{{/filter}}";
655
- var t = Hogan.compile(text);
656
- var s = t.render({
657
- filter: function() {
658
- return function(text, render) {
659
- return render(text).toUpperCase();
660
- }
661
- },
662
- bar: "bar"
663
- });
664
- var expected = "FOO BAR"
665
- is(s, expected, "Shootout Filter compiled correctly");
666
- }
667
-
668
- function testShootOutComplex() {
669
- var text =
670
- "<h1>{{header}}</h1>" +
671
- "{{#hasItems}}" +
672
- "<ul>" +
673
- "{{#items}}" +
674
- "{{#current}}" +
675
- "<li><strong>{{name}}</strong></li>" +
676
- "{{/current}}" +
677
- "{{^current}}" +
678
- "<li><a href=\"{{url}}\">{{name}}</a></li>" +
679
- "{{/current}}" +
680
- "{{/items}}" +
681
- "</ul>" +
682
- "{{/hasItems}}" +
683
- "{{^hasItems}}" +
684
- "<p>The list is empty.</p>" +
685
- "{{/hasItems}}";
686
-
687
- var expected = "<h1>Colors</h1><ul><li><strong>red</strong></li><li><a href=\"#Green\">green</a></li><li><a href=\"#Blue\">blue</a></li></ul>";
688
- var t = Hogan.compile(text)
689
- var s = t.render({
690
- header: function() {
691
- return "Colors";
692
- },
693
- items: [
694
- {name: "red", current: true, url: "#Red"},
695
- {name: "green", current: false, url: "#Green"},
696
- {name: "blue", current: false, url: "#Blue"}
697
- ],
698
- hasItems: function() {
699
- return this.items.length !== 0;
700
- },
701
- empty: function() {
702
- return this.items.length === 0;
703
- }
704
- })
705
-
706
- is(s, expected, "Shootout Complex compiled correctly");
707
- }
708
-
709
- function testRenderOutput() {
710
- if (doc) return
711
- var fs = require('fs');
712
- var inPath = 'test/templates';
713
- var outPath = 'test/html';
714
-
715
- fs.readdirSync(inPath).forEach(function (file) {
716
- var i = fs.readFileSync([inPath, file].join('/'), 'utf-8');
717
- var t = Hogan.compile(i);
718
- var r = t.render({});
719
- var o = fs.readFileSync([outPath, file].join('/').replace(/mustache$/, 'html')).toString();
720
- is(r === o, true, file + ' should correctly render html')
721
- })
722
- }
723
-
724
- function testDefaultRenderImpl() {
725
- var ht = new Hogan.Template();
726
- is(ht.render() === '', true, 'default renderImpl returns an array.');
727
- }
728
-
729
-
730
- function appendText(el, text) {
731
- var textNode = document.createTextNode(text);
732
- el.appendChild(textNode);
733
- el.appendChild(document.createElement('br'));
734
- }
735
-
736
- if (!this["output"]) {
737
- var output = function (s) {
738
- return doc ? appendText(doc.getElementById('console'), s) : console.log(s);
739
- };
740
- }
741
- var passed = 0;
742
- var failed = 0;
743
-
744
- function is(got, expected, msg) {
745
- if (got === expected) {
746
- output("OK: " + msg);
747
- ++passed;
748
- } else {
749
- output("FAIL: " + msg);
750
- output("Expected |" + expected + "|");
751
- output(" Got |" + got + "|");
752
- ++failed;
753
- }
754
- }
755
-
756
- function complete() {
757
- output("\nTests Complete");
758
- output("--------------");
759
- output("Passed: " + passed);
760
- output("Failed: " + failed);
761
- output("\n");
762
- }
763
-
764
- function runTests() {
765
- output("Tests Starting");
766
- output("--------------");
767
- testScanTextNoTags();
768
- testScanOneTag();
769
- testScanMultipleTags();
770
- testScanSectionOpen();
771
- testScanSectionClose();
772
- testScanSection();
773
- testScanSectionInContent();
774
- testScanNegativeSection();
775
- testScanPartial();
776
- testScanBackwardPartial();
777
- testScanAmpersandNoEscapeTag();
778
- testScanTripleStache();
779
- testScanSectionWithTripleStacheInside();
780
- testScanSetDelimiter();
781
- testScanResetDelimiter();
782
- testSetDelimiterWithWhitespace();
783
- testSingleCharDelimiter();
784
- testParseBasic();
785
- testParseVariables();
786
- testParseSection();
787
- testParseIndexes();
788
- testParseNegativeSection();
789
- testParseNestedSections();
790
- testMissingClosingTag();
791
- testBadNesting();
792
- testBasicOutput();
793
- //testBasicOutputAsString();
794
- testOneVariable();
795
- //testOneVariableAsString();
796
- testMultipleVariables();
797
- testNumberValues();
798
- testObjectRender();
799
- testObjectToStringRender();
800
- testArrayRender();
801
- testEscaping();
802
- testMustacheInjection();
803
- testTripleStache();
804
- testAmpNoEscaping();
805
- testPartial();
806
- testNestedPartials();
807
- testNegativeSection();
808
- testSectionElision();
809
- testSectionObjectContext();
810
- testSectionArrayContext();
811
- testRenderWithWhitespace();
812
- testRenderWithWhitespaceAroundTripleStache();
813
- testRenderWithWhitespaceAroundAmpersand();
814
- testFalsyVariableNoRender();
815
- testRenderOutput();
816
- testDefaultRenderImpl();
817
- testSectionExtensions();
818
- testMisnestedSectionExtensions();
819
- testNestedSection();
820
- testShootOutString();
821
- testShootOutReplace();
822
- testShootOutArray();
823
- testShootOutObject();
824
- testShootOutPartial();
825
- testShootOutRecurse();
826
- testShootOutFilter();
827
- testShootOutComplex();
828
- testDottedNames();
829
- testImplicitIterator();
830
- testPartialsAndDelimiters();
831
- testStringPartials();
832
- testMissingPartials();
833
- testIndentedStandaloneComment();
834
- testNewLineBetweenDelimiterChanges();
835
- testMustacheJSApostrophe();
836
- testMustacheJSArrayOfImplicitPartials();
837
- testMustacheJSArrayOfPartials();
838
- testMustacheJSArrayOfStrings();
839
- testMustacheJSUndefinedString();
840
- testMustacheJSTripleStacheAltDelimiter();
841
- complete();
842
- }
843
-
844
- if (doc) {
845
- window.onload = runTests;
846
- } else {
847
- runTests();
848
- }