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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -12,8 +12,27 @@ cert_chain: []
12
12
 
13
13
  date: 2009-07-06 00:00:00 -07:00
14
14
  default_executable:
15
- dependencies: []
16
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: yard
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.2.3
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: maruku
28
+ type: :development
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.5.9
35
+ version:
17
36
  description: Haml (HTML Abstraction Markup Language) is a layer on top of XHTML or XML that's designed to express the structure of XHTML or XML documents in a non-repetitive, elegant, easy way, using indentation rather than closing tags and allowing Ruby to be embedded with ease. It was originally envisioned as a plugin for Ruby on Rails, but it can function as a stand-alone templating engine.
18
37
  email: haml@googlegroups.com
19
38
  executables:
@@ -24,42 +43,60 @@ executables:
24
43
  extensions: []
25
44
 
26
45
  extra_rdoc_files:
27
- - FAQ
46
+ - VERSION_NAME
47
+ - README.md
28
48
  - MIT-LICENSE
29
49
  - VERSION
30
- - README.rdoc
31
50
  - REVISION
32
51
  files:
33
52
  - rails/init.rb
34
53
  - lib/sass.rb
35
54
  - lib/sass
36
55
  - lib/sass/css.rb
56
+ - lib/sass/script
57
+ - lib/sass/script/node.rb
58
+ - lib/sass/script/number.rb
59
+ - lib/sass/script/operation.rb
60
+ - lib/sass/script/literal.rb
61
+ - lib/sass/script/functions.rb
62
+ - lib/sass/script/bool.rb
63
+ - lib/sass/script/color.rb
64
+ - lib/sass/script/lexer.rb
65
+ - lib/sass/script/parser.rb
66
+ - lib/sass/script/variable.rb
67
+ - lib/sass/script/string.rb
68
+ - lib/sass/script/funcall.rb
69
+ - lib/sass/script/unary_operation.rb
70
+ - lib/sass/script.rb
37
71
  - lib/sass/error.rb
72
+ - lib/sass/repl.rb
38
73
  - lib/sass/tree
39
74
  - lib/sass/tree/comment_node.rb
40
75
  - lib/sass/tree/node.rb
41
- - lib/sass/tree/value_node.rb
76
+ - lib/sass/tree/for_node.rb
77
+ - lib/sass/tree/debug_node.rb
78
+ - lib/sass/tree/while_node.rb
79
+ - lib/sass/tree/mixin_def_node.rb
80
+ - lib/sass/tree/if_node.rb
81
+ - lib/sass/tree/mixin_node.rb
42
82
  - lib/sass/tree/directive_node.rb
43
- - lib/sass/tree/attr_node.rb
83
+ - lib/sass/tree/file_node.rb
44
84
  - lib/sass/tree/rule_node.rb
85
+ - lib/sass/tree/prop_node.rb
86
+ - lib/sass/tree/variable_node.rb
45
87
  - lib/sass/plugin
46
88
  - lib/sass/plugin/rails.rb
47
89
  - lib/sass/plugin/merb.rb
48
- - lib/sass/constant.rb
90
+ - lib/sass/environment.rb
91
+ - lib/sass/files.rb
49
92
  - lib/sass/engine.rb
50
93
  - lib/sass/plugin.rb
51
- - lib/sass/constant
52
- - lib/sass/constant/number.rb
53
- - lib/sass/constant/operation.rb
54
- - lib/sass/constant/literal.rb
55
- - lib/sass/constant/color.rb
56
- - lib/sass/constant/string.rb
57
- - lib/sass/constant/nil.rb
58
94
  - lib/haml
59
95
  - lib/haml/filters.rb
60
96
  - lib/haml/exec.rb
61
97
  - lib/haml/error.rb
62
98
  - lib/haml/template.rb
99
+ - lib/haml/shared.rb
63
100
  - lib/haml/engine.rb
64
101
  - lib/haml/version.rb
65
102
  - lib/haml/template
@@ -81,14 +118,16 @@ files:
81
118
  - test/linked_rails.rb
