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.
- data/.yardopts +5 -0
- data/MIT-LICENSE +1 -1
- data/README.md +347 -0
- data/Rakefile +124 -19
- data/VERSION +1 -1
- data/VERSION_NAME +1 -0
- data/extra/haml-mode.el +397 -78
- data/extra/sass-mode.el +148 -36
- data/extra/update_watch.rb +13 -0
- data/lib/haml.rb +15 -993
- data/lib/haml/buffer.rb +131 -84
- data/lib/haml/engine.rb +129 -97
- data/lib/haml/error.rb +7 -7
- data/lib/haml/exec.rb +127 -42
- data/lib/haml/filters.rb +107 -42
- data/lib/haml/helpers.rb +210 -156
- data/lib/haml/helpers/action_view_extensions.rb +34 -39
- data/lib/haml/helpers/action_view_mods.rb +132 -139
- data/lib/haml/html.rb +77 -65
- data/lib/haml/precompiler.rb +404 -213
- data/lib/haml/shared.rb +78 -0
- data/lib/haml/template.rb +14 -14
- data/lib/haml/template/patch.rb +2 -2
- data/lib/haml/template/plugin.rb +2 -3
- data/lib/haml/util.rb +211 -6
- data/lib/haml/version.rb +30 -13
- data/lib/sass.rb +7 -856
- data/lib/sass/css.rb +169 -161
- data/lib/sass/engine.rb +344 -328
- data/lib/sass/environment.rb +79 -0
- data/lib/sass/error.rb +33 -11
- data/lib/sass/files.rb +139 -0
- data/lib/sass/plugin.rb +160 -117
- data/lib/sass/plugin/merb.rb +7 -6
- data/lib/sass/plugin/rails.rb +5 -6
- data/lib/sass/repl.rb +58 -0
- data/lib/sass/script.rb +59 -0
- data/lib/sass/script/bool.rb +17 -0
- data/lib/sass/script/color.rb +183 -0
- data/lib/sass/script/funcall.rb +50 -0
- data/lib/sass/script/functions.rb +198 -0
- data/lib/sass/script/lexer.rb +178 -0
- data/lib/sass/script/literal.rb +177 -0
- data/lib/sass/script/node.rb +14 -0
- data/lib/sass/script/number.rb +381 -0
- data/lib/sass/script/operation.rb +45 -0
- data/lib/sass/script/parser.rb +172 -0
- data/lib/sass/script/string.rb +12 -0
- data/lib/sass/script/unary_operation.rb +34 -0
- data/lib/sass/script/variable.rb +31 -0
- data/lib/sass/tree/comment_node.rb +73 -10
- data/lib/sass/tree/debug_node.rb +30 -0
- data/lib/sass/tree/directive_node.rb +42 -17
- data/lib/sass/tree/file_node.rb +41 -0
- data/lib/sass/tree/for_node.rb +48 -0
- data/lib/sass/tree/if_node.rb +54 -0
- data/lib/sass/tree/mixin_def_node.rb +29 -0
- data/lib/sass/tree/mixin_node.rb +48 -0
- data/lib/sass/tree/node.rb +214 -11
- data/lib/sass/tree/prop_node.rb +109 -0
- data/lib/sass/tree/rule_node.rb +178 -51
- data/lib/sass/tree/variable_node.rb +34 -0
- data/lib/sass/tree/while_node.rb +31 -0
- data/test/haml/engine_test.rb +331 -36
- data/test/haml/helper_test.rb +12 -1
- data/test/haml/results/content_for_layout.xhtml +0 -3
- data/test/haml/results/filters.xhtml +2 -0
- data/test/haml/results/list.xhtml +1 -1
- data/test/haml/template_test.rb +7 -2
- data/test/haml/templates/content_for_layout.haml +0 -2
- data/test/haml/templates/list.haml +1 -1
- data/test/haml/util_test.rb +92 -0
- data/test/sass/css2sass_test.rb +69 -24
- data/test/sass/engine_test.rb +586 -64
- data/test/sass/functions_test.rb +125 -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 +81 -28
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/{constants.css → script.css} +4 -4
- data/test/sass/results/subdir/subdir.css +2 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/script_test.rb +258 -0
- data/test/sass/templates/import.sass +1 -1
- data/test/sass/templates/importee.sass +7 -2
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/{constants.sass → script.sass} +11 -10
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/subdir.sass +2 -2
- data/test/sass/templates/units.sass +11 -0
- data/test/test_helper.rb +14 -0
- metadata +77 -19
- data/FAQ +0 -138
- data/README.rdoc +0 -319
- data/lib/sass/constant.rb +0 -216
- data/lib/sass/constant/color.rb +0 -101
- data/lib/sass/constant/literal.rb +0 -54
- data/lib/sass/constant/nil.rb +0 -9
- data/lib/sass/constant/number.rb +0 -87
- data/lib/sass/constant/operation.rb +0 -30
- data/lib/sass/constant/string.rb +0 -22
- data/lib/sass/tree/attr_node.rb +0 -57
- data/lib/sass/tree/value_node.rb +0 -20
@@ -1,45 +1,40 @@
|
|
1
1
|
require 'haml/helpers/action_view_mods'
|
2
2
|
|
3
|
-
|
4
|
-
module
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
@@ -1,166 +1,139 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
module ActionView
|
2
|
+
class Base
|
3
|
+
def render_with_haml(*args, &block)
|
4
|
+
options = args.first
|
5
|
+
|
6
|
+
# If render :layout is used with a block,
|
7
|
+
# it concats rather than returning a string
|
8
|
+
# so we need it to keep thinking it's Haml
|
9
|
+
# until it hits the sub-render
|
10
|
+
if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
|
11
|
+
return non_haml { render_without_haml(*args, &block) }
|
12
|
+
end
|
13
|
+
render_without_haml(*args, &block)
|
14
|
+
end
|
15
|
+
alias_method :render_without_haml, :render
|
16
|
+
alias_method :render, :render_with_haml
|
17
|
+
|
18
|
+
# Rails >2.1
|
19
|
+
if Haml::Util.has?(:instance_method, self, :output_buffer)
|
20
|
+
def output_buffer_with_haml
|
21
|
+
return haml_buffer.buffer if is_haml?
|
22
|
+
output_buffer_without_haml
|
15
23
|
end
|
16
|
-
alias_method :
|
17
|
-
alias_method :
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
alias_method :output_buffer_without_haml, :output_buffer
|
25
|
+
alias_method :output_buffer, :output_buffer_with_haml
|
26
|
+
|
27
|
+
def set_output_buffer_with_haml(new)
|
28
|
+
if is_haml?
|
29
|
+
haml_buffer.buffer = new
|
30
|
+
else
|
31
|
+
set_output_buffer_without_haml new
|
24
32
|
end
|
25
|
-
|
26
|
-
|
33
|
+
end
|
34
|
+
alias_method :set_output_buffer_without_haml, :output_buffer=
|
35
|
+
alias_method :output_buffer=, :set_output_buffer_with_haml
|
36
|
+
end
|
37
|
+
end
|
27
38
|
|
28
|
-
|
29
|
-
|
30
|
-
|
39
|
+
module Helpers
|
40
|
+
# In Rails <=2.1, we've got to override considerable capturing infrastructure.
|
41
|
+
# In Rails >2.1, we can make do with only overriding #capture
|
42
|
+
# (which no longer behaves differently in helper contexts).
|
43
|
+
unless Haml::Util.has?(:instance_method, ActionView::Base, :output_buffer)
|
44
|
+
module CaptureHelper
|
45
|
+
def capture_with_haml(*args, &block)
|
46
|
+
# Rails' #capture helper will just return the value of the block
|
47
|
+
# if it's not actually in the template context,
|
48
|
+
# as detected by the existance of an _erbout variable.
|
49
|
+
# We've got to do the same thing for compatibility.
|
50
|
+
|
51
|
+
if is_haml? && block_is_haml?(block)
|
52
|
+
capture_haml(*args, &block)
|
31
53
|
else
|
32
|
-
|
54
|
+
capture_without_haml(*args, &block)
|
33
55
|
end
|
34
56
|
end
|
35
|
-
alias_method :
|
36
|
-
alias_method :
|
37
|
-
end
|
38
|
-
end
|
57
|
+
alias_method :capture_without_haml, :capture
|
58
|
+
alias_method :capture, :capture_with_haml
|
39
59
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
60
|
+
def capture_erb_with_buffer_with_haml(buffer, *args, &block)
|
61
|
+
if is_haml?
|
62
|
+
capture_haml(*args, &block)
|
63
|
+
else
|
64
|
+
capture_erb_with_buffer_without_haml(buffer, *args, &block)
|
70
65
|
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
66
|
end
|
67
|
+
alias_method :capture_erb_with_buffer_without_haml, :capture_erb_with_buffer
|
68
|
+
alias_method :capture_erb_with_buffer, :capture_erb_with_buffer_with_haml
|
69
|
+
end
|
74
70
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
71
|
+
module TextHelper
|
72
|
+
def concat_with_haml(string, binding = nil)
|
73
|
+
if is_haml?
|
74
|
+
haml_buffer.buffer.concat(string)
|
75
|
+
else
|
76
|
+
concat_without_haml(string, binding)
|
82
77
|
end
|
83
|
-
alias_method :concat_without_haml, :concat
|
84
|
-
alias_method :concat, :concat_with_haml
|
85
78
|
end
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
79
|
+
alias_method :concat_without_haml, :concat
|
80
|
+
alias_method :concat, :concat_with_haml
|
81
|
+
end
|
82
|
+
else
|
83
|
+
module CaptureHelper
|
84
|
+
def capture_with_haml(*args, &block)
|
85
|
+
if Haml::Helpers.block_is_haml?(block)
|
86
|
+
capture_haml(*args, &block)
|
87
|
+
else
|
88
|
+
capture_without_haml(*args, &block)
|
94
89
|
end
|
95
|
-
alias_method :capture_without_haml, :capture
|
96
|
-
alias_method :capture, :capture_with_haml
|
97
90
|
end
|
91
|
+
alias_method :capture_without_haml, :capture
|
92
|
+
alias_method :capture, :capture_with_haml
|
98
93
|
end
|
94
|
+
end
|
99
95
|
|
100
|
-
|
101
|
-
|
102
|
-
|
96
|
+
module TagHelper
|
97
|
+
def content_tag_with_haml(name, *args, &block)
|
98
|
+
return content_tag_without_haml(name, *args, &block) unless is_haml?
|
103
99
|
|
104
|
-
|
100
|
+
preserve = haml_buffer.options[:preserve].include?(name.to_s)
|
105
101
|
|
106
|
-
|
107
|
-
|
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
|
102
|
+
if block_given? && block_is_haml?(block) && preserve
|
103
|
+
return content_tag_without_haml(name, *args) {preserve(&block)}
|
113
104
|
end
|
114
105
|
|
115
|
-
|
116
|
-
|
106
|
+
returning content_tag_without_haml(name, *args, &block) do |content|
|
107
|
+
return Haml::Helpers.preserve(content) if preserve && content
|
108
|
+
end
|
117
109
|
end
|
118
110
|
|
119
|
-
|
120
|
-
|
111
|
+
alias_method :content_tag_without_haml, :content_tag
|
112
|
+
alias_method :content_tag, :content_tag_with_haml
|
113
|
+
end
|
121
114
|
|
122
|
-
|
123
|
-
|
124
|
-
end
|
115
|
+
class InstanceTag
|
116
|
+
# Includes TagHelper
|
125
117
|
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
alias_method :content_tag_without_haml, :content_tag
|
131
|
-
alias_method :content_tag, :content_tag_with_haml
|
118
|
+
def haml_buffer
|
119
|
+
@template_object.send :haml_buffer
|
132
120
|
end
|
133
121
|
|
134
|
-
|
135
|
-
|
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
|
122
|
+
def is_haml?
|
123
|
+
@template_object.send :is_haml?
|
157
124
|
end
|
158
125
|
|
159
|
-
|
160
|
-
|
161
|
-
|
126
|
+
alias_method :content_tag_without_haml, :content_tag
|
127
|
+
alias_method :content_tag, :content_tag_with_haml
|
128
|
+
end
|
129
|
+
|
130
|
+
module FormTagHelper
|
131
|
+
def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
|
132
|
+
if is_haml?
|
133
|
+
if block_given?
|
162
134
|
oldproc = proc
|
163
135
|
proc = haml_bind_proc do |*args|
|
136
|
+
concat "\n"
|
164
137
|
tab_up
|
165
138
|
oldproc.call(*args)
|
166
139
|
tab_down
|
@@ -168,14 +141,34 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
|
|
168
141
|
end
|
169
142
|
concat haml_indent
|
170
143
|
end
|
171
|
-
|
172
|
-
concat "\n" if block_given?
|
144
|
+
res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
|
145
|
+
concat "\n" if block_given?
|
146
|
+
res
|
147
|
+
else
|
148
|
+
form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
|
173
149
|
end
|
174
|
-
alias_method :form_for_without_haml, :form_for
|
175
|
-
alias_method :form_for, :form_for_with_haml
|
176
150
|
end
|
177
|
-
|
151
|
+
alias_method :form_tag_without_haml, :form_tag
|
152
|
+
alias_method :form_tag, :form_tag_with_haml
|
153
|
+
end
|
154
|
+
|
155
|
+
module FormHelper
|
156
|
+
def form_for_with_haml(object_name, *args, &proc)
|
157
|
+
if block_given? && is_haml?
|
158
|
+
oldproc = proc
|
159
|
+
proc = haml_bind_proc do |*args|
|
160
|
+
tab_up
|
161
|
+
oldproc.call(*args)
|
162
|
+
tab_down
|
163
|
+
concat haml_indent
|
164
|
+
end
|
165
|
+
concat haml_indent
|
166
|
+
end
|
167
|
+
form_for_without_haml(object_name, *args, &proc)
|
168
|
+
concat "\n" if block_given? && is_haml?
|
169
|
+
end
|
170
|
+
alias_method :form_for_without_haml, :form_for
|
171
|
+
alias_method :form_for, :form_for_with_haml
|
178
172
|
end
|
179
173
|
end
|
180
174
|
end
|
181
|
-
|
data/lib/haml/html.rb
CHANGED
@@ -6,15 +6,21 @@ require 'hpricot'
|
|
6
6
|
require 'cgi'
|
7
7
|
|
8
8
|
module Haml
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
9
|
+
# Converts HTML documents into Haml templates.
|
10
|
+
# Depends on [Hpricot](http://code.whytheluckystiff.net/hpricot/) for HTML parsing.
|
11
|
+
#
|
12
|
+
# Example usage:
|
13
|
+
#
|
14
|
+
# Haml::Engine.new("<a href='http://google.com'>Blat</a>").render
|
15
|
+
# #=> "%a{:href => 'http://google.com'} Blat"
|
12
16
|
class HTML
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
17
|
+
# @param template [String, Hpricot::Node] The HTML template to convert
|
18
|
+
# @option options :rhtml [Boolean] (false) Whether or not to parse
|
19
|
+
# ERB's `<%= %>` and `<% %>` into Haml's `=` and `-`
|
20
|
+
# @option options :xhtml [Boolean] (false) Whether or not to parse
|
21
|
+
# the HTML strictly as XHTML
|
16
22
|
def initialize(template, options = {})
|
17
|
-
|
23
|
+
@options = options
|
18
24
|
|
19
25
|
if template.is_a? Hpricot::Node
|
20
26
|
@template = template
|
@@ -23,12 +29,12 @@ module Haml
|
|
23
29
|
template = template.read
|
24
30
|
end
|
25
31
|
|
26
|
-
if
|
32
|
+
if @options[:rhtml]
|
27
33
|
match_to_html(template, /<%=(.*?)-?%>/m, 'loud')
|
28
34
|
match_to_html(template, /<%-?(.*?)-?%>/m, 'silent')
|
29
35
|
end
|
30
36
|
|
31
|
-
method =
|
37
|
+
method = @options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot)
|
32
38
|
@template = method.call(template.gsub('&', '&'))
|
33
39
|
end
|
34
40
|
end
|
@@ -36,14 +42,18 @@ module Haml
|
|
36
42
|
# Processes the document and returns the result as a string
|
37
43
|
# containing the Haml template.
|
38
44
|
def render
|
39
|
-
@template.to_haml(0)
|
45
|
+
@template.to_haml(0, @options)
|
40
46
|
end
|
41
47
|
alias_method :to_haml, :render
|
42
48
|
|
49
|
+
# Haml monkeypatches various Hpricot classes
|
50
|
+
# to add methods for conversion to Haml.
|
43
51
|
module ::Hpricot::Node
|
44
|
-
# Returns the Haml representation of the given node
|
45
|
-
#
|
46
|
-
|
52
|
+
# Returns the Haml representation of the given node.
|
53
|
+
#
|
54
|
+
# @param tabs [Fixnum] The indentation level of the resulting Haml.
|
55
|
+
# @option options (see Haml::HTML#initialize)
|
56
|
+
def to_haml(tabs, options)
|
47
57
|
parse_text(self.to_s, tabs)
|
48
58
|
end
|
49
59
|
|
@@ -68,34 +78,36 @@ module Haml
|
|
68
78
|
end
|
69
79
|
end
|
70
80
|
|
71
|
-
# :stopdoc:
|
72
|
-
|
73
|
-
def self.options
|
74
|
-
@@options
|
75
|
-
end
|
76
|
-
|
77
81
|
TEXT_REGEXP = /^(\s*).*$/
|
78
82
|
|
83
|
+
# @see Hpricot::Node
|
79
84
|
class ::Hpricot::Doc
|
80
|
-
|
81
|
-
|
85
|
+
# @see Hpricot::Node#to_haml
|
86
|
+
def to_haml(tabs, options)
|
87
|
+
(children || []).inject('') {|s, c| s << c.to_haml(0, options)}
|
82
88
|
end
|
83
89
|
end
|
84
90
|
|
91
|
+
# @see Hpricot::Node
|
85
92
|
class ::Hpricot::XMLDecl
|
86
|
-
|
93
|
+
# @see Hpricot::Node#to_haml
|
94
|
+
def to_haml(tabs, options)
|
87
95
|
"#{tabulate(tabs)}!!! XML\n"
|
88
96
|
end
|
89
97
|
end
|
90
98
|
|
99
|
+
# @see Hpricot::Node
|
91
100
|
class ::Hpricot::CData
|
92
|
-
|
101
|
+
# @see Hpricot::Node#to_haml
|
102
|
+
def to_haml(tabs, options)
|
93
103
|
"#{tabulate(tabs)}:cdata\n#{parse_text(self.content, tabs + 1)}"
|
94
104
|
end
|
95
105
|
end
|
96
106
|
|
107
|
+
# @see Hpricot::Node
|
97
108
|
class ::Hpricot::DocType
|
98
|
-
|
109
|
+
# @see Hpricot::Node#to_haml
|
110
|
+
def to_haml(tabs, options)
|
99
111
|
attrs = public_id.scan(/DTD\s+([^\s]+)\s*([^\s]*)\s*([^\s]*)\s*\/\//)[0]
|
100
112
|
if attrs == nil
|
101
113
|
raise Exception.new("Invalid doctype")
|
@@ -125,35 +137,40 @@ module Haml
|
|
125
137
|
end
|
126
138
|
end
|
127
139
|
|
140
|
+
# @see Hpricot::Node
|
128
141
|
class ::Hpricot::Comment
|
129
|
-
|
142
|
+
# @see Hpricot::Node#to_haml
|
143
|
+
def to_haml(tabs, options)
|
130
144
|
"#{tabulate(tabs)}/\n#{parse_text(self.content, tabs + 1)}"
|
131
145
|
end
|
132
146
|
end
|
133
147
|
|
148
|
+
# @see Hpricot::Node
|
134
149
|
class ::Hpricot::Elem
|
135
|
-
|
150
|
+
# @see Hpricot::Node#to_haml
|
151
|
+
def to_haml(tabs, options)
|
136
152
|
output = "#{tabulate(tabs)}"
|
137
|
-
if
|
138
|
-
return output +
|
153
|
+
if options[:rhtml] && name[0...5] == 'haml:'
|
154
|
+
return output + send("haml_tag_#{name[5..-1]}", CGI.unescapeHTML(self.inner_text))
|
139
155
|
end
|
140
156
|
|
141
|
-
output += "%#{name}" unless name == 'div' &&
|
157
|
+
output += "%#{name}" unless name == 'div' &&
|
158
|
+
(static_id?(options) || static_classname?(options))
|
142
159
|
|
143
160
|
if attributes
|
144
|
-
if static_id?
|
161
|
+
if static_id?(options)
|
145
162
|
output += "##{attributes['id']}"
|
146
163
|
remove_attribute('id')
|
147
164
|
end
|
148
|
-
if static_classname?
|
165
|
+
if static_classname?(options)
|
149
166
|
attributes['class'].split(' ').each { |c| output += ".#{c}" }
|
150
167
|
remove_attribute('class')
|
151
168
|
end
|
152
|
-
output += haml_attributes if attributes.length > 0
|
169
|
+
output += haml_attributes(options) if attributes.length > 0
|
153
170
|
end
|
154
171
|
|
155
172
|
(self.children || []).inject(output + "\n") do |output, child|
|
156
|
-
output + child.to_haml(tabs + 1)
|
173
|
+
output + child.to_haml(tabs + 1, options)
|
157
174
|
end
|
158
175
|
end
|
159
176
|
|
@@ -161,44 +178,48 @@ module Haml
|
|
161
178
|
|
162
179
|
def dynamic_attributes
|
163
180
|
@dynamic_attributes ||= begin
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
full_match ? $1: "\#{#{$1}}"
|
171
|
-
end
|
172
|
-
unless ruby_value == value
|
173
|
-
dynamic[name] = full_match ? ruby_value : %("#{ruby_value}")
|
174
|
-
end
|
181
|
+
Haml::Util.map_hash(attributes) do |name, value|
|
182
|
+
next if value.empty?
|
183
|
+
full_match = nil
|
184
|
+
ruby_value = value.gsub(%r{<haml:loud>\s*(.+?)\s*</haml:loud>}) do
|
185
|
+
full_match = $`.empty? && $'.empty?
|
186
|
+
full_match ? $1: "\#{#{$1}}"
|
175
187
|
end
|
176
|
-
|
188
|
+
next if ruby_value == value
|
189
|
+
[name, full_match ? ruby_value : %("#{ruby_value}")]
|
177
190
|
end
|
178
191
|
end
|
179
192
|
end
|
180
|
-
|
181
|
-
def
|
182
|
-
|
193
|
+
|
194
|
+
def haml_tag_loud(text)
|
195
|
+
"= #{text.gsub(/\n\s*/, ' ').strip}\n"
|
196
|
+
end
|
197
|
+
|
198
|
+
def haml_tag_silent(text)
|
199
|
+
text.split("\n").map { |line| "- #{line.strip}\n" }.join
|
200
|
+
end
|
201
|
+
|
202
|
+
def static_attribute?(name, options)
|
203
|
+
attributes[name] and !dynamic_attribute?(name, options)
|
183
204
|
end
|
184
205
|
|
185
|
-
def dynamic_attribute?(name)
|
186
|
-
|
206
|
+
def dynamic_attribute?(name, options)
|
207
|
+
options[:rhtml] and dynamic_attributes.key?(name)
|
187
208
|
end
|
188
209
|
|
189
|
-
def static_id?
|
190
|
-
static_attribute?
|
210
|
+
def static_id?(options)
|
211
|
+
static_attribute?('id', options)
|
191
212
|
end
|
192
213
|
|
193
|
-
def static_classname?
|
194
|
-
static_attribute?
|
214
|
+
def static_classname?(options)
|
215
|
+
static_attribute?('class', options)
|
195
216
|
end
|
196
217
|
|
197
218
|
# Returns a string representation of an attributes hash
|
198
219
|
# that's prettier than that produced by Hash#inspect
|
199
|
-
def haml_attributes
|
220
|
+
def haml_attributes(options)
|
200
221
|
attrs = attributes.map do |name, value|
|
201
|
-
value = dynamic_attribute?(name) ? dynamic_attributes[name] : value.inspect
|
222
|
+
value = dynamic_attribute?(name, options) ? dynamic_attributes[name] : value.inspect
|
202
223
|
name = name.index(/\W/) ? name.inspect : ":#{name}"
|
203
224
|
"#{name} => #{value}"
|
204
225
|
end
|
@@ -206,14 +227,6 @@ module Haml
|
|
206
227
|
end
|
207
228
|
end
|
208
229
|
|
209
|
-
def self.haml_tag_loud(text)
|
210
|
-
"= #{text.gsub(/\n\s*/, ' ').strip}\n"
|
211
|
-
end
|
212
|
-
|
213
|
-
def self.haml_tag_silent(text)
|
214
|
-
text.split("\n").map { |line| "- #{line.strip}\n" }.join
|
215
|
-
end
|
216
|
-
|
217
230
|
private
|
218
231
|
|
219
232
|
def match_to_html(string, regex, tag)
|
@@ -221,6 +234,5 @@ module Haml
|
|
221
234
|
"<haml:#{tag}>#{CGI.escapeHTML($1)}</haml:#{tag}>"
|
222
235
|
end
|
223
236
|
end
|
224
|
-
# :startdoc:
|
225
237
|
end
|
226
238
|
end
|