haml-edge 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/EDGE_GEM_VERSION +1 -0
  2. data/FAQ +138 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +332 -0
  5. data/REVISION +1 -0
  6. data/Rakefile +226 -0
  7. data/VERSION +1 -0
  8. data/bin/css2sass +7 -0
  9. data/bin/haml +9 -0
  10. data/bin/html2haml +7 -0
  11. data/bin/sass +8 -0
  12. data/extra/edge_gem_watch.rb +13 -0
  13. data/extra/haml-mode.el +596 -0
  14. data/extra/sass-mode.el +200 -0
  15. data/init.rb +8 -0
  16. data/lib/haml/buffer.rb +255 -0
  17. data/lib/haml/engine.rb +268 -0
  18. data/lib/haml/error.rb +22 -0
  19. data/lib/haml/exec.rb +395 -0
  20. data/lib/haml/filters.rb +275 -0
  21. data/lib/haml/helpers/action_view_extensions.rb +45 -0
  22. data/lib/haml/helpers/action_view_mods.rb +181 -0
  23. data/lib/haml/helpers.rb +488 -0
  24. data/lib/haml/html.rb +222 -0
  25. data/lib/haml/precompiler.rb +904 -0
  26. data/lib/haml/shared.rb +45 -0
  27. data/lib/haml/template/patch.rb +58 -0
  28. data/lib/haml/template/plugin.rb +72 -0
  29. data/lib/haml/template.rb +42 -0
  30. data/lib/haml/util.rb +88 -0
  31. data/lib/haml/version.rb +47 -0
  32. data/lib/haml.rb +1044 -0
  33. data/lib/sass/css.rb +388 -0
  34. data/lib/sass/engine.rb +495 -0
  35. data/lib/sass/environment.rb +46 -0
  36. data/lib/sass/error.rb +35 -0
  37. data/lib/sass/plugin/merb.rb +56 -0
  38. data/lib/sass/plugin/rails.rb +24 -0
  39. data/lib/sass/plugin.rb +204 -0
  40. data/lib/sass/repl.rb +51 -0
  41. data/lib/sass/script/bool.rb +13 -0
  42. data/lib/sass/script/color.rb +97 -0
  43. data/lib/sass/script/funcall.rb +29 -0
  44. data/lib/sass/script/functions.rb +134 -0
  45. data/lib/sass/script/lexer.rb +148 -0
  46. data/lib/sass/script/literal.rb +82 -0
  47. data/lib/sass/script/number.rb +231 -0
  48. data/lib/sass/script/operation.rb +30 -0
  49. data/lib/sass/script/parser.rb +142 -0
  50. data/lib/sass/script/string.rb +9 -0
  51. data/lib/sass/script/unary_operation.rb +21 -0
  52. data/lib/sass/script/variable.rb +20 -0
  53. data/lib/sass/script.rb +38 -0
  54. data/lib/sass/tree/attr_node.rb +64 -0
  55. data/lib/sass/tree/comment_node.rb +30 -0
  56. data/lib/sass/tree/debug_node.rb +22 -0
  57. data/lib/sass/tree/directive_node.rb +50 -0
  58. data/lib/sass/tree/file_node.rb +27 -0
  59. data/lib/sass/tree/for_node.rb +29 -0
  60. data/lib/sass/tree/if_node.rb +27 -0
  61. data/lib/sass/tree/mixin_def_node.rb +18 -0
  62. data/lib/sass/tree/mixin_node.rb +35 -0
  63. data/lib/sass/tree/node.rb +99 -0
  64. data/lib/sass/tree/rule_node.rb +161 -0
  65. data/lib/sass/tree/variable_node.rb +24 -0
  66. data/lib/sass/tree/while_node.rb +21 -0
  67. data/lib/sass.rb +1062 -0
  68. data/rails/init.rb +1 -0
  69. data/test/benchmark.rb +99 -0
  70. data/test/haml/engine_test.rb +795 -0
  71. data/test/haml/helper_test.rb +228 -0
  72. data/test/haml/html2haml_test.rb +108 -0
  73. data/test/haml/markaby/standard.mab +52 -0
  74. data/test/haml/mocks/article.rb +6 -0
  75. data/test/haml/results/content_for_layout.xhtml +15 -0
  76. data/test/haml/results/eval_suppressed.xhtml +9 -0
  77. data/test/haml/results/filters.xhtml +62 -0
  78. data/test/haml/results/helpers.xhtml +93 -0
  79. data/test/haml/results/helpful.xhtml +10 -0
  80. data/test/haml/results/just_stuff.xhtml +68 -0
  81. data/test/haml/results/list.xhtml +12 -0
  82. data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
  83. data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  84. data/test/haml/results/original_engine.xhtml +20 -0
  85. data/test/haml/results/partial_layout.xhtml +5 -0
  86. data/test/haml/results/partials.xhtml +21 -0
  87. data/test/haml/results/render_layout.xhtml +3 -0
  88. data/test/haml/results/silent_script.xhtml +74 -0
  89. data/test/haml/results/standard.xhtml +162 -0
  90. data/test/haml/results/tag_parsing.xhtml +23 -0
  91. data/test/haml/results/very_basic.xhtml +5 -0
  92. data/test/haml/results/whitespace_handling.xhtml +89 -0
  93. data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
  94. data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
  95. data/test/haml/rhtml/action_view.rhtml +62 -0
  96. data/test/haml/rhtml/standard.rhtml +54 -0
  97. data/test/haml/template_test.rb +204 -0
  98. data/test/haml/templates/_av_partial_1.haml +9 -0
  99. data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
  100. data/test/haml/templates/_av_partial_2.haml +5 -0
  101. data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
  102. data/test/haml/templates/_layout.erb +3 -0
  103. data/test/haml/templates/_layout_for_partial.haml +3 -0
  104. data/test/haml/templates/_partial.haml +8 -0
  105. data/test/haml/templates/_text_area.haml +3 -0
  106. data/test/haml/templates/action_view.haml +47 -0
  107. data/test/haml/templates/action_view_ugly.haml +47 -0
  108. data/test/haml/templates/breakage.haml +8 -0
  109. data/test/haml/templates/content_for_layout.haml +10 -0
  110. data/test/haml/templates/eval_suppressed.haml +11 -0
  111. data/test/haml/templates/filters.haml +66 -0
  112. data/test/haml/templates/helpers.haml +95 -0
  113. data/test/haml/templates/helpful.haml +11 -0
  114. data/test/haml/templates/just_stuff.haml +83 -0
  115. data/test/haml/templates/list.haml +12 -0
  116. data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
  117. data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  118. data/test/haml/templates/original_engine.haml +17 -0
  119. data/test/haml/templates/partial_layout.haml +3 -0
  120. data/test/haml/templates/partialize.haml +1 -0
  121. data/test/haml/templates/partials.haml +12 -0
  122. data/test/haml/templates/render_layout.haml +2 -0
  123. data/test/haml/templates/silent_script.haml +40 -0
  124. data/test/haml/templates/standard.haml +42 -0
  125. data/test/haml/templates/standard_ugly.haml +42 -0
  126. data/test/haml/templates/tag_parsing.haml +21 -0
  127. data/test/haml/templates/very_basic.haml +4 -0
  128. data/test/haml/templates/whitespace_handling.haml +87 -0
  129. data/test/haml/util_test.rb +87 -0
  130. data/test/linked_rails.rb +12 -0
  131. data/test/sass/css2sass_test.rb +193 -0
  132. data/test/sass/engine_test.rb +709 -0
  133. data/test/sass/functions_test.rb +109 -0
  134. data/test/sass/more_results/more1.css +9 -0
  135. data/test/sass/more_results/more1_with_line_comments.css +26 -0
  136. data/test/sass/more_results/more_import.css +29 -0
  137. data/test/sass/more_templates/_more_partial.sass +2 -0
  138. data/test/sass/more_templates/more1.sass +23 -0
  139. data/test/sass/more_templates/more_import.sass +11 -0
  140. data/test/sass/plugin_test.rb +213 -0
  141. data/test/sass/results/alt.css +4 -0
  142. data/test/sass/results/basic.css +9 -0
  143. data/test/sass/results/compact.css +5 -0
  144. data/test/sass/results/complex.css +87 -0
  145. data/test/sass/results/compressed.css +1 -0
  146. data/test/sass/results/expanded.css +19 -0
  147. data/test/sass/results/import.css +29 -0
  148. data/test/sass/results/line_numbers.css +49 -0
  149. data/test/sass/results/mixins.css +95 -0
  150. data/test/sass/results/multiline.css +24 -0
  151. data/test/sass/results/nested.css +22 -0
  152. data/test/sass/results/parent_ref.css +13 -0
  153. data/test/sass/results/script.css +16 -0
  154. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  155. data/test/sass/results/subdir/subdir.css +3 -0
  156. data/test/sass/results/units.css +11 -0
  157. data/test/sass/script_test.rb +250 -0
  158. data/test/sass/templates/_partial.sass +2 -0
  159. data/test/sass/templates/alt.sass +16 -0
  160. data/test/sass/templates/basic.sass +23 -0
  161. data/test/sass/templates/bork.sass +2 -0
  162. data/test/sass/templates/bork2.sass +2 -0
  163. data/test/sass/templates/compact.sass +17 -0
  164. data/test/sass/templates/complex.sass +309 -0
  165. data/test/sass/templates/compressed.sass +15 -0
  166. data/test/sass/templates/expanded.sass +17 -0
  167. data/test/sass/templates/import.sass +11 -0
  168. data/test/sass/templates/importee.sass +19 -0
  169. data/test/sass/templates/line_numbers.sass +13 -0
  170. data/test/sass/templates/mixins.sass +76 -0
  171. data/test/sass/templates/multiline.sass +20 -0
  172. data/test/sass/templates/nested.sass +25 -0
  173. data/test/sass/templates/parent_ref.sass +25 -0
  174. data/test/sass/templates/script.sass +101 -0
  175. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  176. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  177. data/test/sass/templates/subdir/subdir.sass +6 -0
  178. data/test/sass/templates/units.sass +11 -0
  179. data/test/test_helper.rb +21 -0
  180. metadata +278 -0
