haml-edge 2.1.21 → 2.1.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/EDGE_GEM_VERSION +1 -1
  2. data/FAQ.md +142 -0
  3. data/{README.rdoc → README.md} +141 -141
  4. data/Rakefile +29 -17
  5. data/VERSION +1 -1
  6. data/lib/haml/buffer.rb +63 -27
  7. data/lib/haml/engine.rb +103 -80
  8. data/lib/haml/error.rb +7 -7
  9. data/lib/haml/exec.rb +80 -26
  10. data/lib/haml/filters.rb +106 -40
  11. data/lib/haml/helpers/action_view_extensions.rb +34 -39
  12. data/lib/haml/helpers/action_view_mods.rb +132 -139
  13. data/lib/haml/helpers.rb +207 -153
  14. data/lib/haml/html.rb +40 -21
  15. data/lib/haml/precompiler.rb +2 -0
  16. data/lib/haml/shared.rb +34 -3
  17. data/lib/haml/template/patch.rb +1 -1
  18. data/lib/haml/template/plugin.rb +0 -2
  19. data/lib/haml/template.rb +5 -0
  20. data/lib/haml/util.rb +136 -1
  21. data/lib/haml/version.rb +16 -4
  22. data/lib/haml.rb +502 -481
  23. data/lib/sass/css.rb +106 -68
  24. data/lib/sass/engine.rb +55 -22
  25. data/lib/sass/environment.rb +52 -21
  26. data/lib/sass/error.rb +23 -12
  27. data/lib/sass/files.rb +27 -0
  28. data/lib/sass/plugin/merb.rb +2 -2
  29. data/lib/sass/plugin/rails.rb +0 -2
  30. data/lib/sass/plugin.rb +32 -23
  31. data/lib/sass/repl.rb +7 -0
  32. data/lib/sass/script/bool.rb +9 -5
  33. data/lib/sass/script/color.rb +87 -1
  34. data/lib/sass/script/funcall.rb +23 -2
  35. data/lib/sass/script/functions.rb +93 -44
  36. data/lib/sass/script/lexer.rb +33 -3
  37. data/lib/sass/script/literal.rb +93 -1
  38. data/lib/sass/script/node.rb +14 -0
  39. data/lib/sass/script/number.rb +128 -4
  40. data/lib/sass/script/operation.rb +16 -1
  41. data/lib/sass/script/parser.rb +51 -21
  42. data/lib/sass/script/string.rb +7 -4
  43. data/lib/sass/script/unary_operation.rb +14 -1
  44. data/lib/sass/script/variable.rb +12 -1
  45. data/lib/sass/script.rb +26 -5
  46. data/lib/sass/tree/attr_node.rb +46 -9
  47. data/lib/sass/tree/comment_node.rb +41 -1
  48. data/lib/sass/tree/debug_node.rb +8 -0
  49. data/lib/sass/tree/directive_node.rb +20 -0
  50. data/lib/sass/tree/file_node.rb +12 -0
  51. data/lib/sass/tree/for_node.rb +15 -0
  52. data/lib/sass/tree/if_node.rb +22 -0
  53. data/lib/sass/tree/mixin_def_node.rb +12 -1
  54. data/lib/sass/tree/mixin_node.rb +13 -0
  55. data/lib/sass/tree/node.rb +136 -6
  56. data/lib/sass/tree/rule_node.rb +66 -7
  57. data/lib/sass/tree/variable_node.rb +10 -0
  58. data/lib/sass/tree/while_node.rb +11 -1
  59. data/lib/sass.rb +544 -534
  60. metadata +7 -6
  61. data/FAQ +0 -138
data/lib/haml/exec.rb CHANGED
@@ -2,19 +2,18 @@ require 'optparse'
2
2
  require 'fileutils'
3
3
 
4
4
  module Haml
