drnic-haml 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. data/.yardopts +5 -0
  2. data/CONTRIBUTING +4 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +347 -0
  5. data/REVISION +1 -0
  6. data/Rakefile +371 -0
  7. data/VERSION +1 -0
  8. data/VERSION_NAME +1 -0
  9. data/bin/css2sass +7 -0
  10. data/bin/haml +9 -0
  11. data/bin/html2haml +7 -0
  12. data/bin/sass +8 -0
  13. data/extra/haml-mode.el +663 -0
  14. data/extra/sass-mode.el +205 -0
  15. data/extra/update_watch.rb +13 -0
  16. data/init.rb +8 -0
  17. data/lib/haml.rb +40 -0
  18. data/lib/haml/buffer.rb +307 -0
  19. data/lib/haml/engine.rb +301 -0
  20. data/lib/haml/error.rb +22 -0
  21. data/lib/haml/exec.rb +470 -0
  22. data/lib/haml/filters.rb +341 -0
  23. data/lib/haml/helpers.rb +560 -0
  24. data/lib/haml/helpers/action_view_extensions.rb +40 -0
  25. data/lib/haml/helpers/action_view_mods.rb +176 -0
  26. data/lib/haml/herb.rb +96 -0
  27. data/lib/haml/html.rb +308 -0
  28. data/lib/haml/precompiler.rb +997 -0
  29. data/lib/haml/shared.rb +78 -0
  30. data/lib/haml/template.rb +51 -0
  31. data/lib/haml/template/patch.rb +58 -0
  32. data/lib/haml/template/plugin.rb +71 -0
  33. data/lib/haml/util.rb +244 -0
  34. data/lib/haml/version.rb +64 -0
  35. data/lib/sass.rb +24 -0
  36. data/lib/sass/css.rb +423 -0
  37. data/lib/sass/engine.rb +491 -0
  38. data/lib/sass/environment.rb +79 -0
  39. data/lib/sass/error.rb +162 -0
  40. data/lib/sass/files.rb +133 -0
  41. data/lib/sass/plugin.rb +170 -0
  42. data/lib/sass/plugin/merb.rb +57 -0
  43. data/lib/sass/plugin/rails.rb +23 -0
  44. data/lib/sass/repl.rb +58 -0
  45. data/lib/sass/script.rb +55 -0
  46. data/lib/sass/script/bool.rb +17 -0
  47. data/lib/sass/script/color.rb +183 -0
  48. data/lib/sass/script/funcall.rb +50 -0
  49. data/lib/sass/script/functions.rb +199 -0
  50. data/lib/sass/script/lexer.rb +191 -0
  51. data/lib/sass/script/literal.rb +177 -0
  52. data/lib/sass/script/node.rb +14 -0
  53. data/lib/sass/script/number.rb +381 -0
  54. data/lib/sass/script/operation.rb +45 -0
  55. data/lib/sass/script/parser.rb +222 -0
  56. data/lib/sass/script/string.rb +12 -0
  57. data/lib/sass/script/unary_operation.rb +34 -0
  58. data/lib/sass/script/variable.rb +31 -0
  59. data/lib/sass/tree/comment_node.rb +84 -0
  60. data/lib/sass/tree/debug_node.rb +30 -0
  61. data/lib/sass/tree/directive_node.rb +70 -0
  62. data/lib/sass/tree/for_node.rb +48 -0
  63. data/lib/sass/tree/if_node.rb +54 -0
  64. data/lib/sass/tree/import_node.rb +69 -0
  65. data/lib/sass/tree/mixin_def_node.rb +29 -0
  66. data/lib/sass/tree/mixin_node.rb +48 -0
  67. data/lib/sass/tree/node.rb +252 -0
  68. data/lib/sass/tree/prop_node.rb +106 -0
  69. data/lib/sass/tree/root_node.rb +56 -0
  70. data/lib/sass/tree/rule_node.rb +220 -0
  71. data/lib/sass/tree/variable_node.rb +34 -0
  72. data/lib/sass/tree/while_node.rb +31 -0
  73. data/rails/init.rb +1 -0
  74. data/test/benchmark.rb +99 -0
  75. data/test/haml/engine_test.rb +1129 -0
  76. data/test/haml/helper_test.rb +282 -0
  77. data/test/haml/html2haml_test.rb +258 -0
  78. data/test/haml/markaby/standard.mab +52 -0
  79. data/test/haml/mocks/article.rb +6 -0
  80. data/test/haml/results/content_for_layout.xhtml +12 -0
  81. data/test/haml/results/eval_suppressed.xhtml +9 -0
  82. data/test/haml/results/filters.xhtml +62 -0
  83. data/test/haml/results/helpers.xhtml +93 -0
  84. data/test/haml/results/helpful.xhtml +10 -0
  85. data/test/haml/results/just_stuff.xhtml +68 -0
  86. data/test/haml/results/list.xhtml +12 -0
  87. data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
  88. data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  89. data/test/haml/results/original_engine.xhtml +20 -0
  90. data/test/haml/results/partial_layout.xhtml +5 -0
  91. data/test/haml/results/partials.xhtml +21 -0
  92. data/test/haml/results/render_layout.xhtml +3 -0
  93. data/test/haml/results/silent_script.xhtml +74 -0
  94. data/test/haml/results/standard.xhtml +162 -0
  95. data/test/haml/results/tag_parsing.xhtml +23 -0
  96. data/test/haml/results/very_basic.xhtml +5 -0
  97. data/test/haml/results/whitespace_handling.xhtml +89 -0
  98. data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
  99. data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
  100. data/test/haml/rhtml/action_view.rhtml +62 -0
  101. data/test/haml/rhtml/standard.rhtml +54 -0
  102. data/test/haml/spec_test.rb +44 -0
  103. data/test/haml/template_test.rb +217 -0
  104. data/test/haml/templates/_av_partial_1.haml +9 -0
  105. data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
  106. data/test/haml/templates/_av_partial_2.haml +5 -0
  107. data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
  108. data/test/haml/templates/_layout.erb +3 -0
  109. data/test/haml/templates/_layout_for_partial.haml +3 -0
  110. data/test/haml/templates/_partial.haml +8 -0
  111. data/test/haml/templates/_text_area.haml +3 -0
  112. data/test/haml/templates/action_view.haml +47 -0
  113. data/test/haml/templates/action_view_ugly.haml +47 -0
  114. data/test/haml/templates/breakage.haml +8 -0
  115. data/test/haml/templates/content_for_layout.haml +8 -0
  116. data/test/haml/templates/eval_suppressed.haml +11 -0
  117. data/test/haml/templates/filters.haml +66 -0
  118. data/test/haml/templates/helpers.haml +95 -0
  119. data/test/haml/templates/helpful.haml +11 -0
  120. data/test/haml/templates/just_stuff.haml +83 -0
  121. data/test/haml/templates/list.haml +12 -0
  122. data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
  123. data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  124. data/test/haml/templates/original_engine.haml +17 -0
  125. data/test/haml/templates/partial_layout.haml +3 -0
  126. data/test/haml/templates/partialize.haml +1 -0
  127. data/test/haml/templates/partials.haml +12 -0
  128. data/test/haml/templates/render_layout.haml +2 -0
  129. data/test/haml/templates/silent_script.haml +40 -0
  130. data/test/haml/templates/standard.haml +42 -0
  131. data/test/haml/templates/standard_ugly.haml +42 -0
  132. data/test/haml/templates/tag_parsing.haml +21 -0
  133. data/test/haml/templates/very_basic.haml +4 -0
  134. data/test/haml/templates/whitespace_handling.haml +87 -0
  135. data/test/haml/util_test.rb +92 -0
  136. data/test/linked_rails.rb +12 -0
  137. data/test/sass/css2sass_test.rb +294 -0
  138. data/test/sass/engine_test.rb +956 -0
  139. data/test/sass/functions_test.rb +126 -0
  140. data/test/sass/more_results/more1.css +9 -0
  141. data/test/sass/more_results/more1_with_line_comments.css +26 -0
  142. data/test/sass/more_results/more_import.css +29 -0
  143. data/test/sass/more_templates/_more_partial.sass +2 -0
  144. data/test/sass/more_templates/more1.sass +23 -0
  145. data/test/sass/more_templates/more_import.sass +11 -0
  146. data/test/sass/plugin_test.rb +229 -0
  147. data/test/sass/results/alt.css +4 -0
  148. data/test/sass/results/basic.css +9 -0
  149. data/test/sass/results/compact.css +5 -0
  150. data/test/sass/results/complex.css +87 -0
  151. data/test/sass/results/compressed.css +1 -0
  152. data/test/sass/results/expanded.css +19 -0
  153. data/test/sass/results/import.css +29 -0
  154. data/test/sass/results/line_numbers.css +49 -0
  155. data/test/sass/results/mixins.css +95 -0
  156. data/test/sass/results/multiline.css +24 -0
  157. data/test/sass/results/nested.css +22 -0
  158. data/test/sass/results/parent_ref.css +13 -0
  159. data/test/sass/results/script.css +16 -0
  160. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  161. data/test/sass/results/subdir/subdir.css +3 -0
  162. data/test/sass/results/units.css +11 -0
  163. data/test/sass/script_test.rb +261 -0
  164. data/test/sass/templates/_partial.sass +2 -0
  165. data/test/sass/templates/alt.sass +16 -0
  166. data/test/sass/templates/basic.sass +23 -0
  167. data/test/sass/templates/bork1.sass +2 -0
  168. data/test/sass/templates/bork2.sass +2 -0
  169. data/test/sass/templates/bork3.sass +2 -0
  170. data/test/sass/templates/compact.sass +17 -0
  171. data/test/sass/templates/complex.sass +307 -0
  172. data/test/sass/templates/compressed.sass +15 -0
  173. data/test/sass/templates/expanded.sass +17 -0
  174. data/test/sass/templates/import.sass +11 -0
  175. data/test/sass/templates/importee.sass +19 -0
  176. data/test/sass/templates/line_numbers.sass +13 -0
  177. data/test/sass/templates/mixins.sass +76 -0
  178. data/test/sass/templates/multiline.sass +20 -0
  179. data/test/sass/templates/nested.sass +25 -0
  180. data/test/sass/templates/nested_bork1.sass +2 -0
  181. data/test/sass/templates/nested_bork2.sass +2 -0
  182. data/test/sass/templates/nested_bork3.sass +2 -0
  183. data/test/sass/templates/parent_ref.sass +25 -0
  184. data/test/sass/templates/script.sass +101 -0
  185. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  186. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  187. data/test/sass/templates/subdir/subdir.sass +6 -0
  188. data/test/sass/templates/units.sass +11 -0
  189. data/test/test_helper.rb +44 -0
  190. metadata +298 -0
