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
@@ -1,24 +1,31 @@
1
- require 'haml/helpers/action_view_mods'
2
- require 'haml/helpers/action_view_extensions'
1
+ if defined?(ActionView)
2
+ require 'haml/helpers/action_view_mods'
3
+ require 'haml/helpers/action_view_extensions'
4
+ end
3
5
 
4
6
  module Haml
5
- # This module contains various helpful methods to make it easier to do
6
- # various tasks. Haml::Helpers is automatically included in the context
7
+ # This module contains various helpful methods to make it easier to do various tasks.
8
+ # {Haml::Helpers} is automatically included in the context
7
9
  # that a Haml template is parsed in, so all these methods are at your
8
10
  # disposal from within the template.
9
11
  module Helpers
10
- # An object that raises an error when #to_s is called.
12
+ # An object that raises an error when \{#to\_s} is called.
11
13
  # It's used to raise an error when the return value of a helper is used
12
14
  # when it shouldn't be.
13
15
  class ErrorReturn
16
+ # @param message [String] The error message to raise when \{#to\_s} is called
14
17
  def initialize(message)
15
18
  @message = message
16
19
  end
17
20
 
21
+ # Raises an error.
22
+ #
23
+ # @raise [Haml::Error] The error
18
24
  def to_s
19
25
  raise Haml::Error.new(@message)
20
26
  end
21
27
 
28
+ # @return [String] A human-readable string representation
22
29
  def inspect
23
30
  "Haml::Helpers::ErrorReturn(#{@message.inspect})"
24
31
  end
@@ -29,45 +36,41 @@ module Haml
29
36
  @@action_view_defined = defined?(ActionView)
30
37
  @@force_no_action_view = false
31
38
 
32
- # Returns whether or not ActionView is installed on the system.
39
+ # @return [Boolean] Whether or not ActionView is loaded
33
40
  def self.action_view?
34
41
  @@action_view_defined
35
42
  end
36
43
 
37
- # Note: this does *not* need to be called
38
- # when using Haml helpers normally
39
- # in Rails.
44
+ # Note: this does **not** need to be called when using Haml helpers
45
+ # normally in Rails.
40
46
  #
41
- # Initializes the current object
42
- # as though it were in the same context
43
- # as a normal ActionView rendering
44
- # using Haml.
47
+ # Initializes the current object as though it were in the same context
48
+ # as a normal ActionView instance using Haml.
45
49
  # This is useful if you want to use the helpers in a context
46
50
  # other than the normal setup with ActionView.
47
51
  # For example:
48
52
  #
49
- # context = Object.new
50
- # class << context
51
- # include Haml::Helpers
52
- # end
53
- # context.init_haml_helpers
54
- # context.haml_tag :p, "Stuff"
53
+ # context = Object.new
54
+ # class << context
55
+ # include Haml::Helpers
56
+ # end
57
+ # context.init_haml_helpers
58
+ # context.haml_tag :p, "Stuff"
55
59
  #
56
60
  def init_haml_helpers
57
61
  @haml_buffer = Haml::Buffer.new(@haml_buffer, Haml::Engine.new('').send(:options_for_buffer))
58
62
  nil
59
63
  end
60
64
 
61
- # call-seq:
62
- # non_haml { ... }
63
- #
64
65
  # Runs a block of code in a non-Haml context
65
- # (i.e. #is_haml? will return false).
66
+ # (i.e. \{#is\_haml?} will return false).
66
67
  #
67
68
  # This is mainly useful for rendering sub-templates such as partials in a non-Haml language,
68
69
  # particularly where helpers may behave differently when run from Haml.
69
70
  #
70
71
  # Note that this is automatically applied to Rails partials.
72
+ #
73
+ # @yield A block which won't register as Haml
71
74
  def non_haml
72
75
  was_active = @haml_buffer.active?
73
76
  @haml_buffer.active = false
@@ -76,16 +79,21 @@ module Haml
76
79
  @haml_buffer.active = was_active
77
80
  end
78
81
 