5
- # This module contains code for working with the
6
- # haml, sass, and haml2html executables,
7
- # such as command-line parsing stuff.
8
- # It shouldn't need to be invoked by client code.
9
- module Exec # :nodoc:
10
- # A class that encapsulates the executable code
11
- # for all three executables.
12
- class Generic # :nodoc:
5
+ # This module handles the various Haml executables (`haml`, `sass`, `css2sass`, etc).
6
+ module Exec
7
+ # An abstract class that encapsulates the executable code for all three executables.
8
+ class Generic
9
+ # @param args [Array<String>] The command-line arguments
13
10
  def initialize(args)
14
11
  @args = args
15
12
  @options = {}
16
13
  end
17
14
 
15
+ # Parses the command-line arguments and runs the executable.
16
+ # Calls `Kernel#exit` at the end, so it never returns.
18
17
  def parse!
19
18
  begin
20
19
  @opts = OptionParser.new(&method(:set_opts))
@@ -32,12 +31,18 @@ module Haml
32
31
  exit 0
33
32
  end
34
33
 
34
+ # @return [String] A description of the executable
35
35
  def to_s
36
36
  @opts.to_s
37
37
  end
38
38
 
39
39
  protected
40
40
 
41
+ # Finds the line of the source template
42
+ # on which an exception was raised.
43
+ #
44
+ # @param exception [Exception] The exception
45
+ # @return [String] The line number
41
46
  def get_line(exception)
42
47
  # SyntaxErrors have weird line reporting
43
48
  # when there's trailing whitespace,
@@ -46,8 +51,13 @@ module Haml
46
51
  exception.backtrace[0].scan(/:(\d+)/).first.first
47
52
  end
48
53
 
49
- private
50
-
54
+ # Tells optparse how to parse the arguments
55
+ # available for all executables.
56
+ #
57
+ # This is meant to be overridden by subclasses
58
+ # so they can add their own options.
59
+ #
60
+ # @param opts [OptionParser]
51
61
  def set_opts(opts)
52
62
  opts.on('-s', '--stdin', :NONE, 'Read input from standard input instead of an input file') do
53
63
  @options[:input] = $stdin
@@ -68,6 +78,12 @@ module Haml
68
78
  end
69
79
  end
70
80
 
81
+ # Processes the options set by the command-line arguments.
82
+ # In particular, sets `@options[:input]` and `@options[:output]`
83
+ # to appropriate IO streams.
84
+ #
85
+ # This is meant to be overridden by subclasses
86
+ # so they can run their respective programs.
71
87
  def process_result
72
88
  input, output = @options[:input], @options[:output]
73
89
  input_file, output_file = if input
@@ -85,22 +101,32 @@ module Haml
85
101
  @options[:input], @options[:output] = input, output
86
102
  end
87
103
 
104
+ private
105
+
88
106
  def open_file(filename, flag = 'r')
89
107
  return if filename.nil?
90
108
  File.open(filename, flag)
91
109
  end
92
110
  end
93
111
 
94
- # A class encapsulating the executable functionality
95
- # specific to Haml and Sass.
96
- class HamlSass < Generic # :nodoc:
112
+ # An abstrac class that encapsulates the code
113
+ # specific to the `haml` and `sass` executables.
114
+ class HamlSass < Generic
115
+ # @param args [Array<String>] The command-line arguments
97
116
  def initialize(args)
98
117
  super
99
118
  @options[:for_engine] = {}
100
119
  end
101
120
 
102
- private
121
+ protected
103
122
 
123
+ # Tells optparse how to parse the arguments
124
+ # available for the `haml` and `sass` executables.
125
+ #
126
+ # This is meant to be overridden by subclasses
127
+ # so they can add their own options.
128
+ #
129
+ # @param opts [OptionParser]
104
130
  def set_opts(opts)
105
131
  opts.banner = <<END
106
132
  Usage: #{@name.downcase} [options] [INPUT] [OUTPUT]
@@ -155,6 +181,12 @@ END
155
181
  super
156
182
  end
157
183
 
