wireframe-haml 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +332 -0
- data/VERSION.yml +4 -0
- data/bin/css2sass +7 -0
- data/bin/haml +9 -0
- data/bin/html2haml +7 -0
- data/bin/sass +8 -0
- data/lib/haml/buffer.rb +255 -0
- data/lib/haml/engine.rb +268 -0
- data/lib/haml/error.rb +22 -0
- data/lib/haml/exec.rb +395 -0
- data/lib/haml/filters.rb +276 -0
- data/lib/haml/helpers/action_view_extensions.rb +45 -0
- data/lib/haml/helpers/action_view_mods.rb +181 -0
- data/lib/haml/helpers.rb +468 -0
- data/lib/haml/html.rb +218 -0
- data/lib/haml/precompiler.rb +889 -0
- data/lib/haml/shared.rb +45 -0
- data/lib/haml/template/patch.rb +58 -0
- data/lib/haml/template/plugin.rb +72 -0
- data/lib/haml/template.rb +51 -0
- data/lib/haml/util.rb +77 -0
- data/lib/haml/version.rb +47 -0
- data/lib/haml.rb +1042 -0
- data/lib/sass/css.rb +388 -0
- data/lib/sass/engine.rb +499 -0
- data/lib/sass/environment.rb +33 -0
- data/lib/sass/error.rb +35 -0
- data/lib/sass/plugin/merb.rb +56 -0
- data/lib/sass/plugin/rails.rb +24 -0
- data/lib/sass/plugin.rb +203 -0
- data/lib/sass/repl.rb +51 -0
- data/lib/sass/script/bool.rb +13 -0
- data/lib/sass/script/color.rb +97 -0
- data/lib/sass/script/funcall.rb +28 -0
- data/lib/sass/script/functions.rb +122 -0
- data/lib/sass/script/lexer.rb +152 -0
- data/lib/sass/script/literal.rb +60 -0
- data/lib/sass/script/number.rb +231 -0
- data/lib/sass/script/operation.rb +30 -0
- data/lib/sass/script/parser.rb +142 -0
- data/lib/sass/script/string.rb +42 -0
- data/lib/sass/script/unary_operation.rb +21 -0
- data/lib/sass/script/variable.rb +20 -0
- data/lib/sass/script.rb +38 -0
- data/lib/sass/tree/attr_node.rb +64 -0
- data/lib/sass/tree/comment_node.rb +34 -0
- data/lib/sass/tree/debug_node.rb +22 -0
- data/lib/sass/tree/directive_node.rb +50 -0
- data/lib/sass/tree/file_node.rb +27 -0
- data/lib/sass/tree/for_node.rb +29 -0
- data/lib/sass/tree/if_node.rb +27 -0
- data/lib/sass/tree/mixin_def_node.rb +18 -0
- data/lib/sass/tree/mixin_node.rb +34 -0
- data/lib/sass/tree/node.rb +99 -0
- data/lib/sass/tree/rule_node.rb +120 -0
- data/lib/sass/tree/variable_node.rb +24 -0
- data/lib/sass/tree/while_node.rb +20 -0
- data/lib/sass.rb +1062 -0
- data/test/benchmark.rb +99 -0
- data/test/haml/engine_test.rb +734 -0
- data/test/haml/helper_test.rb +224 -0
- data/test/haml/html2haml_test.rb +92 -0
- data/test/haml/markaby/standard.mab +52 -0
- data/test/haml/mocks/article.rb +6 -0
- data/test/haml/results/content_for_layout.xhtml +15 -0
- data/test/haml/results/eval_suppressed.xhtml +9 -0
- data/test/haml/results/filters.xhtml +62 -0
- data/test/haml/results/helpers.xhtml +93 -0
- data/test/haml/results/helpful.xhtml +10 -0
- data/test/haml/results/just_stuff.xhtml +68 -0
- data/test/haml/results/list.xhtml +12 -0
- data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
- data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
- data/test/haml/results/original_engine.xhtml +20 -0
- data/test/haml/results/partial_layout.xhtml +5 -0
- data/test/haml/results/partials.xhtml +21 -0
- data/test/haml/results/render_layout.xhtml +3 -0
- data/test/haml/results/silent_script.xhtml +74 -0
- data/test/haml/results/standard.xhtml +42 -0
- data/test/haml/results/tag_parsing.xhtml +23 -0
- data/test/haml/results/very_basic.xhtml +5 -0
- data/test/haml/results/whitespace_handling.xhtml +89 -0
- data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
- data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
- data/test/haml/rhtml/action_view.rhtml +62 -0
- data/test/haml/rhtml/standard.rhtml +54 -0
- data/test/haml/template_test.rb +204 -0
- data/test/haml/templates/_av_partial_1.haml +9 -0
- data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
- data/test/haml/templates/_av_partial_2.haml +5 -0
- data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
- data/test/haml/templates/_layout.erb +3 -0
- data/test/haml/templates/_layout_for_partial.haml +3 -0
- data/test/haml/templates/_partial.haml +8 -0
- data/test/haml/templates/_text_area.haml +3 -0
- data/test/haml/templates/action_view.haml +47 -0
- data/test/haml/templates/action_view_ugly.haml +47 -0
- data/test/haml/templates/breakage.haml +8 -0
- data/test/haml/templates/content_for_layout.haml +10 -0
- data/test/haml/templates/eval_suppressed.haml +11 -0
- data/test/haml/templates/filters.haml +66 -0
- data/test/haml/templates/helpers.haml +95 -0
- data/test/haml/templates/helpful.haml +11 -0
- data/test/haml/templates/just_stuff.haml +83 -0
- data/test/haml/templates/list.haml +12 -0
- data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
- data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
- data/test/haml/templates/original_engine.haml +17 -0
- data/test/haml/templates/partial_layout.haml +3 -0
- data/test/haml/templates/partialize.haml +1 -0
- data/test/haml/templates/partials.haml +12 -0
- data/test/haml/templates/render_layout.haml +2 -0
- data/test/haml/templates/silent_script.haml +40 -0
- data/test/haml/templates/standard.haml +42 -0
- data/test/haml/templates/standard_ugly.haml +1 -0
- data/test/haml/templates/tag_parsing.haml +21 -0
- data/test/haml/templates/very_basic.haml +4 -0
- data/test/haml/templates/whitespace_handling.haml +87 -0
- data/test/linked_rails.rb +12 -0
- data/test/sass/css2sass_test.rb +193 -0
- data/test/sass/engine_test.rb +786 -0
- data/test/sass/functions_test.rb +96 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +208 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +87 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/import.css +29 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/script_test.rb +153 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +309 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/import.sass +11 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/test_helper.rb +21 -0
- metadata +247 -0
data/lib/haml/filters.rb
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
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
|
+
base.instance_variable_set "@lazy_requires", nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Takes a string, the source text that should be passed to the filter,
|
|
39
|
+
# and returns the string resulting from running the filter on <tt>text</tt>.
|
|
40
|
+
#
|
|
41
|
+
# This should be overridden in most individual filter modules
|
|
42
|
+
# to render text with the given filter.
|
|
43
|
+
# If compile is overridden, however, render doesn't need to be.
|
|
44
|
+
def render(text)
|
|
45
|
+
raise Error.new("#{self.inspect}#render not defined!")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Same as render, but takes the Haml options hash as well.
|
|
49
|
+
# It's only safe to rely on options made available in Haml::Engine#options_for_buffer.
|
|
50
|
+
def render_with_options(text, options)
|
|
51
|
+
render(text)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def internal_compile(*args) # :nodoc:
|
|
55
|
+
resolve_lazy_requires
|
|
56
|
+
compile(*args)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# compile should be overridden when a filter needs to have access
|
|
60
|
+
# to the Haml evaluation context.
|
|
61
|
+
# Rather than applying a filter to a string at compile-time,
|
|
62
|
+
# compile uses the Haml::Precompiler instance to compile the string to Ruby code
|
|
63
|
+
# that will be executed in the context of the active Haml template.
|
|
64
|
+
#
|
|
65
|
+
# Warning: the Haml::Precompiler interface is neither well-documented
|
|
66
|
+
# nor guaranteed to be stable.
|
|
67
|
+
# If you want to make use of it,
|
|
68
|
+
# you'll probably need to look at the source code
|
|
69
|
+
# and should test your filter when upgrading to new Haml versions.
|
|
70
|
+
def compile(precompiler, text)
|
|
71
|
+
resolve_lazy_requires
|
|
72
|
+
filter = self
|
|
73
|
+
precompiler.instance_eval do
|
|
74
|
+
if contains_interpolation?(text)
|
|
75
|
+
return if options[:suppress_eval]
|
|
76
|
+
|
|
77
|
+
push_script <<RUBY
|
|
78
|
+
find_and_preserve(#{filter.inspect}.render_with_options(#{unescape_interpolation(text)}, _hamlout.options))
|
|
79
|
+
RUBY
|
|
80
|
+
return
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
rendered = Haml::Helpers::find_and_preserve(filter.render_with_options(text, precompiler.options), precompiler.options[:preserve])
|
|
84
|
+
|
|
85
|
+
if !options[:ugly]
|
|
86
|
+
push_text(rendered.rstrip.gsub("\n", "\n#{' ' * @output_tabs}"))
|
|
87
|
+
else
|
|
88
|
+
push_text(rendered.rstrip)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# This becomes a class method of modules that include Base.
|
|
94
|
+
# It allows the module to specify one or more Ruby files
|
|
95
|
+
# that Haml should try to require when compiling the filter.
|
|
96
|
+
#
|
|
97
|
+
# The first file specified is tried first,
|
|
98
|
+
# then the second, etc.
|
|
99
|
+
# If none are found, the compilation throws an exception.
|
|
100
|
+
#
|
|
101
|
+
# For example:
|
|
102
|
+
#
|
|
103
|
+
# module Haml::Filters::Markdown
|
|
104
|
+
# lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth'
|
|
105
|
+
#
|
|
106
|
+
# ...
|
|
107
|
+
# end
|
|
108
|
+
#
|
|
109
|
+
def lazy_require(*reqs)
|
|
110
|
+
@lazy_requires = reqs
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
def resolve_lazy_requires
|
|
116
|
+
return unless @lazy_requires
|
|
117
|
+
|
|
118
|
+
@lazy_requires[0...-1].each do |req|
|
|
119
|
+
begin
|
|
120
|
+
@required = req
|
|
121
|
+
require @required
|
|
122
|
+
return
|
|
123
|
+
rescue LoadError; end # RCov doesn't see this, but it is run
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
begin
|
|
127
|
+
@required = @lazy_requires[-1]
|
|
128
|
+
require @required
|
|
129
|
+
rescue LoadError => e
|
|
130
|
+
classname = self.name.match(/\w+$/)[0]
|
|
131
|
+
|
|
132
|
+
if @lazy_requires.size == 1
|
|
133
|
+
raise Error.new("Can't run #{classname} filter; required file '#{@lazy_requires.first}' not found")
|
|
134
|
+
else
|
|
135
|
+
raise Error.new("Can't run #{classname} filter; required #{@lazy_requires.map { |r| "'#{r}'" }.join(' or ')}, but none were found")
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# :stopdoc:
|
|
144
|
+
|
|
145
|
+
begin
|
|
146
|
+
require 'rubygems'
|
|
147
|
+
rescue LoadError; end
|
|
148
|
+
|
|
149
|
+
module Haml
|
|
150
|
+
module Filters
|
|
151
|
+
module Plain
|
|
152
|
+
include Base
|
|
153
|
+
|
|
154
|
+
def render(text); text; end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
module Javascript
|
|
158
|
+
include Base
|
|
159
|
+
|
|
160
|
+
def render_with_options(text, options)
|
|
161
|
+
<<END
|
|
162
|
+
<script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>
|
|
163
|
+
//<![CDATA[
|
|
164
|
+
#{text.rstrip.gsub("\n", "\n ")}
|
|
165
|
+
//]]>
|
|
166
|
+
</script>
|
|
167
|
+
END
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
module Cdata
|
|
172
|
+
include Base
|
|
173
|
+
|
|
174
|
+
def render(text)
|
|
175
|
+
"<![CDATA[#{("\n" + text).rstrip.gsub("\n", "\n ")}\n]]>"
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
module Escaped
|
|
180
|
+
include Base
|
|
181
|
+
|
|
182
|
+
def render(text)
|
|
183
|
+
Haml::Helpers.html_escape text
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
module Ruby
|
|
188
|
+
include Base
|
|
189
|
+
lazy_require 'stringio'
|
|
190
|
+
|
|
191
|
+
def compile(precompiler, text)
|
|
192
|
+
return if precompiler.options[:suppress_eval]
|
|
193
|
+
precompiler.instance_eval do
|
|
194
|
+
push_silent <<-FIRST.gsub("\n", ';') + text + <<-LAST.gsub("\n", ';')
|
|
195
|
+
_haml_old_stdout = $stdout
|
|
196
|
+
$stdout = StringIO.new(_hamlout.buffer, 'a')
|
|
197
|
+
FIRST
|
|
198
|
+
_haml_old_stdout, $stdout = $stdout, _haml_old_stdout
|
|
199
|
+
_haml_old_stdout.close
|
|
200
|
+
LAST
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
module Preserve
|
|
206
|
+
include Base
|
|
207
|
+
|
|
208
|
+
def render(text)
|
|
209
|
+
Haml::Helpers.preserve text
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
module Sass
|
|
214
|
+
include Base
|
|
215
|
+
lazy_require 'sass/plugin'
|
|
216
|
+
|
|
217
|
+
def render(text)
|
|
218
|
+
::Sass::Engine.new(text, ::Sass::Plugin.engine_options).render
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
module ERB
|
|
223
|
+
include Base
|
|
224
|
+
lazy_require 'erb'
|
|
225
|
+
|
|
226
|
+
def compile(precompiler, text)
|
|
227
|
+
return if precompiler.options[:suppress_eval]
|
|
228
|
+
src = ::ERB.new(text).src.sub(/^#coding:.*?\n/, '').
|
|
229
|
+
sub(/^_erbout = '';/, "").gsub("\n", ';')
|
|
230
|
+
precompiler.send(:push_silent, src)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
module Textile
|
|
235
|
+
include Base
|
|
236
|
+
lazy_require 'redcloth'
|
|
237
|
+
|
|
238
|
+
def render(text)
|
|
239
|
+
::RedCloth.new(text).to_html(:textile)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
RedCloth = Textile
|
|
243
|
+
Filters.defined['redcloth'] = RedCloth
|
|
244
|
+
|
|
245
|
+
# Uses BlueCloth or RedCloth to provide only Markdown (not Textile) parsing
|
|
246
|
+
module Markdown
|
|
247
|
+
include Base
|
|
248
|
+
lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth'
|
|
249
|
+
|
|
250
|
+
def render(text)
|
|
251
|
+
engine = case @required
|
|
252
|
+
when 'rdiscount'
|
|
253
|
+
::RDiscount
|
|
254
|
+
when 'peg_markdown'
|
|
255
|
+
::PEGMarkdown
|
|
256
|
+
when 'maruku'
|
|
257
|
+
::Maruku
|
|
258
|
+
when 'bluecloth'
|
|
259
|
+
::BlueCloth
|
|
260
|
+
end
|
|
261
|
+
engine.new(text).to_html
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
module Maruku
|
|
266
|
+
include Base
|
|
267
|
+
lazy_require 'maruku'
|
|
268
|
+
|
|
269
|
+
def render(text)
|
|
270
|
+
::Maruku.new(text).to_html
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
# :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
|
+
|