79
- # call-seq:
80
- # find_and_preserve(input, tags = haml_buffer.options[:preserve])
81
- # find_and_preserve {...}
82
- #
83
- # Uses preserve to convert any newlines inside whitespace-sensitive tags
82
+ # Uses \{#preserve} to convert any newlines inside whitespace-sensitive tags
84
83
  # into the HTML entities for endlines.
85
- # +tags+ is an array of tags to preserve.
86
- # It defaults to the value of the <tt>:preserve</tt> option.
87
- def find_and_preserve(input = '', tags = haml_buffer.options[:preserve], &block)
88
- return find_and_preserve(capture_haml(&block)) if block
84
+ #
85
+ # @param tags [Array<String>] Tags that should have newlines escaped
86
+ #
87
+ # @overload find_and_preserve(input, tags = haml_buffer.options[:preserve])
88
+ # Escapes newlines within a string.
89
+ #
90
+ # @param input [String] The string within which to escape newlines
91
+ # @overload find_and_preserve(tags = haml_buffer.options[:preserve])
92
+ # Escapes newlines within a block of Haml code.
93
+ #
94
+ # @yield The block within which to escape newlines
95
+ def find_and_preserve(input = nil, tags = haml_buffer.options[:preserve], &block)
96
+ return find_and_preserve(capture_haml(&block), input || tags) if block
89
97
 
90
98
  input = input.to_s
91
99
  input.gsub(/<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im) do
@@ -93,55 +101,62 @@ module Haml
93
101
  end
94
102
  end
95
103
 
96
- # call-seq:
97
- # preserve(input)
98
- # preserve {...}
99
- #
100
- # Takes any string, finds all the endlines and converts them to
101
- # HTML entities for endlines so they'll render correctly in
104
+ # Takes any string, finds all the newlines, and converts them to
105
+ # HTML entities so they'll render correctly in
102
106
  # whitespace-sensitive tags without screwing up the indentation.
107
+ #
108
+ # @overload perserve(input)
109
+ # Escapes newlines within a string.
110
+ #
111
+ # @param input [String] The string within which to escape all newlines
112
+ # @overload perserve
113
+ # Escapes newlines within a block of Haml code.
114
+ #
115
+ # @yield The block within which to escape newlines
103
116
  def preserve(input = '', &block)
104
117
  return preserve(capture_haml(&block)) if block
105
118
 
106
119
  input.chomp("\n").gsub(/\n/, '&#x000A;').gsub(/\r/, '')
107
120
  end
108
-
109
121
  alias_method :flatten, :preserve
110
122
 
111
- # Takes an Enumerable object and a block
112
- # and iterates over the object,
123
+ # Takes an `Enumerable` object and a block
124
+ # and iterates over the enum,
113
125
  # yielding each element to a Haml block
114
- # and putting the result into <tt><li></tt> elements.
126
+ # and putting the result into `<li>` elements.
115
127
  # This creates a list of the results of the block.
116
128
  # For example:
117
129
  #
118
- # = list_of([['hello'], ['yall']]) do |i|
119
- # = i[0]
130
+ # = list_of([['hello'], ['yall']]) do |i|
131
+ # = i[0]
120
132
  #
121
133
  # Produces:
122
134
  #
123
- # <li>hello</li>
124
- # <li>yall</li>
135
+ # <li>hello</li>
136
+ # <li>yall</li>
125
137
  #
126
138
  # And
127
139
  #
128
- # = list_of({:title => 'All the stuff', :description => 'A book about all the stuff.'}) do |key, val|
129
- # %h3= key.humanize
130
- # %p= val
140
+ # = list_of({:title => 'All the stuff', :description => 'A book about all the stuff.'}) do |key, val|
141
+ # %h3= key.humanize
142
+ # %p= val
131
143
  #
132
144
  # Produces:
133
145
  #