184
+ # Processes the options set by the command-line arguments.
185
+ # In particular, sets `@options[:for_engine][:filename]` to the input filename
186
+ # and requires the appropriate file.
187
+ #
188
+ # This is meant to be overridden by subclasses
189
+ # so they can run their respective programs.
158
190
  def process_result
159
191
  super
160
192
  @options[:for_engine][:filename] = @options[:filename] if @options[:filename]
@@ -162,15 +194,20 @@ END
162
194
  end
163
195
  end
164
196
 
165
- # A class encapsulating executable functionality
166
- # specific to Sass.
167
- class Sass < HamlSass # :nodoc:
197
+ # The `sass` executable.
198
+ class Sass < HamlSass
199
+ # @param args [Array<String>] The command-line arguments
168
200
  def initialize(args)
169
201
  super
170
202
  @name = "Sass"
171
203
  @options[:for_engine][:load_paths] = ['.'] + (ENV['SASSPATH'] || '').split(File::PATH_SEPARATOR)
172
204
  end
173
205
 
206
+ protected
207
+
208
+ # Tells optparse how to parse the arguments.
209
+ #
210
+ # @param opts [OptionParser]
174
211
  def set_opts(opts)
175
212
  super
176
213
 
@@ -197,6 +234,8 @@ END
197
234
  end
198
235
  end
199
236
 
237
+ # Processes the options set by the command-line arguments,
238
+ # and runs the Sass compiler appropriately.
200
239
  def process_result
201
240
  if @options[:interactive]
202
241
  require 'sass'
@@ -229,9 +268,9 @@ END
229
268
  end
230
269
  end
231
270
 
232
- # A class encapsulating executable functionality
233
- # specific to Haml.
234
- class Haml < HamlSass # :nodoc:
271
+ # The `haml` executable.
272
+ class Haml < HamlSass
273
+ # @param args [Array<String>] The command-line arguments
235
274
  def initialize(args)
236
275
  super
237
276
  @name = "Haml"
@@ -239,6 +278,9 @@ END
239
278
  @options[:load_paths] = []
240
279
  end
241
280
 
281
+ # Tells optparse how to parse the arguments.
282
+ #
283
+ # @param opts [OptionParser]
242
284
  def set_opts(opts)
243
285
  super
244
286
 
@@ -270,6 +312,8 @@ END
270
312
  end
271
313
  end
272
314
 
315
+ # Processes the options set by the command-line arguments,
316
+ # and runs the Haml compiler appropriately.
273
317
  def process_result
274
318
  super
275
319
  input = @options[:input]
@@ -309,9 +353,9 @@ END
309
353
  end
310
354
  end
311
355
 
312
- # A class encapsulating executable functionality
313
- # specific to the html2haml executable.
314
- class HTML2Haml < Generic # :nodoc:
356
+ # The `html2haml` executable.
357
+ class HTML2Haml < Generic
358
+ # @param args [Array<String>] The command-line arguments
315
359
  def initialize(args)
316
360
  super
317
361
 
@@ -326,6 +370,9 @@ END
326
370
  end
327
371
  end
328
372
 
373
+ # Tells optparse how to parse the arguments.
374
+ #
375
+ # @param opts [OptionParser]
329
376
  def set_opts(opts)
330
377
  opts.banner = <<END
331
378
  Usage: html2haml [options] [INPUT] [OUTPUT]
@@ -350,6 +397,8 @@ END
350
397
  super
351
398
  end
352
399
 
400
+ # Processes the options set by the command-line arguments,
401
+ # and runs the HTML compiler appropriately.
353
402
  def process_result
354
403
  super
355
404
 
@@ -363,9 +412,9 @@ END
363
412
  end
364
413
  end
365
414
 
366
- # A class encapsulating executable functionality
367
- # specific to the css2sass executable.
368
- class CSS2Sass < Generic # :nodoc:
415
+ # The `css2sass` executable.
416
+ class CSS2Sass < Generic
417
+ # @param args [Array<String>] The command-line arguments
369
418
  def initialize(args)
370
419
  super
371
420
 
@@ -374,6 +423,9 @@ END
374
423
  require 'sass/css'