82
119
  - test/benchmark.rb
83
120
  - test/sass
121
+ - test/sass/script_test.rb
84
122
  - test/sass/css2sass_test.rb
85
123
  - test/sass/results
86
- - test/sass/results/constants.css
124
+ - test/sass/results/units.css
87
125
  - test/sass/results/parent_ref.css
88
126
  - test/sass/results/compressed.css
89
127
  - test/sass/results/complex.css
90
128
  - test/sass/results/compact.css
91
129
  - test/sass/results/mixins.css
130
+ - test/sass/results/line_numbers.css
92
131
  - test/sass/results/alt.css
93
132
  - test/sass/results/subdir
94
133
  - test/sass/results/subdir/subdir.css
@@ -97,29 +136,42 @@ files:
97
136
  - test/sass/results/nested.css
98
137
  - test/sass/results/import.css
99
138
  - test/sass/results/multiline.css
139
+ - test/sass/results/script.css
100
140
  - test/sass/results/basic.css
101
141
  - test/sass/results/expanded.css
142
+ - test/sass/more_results
143
+ - test/sass/more_results/more_import.css
144
+ - test/sass/more_results/more1_with_line_comments.css
145
+ - test/sass/more_results/more1.css
102
146
  - test/sass/templates
103
147
  - test/sass/templates/basic.sass
104
148
  - test/sass/templates/bork.sass
105
149
  - test/sass/templates/compressed.sass
106
150
  - test/sass/templates/import.sass
107
- - test/sass/templates/constants.sass
151
+ - test/sass/templates/script.sass
108
152
  - test/sass/templates/expanded.sass
109
153
  - test/sass/templates/nested.sass
110
154
  - test/sass/templates/_partial.sass
155
+ - test/sass/templates/line_numbers.sass
111
156
  - test/sass/templates/compact.sass
112
157
  - test/sass/templates/subdir
113
158
  - test/sass/templates/subdir/subdir.sass
114
159
  - test/sass/templates/subdir/nested_subdir
115
160
  - test/sass/templates/subdir/nested_subdir/nested_subdir.sass
161
+ - test/sass/templates/subdir/nested_subdir/_nested_partial.sass
116
162
  - test/sass/templates/parent_ref.sass
117
163
  - test/sass/templates/alt.sass
118
164
  - test/sass/templates/importee.sass
119
165
  - test/sass/templates/mixins.sass
120
166
  - test/sass/templates/multiline.sass
167
+ - test/sass/templates/units.sass
121
168
  - test/sass/templates/complex.sass
122
169
  - test/sass/templates/bork2.sass
170
+ - test/sass/more_templates
171
+ - test/sass/more_templates/_more_partial.sass
172
+ - test/sass/more_templates/more1.sass
173
+ - test/sass/more_templates/more_import.sass
174
+ - test/sass/functions_test.rb
123
175
  - test/sass/engine_test.rb
124
176
  - test/sass/plugin_test.rb
125
177
  - test/haml
@@ -130,6 +182,7 @@ files:
130
182
  - test/haml/rhtml/standard.rhtml
131
183
  - test/haml/rhtml/_av_partial_1.rhtml
132
184
  - test/haml/rhtml/action_view.rhtml
185
+ - test/haml/util_test.rb
133
186
  - test/haml/html2haml_test.rb
134
187
  - test/haml/template_test.rb
135
188
  - test/haml/helper_test.rb
@@ -191,12 +244,14 @@ files:
191
244
  - test/rails
192
245
  - extra/haml-mode.el
193
246
  - extra/sass-mode.el
247
+ - extra/update_watch.rb
194
248
  - Rakefile
195
249
  - init.rb
196
- - FAQ
250
+ - .yardopts
251
+ - VERSION_NAME
252
+ - README.md
197
253
  - MIT-LICENSE
198
254
  - VERSION
199
- - README.rdoc
200
255
  - REVISION
201
256
  has_rdoc: true
202
257
  homepage: http://haml.hamptoncatlin.com/