@@ -0,0 +1,275 @@
1
+ module Haml
2
+ # The module containing the default filters,
3
+ # as well as the base module,
4
+ # Haml::Filters::Base.
5
+ module Filters
6
+ # Returns a hash of defined filters.
7
+ def self.defined
8
+ @defined ||= {}
9
+ end
10
+
11
+ # The base module for Haml filters.
12
+ # User-defined filters should be modules including this module.
13
+ #
14
+ # A user-defined filter should override either Base#render or Base #compile.
15
+ # Base#render is the most common.
16
+ # It takes a string, the filter source,
17
+ # and returns another string,
18
+ # the result of the filter.
19
+ # For example:
20
+ #
21
+ # module Haml::Filters::Sass
22
+ # include Haml::Filters::Base
23
+ #
24
+ # def render(text)
25
+ # ::Sass::Engine.new(text).render
26
+ # end
27
+ # end
28
+ #
29
+ # For details on overriding #compile, see its documentation.
30
+ #
31
+ module Base
32
+ def self.included(base) # :nodoc:
33
+ Filters.defined[base.name.split("::").last.downcase] = base
34
+ base.extend(base)
35
+ end
36
+
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>.
39
+ #
40
+ # This should be overridden in most individual filter modules
41
+ # to render text with the given filter.
42
+ # If compile is overridden, however, render doesn't need to be.
43
+ def render(text)
44
+ raise Error.new("#{self.inspect}#render not defined!")
45
+ end
46
+
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.
49
+ def render_with_options(text, options)
50
+ render(text)
51
+ end
52
+
53
+ def internal_compile(*args) # :nodoc:
54
+ resolve_lazy_requires
55
+ compile(*args)
56
+ end
57
+
58
+ # compile should be overridden when a filter needs to have access
59
+ # to the Haml evaluation context.
60
+ # 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
62
+ # that will be executed in the context of the active Haml template.
63
+ #
64
+ # Warning: the Haml::Precompiler interface is neither well-documented
65
+ # 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
68
+ # and should test your filter when upgrading to new Haml versions.
69
+ def compile(precompiler, text)
70
+ resolve_lazy_requires
71
+ filter = self
72
+ precompiler.instance_eval do
73
+ if contains_interpolation?(text)
74
+ return if options[:suppress_eval]
75
+
76
+ push_script <<RUBY
77
+ find_and_preserve(#{filter.inspect}.render_with_options(#{unescape_interpolation(text)}, _hamlout.options))
78
+ RUBY
79
+ return
80
+ end
81
+
82
+ rendered = Haml::Helpers::find_and_preserve(filter.render_with_options(text, precompiler.options), precompiler.options[:preserve])
83
+
84
+ if !options[:ugly]
85
+ push_text(rendered.rstrip.gsub("\n", "\n#{' ' * @output_tabs}"))
86
+ else
87
+ push_text(rendered.rstrip)
88
+ end
89
+ end
90
+ end
91
+
92
+ # This becomes a class method of modules that include Base.
93
+ # It allows the module to specify one or more Ruby files
94
+ # that Haml should try to require when compiling the filter.
95
+ #
96
+ # The first file specified is tried first,
97
+ # then the second, etc.
98
+ # If none are found, the compilation throws an exception.
99
+ #
100
+ # For example:
101
+ #
102
+ # module Haml::Filters::Markdown
103
+ # lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth'
104
+ #
105
+ # ...
106
+ # end
107
+ #
108
+ def lazy_require(*reqs)
109
+ @lazy_requires = reqs
110
+ end
111
+
112
+ private
113
+
114
+ def resolve_lazy_requires
115
+ return unless @lazy_requires
116
+
117
+ @lazy_requires[0...-1].each do |req|
118
+ begin
119
+ @required = req
120
+ require @required
121
+ return
122
+ rescue LoadError; end # RCov doesn't see this, but it is run
123
+ end
124
+
125
+ begin
126
+ @required = @lazy_requires[-1]
127
+ require @required
128
+ rescue LoadError => e
129
+ classname = self.name.match(/\w+$/)[0]
130
+
131
+ if @lazy_requires.size == 1
132
+ raise Error.new("Can't run #{classname} filter; required file '#{@lazy_requires.first}' not found")
133
+ else
134
+ raise Error.new("Can't run #{classname} filter; required #{@lazy_requires.map { |r| "'#{r}'" }.join(' or ')}, but none were found")
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ # :stopdoc:
143
+
144
+ begin
145
+ require 'rubygems'
146
+ rescue LoadError; end
147
+
148
+ module Haml
149
+ module Filters
150
+ module Plain
151
+ include Base
152
+
153
+ def render(text); text; end
154
+ end
155
+
156
+ module Javascript
157
+ include Base
158
+
159
+ def render_with_options(text, options)
160
+ <<END
161
+ <script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>
162
+ //<![CDATA[
163
+ #{text.rstrip.gsub("\n", "\n ")}
164
+ //]]>
165
+ </script>
166
+ END
167
+ end
168
+ end
169
+
170
+ module Cdata
171
+ include Base
172
+
173
+ def render(text)
174
+ "<![CDATA[#{("\n" + text).rstrip.gsub("\n", "\n ")}\n]]>"
175
+ end
176
+ end
177
+
178
+ module Escaped
179
+ include Base
180
+
181
+ def render(text)
182
+ Haml::Helpers.html_escape text
183
+ end
184
+ end
185
+
186
+ module Ruby
187
+ include Base
188
+ lazy_require 'stringio'
189
+
190
+ def compile(precompiler, text)
191
+ return if precompiler.options[:suppress_eval]
192
+ precompiler.instance_eval do
193
+ push_silent <<-FIRST.gsub("\n", ';') + text + <<-LAST.gsub("\n", ';')
194
+ _haml_old_stdout = $stdout
195
+ $stdout = StringIO.new(_hamlout.buffer, 'a')
196
+ FIRST
197
+ _haml_old_stdout, $stdout = $stdout, _haml_old_stdout
198
+ _haml_old_stdout.close
199
+ LAST
200
+ end
201
+ end
202
+ end
203
+
204
+ module Preserve
205
+ include Base
206
+
207
+ def render(text)
208
+ Haml::Helpers.preserve text
209
+ end
210
+ end
211
+
212
+ module Sass
213
+ include Base
214
+ lazy_require 'sass/plugin'
215
+
216
+ def render(text)
217
+ ::Sass::Engine.new(text, ::Sass::Plugin.engine_options).render
218
+ end
219
+ end
220
+
221
+ module ERB
222
+ include Base
223
+ lazy_require 'erb'
224
+
225
+ def compile(precompiler, text)
226
+ return if precompiler.options[:suppress_eval]
227
+ src = ::ERB.new(text).src.sub(/^#coding:.*?\n/, '').
228
+ sub(/^_erbout = '';/, "").gsub("\n", ';')
229
+ precompiler.send(:push_silent, src)
230
+ end
231
+ end
232
+
233
+ module Textile
234
+ include Base
235
+ lazy_require 'redcloth'
236
+
237
+ def render(text)
238
+ ::RedCloth.new(text).to_html(:textile)
239
+ end
240
+ end
241
+ RedCloth = Textile
242
+ Filters.defined['redcloth'] = RedCloth
243
+
244
+ # Uses BlueCloth or RedCloth to provide only Markdown (not Textile) parsing
245
+ module Markdown
246
+ include Base
247
+ lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth'
248
+
249
+ def render(text)
250
+ engine = case @required
251
+ when 'rdiscount'
252
+ ::RDiscount
253
+ when 'peg_markdown'
254
+ ::PEGMarkdown
255
+ when 'maruku'
256
+ ::Maruku
257
+ when 'bluecloth'
258
+ ::BlueCloth
259
+ end
260
+ engine.new(text).to_html
261
+ end
262
+ end
263
+
264
+ module Maruku
265
+ include Base
266
+ lazy_require 'maruku'
267
+
268
+ def render(text)
269
+ ::Maruku.new(text).to_html
270
+ end
271
+ end
272
+ end
273
+ end
274
+
275
+ # :startdoc:
@@ -0,0 +1,45 @@
1
+ require 'haml/helpers/action_view_mods'
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:
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,181 @@
1
+ if defined?(ActionView) and not defined?(Merb::Plugins)
2
+ module ActionView
3
+ class Base # :nodoc:
4
+ def render_with_haml(*args, &block)
5
+ options = args.first
6
+
7
+ # If render :layout is used with a block,
8
+ # it concats rather than returning a string
9
+ # so we need it to keep thinking it's Haml
10
+ # until it hits the sub-render
11
+ if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
12
+ return non_haml { render_without_haml(*args, &block) }
13
+ end
14
+ render_without_haml(*args, &block)
15
+ end
16
+ alias_method :render_without_haml, :render
17
+ alias_method :render, :render_with_haml
18
+
19
+ # Rails >2.1
20
+ if Haml::Util.has?(:instance_method, self, :output_buffer)
21
+ def output_buffer_with_haml
22
+ return haml_buffer.buffer if is_haml?
23
+ output_buffer_without_haml
24
+ end
25
+ alias_method :output_buffer_without_haml, :output_buffer
26
+ alias_method :output_buffer, :output_buffer_with_haml
27
+
28
+ def set_output_buffer_with_haml(new)
29
+ if is_haml?
30
+ haml_buffer.buffer = new
31
+ else
32
+ set_output_buffer_without_haml new
33
+ end
34
+ end
35
+ alias_method :set_output_buffer_without_haml, :output_buffer=
36
+ alias_method :output_buffer=, :set_output_buffer_with_haml
37
+ end
38
+ end
39
+
40
+ # This overrides various helpers in ActionView
41
+ # to make them work more effectively with Haml.
42
+ module Helpers
43
+ # :stopdoc:
44
+ # In Rails <=2.1, we've got to override considerable capturing infrastructure.
45
+ # In Rails >2.1, we can make do with only overriding #capture
46
+ # (which no longer behaves differently in helper contexts).
47
+ unless Haml::Util.has?(:instance_method, ActionView::Base, :output_buffer)
48
+ module CaptureHelper
49
+ def capture_with_haml(*args, &block)
50
+ # Rails' #capture helper will just return the value of the block
51
+ # if it's not actually in the template context,
52
+ # as detected by the existance of an _erbout variable.
53
+ # We've got to do the same thing for compatibility.
54
+
55
+ if is_haml? && block_is_haml?(block)
56
+ capture_haml(*args, &block)
57
+ else
58
+ capture_without_haml(*args, &block)
59
+ end
60
+ end
61
+ alias_method :capture_without_haml, :capture
62
+ alias_method :capture, :capture_with_haml
63
+
64
+ def capture_erb_with_buffer_with_haml(buffer, *args, &block)
65
+ if is_haml?
66
+ capture_haml(*args, &block)
67
+ else
68
+ capture_erb_with_buffer_without_haml(buffer, *args, &block)
69
+ end
70
+ end
71
+ alias_method :capture_erb_with_buffer_without_haml, :capture_erb_with_buffer
72
+ alias_method :capture_erb_with_buffer, :capture_erb_with_buffer_with_haml
73
+ end
74
+
75
+ module TextHelper
76
+ def concat_with_haml(string, binding = nil)
77
+ if is_haml?
78
+ haml_buffer.buffer.concat(string)
79
+ else
80
+ concat_without_haml(string, binding)
81
+ end
82
+ end
83
+ alias_method :concat_without_haml, :concat
84
+ alias_method :concat, :concat_with_haml
85
+ end
86
+ else
87
+ module CaptureHelper
88
+ def capture_with_haml(*args, &block)
89
+ if Haml::Helpers.block_is_haml?(block)
90
+ capture_haml(*args, &block)
91
+ else
92
+ capture_without_haml(*args, &block)
93
+ end
94
+ end
95
+ alias_method :capture_without_haml, :capture
96
+ alias_method :capture, :capture_with_haml
97
+ end
98
+ end
99
+
100
+ module TagHelper
101
+ def content_tag_with_haml(name, *args, &block)
102
+ return content_tag_without_haml(name, *args, &block) unless is_haml?
103
+
104
+ preserve = haml_buffer.options[:preserve].include?(name.to_s)
105
+
106
+ if block_given? && block_is_haml?(block) && preserve
107
+ return content_tag_without_haml(name, *args) {preserve(&block)}
108
+ end
109
+
110
+ returning content_tag_without_haml(name, *args, &block) do |content|
111
+ return Haml::Helpers.preserve(content) if preserve && content
112
+ end
113
+ end
114
+
115
+ alias_method :content_tag_without_haml, :content_tag
116
+ alias_method :content_tag, :content_tag_with_haml
117
+ end
118
+
119
+ class InstanceTag
120
+ # Includes TagHelper
121
+
122
+ def haml_buffer
123
+ @template_object.send :haml_buffer
124
+ end
125
+
126
+ def is_haml?
127
+ @template_object.send :is_haml?
128
+ end
129
+
130
+ alias_method :content_tag_without_haml, :content_tag
131
+ alias_method :content_tag, :content_tag_with_haml
132
+ end
133
+
134
+ module FormTagHelper
135
+ def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
136
+ if is_haml?
137
+ if block_given?
138
+ oldproc = proc
139
+ proc = haml_bind_proc do |*args|
140
+ concat "\n"
141
+ tab_up
142
+ oldproc.call(*args)
143
+ tab_down
144
+ concat haml_indent
145
+ end
146
+ concat haml_indent
147
+ end
148
+ res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
149
+ concat "\n" if block_given?
150
+ res
151
+ else
152
+ form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
153
+ end
154
+ end
155
+ alias_method :form_tag_without_haml, :form_tag
156
+ alias_method :form_tag, :form_tag_with_haml
157
+ end
158
+
159
+ module FormHelper
160
+ def form_for_with_haml(object_name, *args, &proc)
161
+ if block_given? && is_haml?
162
+ oldproc = proc
163
+ proc = haml_bind_proc do |*args|
164
+ tab_up
165
+ oldproc.call(*args)
166
+ tab_down
167
+ concat haml_indent
168
+ end
169
+ concat haml_indent
170
+ end
171
+ form_for_without_haml(object_name, *args, &proc)
172
+ concat "\n" if block_given? && is_haml?
173
+ end
174
+ alias_method :form_for_without_haml, :form_for
175
+ alias_method :form_for, :form_for_with_haml
176
+ end
177
+ # :startdoc:
178
+ end
179
+ end
180
+ end
181
+