@@ -0,0 +1,5 @@
1
+ --readme README.md
2
+ --markup markdown
3
+ --markup-provider maruku
4
+ --protected
5
+ --no-highlight
@@ -0,0 +1,4 @@
1
+ Contributions are welcomed. Please see the following sites for guidelines:
2
+
3
+ http://haml-lang.com/development.html#contributing
4
+ http://sass-lang.com/development.html#contributing
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,347 @@
1
+ # Haml and Sass
2
+
3
+ Haml and Sass are templating engines
4
+ for the two most common types of documents on the web:
5
+ HTML and CSS, respectively.
6
+ They are designed to make it both easier and more pleasant
7
+ to code HTML and CSS documents,
8
+ by eliminating redundancy,
9
+ reflecting the underlying structure that the document represents,
10
+ and providing elegant, easily understandable, and powerful syntax.
11
+
12
+ ## Using
13
+
14
+ Haml and Sass can be used from the command line
15
+ or as part of a Ruby web framework.
16
+ The first step is to install the gem:
17
+
18
+ gem install haml
19
+
20
+ After you convert some HTML to Haml or some CSS to Sass,
21
+ you can run
22
+
23
+ haml document.haml
24
+ sass style.sass
25
+
26
+ to compile them.
27
+ For more information on these commands, check out
28
+
29
+ haml --help
30
+ sass --help
31
+
32
+ To install Haml and Sass as a Rails plugin,
33
+ just run `haml --rails path/to/rails/app`
34
+ and both Haml and Sass will be installed.
35
+ Views with the `.html.haml` extension will automatically use Haml.
36
+ Sass is a little more complicated;
37
+ `.sass` files should be placed in `public/stylesheets/sass`,
38
+ where they'll be automatically compiled
39
+ to corresponding CSS files in `public/stylesheets` when needed
40
+ (the Sass template directory is customizable...
41
+ see [the Sass reference](http://sass-lang.com/docs/yardoc/SASS_REFERENCE.md.html#template_location-option) for details).
42
+
43
+ For Merb, `.html.haml` views will work without any further modification.
44
+ To enable Sass, you also need to add a dependency.
45
+ To do so, just add
46
+
47
+ dependency "merb-haml"
48
+
49
+ to `config/dependencies.rb` (or `config/init.rb` in a flat/very flat Merb application).
50
+ Then it'll work just like it does in Rails.
51
+
52
+ To use Haml and Sass programatically,
53
+ check out the [YARD documentation](http://haml-lang.com/docs/yardoc).
54
+
55
+ ## Formatting
56
+
57
+ ### Haml
58
+
59
+ The most basic element of Haml
60
+ is a shorthand for creating HTML:
61
+
62
+ %tagname{:attr1 => 'value1', :attr2 => 'value2'} Contents
63
+
64
+ No end-tag is needed; Haml handles that automatically.
65
+ If you prefer HTML-style attributes, you can also use:
66
+
67
+ %tagname(attr1='value1' attr2='value2') Contents
68
+
69
+ Adding `class` and `id` attributes is even easier.
70
+ Haml uses the same syntax as the CSS that styles the document:
71
+
72
+ %tagname#id.class
73
+
74
+ In fact, when you're using the `<div>` tag,
75
+ it becomes _even easier_.
76
+ Because `<div>` is such a common element,
77
+ a tag without a name defaults to a div. So
78
+
79
+ #foo Hello!
80
+
81
+ becomes
82
+
83
+ <div id='foo'>Hello!</div>
84
+
85
+ Haml uses indentation
86
+ to bring the individual elements to represent the HTML structure.
87
+ A tag's children are indented beneath than the parent tag.
88
+ Again, a closing tag is automatically added.
89
+ For example:
90
+
91
+ %ul
92
+ %li Salt
93
+ %li Pepper
94
+
95
+ becomes:
96
+
97
+ <ul>
98
+ <li>Salt</li>
99
+ <li>Pepper</li>
100
+ </ul>
101
+
102
+ You can also put plain text as a child of an element:
103
+
104
+ %p
105
+ Hello,
106
+ World!
107
+
108
+ It's also possible to embed Ruby code into Haml documents.
109
+ An equals sign, `=`, will output the result of the code.
110
+ A hyphen, `-`, will run the code but not output the result.
111
+ You can even use control statements
112
+ like `if` and `while`:
113
+
114
+ %p
115
+ Date/Time:
116
+ - now = DateTime.now
117
+ %strong= now
118
+ - if now > DateTime.parse("December 31, 2006")
119
+ = "Happy new " + "year!"
120
+
121
+ Haml provides far more tools than those presented here.
122
+ Check out the reference documentation in the Haml module.
123
+
124
+ ### Sass
125
+
126
+ At its most basic,
127
+ Sass is just another way of writing CSS.
128
+ Although it's very much like normal CSS,
129
+ the basic syntax offers a few helpful features:
130
+ indentation indicates the properties in a rule,
131
+ rather than non-DRY brackets;
132
+ and newlines indicate the end of a properties,
133
+ rather than a semicolon.
134
+ For example:
135
+
136
+ #main
137
+ background-color: #f00
138
+ width: 98%
139
+
140
+ becomes:
141
+
142
+ #main {
143
+ background-color: #f00;
144
+ width: 98% }
145
+
146
+ However, Sass provides much more than a way to make CSS look nice.
147
+ In CSS, it's important to have accurate selectors,
148
+ so your styles don't just apply to everything.
149
+ However, in order to do this,
150
+ you need to use nested element selectors.
151
+ These get very ugly very quickly.
152
+ I'm sure everyone's had to write something like
153
+ "#main .sidebar .top p h1 a",
154
+ followed by
155
+ "#main .sidebar .top p h1 a:visited" and
156
+ "#main .sidebar .top p h1 a:hover".
157
+ Well, Sass gets rid of that.
158
+ Like Haml, it uses indentation to indicate the structure of the document.
159
+ So, what was:
160
+
161
+ #main {
162
+ width: 90%;
163
+ }
164
+ #main p {
165
+ border-style: solid;
166
+ border-width: 1px;
167
+ border-color: #00f;
168
+ }
169
+ #main p a {
170
+ text-decoration: none;
171
+ font-weight: bold;
172
+ }
173
+ #main p a:hover {
174
+ text-decoration: underline;
175
+ }
176
+
177
+ becomes:
178
+
179
+ #main
180
+ width: 90%
181
+ p
182
+ border-style: solid
183
+ border-width: 1px
184
+ border-color: #00f
185
+ a
186
+ text-decoration: none
187
+ font-weight: bold
188
+ a:hover
189
+ text-decoration: underline
190
+
191
+ Pretty nice, no? Well, it gets better.
192
+ One of the main complaints against CSS is that it doesn't allow variables.
193
+ What if have a color or a width you re-use all the time?
194
+ In CSS, you just have to re-type it each time,
195
+ which is a nightmare when you decide to change it later.
196
+ Not so for Sass!
197
+ You can use the `!` character to set variables.
198
+ Then, if you put `=` after your property name,
199
+ you can set it to a variable.
200
+ For example:
201
+
202
+ !note_bg= #55aaff
203
+
204
+ #main
205
+ width: 70%
206
+ .note
207
+ background-color = !note_bg
208
+ p
209
+ width: 5em
210
+ background-color = !note_bg
211
+
212
+ becomes:
213
+
214
+ #main {
215
+ width: 70%; }
216
+ #main .note {
217
+ background-color: #55aaff; }
218
+ #main p {
219
+ width: 5em;
220
+ background-color: #55aaff; }
221
+
222
+ You can even do simple arithmetic operations with variables,
223
+ adding numbers and even colors together:
224
+
225
+ !main_bg= #46ar12
226
+ !main_width= 40em
227
+
228
+ #main
229
+ background-color = !main_bg
230
+ width = !main_width
231
+ .sidebar
232
+ background-color = !main_bg + #333333
233
+ width = !main_width - 25em
234
+
235
+ becomes:
236
+
237
+ #main {
238
+ background-color: #46a312;
239
+ width: 40em; }
240
+ #main .sidebar {
241
+ background-color: #79d645;
242
+ width: 15em; }
243
+
244
+ Taking the idea of variables a bit further are mixins.
245
+ These let you group whole bunches of CSS properties into a single
246
+ directive and then include those anywhere you want:
247
+
248
+ =blue-border
249
+ border:
250
+ color: blue
251
+ width: 2px
252
+ style: dotted
253
+
254
+ .comment
255
+ +blue-border
256
+ padding: 2px
257
+ margin: 10px 0
258
+
259
+ .reply
260
+ +blue-border
261
+
262
+ becomes:
263
+
264
+ .comment {
265
+ border-color: blue;
266
+ border-width: 2px;
267
+ border-style: dotted;
268
+ padding: 2px;
269
+ margin: 10px 0;
270
+ }
271
+
272
+ .reply {
273
+ border-color: blue;
274
+ border-width: 2px;
275
+ border-style: dotted;
276
+ }
277
+
278
+ A comprehensive list of features is in
279
+ the documentation for the Sass module.
280
+
281
+ ## Indentation
282
+
283
+ Indentation can be made up of one or more tabs or spaces.
284
+ However, indentation must be consistent within a given document.
285
+ Hard tabs and spaces can't be mixed,
286
+ and the same number of tabs or spaces must be used throughout.
287
+
288
+ ## Executables
289
+
290
+ The Haml gem includes several executables that are useful
291
+ for dealing with Haml and Sass from the command line.
292
+
293
+ ### `haml`
294
+
295
+ The `haml` executable transforms a source Haml file into HTML.
296
+ See `haml --help` for further information and options.
297
+
298
+ ### `sass`
299
+
300
+ The `sass` executable transforms a source Sass file into CSS.
301
+ See `sass --help` for further information and options.
302
+
303
+ ### `html2haml`
304
+
305
+ The `html2haml` executable attempts to transform HTML,
306
+ optionally with ERB markup, into Haml code.
307
+ Since HTML is so variable, this transformation is not always perfect;
308
+ it's a good idea to have a human check the output of this tool.
309
+ See `html2haml --help` for further information and options.
310
+
311
+ ### `css2sass`
312
+
313
+ The `css2sass` executable attempts to transform CSS into Sass code.
314
+ This transformation attempts to use Sass nesting where possible.
315
+ See `css2sass --help` for further information and options.
316
+
317
+ ## Authors
318
+
319
+ Haml and Sass were created by [Hampton Catlin](http://hamptoncatlin.com)
320
+ (hcatlin) and he is the author of the original implementation. However, Hampton
321
+ doesn't even know his way around the code anymore and now occasionally consults
322
+ on the language issues. Hampton lives in Jacksonville, Florida and is the lead
323
+ mobile developer for Wikimedia.
324
+
325
+ [Nathan Weizenbaum](http://nex-3.com) is the primary developer and architect of
326
+ the "modern" Ruby implementation of Haml. His hard work has kept the project
327
+ alive by endlessly answering forum posts, fixing bugs, refactoring, finding
328
+ speed improvements, writing documentation, implementing new features, and
329
+ getting Hampton coffee (a fitting task for a boy-genius). Nathan lives in
330
+ Seattle, Washington and while not being a student at the University of
331
+ Washington or working at an internship, he consults for Unspace Interactive.
332
+
333
+ [Chris Eppstein](http://acts-as-architect.blogspot.com) is a core contributor to
334
+ Sass and the creator of Compass, the first Sass-based framework. Chris focuses
335
+ on making Sass more powerful, easy to use, and on ways to speed its adoption
336
+ through the web development community. Chris lives in San Jose, California with
337
+ his wife and daughter. He is the Software Architect for
338
+ [Caring.com](http://caring.com), a website devoted to the 34 Million caregivers
339
+ whose parents are sick or elderly, that uses Haml and Sass.
340
+
341
+ If you use this software, you must pay Hampton a compliment. And
342
+ buy Nathan some jelly beans. Maybe pet a kitten. Yeah. Pet that kitty.
343
+
344
+ Some of the work on Haml was supported by Unspace Interactive.
345
+
346
+ Beyond that, the implementation is licensed under the MIT License.
347
+ Okay, fine, I guess that means compliments aren't __required__.
@@ -0,0 +1 @@
1
+ (unknown)
@@ -0,0 +1,371 @@
1
+ # ----- Benchmarking -----
2
+
3
+ desc <<END
4
+ Benchmark haml against ERb.
5
+ TIMES=n sets the number of runs. Defaults to 1000.
6
+ END
7
+ task :benchmark do
8
+ sh "ruby test/benchmark.rb #{ENV['TIMES']}"
9
+ end
10
+
11
+ # ----- Default: Testing ------
12
+
13
+ if ENV["RUN_CODE_RUN"] == "true"
14
+ task :default => :"test:rails_compatibility"
15
+ else
16
+ task :default => :test
17
+ end
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new do |t|
22
+ t.libs << 'lib'
23
+ test_files = FileList['test/**/*_test.rb']
24
+ test_files.exclude('test/rails/*')
25
+ test_files.exclude('test/haml/spec/*')
26
+ t.test_files = test_files
27
+ t.verbose = true
28
+ end
29
+ Rake::Task[:test].send(:add_comment, <<END)
30
+ To run with an alternate version of Rails, make test/rails a symlink to that version.
31
+ END
32
+
33
+ # ----- Packaging -----
34
+
35
+ require 'rake/gempackagetask'
36
+ load 'haml.gemspec'
37
+
38
+ Rake::GemPackageTask.new(HAML_GEMSPEC) do |pkg|
39
+ if Rake.application.top_level_tasks.include?('release')
40
+ pkg.need_tar_gz = true
41
+ pkg.need_tar_bz2 = true
42
+ pkg.need_zip = true
43
+ end
44
+ end
45
+
46
+ task :revision_file do
47
+ require 'lib/haml'
48
+
49
+ release = Rake.application.top_level_tasks.include?('release') || File.exist?('EDGE_GEM_VERSION')
50
+ if Haml.version[:rev] && !release
51
+ File.open('REVISION', 'w') { |f| f.puts Haml.version[:rev] }
52
+ elsif release
53
+ File.open('REVISION', 'w') { |f| f.puts "(release)" }
54
+ else
55
+ File.open('REVISION', 'w') { |f| f.puts "(unknown)" }
56
+ end
57
+ end
58
+ Rake::Task[:package].prerequisites.insert(0, :revision_file)
59
+
60
+ # We also need to get rid of this file after packaging.
61
+ at_exit { File.delete('REVISION') rescue nil }
62
+
63
+ desc "Install Haml as a gem."
64
+ task :install => [:package] do
65
+ sudo = RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
66
+ gem = RUBY_PLATFORM =~ /java/ ? 'jgem' : 'gem'
67
+ sh %{#{sudo} #{gem} install --no-ri pkg/haml-#{File.read('VERSION').strip}}
68
+ end
69
+
70
+ desc "Release a new Haml package to Rubyforge."
71
+ task :release => [:check_release, :release_elpa, :package] do
72
+ name = File.read("VERSION_NAME").strip
73
+ version = File.read("VERSION").strip
74
+ sh %{rubyforge login}
75
+ sh %{rubyforge add_release haml haml "#{name} (v#{version})" pkg/haml-#{version}.gem}
76
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.gz}
77
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.bz2}
78
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.zip}
79
+ end
80
+
81
+ # Releases haml-mode.el and sass-mode.el to ELPA.
82
+ task :release_elpa do
83
+ require 'tlsmail'
84
+ require 'time'
85
+
86
+ version = File.read("VERSION").strip
87
+
88
+ haml_unchanged = mode_unchanged?(:haml, version)
89
+ sass_unchanged = mode_unchanged?(:sass, version)
90
+ next if haml_unchanged && sass_unchanged
91
+ raise "haml-mode.el and sass-mode.el are out of sync." if haml_unchanged ^ sass_unchanged
92
+
93
+ rev = File.read('.git/HEAD').strip
94
+ if rev =~ /^ref: (.*)$/
95
+ rev = File.read(".git/#{$1}").strip
96
+ end
97
+
98
+ from = `git config user.email`.strip
99
+ raise "Don't know how to send emails except via Gmail" unless from =~ /@gmail.com$/
100
+
101
+ to = "elpa@tromey.com"
102
+ Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
103
+ Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', from, read_password("GMail Password"), :login) do |smtp|
104
+ smtp.send_message(<<CONTENT, from, to)
105
+ From: Nathan Weizenbaum <#{from}>
106
+ To: #{to}
107
+ Subject: Submitting haml-mode and sass-mode #{version}
108
+ Date: #{Time.now.rfc2822}
109
+
110
+ haml-mode and sass-mode #{version} are packaged and ready to be included in ELPA.
111
+ They can be downloaded from:
112
+
113
+ http://github.com/nex3/haml/raw/#{rev}/extra/haml-mode.el
114
+ http://github.com/nex3/haml/raw/#{rev}/extra/sass-mode.el
115
+ CONTENT
116
+ end
117
+ end
118
+
119
+ # Ensures that the version have been updated for a new release.
120
+ task :check_release do
121
+ version = File.read("VERSION").strip
122
+ raise "There have been changes since current version (#{version})" if changed_since?(version)
123
+ raise "VERSION_NAME must not be 'Bleeding Edge'" if File.read("VERSION_NAME") == "Bleeding Edge"
124
+ end
125
+
126
+ # Reads a password from the command line.
127
+ #
128
+ # @param name [String] The prompt to use to read the password
129
+ def read_password(prompt)
130
+ require 'readline'
131
+ system "stty -echo"
132
+ Readline.readline("#{prompt}: ").strip
133
+ ensure
134
+ system "stty echo"
135
+ puts
136
+ end
137
+
138
+ # Returns whether or not the repository, or specific files,
139
+ # has/have changed since a given revision.
140
+ #
141
+ # @param rev [String] The revision to check against
142
+ # @param files [Array<String>] The files to check.
143
+ # If this is empty, checks the entire repository
144
+ def changed_since?(rev, *files)
145
+ IO.popen("git diff --exit-code #{rev} #{files.join(' ')}") {}
146
+ return !$?.success?
147
+ end
148
+
149
+ # Returns whether or not the given Emacs mode file (haml or sass)
150
+ # has changed since the given version.
151
+ #
152
+ # @param mode [String, Symbol] The name of the mode
153
+ # @param version [String] The version number
154
+ def mode_unchanged?(mode, version)
155
+ mode_version = File.read("extra/#{mode}-mode.el").scan(/^;; Version: (.*)$/).first.first
156
+ return false if mode_version == version
157
+ return true unless changed_since?(mode_version, "extra/#{mode}-mode.el")
158
+ raise "#{mode}-mode.el version is #{version.inspect}, but it has changed as of #{version.inspect}"
159
+ return false
160
+ end
161
+
162
+ task :release_edge do
163
+ ensure_git_cleanup do
164
+ puts "#{'=' * 50} Running rake release_edge"
165
+
166
+ sh %{git checkout edge-gem}
167
+ sh %{git reset --hard origin/edge-gem}
168
+ sh %{git merge origin/master}
169
+
170
+ # Get the current master branch version
171
+ version = File.read('VERSION').strip.split('.').map {|n| n.to_i}
172
+ unless version[1] % 2 == 1 && version[2] == 0
173
+ raise "#{version.join('.')} is not a development version"
174
+ end
175
+
176
+ # Bump the edge gem version
177
+ edge_version = File.read('EDGE_GEM_VERSION').strip.split('.').map {|n| n.to_i}
178
+ if edge_version[0..1] != version[0..1]
179
+ # A new master branch version was released, reset the edge gem version
180
+ edge_version[0..1] = version[0..1]
181
+ edge_version[2] = 0
182
+ else
183
+ # Just bump the teeny version
184
+ edge_version[2] += 1
185
+ end
186
+ edge_version = edge_version.join('.')
187
+ File.open('EDGE_GEM_VERSION', 'w') {|f| f.puts(edge_version)}
188
+ sh %{git commit -m "Bump edge gem version to #{edge_version}." EDGE_GEM_VERSION}
189
+ sh %{git push origin edge-gem}
190
+
191
+ # Package the edge gem with the proper version
192
+ File.open('VERSION', 'w') {|f| f.puts(edge_version)}
193
+ sh %{rake package}
194
+ sh %{git checkout VERSION}
195
+
196
+ sh %{rubyforge login}
197
+ sh %{rubyforge add_release haml haml-edge "Bleeding Edge (v#{edge_version})" pkg/haml-edge-#{edge_version}.gem}
198
+ end
199
+ end
200
+
201
+ task :watch_for_update do
202
+ sh %{ruby extra/update_watch.rb}
203
+ end
204
+
205
+ # ----- Documentation -----
206
+
207
+ task :rdoc do
208
+ puts '=' * 100, <<END, '=' * 100
209
+ Haml uses the YARD documentation system (http://github.com/lsegal/yard).
210
+ Install the yard gem and then run "rake doc".
211
+ END
212
+ end
213
+
214
+ begin
215
+ require 'yard'
216
+
217
+ YARD::Rake::YardocTask.new do |t|
218
+ t.files = FileList.new('lib/**/*.rb') do |list|
219
+ list.exclude('lib/haml/template/*.rb')
220
+ list.exclude('lib/haml/helpers/action_view_mods.rb')
221
+ end.to_a
222
+ t.options << '--use-cache' if Rake.application.top_level_tasks.include?('redoc')
223
+ t.options += FileList.new('yard/*.rb').to_a.map {|f| ['-e', f]}.flatten
224
+ files = FileList.new('doc-src/*').to_a.sort_by {|s| s.size} + %w[MIT-LICENSE VERSION]
225
+ t.options << '--files' << files.join(',')
226
+ end
227
+ Rake::Task['yardoc'].instance_variable_set('@comment', nil)
228
+
229
+ desc "Generate Documentation"
230
+ task :doc => :yardoc
231
+ task :redoc => :yardoc
232
+ rescue LoadError
233
+ desc "Generate Documentation"
234
+ task :doc => :rdoc
235
+ task :yardoc => :rdoc
236
+ end
237
+
238
+ task :pages do
239
+ ensure_git_cleanup do
240
+ puts "#{'=' * 50} Running rake pages PROJ=#{ENV["PROJ"].inspect}"
241
+ raise 'No ENV["PROJ"]!' unless proj = ENV["PROJ"]
242
+ sh %{git checkout #{proj}-pages}
243
+ sh %{git reset --hard origin/#{proj}-pages}
244
+
245
+ sh %{rake build --trace}
246
+ sh %{rsync -av --delete site/ /var/www/#{proj}-pages}
247
+ end
248
+ end
249
+
250
+ # ----- Coverage -----
251
+
252
+ begin
253
+ require 'rcov/rcovtask'
254
+
255
+ Rcov::RcovTask.new do |t|
256
+ t.test_files = FileList['test/**/*_test.rb']
257
+ t.rcov_opts << '-x' << '"^\/"'
258
+ if ENV['NON_NATIVE']
259
+ t.rcov_opts << "--no-rcovrt"
260
+ end
261
+ t.verbose = true
262
+ end
263
+ rescue LoadError; end
264
+
265
+ # ----- Profiling -----
266
+
267
+ begin
268
+ require 'ruby-prof'
269
+
270
+ desc <<END
271
+ Run a profile of haml.
272
+ ENGINE=str sets the engine to be profiled. Defaults to Haml.
273
+ TIMES=n sets the number of runs. Defaults to 1000.
274
+ FILE=str sets the file to profile.
275
+ Defaults to 'standard' for Haml and 'complex' for Sass.
276
+ OUTPUT=str sets the ruby-prof output format.
277
+ Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
278
+ END
279
+ task :profile do
280
+ engine = (ENV['ENGINE'] || 'haml').downcase
281
+ times = (ENV['TIMES'] || '1000').to_i
282
+ file = ENV['FILE']
283
+
284
+ if engine == 'sass'
285
+ require 'lib/sass'
286
+
287
+ file = File.read("#{File.dirname(__FILE__)}/test/sass/templates/#{file || 'complex'}.sass")
288
+ result = RubyProf.profile { times.times { Sass::Engine.new(file).render } }
289
+ else
290
+ require 'lib/haml'
291
+
292
+ file = File.read("#{File.dirname(__FILE__)}/test/haml/templates/#{file || 'standard'}.haml")
293
+ obj = Object.new
294
+ Haml::Engine.new(file).def_method(obj, :render)
295
+ result = RubyProf.profile { times.times { obj.render } }
296
+ end
297
+
298
+ RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
299
+ end
300
+ rescue LoadError; end
301
+
302
+ # ----- Testing Multiple Rails Versions -----
303
+
304
+ rails_versions = [
305
+ "v2.3.0",
306
+ "v2.2.2",
307
+ "v2.1.2",
308
+ "v2.0.5"
309
+ ]
310
+
311
+ namespace :test do
312
+ desc "Test all supported versions of rails. This takes a while."
313
+ task :rails_compatibility do
314
+ `rm -rf test/rails`
315
+ puts "Checking out rails. Please wait."
316
+ `git clone git://github.com/rails/rails.git test/rails` rescue nil
317
+ begin
318
+ rails_versions.each do |version|
319
+ Dir.chdir "test/rails" do
320
+ `git checkout #{version}`
321
+ end
322
+ puts "Testing Rails #{version}"
323
+ Rake::Task['test'].reenable
324
+ Rake::Task['test'].execute
325
+ end
326
+ ensure
327
+ `rm -rf test/rails`
328
+ end
329
+ end
330
+ end
331
+
332
+ # ----- Handling Updates -----
333
+
334
+ def ensure_git_cleanup
335
+ yield
336
+ ensure
337
+ sh %{git reset --hard HEAD}
338
+ sh %{git clean -xdf}
339
+ sh %{git checkout master}
340
+ end
341
+
342
+ task :handle_update do
343
+ unless ENV["REF"] =~ %r{^refs/heads/(master|stable|(?:haml|sass)-pages)$}
344
+ puts "#{'=' * 20} Ignoring rake handle_update REF=#{ENV["REF"].inspect}"
345
+ next
346
+ end
347
+ branch = $1
348
+
349
+ puts
350
+ puts
351
+ puts '=' * 150
352
+ puts "Running rake handle_update REF=#{ENV["REF"].inspect}"
353
+
354
+ sh %{git fetch origin}
355
+ sh %{git checkout stable}
356
+ sh %{git reset --hard origin/stable}
357
+ sh %{git checkout master}
358
+ sh %{git reset --hard origin/master}
359
+
360
+ if branch == "master"
361
+ sh %{rake release_edge --trace}
362
+ elsif branch == "stable"
363
+ sh %{rake pages --trace PROJ=haml}
364
+ sh %{rake pages --trace PROJ=sass}
365
+ elsif branch =~ /^(haml|sass)-pages$/
366
+ sh %{rake pages --trace PROJ=#{$1}}
367
+ end
368
+
369
+ puts 'Done running handle_update'
370
+ puts '=' * 150
371
+ end