134
- # <li>
135
- # <h3>Title</h3>
136
- # <p>All the stuff</p>
137
- # </li>
138
- # <li>
139
- # <h3>Description</h3>
140
- # <p>A book about all the stuff.</p>
141
- # </li>
142
- #
143
- def list_of(array, &block) # :yields: item
144
- to_return = array.collect do |i|
146
+ # <li>
147
+ # <h3>Title</h3>
148
+ # <p>All the stuff</p>
149
+ # </li>
150
+ # <li>
151
+ # <h3>Description</h3>
152
+ # <p>A book about all the stuff.</p>
153
+ # </li>
154
+ #
155
+ # @param enum [Enumerable] The list of objects to iterate over
156
+ # @yield [item] A block which contains Haml code that goes within list items
157
+ # @yieldparam item An element of `enum`
158
+ def list_of(enum, &block)
159
+ to_return = enum.collect do |i|
145
160
  result = capture_haml(i, &block)
146
161
 
147
162
  if result.count("\n") > 1
@@ -156,18 +171,18 @@ module Haml
156
171
  to_return.join("\n")
157
172
  end
158
173
 
159
- # Returns a hash containing default assignments for the xmlns and xml:lang
160
- # attributes of the <tt>html</tt> HTML element.
161
- # It also takes an optional argument for the value of xml:lang and lang,
162
- # which defaults to 'en-US'.
174
+ # Returns a hash containing default assignments for the `xmlns`, `lang`, and `xml:lang`
175
+ # attributes of the `html` HTML element.
163
176
  # For example,
164
177
  #
165
- # %html{html_attrs}
178
+ # %html{html_attrs}
166
179
  #
167
180
  # becomes
168
181
  #
169
- # <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-US' lang='en-US'>
182
+ # <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-US' lang='en-US'>
170
183
  #
184
+ # @param lang [String] The value of `xml:lang` and `lang`
185
+ # @return [Hash<#to_s, String>] The attribute hash
171
186
  def html_attrs(lang = 'en-US')
172
187
  {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang}
173
188
  end
@@ -176,18 +191,20 @@ module Haml
176
191
  # to the lines of the template.
177
192
  # For example:
178
193
  #
179
- # %h1 foo
180
- # - tab_up
181
- # %p bar
182
- # - tab_down
183
- # %strong baz
194
+ # %h1 foo
195
+ # - tab_up
196
+ # %p bar
197
+ # - tab_down
198
+ # %strong baz
184
199
  #
185
200
  # Produces:
186
201
  #
187
- # <h1>foo</h1>
188
- # <p>bar</p>
189
- # <strong>baz</strong>
202
+ # <h1>foo</h1>
203
+ # <p>bar</p>
204
+ # <strong>baz</strong>
190
205
  #
206
+ # @param i [Fixnum] The number of tabs by which to increase the indentation
207
+ # @see #tab_down
191
208
  def tab_up(i = 1)
192
209
  haml_buffer.tabulation += i
193
210
  end
@@ -195,81 +212,91 @@ module Haml
195
212
  # Decrements the number of tabs the buffer automatically adds
196
213
  # to the lines of the template.
197
214
  #
198
- # See also tab_up.
215
+ # @param i [Fixnum] The number of tabs by which to decrease the indentation
216
+ # @see #tab_up
199
217
  def tab_down(i = 1)
200
218
  haml_buffer.tabulation -= i
201
219
  end
202
220
 
203
- # Surrounds the given block of Haml code with the given characters,
221
+ # Surrounds a block of Haml code with strings,
204
222
  # with no whitespace in between.
205
223
  # For example:
206
224
  #
207
- # = surround '(', ')' do
208
- # %a{:href => "food"} chicken
225
+ # = surround '(', ')' do
226
+ # %a{:href => "food"} chicken
209
227
  #
210
228
  # Produces:
211
229
  #
212
- # (<a href='food'>chicken</a>)
230
+ # (<a href='food'>chicken</a>)
213
231
  #
214
232
  # and
215
233
  #
216
- # = surround '*' do
217
- # %strong angry
234
+ # = surround '*' do
235
+ # %strong angry
218
236
  #
219
237
  # Produces:
220
238
  #
221
- # *<strong>angry</strong>*
239
+ # *<strong>angry</strong>*
222
240
  #
223
- def surround(front, back = nil, &block)
224
- back ||= front
241
+ # @param front [String] The string to add before the Haml
242
+ # @param back [String] The string to add after the Haml
243
+ # @yield A block of Haml to surround
244
+ def surround(front, back = front, &block)
225
245
  output = capture_haml(&block)
