haml 2.0.10 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

Files changed (107) hide show
  1. data/.yardopts +5 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +347 -0
  4. data/Rakefile +124 -19
  5. data/VERSION +1 -1
  6. data/VERSION_NAME +1 -0
  7. data/extra/haml-mode.el +397 -78
  8. data/extra/sass-mode.el +148 -36
  9. data/extra/update_watch.rb +13 -0
  10. data/lib/haml.rb +15 -993
  11. data/lib/haml/buffer.rb +131 -84
  12. data/lib/haml/engine.rb +129 -97
  13. data/lib/haml/error.rb +7 -7
  14. data/lib/haml/exec.rb +127 -42
  15. data/lib/haml/filters.rb +107 -42
  16. data/lib/haml/helpers.rb +210 -156
  17. data/lib/haml/helpers/action_view_extensions.rb +34 -39
  18. data/lib/haml/helpers/action_view_mods.rb +132 -139
  19. data/lib/haml/html.rb +77 -65
  20. data/lib/haml/precompiler.rb +404 -213
  21. data/lib/haml/shared.rb +78 -0
  22. data/lib/haml/template.rb +14 -14
  23. data/lib/haml/template/patch.rb +2 -2
  24. data/lib/haml/template/plugin.rb +2 -3
  25. data/lib/haml/util.rb +211 -6
  26. data/lib/haml/version.rb +30 -13
  27. data/lib/sass.rb +7 -856
  28. data/lib/sass/css.rb +169 -161
  29. data/lib/sass/engine.rb +344 -328
  30. data/lib/sass/environment.rb +79 -0
  31. data/lib/sass/error.rb +33 -11
  32. data/lib/sass/files.rb +139 -0
  33. data/lib/sass/plugin.rb +160 -117
  34. data/lib/sass/plugin/merb.rb +7 -6
  35. data/lib/sass/plugin/rails.rb +5 -6
  36. data/lib/sass/repl.rb +58 -0
  37. data/lib/sass/script.rb +59 -0
  38. data/lib/sass/script/bool.rb +17 -0
  39. data/lib/sass/script/color.rb +183 -0
  40. data/lib/sass/script/funcall.rb +50 -0
  41. data/lib/sass/script/functions.rb +198 -0
  42. data/lib/sass/script/lexer.rb +178 -0
  43. data/lib/sass/script/literal.rb +177 -0
  44. data/lib/sass/script/node.rb +14 -0
  45. data/lib/sass/script/number.rb +381 -0
  46. data/lib/sass/script/operation.rb +45 -0
  47. data/lib/sass/script/parser.rb +172 -0
  48. data/lib/sass/script/string.rb +12 -0
  49. data/lib/sass/script/unary_operation.rb +34 -0
  50. data/lib/sass/script/variable.rb +31 -0
  51. data/lib/sass/tree/comment_node.rb +73 -10
  52. data/lib/sass/tree/debug_node.rb +30 -0
  53. data/lib/sass/tree/directive_node.rb +42 -17
  54. data/lib/sass/tree/file_node.rb +41 -0
  55. data/lib/sass/tree/for_node.rb +48 -0
  56. data/lib/sass/tree/if_node.rb +54 -0
  57. data/lib/sass/tree/mixin_def_node.rb +29 -0
  58. data/lib/sass/tree/mixin_node.rb +48 -0
  59. data/lib/sass/tree/node.rb +214 -11
  60. data/lib/sass/tree/prop_node.rb +109 -0
  61. data/lib/sass/tree/rule_node.rb +178 -51
  62. data/lib/sass/tree/variable_node.rb +34 -0
  63. data/lib/sass/tree/while_node.rb +31 -0
  64. data/test/haml/engine_test.rb +331 -36
  65. data/test/haml/helper_test.rb +12 -1
  66. data/test/haml/results/content_for_layout.xhtml +0 -3
  67. data/test/haml/results/filters.xhtml +2 -0
  68. data/test/haml/results/list.xhtml +1 -1
  69. data/test/haml/template_test.rb +7 -2
  70. data/test/haml/templates/content_for_layout.haml +0 -2
  71. data/test/haml/templates/list.haml +1 -1
  72. data/test/haml/util_test.rb +92 -0
  73. data/test/sass/css2sass_test.rb +69 -24
  74. data/test/sass/engine_test.rb +586 -64
  75. data/test/sass/functions_test.rb +125 -0
  76. data/test/sass/more_results/more1.css +9 -0
  77. data/test/sass/more_results/more1_with_line_comments.css +26 -0
  78. data/test/sass/more_results/more_import.css +29 -0
  79. data/test/sass/more_templates/_more_partial.sass +2 -0
  80. data/test/sass/more_templates/more1.sass +23 -0
  81. data/test/sass/more_templates/more_import.sass +11 -0
  82. data/test/sass/plugin_test.rb +81 -28
  83. data/test/sass/results/line_numbers.css +49 -0
  84. data/test/sass/results/{constants.css → script.css} +4 -4
  85. data/test/sass/results/subdir/subdir.css +2 -0
  86. data/test/sass/results/units.css +11 -0
  87. data/test/sass/script_test.rb +258 -0
  88. data/test/sass/templates/import.sass +1 -1
  89. data/test/sass/templates/importee.sass +7 -2
  90. data/test/sass/templates/line_numbers.sass +13 -0
  91. data/test/sass/templates/{constants.sass → script.sass} +11 -10
  92. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  93. data/test/sass/templates/subdir/subdir.sass +2 -2
  94. data/test/sass/templates/units.sass +11 -0
  95. data/test/test_helper.rb +14 -0
  96. metadata +77 -19
  97. data/FAQ +0 -138
  98. data/README.rdoc +0 -319
  99. data/lib/sass/constant.rb +0 -216
  100. data/lib/sass/constant/color.rb +0 -101
  101. data/lib/sass/constant/literal.rb +0 -54
  102. data/lib/sass/constant/nil.rb +0 -9
  103. data/lib/sass/constant/number.rb +0 -87
  104. data/lib/sass/constant/operation.rb +0 -30
  105. data/lib/sass/constant/string.rb +0 -22
  106. data/lib/sass/tree/attr_node.rb +0 -57
  107. data/lib/sass/tree/value_node.rb +0 -20