375
424
  end
376
425
 
426
+ # Tells optparse how to parse the arguments.
427
+ #
428
+ # @param opts [OptionParser]
377
429
  def set_opts(opts)
378
430
  opts.banner = <<END
379
431
  Usage: css2sass [options] [INPUT] [OUTPUT]
@@ -390,6 +442,8 @@ END
390
442
  super
391
443
  end
392
444
 
445
+ # Processes the options set by the command-line arguments,
446
+ # and runs the CSS compiler appropriately.
393
447
  def process_result
394
448
  super
395
449
 
data/lib/haml/filters.rb CHANGED
@@ -1,71 +1,98 @@
1
1
  module Haml
2
- # The module containing the default filters,
3
- # as well as the base module,
4
- # Haml::Filters::Base.
2
+ # The module containing the default Haml filters,
3
+ # as well as the base module, {Haml::Filters::Base}.
4
+ #
5
+ # @see Haml::Filters::Base
5
6
  module Filters
6
- # Returns a hash of defined filters.
7
+ # @return [Hash<String, Haml::Filters::Base>] a hash of filter names to classes
7
8
  def self.defined
8
9
  @defined ||= {}
9
10
  end
10
11
 
11
12
  # The base module for Haml filters.
12
13
  # User-defined filters should be modules including this module.
14
+ # The name of the filter is taken by downcasing the module name.
15
+ # For instance, if the module is named `FooBar`, the filter will be `:foobar`.
13
16
  #
14
- # A user-defined filter should override either Base#render or Base #compile.
15
- # Base#render is the most common.
17
+ # A user-defined filter should override either \{#render} or {\#compile}.
18
+ # \{#render} is the most common.
16
19
  # It takes a string, the filter source,
17
- # and returns another string,
18
- # the result of the filter.
19
- # For example:
20
+ # and returns another string, the result of the filter.
21
+ # For example, the following will define a filter named `:sass`:
20
22
  #
21
- # module Haml::Filters::Sass
22
- # include Haml::Filters::Base
23
+ # module Haml::Filters::Sass
24
+ # include Haml::Filters::Base
23
25
  #
24
- # def render(text)
25
- # ::Sass::Engine.new(text).render
26
+ # def render(text)
27
+ # ::Sass::Engine.new(text).render
28
+ # end
26
29
  # end
27
- # end
28
30
  #
29
- # For details on overriding #compile, see its documentation.
31
+ # For details on overriding \{#compile}, see its documentation.
30
32
  #
33
+ # Note that filters overriding \{#render} automatically support `#{}`
34
+ # for interpolating Ruby code.
35
+ # Those overriding \{#compile} will need to add such support manually
36
+ # if it's desired.
31
37
  module Base
32
- def self.included(base) # :nodoc:
38
+ # This method is automatically called when {Base} is included in a module.
39
+ # It automatically defines a filter
40
+ # with the downcased name of that module.
41
+ # For example, if the module is named `FooBar`, the filter will be `:foobar`.
42
+ #
43
+ # @param base [Module, Class] The module that this is included in
44
+ def self.included(base)
33
45
  Filters.defined[base.name.split("::").last.downcase] = base
34
46
  base.extend(base)
35
47
  end
36
48
 
37
- # Takes a string, the source text that should be passed to the filter,
38
- # and returns the string resulting from running the filter on <tt>text</tt>.
49
+ # Takes the source text that should be passed to the filter
50
+ # and returns the result of running the filter on that string.
39
51
  #
40
52
  # This should be overridden in most individual filter modules
41
53
  # to render text with the given filter.
42
- # If compile is overridden, however, render doesn't need to be.
54
+ # If \{#compile} is overridden, however, \{#render} doesn't need to be.
55
+ #
56
+ # @param text [String] The source text for the filter to process
57
+ # @return [String] The filtered result
58
+ # @raise [Haml::Error] if it's not overridden
43
59
  def render(text)
44
60
  raise Error.new("#{self.inspect}#render not defined!")