226
246
 
227
247
  "#{front}#{output.chomp}#{back}\n"
228
248
  end
229
249
 
230
- # Prepends the given character to the beginning of the Haml block,
250
+ # Prepends a string to the beginning of a Haml block,
231
251
  # with no whitespace between.
232
252
  # For example:
233
253
  #
234
- # = precede '*' do
235
- # %span.small Not really
254
+ # = precede '*' do
255
+ # %span.small Not really
236
256
  #
237
257
  # Produces:
238
258
  #
239
- # *<span class='small'>Not really</span>
259
+ # *<span class='small'>Not really</span>
240
260
  #
241
- def precede(char, &block)
242
- "#{char}#{capture_haml(&block).chomp}\n"
261
+ # @param str [String] The string to add before the Haml
262
+ # @yield A block of Haml to prepend to
263
+ def precede(str, &block)
264
+ "#{str}#{capture_haml(&block).chomp}\n"
243
265
  end
244
266
 
245
- # Appends the given character to the end of the Haml block,
267
+ # Appends a string to the end of a Haml block,
246
268
  # with no whitespace between.
247
269
  # For example:
248
270
  #
249
- # click
250
- # = succeed '.' do
251
- # %a{:href=>"thing"} here
271
+ # click
272
+ # = succeed '.' do
273
+ # %a{:href=>"thing"} here
252
274
  #
253
275
  # Produces:
254
276
  #
255
- # click
256
- # <a href='thing'>here</a>.
277
+ # click
278
+ # <a href='thing'>here</a>.
257
279
  #
258
- def succeed(char, &block)
259
- "#{capture_haml(&block).chomp}#{char}\n"
280
+ # @param str [String] The string to add after the Haml
281
+ # @yield A block of Haml to append to
282
+ def succeed(str, &block)
283
+ "#{capture_haml(&block).chomp}#{str}\n"
260
284
  end
261
285
 
262
- # Captures the result of the given block of Haml code,
286
+ # Captures the result of a block of Haml code,
263
287
  # gets rid of the excess indentation,
264
288
  # and returns it as a string.
265
289
  # For example, after the following,
266
290
  #
267
- # .foo
268
- # - foo = capture_haml(13) do |a|
269
- # %p= a
291
+ # .foo
292
+ # - foo = capture_haml(13) do |a|
293
+ # %p= a
270
294
  #
271
- # the local variable <tt>foo</tt> would be assigned to "<p>13</p>\n".
295
+ # the local variable `foo` would be assigned to `"<p>13</p>\n"`.
272
296
  #
297
+ # @param args [Array] Arguments to pass into the block
298
+ # @yield [args] A block of Haml code that will be converted to a string
299
+ # @yieldparam args [Array] `args`
273
300
  def capture_haml(*args, &block)
274
301
  buffer = eval('_hamlout', block.binding) rescue haml_buffer
275
302
  with_haml_buffer(buffer) do
@@ -295,76 +322,87 @@ module Haml
295
322
  haml_buffer.capture_position = nil
296
323
  end
297
324
 
298
- def puts(*args) # :nodoc:
325
+ # @deprecated This will be removed in version 2.4.
326
+ # @see \{#haml\_concat}
327
+ def puts(*args)
299
328
  warn <<END
300
329
  DEPRECATION WARNING:
301
330
  The Haml #puts helper is deprecated and will be removed in version 2.4.
302
331
  Use the #haml_concat helper instead.
303
332
  END
304
- haml_concat *args
333
+ haml_concat(*args)
305
334
  end
306
335
 
307
- # Outputs text directly to the Haml buffer, with the proper tabulation
336
+ # Outputs text directly to the Haml buffer, with the proper indentation.
337
+ #
338
+ # @param text [#to_s] The text to output
308
339
  def haml_concat(text = "")
309
340
  haml_buffer.buffer << haml_indent << text.to_s << "\n"
310
341
  nil
311
342
  end
312
343
 