@@ -0,0 +1,5 @@
1
+ --readme README.md
2
+ --markup markdown
3
+ --markup-provider maruku
4
+ --protected
5
+ --no-highlight
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2008 Hampton Catlin
1
+ Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -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__.
data/Rakefile CHANGED
@@ -48,9 +48,10 @@ end
48
48
  task :revision_file do
49
49
  require 'lib/haml'
50
50
 
51
- if Haml.version[:rev] && !Rake.application.top_level_tasks.include?('release')
51
+ release = Rake.application.top_level_tasks.include?('release') || File.exist?('EDGE_GEM_VERSION')
52
+ if Haml.version[:rev] && !release
52
53
  File.open('REVISION', 'w') { |f| f.puts Haml.version[:rev] }
53
- elsif Rake.application.top_level_tasks.include?('release')
54
+ elsif release
54
55
  File.open('REVISION', 'w') { |f| f.puts "(release)" }
55
56
  else
56
57
  File.open('REVISION', 'w') { |f| f.puts "(unknown)" }
@@ -70,8 +71,9 @@ end
70
71
 
71
72
  desc "Release a new Haml package to Rubyforge. Requires the NAME and VERSION flags."
72
73
  task :release => [:package] do
73
- name, version = ENV['NAME'], ENV['VERSION']
74
- raise "Must supply NAME and VERSION for release task." unless name && version
74
+ name = File.read("VERSION_NAME").strip
75
+ version = File.read("VERSION").strip
76
+ raise "VERSION_NAME must not be 'Bleeding Edge'" if name == "Bleeding Edge"
75
77
  sh %{rubyforge login}
76
78
  sh %{rubyforge add_release haml haml "#{name} (v#{version})" pkg/haml-#{version}.gem}
77
79
  sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.gz}
@@ -79,27 +81,92 @@ task :release => [:package] do
79
81
  sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.zip}
80
82
  end
81
83
 