@@ -232,9 +287,12 @@ signing_key:
232
287
  specification_version: 2
233
288
  summary: An elegant, structured XHTML/XML templating engine. Comes with Sass, a similar CSS templating engine.
234
289
  test_files:
290
+ - test/sass/script_test.rb
235
291
  - test/sass/css2sass_test.rb
292
+ - test/sass/functions_test.rb
236
293
  - test/sass/engine_test.rb
237
294
  - test/sass/plugin_test.rb
295
+ - test/haml/util_test.rb
238
296
  - test/haml/html2haml_test.rb
239
297
  - test/haml/template_test.rb
240
298
  - test/haml/helper_test.rb
data/FAQ DELETED
@@ -1,138 +0,0 @@
1
- = Frequently Asked Questions
2
-
3
- == Haml
4
-
5
- === How do I put a punctuation mark after an element, like "<tt>I like <strong>cake</strong>!</tt>"?
6
-
7
- Expressing the structure of a document
8
- and expressing inline formatting are two very different problems.
9
- Haml is mostly designed for structure,
10
- so the best way to deal with formatting is to leave it to other languages
11
- that are designed for it.
12
- You could use Textile:
13
-
14
- %p
15
- :textile
16
- I like *cake*!
17
-
18
- or Markdown:
19
-
20
- %p
21
- :markdown
22
- I like **cake**!
23
-
24
- or plain old XHTML:
25
-
26
- %p I like <strong>cake</strong>!
27
-
28
- If you're inserting something that's generated by a helper, like a link,
29
- then it's even easier:
30
-
31
- %p== I like #{link_to 'chocolate', 'http://franschocolates.com'}!
32
-
33
- === How do I stop Haml from indenting the contents of my +pre+ and +textarea+ tags?
34
-
35
- Because Haml automatically indents the HTML source code,
36
- the contents of whitespace-sensitive tags like +pre+ and +textarea+
37
- can get screwed up.
38
- The solution is to replace the newlines inside these tags
39
- with HTML newline entities (<tt>&#x000A;</tt>),
40
- which Haml does using the Haml::Helpers#preserve and Haml::Helpers#find_and_preserve helpers.
41
-
42
- Normally, Haml will do this for you automatically
43
- when you're using a tag that needs it
44
- (this can be customized using the <tt>:preserve</tt> option;
45
- see the Options section of the {Haml reference}(../classes/Haml.html)).
46
- For example,
47
-
48
- %p
49
- %textarea= "Foo\nBar"
50
-
51
- will be compiled to
52
-
53
- <p>
54
- <textarea>Foo&#x000A;Bar</textarea>
55
- </p>
56
-
57
- However, if a helper is generating the tag,
58
- Haml can't detect that and so you'll have to call +find_and_preserve+ yourself.
59
- You can also use <tt>~</tt>, which is the same as <tt>=</tt>
60
- except that it automatically runs +find_and_preserve+ on its input.
61
- For example:
62
-
63
- %p= find_and_preserve "<textarea>Foo\nBar</textarea>"
64
-
65
- is the same as
66
-
67
- %p~ "<textarea>Foo\nBar</textarea>"
68
-
69
- and renders
70
-
71
- <p><textarea>Foo&#x000A;Bar</textarea></p>
72
-
73
- === How do I make my long lines of Ruby code look nicer in my Haml document?
74
-
75
- Put them in a helper or your model.
76
-
77
- Haml purposefully makes it annoying to put lots of Ruby code into your templates,
78
- because lots of code doesn't belong in the view.
79
- If you take that huge +link_to_remote+ call
80
- and move it to a +update_sidebar_link+ helper,
81
- it'll make your view both easier to read and more semantic.
82
-
83
- If you absolutely must put lots of code in your template,
84
- Haml offers a somewhat awkward multiline-continuation tool.
85
- Put a <tt>|</tt> (pipe character) at the end of each line you want to be merged into one
86
- (including the last line!).
87
- For example:
88
-
89
- %p= @this.is(way.too.much). |
90
- code("and I should"). |
91
- really_move.it.into( |
92
- :a => @helper) |
93
-
94
- === I have Haml installed. Why is Rails (only looking for <tt>.html.erb</tt> files | rendering Haml files as plain text | rendering Haml files as blank pages)?
95
-
96
- There are several reasons these things might be happening.
97
- First of all, make sure vendor/plugins/haml really exists
98
- and has an init.rb file in there.
99
- Then try restarting Mongrel or WEBrick or whatever you might be using.
100
-
101
- Finally, if none of these work,
102
- chances are you've got some localization plugin like Globalize installed.
103
- Such plugins often don't play nicely with Haml.
104
- Luckily, there's usually an easy fix.
105
- For Globalize, just edit globalize/lib/globalize/rails/action_view.rb
106
- and change
107
-
108
- @@re_extension = /\.(rjs|rhtml|rxml)$/
109
-
110
- to
111
-
112
- @@re_extension = /\.(rjs|rhtml|rxml|erb|builder|haml)$/
113
-
114
- For other plugins, a little searching will probably turn up a way to fix them as well.
115
-
116
- == Sass
117
-
118
- === Can I use a variable from my controller in my Sass file?
119
-
120
- No. Sass files aren't views.
121
- They're compiled once into static CSS files,
122
- then left along until they're changed and need to be compiled again.
123
- Not only don't you want to be running a full request cycle
124
- every time someone requests a stylesheet,
125
- but it's not a great idea to put much logic in there anyway
126
- due to how browsers handle them.
127
-
128
- If you really need some sort of dynamic CSS,
129
- the best thing to do is put only the snippet you need to dynamically set
130
- in the +head+ of your HTML document.
131
-
132
- == You still haven't answered my question!
133
-
134
- Sorry! Try looking at the Haml or Sass references,
135
- in the doucmentation for the haml and Sass modules, respectively.
136
- If you can't find an answer there,
137
- feel free to ask in #haml on irc.freenode.net
138
- or send an email to the {mailing list}[http://groups.google.com/group/haml?hl=en].
@@ -1,319 +0,0 @@
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
- There are several ways to use Haml and Sass.
15
- They can be used as a plugin for Rails or Merb,
16
- or embedded on their own in other applications.
17
- The first step of all of these is to install the Haml gem:
18
-
19
- gem install haml
20
-
21
- To install Haml and Sass as a Rails plugin,
22
- just run <tt>haml --rails path/to/rails/app</tt>
23
- and both Haml and Sass will be installed.
24
- Views with the <tt>.haml</tt> (or <tt>.html.haml</tt> for edge)
25
- extension will automatically use Haml.
26
- Sass is a little more complicated;
27
- <tt>.sass</tt> files should be placed in public/stylesheets/sass,
28
- where they'll be automatically compiled
29
- to corresponding CSS files in public/stylesheets when needed
30
- (the Sass template directory is customizable...
31
- see the Sass module docs for details).
32
-
33
- For Merb, <tt>.html.haml</tt> views will work without any further modification.
34
- To enable Sass, you also need to add a dependency.
35
- To do so, just add
36
-
37
- dependency "merb-haml"
38
-
39
- to config/dependencies.rb (or config/init.rb in a flat/very flat Merb application).
40
- Then it'll work just like it does in Rails.
41
-
42
- To use Haml and Sass programatically,
43
- check out the RDocs for the Haml and Sass modules.
44
-
45
- == Formatting
46
-
47
- === Haml
48
-
49
- The most basic element of Haml
50
- is a shorthand for creating HTML tags:
51
-
52
- %tagname{ :attr1 => 'value1', :attr2 => 'value2' } Contents
53
-
54
- No end-tag is needed; Haml handles that automatically.
55
- Adding <tt>class</tt> and <tt>id</tt> attributes is even easier.
56
- Haml uses the same syntax as the CSS that styles the document:
57
-
58
- %tagname#id.class
59
-
60
- In fact, when you're using the <tt><div></tt> tag,
61
- it becomes <em>even easier</em>.
62
- Because <tt><div></tt> is such a common element,
63
- a tag without a name defaults to a div. So
64
-
65
- #foo Hello!
66
-
67
- becomes
68
-
69
- <div id='foo'>Hello!</div>
70
-
71
- Haml uses indentation
72
- to bring the individual elements to represent the HTML structure.
73
- A tag's children are indented two spaces more than the parent tag.
74
- Again, a closing tag is automatically added.
75
- For example:
76
-
77
- %ul
78
- %li Salt
79
- %li Pepper
80
-
81
- becomes:
82
-
83
- <ul>
84
- <li>Salt</li>
85
- <li>Pepper</li>
86
- </ul>
87
-
88
- You can also put plain text as a child of an element:
89
-
90
- %p
91
- Hello,
92
- World!
93
-
94
- It's even possible to embed Ruby code into Haml documents.
95
- An equals sign, <tt>=</tt>, will output the result of the code.
96
- A hyphen, <tt>-</tt>, will run the code but not output the result.
97
- You can even use control statements
98
- like <tt>if</tt> and <tt>while</tt>:
99
-
100
- %p
101
- Date/Time:
102
- - now = DateTime.now
103
- %strong= now
104
- - if now > DateTime.parse("December 31, 2006")
105
- = "Happy new " + "year!"
106
-
107
- Haml provides far more tools than those presented here.
108
- Check out the reference documentation in the Haml module.
109
-
110
- === Sass
111
-
112
- At its most basic,
113
- Sass is just another way of writing CSS.
114
- Although it's very much like normal CSS,
115
- the basic syntax offers a few helpful features:
116
- tabulation (using *two spaces*)
117
- indicates the attributes in a rule,
118
- rather than non-DRY brackets;
119
- and newlines indicate the end of an attribute,
120
- rather than a semicolon.
121
- For example:
122
-
123
- #main
124
- :background-color #f00
125
- :width 98%
126
-
127
- becomes:
128
-
129
- #main {
130
- background-color: #f00;
131
- width: 98% }
132
-
133
- However, Sass provides much more than a way to make CSS look nice.
134
- In CSS, it's important to have accurate selectors,
135
- so your styles don't just apply to everything.
136
- However, in order to do this,
137
- you need to use nested element selectors.
138
- These get very ugly very quickly.
139
- I'm sure everyone's had to write something like
140
- "#main .sidebar .top p h1 a",
141
- followed by
142
- "#main .sidebar .top p h1 a:visited" and
143
- "#main .sidebar .top p h1 a:hover".
144
- Well, Sass gets rid of that.
145
- Like Haml, it uses indentation to indicate the structure of the document.
146
- So, what was:
147
-
148
- #main {
149
- width: 90%;
150
- }
151
- #main p {
152
- border-style: solid;
153
- border-width: 1px;
154
- border-color: #00f;
155
- }
156
- #main p a {
157
- text-decoration: none;
158
- font-weight: bold;
159
- }
160
- #main p a:hover {
161
- text-decoration: underline;
162
- }
163
-
164
- becomes:
165
-
166
- #main
167
- :width 90%
168
- p
169
- :border-style solid
170
- :border-width 1px
171
- :border-color #00f
172
- a
173
- :text-decoration none
174
- :font-weight bold
175
- a:hover
176
- :text-decoration underline
177
-
178
- Pretty nice, no? Well, it gets better.
179
- One of the main complaints against CSS is that it doesn't allow constants.
180
- What if have a color or a width you re-use all the time?
181
- In CSS, you just have to re-type it each time,
182
- which is a nightmare when you decide to change it later.
183
- Not so for Sass!
184
- You can use the "!" character to set constants.
185
- Then, if you put "=" after your attribute name,
186
- you can set it to a constant.
187
- For example:
188
-
189
- !note_bg= #55aaff
190
-
191
- #main
192
- :width 70%
193
- .note
194
- :background-color= !note_bg
195
- p
196
- :width 5em
197
- :background-color= !note_bg
198
-
199
- becomes:
200
-
201
- #main {
202
- width: 70%; }
203
- #main .note {
204
- background-color: #55aaff; }
205
- #main p {
206
- width: 5em;
207
- background-color: #55aaff; }
208
-
209
- You can even do simple arithmetic operations with constants,
210
- adding numbers and even colors together:
211
-
212
- !main_bg= #46ar12
213
- !main_width= 40em
214
-
215
- #main
216
- :background-color= !main_bg
217
- :width= !main_width
218
- .sidebar
219
- :background-color= !main_bg + #333333
220
- :width= !main_width - 25em
221
-
222
- becomes:
223
-
224
- #main {
225
- background-color: #46a312;
226
- width: 40em; }
227
- #main .sidebar {
228
- background-color: #79d645;
229
- width: 15em; }
230
-
231
- Taking the idea of constants a bit further are mixins.
232
- These let you group whole swathes of CSS attributes into a single
233
- directive and then include those anywhere you want:
234
-
235
- =blue-border
236
- :border
237
- :color blue
238
- :width 2px
239
- :style dotted
240
-
241
- .comment
242
- +blue-border
243
- :padding 2px
244
- :margin 10px 0
245
-
246
- .reply
247
- +blue-border
248
-
249
- becomes:
250
-
251
- .comment {
252
- border-color: blue;
253
- border-width: 2px;
254
- border-style: dotted;
255
- padding: 2px;
256
- margin: 10px 0;
257
- }
258
-
259
- .reply {
260
- border-color: blue;
261
- border-width: 2px;
262
- border-style: dotted;
263
- }
264
-
265
- A comprehensive list of features is in
266
- the documentation for the Sass module.
267
-
268
- == Executables
269
-
270
- The Haml gem includes several executables that are useful
271
- for dealing with Haml and Sass from the command line.
272
-
273
- === +haml+
274
-
275
- The +haml+ executable transforms a source Haml file into HTML.
276
- See <tt>haml --help</tt> for further information and options.
277
-
278
- === +sass+
279
-
280
- The +sass+ executable transforms a source Sass file into CSS.
281
- See <tt>sass --help</tt> for further information and options.
282
-
283
- === <tt>html2haml</tt>
284
-
285
- The <tt>html2haml</tt> executable attempts to transform HTML,
286
- optionally with ERB markup, into Haml code.
287
- Since HTML is so variable, this transformation is not always perfect;
288
- it's a good idea to have a human check the output of this tool.
289
- See <tt>html2haml --help</tt> for further information and options.
290
-
291
- === <tt>css2sass</tt>
292
-
293
- The <tt>css2sass</tt> executable attempts to transform CSS into Sass code.
294
- This transformation attempts to use Sass nesting where possible.
295
- See <tt>css2sass --help</tt> for further information and options.
296
-
297
- == Authors
298
-
299
- Haml and Sass are designed by Hampton Catlin (hcatlin) and he is the author
300
- of the original implementation. However, Hampton doesn't even know his way
301
- around the code anymore and mostly just concentrates on the language issues.
302
- Hampton lives in Toronto, Ontario (though he's an American by birth) and
303
- is a partner at Unspace Interactive.
304
-
305
- Nathan Weizenbaum is the primary maintainer and architect of the "modern" Ruby
306
- implementation of Haml. His hard work has kept the project alive by endlessly
307
- answering forum posts, fixing bugs, refactoring, finding speed improvements,
308
- writing documentation, implementing new features, and getting Hampton
309
- coffee (a fitting task for a boy-genius). Nathan lives in Seattle, Washington and
310
- while not being a student at University of Washington he consults for
311
- Unspace Interactive and Microsoft.
312
-
313
- If you use this software, you must pay Hampton a compliment. And
314
- buy Nathan some jelly beans. Maybe pet a kitten. Yeah. Pet that kitty.
315
-
316
- Some of the work on Haml was supported by Unspace Interactive.
317
-
318
- Beyond that, the implementation is licensed under the MIT License.
319
- Ok, fine, I guess that means compliments aren't *required*.