313
- # Returns the string that should be used to indent the current line
344
+ # @return [String] The indentation string for the current line
314
345
  def haml_indent
315
346
  ' ' * haml_buffer.tabulation
316
347
  end
317
348
 
318
- #
319
- # call-seq:
320
- # haml_tag(name, *flags, attributes = {}) {...}
321
- # haml_tag(name, text, *flags, attributes = {}) {...}
322
- #
323
349
  # Creates an HTML tag with the given name and optionally text and attributes.
324
- # Can take a block that will be executed
325
- # between when the opening and closing tags are output.
326
- # If the block is a Haml block or outputs text using haml_concat,
350
+ # Can take a block that will run between the opening and closing tags.
351
+ # If the block is a Haml block or outputs text using \{#haml\_concat},
327
352
  # the text will be properly indented.
328
353
  #
329
- # <tt>flags</tt> is a list of symbol flags
354
+ # `flags` is a list of symbol flags
330
355
  # like those that can be put at the end of a Haml tag
331
- # (<tt>:/</tt>, <tt>:<</tt>, and <tt>:></tt>).
332
- # Currently, only <tt>:/</tt> and <tt>:<</tt> are supported.
356
+ # (`:/`, `:<`, and `:>`).
357
+ # Currently, only `:/` and `:<` are supported.
358
+ #
359
+ # `haml_tag` outputs directly to the buffer;
360
+ # its return value should not be used.
361
+ # If you need to get the results as a string,
362
+ # use \{#capture\_haml\}.
333
363
  #
334
364
  # For example,
335
365
  #
336
- # haml_tag :table do
337
- # haml_tag :tr do
338
- # haml_tag :td, {:class => 'cell'} do
339
- # haml_tag :strong, "strong!"
340
- # haml_concat "data"
341
- # end
342
- # haml_tag :td do
343
- # haml_concat "more_data"
366
+ # haml_tag :table do
367
+ # haml_tag :tr do
368
+ # haml_tag :td, {:class => 'cell'} do
369
+ # haml_tag :strong, "strong!"
370
+ # haml_concat "data"
371
+ # end
372
+ # haml_tag :td do
373
+ # haml_concat "more_data"
374
+ # end
344
375
  # end
345
376
  # end
346
- # end
347
377
  #
348
378
  # outputs
349
379
  #
350
- # <table>
351
- # <tr>
352
- # <td class='cell'>
353
- # <strong>
354
- # strong!
355
- # </strong>
356
- # data
357
- # </td>
358
- # <td>
359
- # more_data
360
- # </td>
361
- # </tr>
362
- # </table>
363
- #
380
+ # <table>
381
+ # <tr>
382
+ # <td class='cell'>
383
+ # <strong>
384
+ # strong!
385
+ # </strong>
386
+ # data
387
+ # </td>
388
+ # <td>
389
+ # more_data
390
+ # </td>
391
+ # </tr>
392
+ # </table>
393
+ #
394
+ # @param name [#to_s] The name of the tag
395
+ # @param flags [Array<Symbol>] Haml end-of-tag flags
396
+ #
397
+ # @overload haml_tag(name, *flags, attributes = {})
398
+ # @yield The block of Haml code within the tag
399
+ # @overload haml_tag(name, text, *flags, attributes = {})
400
+ # @param text [#to_s] The text within the tag
364
401
  def haml_tag(name, *rest, &block)
365
402
  ret = ErrorReturn.new(<<MESSAGE)
366
403
  haml_tag outputs directly to the Haml template.
367
- Disregard its return value and use the - operator.
404
+ Disregard its return value and use the - operator,
405
+ or use capture_haml to get the value as a String.
368
406
  MESSAGE
369
407
 
370
408
  name = name.to_s
@@ -414,28 +452,39 @@ MESSAGE
414
452
  # Characters that need to be escaped to HTML entities from user input
415
453
  HTML_ESCAPE = { '&'=>'&amp;', '<'=>'&lt;', '>'=>'&gt;', '"'=>'&quot;', "'"=>'&#039;', }
416
454
 