45
61
  end
46
62
 
47
- # Same as render, but takes the Haml options hash as well.
48
- # It's only safe to rely on options made available in Haml::Engine#options_for_buffer.
63
+ # Same as \{#render}, but takes a {Haml::Engine} options hash as well.
64
+ # It's only safe to rely on options made available in {Haml::Engine#options\_for\_buffer}.
65
+ #
66
+ # @see #render
67
+ # @param text [String] The source text for the filter to process
68
+ # @return [String] The filtered result
69
+ # @raise [Haml::Error] if it or \{#render} isn't overridden
49
70
  def render_with_options(text, options)
50
71
  render(text)
51
72
  end
52
73
 
53
- def internal_compile(*args) # :nodoc:
74
+ # Same as \{#compile}, but requires the necessary files first.
75
+ # *This is used by {Haml::Engine} and is not intended to be overridden or used elsewhere.*
76
+ #
77
+ # @see #compile
78
+ def internal_compile(*args)
54
79
  resolve_lazy_requires
55
80
  compile(*args)
56
81
  end
57
82
 
58
- # compile should be overridden when a filter needs to have access
59
- # to the Haml evaluation context.
83
+ # This should be overridden when a filter needs to have access to the Haml evaluation context.
60
84
  # Rather than applying a filter to a string at compile-time,
61
- # compile uses the Haml::Precompiler instance to compile the string to Ruby code
85
+ # \{#compile} uses the {Haml::Precompiler} instance to compile the string to Ruby code
62
86
  # that will be executed in the context of the active Haml template.
63
87
  #
64
- # Warning: the Haml::Precompiler interface is neither well-documented
88
+ # Warning: the {Haml::Precompiler} interface is neither well-documented
65
89
  # nor guaranteed to be stable.
66
- # If you want to make use of it,
67
- # you'll probably need to look at the source code
90
+ # If you want to make use of it, you'll probably need to look at the source code
68
91
  # and should test your filter when upgrading to new Haml versions.
92
+ #
93
+ # @param precompiler [Haml::Precompiler] The precompiler instance
94
+ # @param text [String] The text of the filter
95
+ # @raise [Haml::Error] if none of \{#compile}, \{#render}, and \{#render_with_options} are overridden
69
96
  def compile(precompiler, text)
70
97
  resolve_lazy_requires
71
98
  filter = self
@@ -89,22 +116,22 @@ RUBY
89
116
  end
90
117
  end
91
118
 
92
- # This becomes a class method of modules that include Base.
119
+ # This becomes a class method of modules that include {Base}.
93
120
  # It allows the module to specify one or more Ruby files
94
121
  # that Haml should try to require when compiling the filter.
95
122
  #
96
- # The first file specified is tried first,
97
- # then the second, etc.
123
+ # The first file specified is tried first, then the second, etc.
98
124
  # If none are found, the compilation throws an exception.
99
125
  #
100
126
  # For example:
101
127
  #
102
- # module Haml::Filters::Markdown
103
- # lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth'
128
+ # module Haml::Filters::Markdown
129
+ # lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth'
104
130
  #
105
- # ...
106
- # end
131
+ # ...
132
+ # end
107
133
  #
134
+ # @param reqs [Array<String>] The requires to run
108
135
  def lazy_require(*reqs)
109
136
  @lazy_requires = reqs
110
137
  end
@@ -139,23 +166,29 @@ RUBY
139
166
  end
140
167
  end
141
168
 
142
- # :stopdoc:
143
-
144
169
  begin
145
170
  require 'rubygems'
146
171
  rescue LoadError; end
147
172
 
148
173
  module Haml
149
174
  module Filters
175
+ # Does not parse the filtered text.
176
+ # This is useful for large blocks of text without HTML tags,
177
+ # when you don't want lines starting with `.` or `-`
178
+ # to be parsed.
150
179
  module Plain
151
180
  include Base
152
181
 
182
+ # @see Base#render
153
183
  def render(text); text; end