84
+ task :release_edge do
85
+ ensure_git_cleanup do
86
+ puts "#{'=' * 50} Running rake release_edge"
87
+
88
+ sh %{git checkout edge-gem}
89
+ sh %{git reset --hard origin/edge-gem}
90
+ sh %{git merge origin/master}
91
+
92
+ # Get the current master branch version
93
+ version = File.read('VERSION').strip.split('.').map {|n| n.to_i}
94
+ unless version[1] % 2 == 1 && version[2] == 0
95
+ raise "#{version.join('.')} is not a development version"
96
+ end
97
+
98
+ # Bump the edge gem version
99
+ edge_version = File.read('EDGE_GEM_VERSION').strip.split('.').map {|n| n.to_i}
100
+ if edge_version[0..1] != version[0..1]
101
+ # A new master branch version was released, reset the edge gem version
102
+ edge_version[0..1] = version[0..1]
103
+ edge_version[2] = 0
104
+ else
105
+ # Just bump the teeny version
106
+ edge_version[2] += 1
107
+ end
108
+ edge_version = edge_version.join('.')
109
+ File.open('EDGE_GEM_VERSION', 'w') {|f| f.puts(edge_version)}
110
+ sh %{git commit -m "Bump edge gem version to #{edge_version}." EDGE_GEM_VERSION}
111
+ sh %{git push origin edge-gem}
112
+
113
+ # Package the edge gem with the proper version
114
+ File.open('VERSION', 'w') {|f| f.puts(edge_version)}
115
+ sh %{rake package}
116
+ sh %{git checkout VERSION}
117
+
118
+ sh %{rubyforge login}
119
+ sh %{rubyforge add_release haml haml-edge "Bleeding Edge (v#{edge_version})" pkg/haml-edge-#{edge_version}.gem}
120
+ end
121
+ end
122
+
123
+ task :watch_for_update do
124
+ sh %{ruby extra/update_watch.rb}
125
+ end
126
+
82
127
  # ----- Documentation -----
83
128
 
129
+ task :rdoc do
130
+ puts '=' * 100, <<END, '=' * 100
131
+ Haml uses the YARD documentation system (http://github.com/lsegal/yard).
132
+ Install the yard gem and then run "rake doc".
133
+ END
134
+ end
135
+
84
136
  begin
85
- require 'hanna/rdoctask'
137
+ require 'yard'
138
+
139
+ YARD::Rake::YardocTask.new do |t|
140
+ t.files = FileList.new('lib/**/*.rb') do |list|
141
+ list.exclude('lib/haml/template/*.rb')
142
+ list.exclude('lib/haml/helpers/action_view_mods.rb')
143
+ end.to_a
144
+ t.options << '--use-cache' if Rake.application.top_level_tasks.include?('redoc')
145
+ t.options += FileList.new('yard/*.rb').to_a.map {|f| ['-e', f]}.flatten
146
+ files = FileList.new('doc-src/*').to_a.sort_by {|s| s.size} + %w[MIT-LICENSE VERSION]
147
+ t.options << '--files' << files.join(',')
148
+ end
149
+ Rake::Task['yardoc'].instance_variable_set('@comment', nil)
150
+
151
+ desc "Generate Documentation"
152
+ task :doc => :yardoc
153
+ task :redoc => :yardoc
86
154
  rescue LoadError
87
- require 'rake/rdoctask'
155
+ desc "Generate Documentation"
156
+ task :doc => :rdoc
157
+ task :yardoc => :rdoc
88
158
  end
89
159
 
90
- Rake::RDocTask.new do |rdoc|
91
- rdoc.title = 'Haml/Sass'
92
- rdoc.options << '--line-numbers' << '--inline-source'
93
- rdoc.rdoc_files.include(*FileList.new('*') do |list|
94
- list.exclude(/(^|[^.a-z])[a-z]+/)
95
- list.exclude('TODO')
96
- end.to_a)
97
- rdoc.rdoc_files.include('lib/**/*.rb')
98
- rdoc.rdoc_files.exclude('TODO')
99
- rdoc.rdoc_files.exclude('lib/haml/buffer.rb')
100
- rdoc.rdoc_files.exclude('lib/sass/tree/*')
101
- rdoc.rdoc_dir = 'rdoc'
102
- rdoc.main = 'README.rdoc'
160
+ task :pages do
161
+ ensure_git_cleanup do
162
+ puts "#{'=' * 50} Running rake pages PROJ=#{ENV["PROJ"].inspect}"
163
+ raise 'No ENV["PROJ"]!' unless proj = ENV["PROJ"]
164
+ sh %{git checkout #{proj}-pages}
165
+ sh %{git reset --hard origin/#{proj}-pages}
166
+
167
+ sh %{rake build --trace}
168
+ sh %{rsync -av --delete site/ /var/www/#{proj}-pages}
169
+ end
103
170
  end
104
171
 
105
172
  # ----- Coverage -----
@@ -183,3 +250,41 @@ namespace :test do
183
250
  end
184
251
  end
185
252
  end
253
+
254
+ # ----- Handling Updates -----
255
+
256
+ def ensure_git_cleanup
257
+ yield
258
+ ensure
259
+ sh %{git reset --hard HEAD}
260
+ sh %{git clean -xdf}
261
+ sh %{git checkout master}
262
+ end
263
+
264
+ task :handle_update do
265
+ unless ENV["REF"] =~ %r{^refs/heads/(master|(?:haml|sass)-pages)$}
266
+ puts "#{'=' * 20} Ignoring rake handle_update REF=#{ENV["REF"].inspect}"
267
+ next
268
+ end
269
+ branch = $1
270
+
271
+ puts
272
+ puts
273
+ puts '=' * 150
274
+ puts "Running rake handle_update REF=#{ENV["REF"].inspect}"
275
+
276
+ sh %{git checkout master}
277
+ sh %{git fetch origin}
278
+ sh %{git reset --hard origin/master}
279
+
280
+ if branch == "master"
281
+ sh %{rake release_edge --trace}
282
+ sh %{rake pages --trace PROJ=haml}
283
+ sh %{rake pages --trace PROJ=sass}
284
+ elsif branch =~ /^(haml|sass)-pages$/
285
+ sh %{rake pages --trace PROJ=#{$1}}
286
+ end
287
+
288
+ puts 'Done running handle_update'
289
+ puts '=' * 150
290
+ end