417
- # Returns a copy of <tt>text</tt> with ampersands, angle brackets and quotes
455
+ # Returns a copy of `text` with ampersands, angle brackets and quotes
418
456
  # escaped into HTML entities.
457
+ #
458
+ # @param text [String] The string to sanitize
459
+ # @return [String] The sanitized string
419
460
  def html_escape(text)
420
461
  text.to_s.gsub(/[\"><&]/) { |s| HTML_ESCAPE[s] }
421
462
  end
422
463
 
423
- # Escapes HTML entities in <tt>text</tt>, but without escaping an ampersand
464
+ # Escapes HTML entities in `text`, but without escaping an ampersand
424
465
  # that is already part of an escaped entity.
466
+ #
467
+ # @param text [String] The string to sanitize
468
+ # @return [String] The sanitized string
425
469
  def escape_once(text)
426
470
  text.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |s| HTML_ESCAPE[s] }
427
471
  end
428
472
 
429
473
  # Returns whether or not the current template is a Haml template.
430
474
  #
431
- # This function, unlike other Haml::Helpers functions,
432
- # also works in other ActionView templates,
475
+ # This function, unlike other {Haml::Helpers} functions,
476
+ # also works in other `ActionView` templates,
433
477
  # where it will always return false.
478
+ #
479
+ # @return [Boolean] Whether or not the current template is a Haml template
434
480
  def is_haml?
435
481
  !@haml_buffer.nil? && @haml_buffer.active?
436
482
  end
437
483
 
438
- # Returns whether or not +block+ is defined directly in a Haml template.
484
+ # Returns whether or not `block` is defined directly in a Haml template.
485
+ #
486
+ # @param block [Proc] A Ruby block
487
+ # @return [Boolean] Whether or not `block` is defined directly in a Haml template
439
488
  def block_is_haml?(block)
440
489
  eval('_hamlout', block.binding)
441
490
  true
@@ -445,10 +494,10 @@ MESSAGE
445
494
 
446
495
  private
447
496
 
448
- # call-seq:
449
- # with_haml_buffer(buffer) {...}
497
+ # Runs a block of code with the given buffer as the currently active buffer.
450
498
  #
451
- # Runs the block with the given buffer as the currently active buffer.
499
+ # @param buffer [Haml::Buffer] The Haml buffer to use temporarily
500
+ # @yield A block in which the given buffer should be used
452
501
  def with_haml_buffer(buffer)
453
502
  @haml_buffer, old_buffer = buffer, @haml_buffer
454
503
  old_buffer.active, was_active = false, old_buffer.active? if old_buffer
@@ -460,13 +509,18 @@ MESSAGE
460
509
  @haml_buffer = old_buffer
461
510
  end
462
511
 
463
- # Gets a reference to the current Haml::Buffer object.
512
+ # The current {Haml::Buffer} object.
513
+ #
514
+ # @return [Haml::Buffer]
464
515
  def haml_buffer
465
516
  @haml_buffer
466
517
  end
467
518
 
468
- # Gives a proc the same local "_hamlout" and "_erbout" variables
519
+ # Gives a proc the same local `_hamlout` and `_erbout` variables
469
520
  # that the current template has.
521
+ #
522
+ # @param proc [#call] The proc to bind
523
+ # @return [Proc] A new proc with the new variables bound
470
524
  def haml_bind_proc(&proc)
471
525
  _hamlout = haml_buffer
472
526
  _erbout = _hamlout.buffer
@@ -478,12 +532,12 @@ MESSAGE
478
532
  end
479
533
 
480
534
  class Object
481
- # Haml overrides various ActionView helpers,
482
- # which call an #is_haml? method
535
+ # Haml overrides various `ActionView` helpers,
536
+ # which call an \{#is\_haml?} method
483
537
  # to determine whether or not the current context object
484
538
  # is a proper Haml context.
485
- # Because ActionView helpers may be included in non-ActionView::Base classes,
486
- # it's a good idea to define is_haml? for all objects.
539
+ # Because `ActionView` helpers may be included in non-`ActionView::Base` classes,
540
+ # it's a good idea to define \{#is\_haml?} for all objects.
487
541
  def is_haml?
488
542
  false
489
543
  end