154
184
  end
155
185
 
186
+ # Surrounds the filtered text with `<script>` and CDATA tags.
187
+ # Useful for including inline Javascript.
156
188
  module Javascript
157
189
  include Base
158
190
 
191
+ # @see Base#render_with_options
159
192
  def render_with_options(text, options)
160
193
  <<END
161
194
  <script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>
@@ -167,26 +200,37 @@ END
167
200
  end
168
201
  end
169
202
 
203
+ # Surrounds the filtered text with CDATA tags.
170
204
  module Cdata
171
205
  include Base
172
206
 
207
+ # @see Base#render
173
208
  def render(text)
174
209
  "<![CDATA[#{("\n" + text).rstrip.gsub("\n", "\n ")}\n]]>"
175
210
  end
176
211
  end
177
212
 
213
+ # Works the same as {Plain}, but HTML-escapes the text
214
+ # before placing it in the document.
178
215
  module Escaped
179
216
  include Base
180
217
 
218
+ # @see Base#render
181
219
  def render(text)
182
220
  Haml::Helpers.html_escape text
183
221
  end
184
222
  end
185
223
 
224
+ # Parses the filtered text with the normal Ruby interpreter.
225
+ # All output sent to `$stdout`, such as with `puts`,
226
+ # is output into the Haml document.
227
+ # Not available if the [`:suppress_eval`](../Haml.html#suppress-eval-option) option is set to true.
228
+ # The Ruby code is evaluated in the same context as the Haml template.
186
229
  module Ruby
187
230
  include Base
188
231
  lazy_require 'stringio'
189
232
 
233
+ # @see Base#compile
190
234
  def compile(precompiler, text)
191
235
  return if precompiler.options[:suppress_eval]
192
236
  precompiler.instance_eval do
@@ -201,27 +245,40 @@ END
201
245
  end
202
246
  end
203
247
 
248
+ # Inserts the filtered text into the template with whitespace preserved.
249
+ # `preserve`d blocks of text aren't indented,
250
+ # and newlines are replaced with the HTML escape code for newlines,
251
+ # to preserve nice-looking output.
252
+ #
253
+ # @see Haml::Helpers#preserve
204
254
  module Preserve
205
255
  include Base
206
256
 
257
+ # @see Base#render
207
258
  def render(text)
208
259
  Haml::Helpers.preserve text
209
260
  end
210
261
  end
211
262
 
263
+ # Parses the filtered text with {Sass} to produce CSS output.
212
264
  module Sass
213
265
  include Base
214
266
  lazy_require 'sass/plugin'
215
267
 
268
+ # @see Base#render
216
269
  def render(text)
217
270
  ::Sass::Engine.new(text, ::Sass::Plugin.engine_options).render
218
271
  end
219
272
  end
220
273
 
274
+ # Parses the filtered text with ERB, like an RHTML template.
275
+ # Not available if the [`:suppress_eval`](../Haml.html#suppress-eval-option) option is set to true.
276
+ # Embedded Ruby code is evaluated in the same context as the Haml template.
221
277
  module ERB
222
278
  include Base
223
279
  lazy_require 'erb'
224
280
 
281
+ # @see Base#compile
225
282
  def compile(precompiler, text)
226
283
  return if precompiler.options[:suppress_eval]
227
284
  src = ::ERB.new(text).src.sub(/^#coding:.*?\n/, '').
@@ -230,10 +287,13 @@ END
230
287
  end
231
288
  end
232
289
 
290
+ # Parses the filtered text with [Textile](http://www.textism.com/tools/textile).
291
+ # Only works if [RedCloth](http://redcloth.org) is installed.
233
292
  module Textile
234
293
  include Base
235
294
  lazy_require 'redcloth'
236
295
 
296
+ # @see Base#render
237
297
  def render(text)
238
298
  ::RedCloth.new(text).to_html(:textile)
239
299
  end
@@ -241,11 +301,16 @@ END
241
301
  RedCloth = Textile
242
302
  Filters.defined['redcloth'] = RedCloth
243
303
 
244
- # Uses BlueCloth or RedCloth to provide only Markdown (not Textile) parsing
304
+ # Parses the filtered text with [Markdown](http://daringfireball.net/projects/markdown).
305
+ # Only works if [RDiscount](http://github.com/rtomayko/rdiscount),
306
+ # [RPeg-Markdown](http://github.com/rtomayko/rpeg-markdown),
307
+ # [Maruku](http://maruku.rubyforge.org),
308
+ # or [BlueCloth](www.deveiate.org/projects/BlueCloth) are installed.
245
309
  module Markdown
246
310
  include Base
247
311
  lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth'
248
312
 
313
+ # @see Base#render
249
314
  def render(text)
250
315
  engine = case @required
251
316
  when 'rdiscount'
@@ -261,15 +326,16 @@ END
261
326
  end
262
327
  end
263
328
 
329
+ # Parses the filtered text with [Maruku](http://maruku.rubyforge.org),
330
+ # which has some non-standard extensions to Markdown.
264
331
  module Maruku
265
332
  include Base
266
333
  lazy_require 'maruku'
267
334
 
335
+ # @see Base#render
268
336
  def render(text)
269
337
  ::Maruku.new(text).to_html
270
338
  end
271
339
  end
272
340
  end
273
341
  end
274
-
275
- # :startdoc:
@@ -1,45 +1,40 @@
1
1
  require 'haml/helpers/action_view_mods'
2
2
 
3
- if defined?(ActionView)
4
- module Haml
5
- module Helpers
6
- # This module contains various useful helper methods
7
- # that either tie into ActionView or the rest of the ActionPack stack,
8
- # or are only useful in that context.
9
- # Thus, the methods defined here are only available
10
- # if ActionView is installed.
11
- module ActionViewExtensions
12
- # Returns a value for the "class" attribute
13
- # unique to this controller/action pair.
14
- # This can be used to target styles specifically at this action or controller.
15
- # For example, if the current action were EntryController#show,
16
- #
17
- # %div{:class => page_class} My Div
18
- #
19
- # would become
20
- #
21
- # <div class="entry show">My Div</div>
22
- #
23
- # Then, in a stylesheet
24
- # (shown here as Sass),
25
- # you could refer to this specific action:
26
- #
27
- # .entry.show
28
- # :font-weight bold
29
- #
30
- # or to all actions in the entry controller:
31
- #
32
- # .entry
33
- # :color #00f
34
- #
35
- def page_class
36
- controller.controller_name + " " + controller.action_name
37
- end
38
-
39
- # :stopdoc:
40
- alias_method :generate_content_class_names, :page_class
41
- # :startdoc:
3
+ module Haml
4
+ module Helpers
5
+ # This module contains various useful helper methods
6
+ # that either tie into ActionView or the rest of the ActionPack stack,
7
+ # or are only useful in that context.
8
+ # Thus, the methods defined here are only available
9
+ # if ActionView is installed.
10
+ module ActionViewExtensions
11
+ # Returns a value for the "class" attribute
12
+ # unique to this controller/action pair.
13
+ # This can be used to target styles specifically at this action or controller.
14
+ # For example, if the current action were `EntryController#show`,
15
+ #
16
+ # %div{:class => page_class} My Div
17
+ #
18
+ # would become
19
+ #
20
+ # <div class="entry show">My Div</div>
21
+ #
22
+ # Then, in a stylesheet (shown here as {Sass}),
23
+ # you could refer to this specific action:
24
+ #
25
+ # .entry.show
26
+ # :font-weight bold
27
+ #
28
+ # or to all actions in the entry controller:
29
+ #
30
+ # .entry
31
+ # :color #00f
32
+ #
33
+ # @return [String] The class name for the current page
34
+ def page_class
35
+ controller.controller_name + " " + controller.action_name
42
36
  end
37
+ alias_method :generate_content_class_names, :page_class
43
38
  end
44
39
  end
45
40
  end