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.
- data/EDGE_GEM_VERSION +1 -1
- data/FAQ.md +142 -0
- data/{README.rdoc → README.md} +141 -141
- data/Rakefile +29 -17
- data/VERSION +1 -1
- data/lib/haml/buffer.rb +63 -27
- data/lib/haml/engine.rb +103 -80
- data/lib/haml/error.rb +7 -7
- data/lib/haml/exec.rb +80 -26
- data/lib/haml/filters.rb +106 -40
- data/lib/haml/helpers/action_view_extensions.rb +34 -39
- data/lib/haml/helpers/action_view_mods.rb +132 -139
- data/lib/haml/helpers.rb +207 -153
- data/lib/haml/html.rb +40 -21
- data/lib/haml/precompiler.rb +2 -0
- data/lib/haml/shared.rb +34 -3
- data/lib/haml/template/patch.rb +1 -1
- data/lib/haml/template/plugin.rb +0 -2
- data/lib/haml/template.rb +5 -0
- data/lib/haml/util.rb +136 -1
- data/lib/haml/version.rb +16 -4
- data/lib/haml.rb +502 -481
- data/lib/sass/css.rb +106 -68
- data/lib/sass/engine.rb +55 -22
- data/lib/sass/environment.rb +52 -21
- data/lib/sass/error.rb +23 -12
- data/lib/sass/files.rb +27 -0
- data/lib/sass/plugin/merb.rb +2 -2
- data/lib/sass/plugin/rails.rb +0 -2
- data/lib/sass/plugin.rb +32 -23
- data/lib/sass/repl.rb +7 -0
- data/lib/sass/script/bool.rb +9 -5
- data/lib/sass/script/color.rb +87 -1
- data/lib/sass/script/funcall.rb +23 -2
- data/lib/sass/script/functions.rb +93 -44
- data/lib/sass/script/lexer.rb +33 -3
- data/lib/sass/script/literal.rb +93 -1
- data/lib/sass/script/node.rb +14 -0
- data/lib/sass/script/number.rb +128 -4
- data/lib/sass/script/operation.rb +16 -1
- data/lib/sass/script/parser.rb +51 -21
- data/lib/sass/script/string.rb +7 -4
- data/lib/sass/script/unary_operation.rb +14 -1
- data/lib/sass/script/variable.rb +12 -1
- data/lib/sass/script.rb +26 -5
- data/lib/sass/tree/attr_node.rb +46 -9
- data/lib/sass/tree/comment_node.rb +41 -1
- data/lib/sass/tree/debug_node.rb +8 -0
- data/lib/sass/tree/directive_node.rb +20 -0
- data/lib/sass/tree/file_node.rb +12 -0
- data/lib/sass/tree/for_node.rb +15 -0
- data/lib/sass/tree/if_node.rb +22 -0
- data/lib/sass/tree/mixin_def_node.rb +12 -1
- data/lib/sass/tree/mixin_node.rb +13 -0
- data/lib/sass/tree/node.rb +136 -6
- data/lib/sass/tree/rule_node.rb +66 -7
- data/lib/sass/tree/variable_node.rb +10 -0
- data/lib/sass/tree/while_node.rb +11 -1
- data/lib/sass.rb +544 -534
- metadata +7 -6
- data/FAQ +0 -138
data/lib/haml/buffer.rb
CHANGED
@@ -1,76 +1,92 @@
|
|
1
1
|
module Haml
|
2
|
-
# This class is used only internally. It holds the buffer of
|
3
|
-
# is eventually output
|
4
|
-
# from within the precompiled code,
|
5
|
-
# processing done within instance_eval
|
2
|
+
# This class is used only internally. It holds the buffer of HTML that
|
3
|
+
# is eventually output as the resulting document.
|
4
|
+
# It's called from within the precompiled code,
|
5
|
+
# and helps reduce the amount of processing done within `instance_eval`ed code.
|
6
6
|
class Buffer
|
7
7
|
include Haml::Helpers
|
8
8
|
include Haml::Util
|
9
9
|
|
10
|
-
# The string that holds the compiled
|
11
|
-
# _erbout for compatibility with ERB-specific code.
|
10
|
+
# The string that holds the compiled HTML. This is aliased as
|
11
|
+
# `_erbout` for compatibility with ERB-specific code.
|
12
|
+
#
|
13
|
+
# @return [String]
|
12
14
|
attr_accessor :buffer
|
13
15
|
|
14
|
-
# The options hash passed in from Haml::Engine.
|
16
|
+
# The options hash passed in from {Haml::Engine}.
|
17
|
+
#
|
18
|
+
# @return [Hash<String, Object>]
|
19
|
+
# @see Haml::Engine#options_for_buffer
|
15
20
|
attr_accessor :options
|
16
21
|
|
17
|
-
# The Buffer for the enclosing Haml document.
|
22
|
+
# The {Buffer} for the enclosing Haml document.
|
18
23
|
# This is set for partials and similar sorts of nested templates.
|
19
|
-
# It's nil at the top level (see #toplevel?).
|
24
|
+
# It's `nil` at the top level (see \{#toplevel?}).
|
25
|
+
#
|
26
|
+
# @return [Buffer]
|
20
27
|
attr_accessor :upper
|
21
28
|
|
22
29
|
# nil if there's no capture_haml block running,
|
23
30
|
# and the position at which it's beginning the capture if there is one.
|
31
|
+
#
|
32
|
+
# @return [Fixnum, nil]
|
24
33
|
attr_accessor :capture_position
|
25
34
|
|
26
|
-
#
|
35
|
+
# @return [Boolean]
|
36
|
+
# @see #active?
|
27
37
|
attr_writer :active
|
28
38
|
|
29
|
-
#
|
39
|
+
# @return [Boolean] Whether or not the format is XHTML
|
30
40
|
def xhtml?
|
31
41
|
not html?
|
32
42
|
end
|
33
43
|
|
34
|
-
#
|
44
|
+
# @return [Boolean] Whether or not the format is any flavor of HTML
|
35
45
|
def html?
|
36
46
|
html4? or html5?
|
37
47
|
end
|
38
48
|
|
39
|
-
#
|
49
|
+
# @return [Boolean] Whether or not the format is HTML4
|
40
50
|
def html4?
|
41
51
|
@options[:format] == :html4
|
42
52
|
end
|
43
53
|
|
44
|
-
#
|
54
|
+
# @return [Boolean] Whether or not the format is HTML5.
|
45
55
|
def html5?
|
46
56
|
@options[:format] == :html5
|
47
57
|
end
|
48
58
|
|
49
|
-
#
|
50
|
-
#
|
59
|
+
# @return [Boolean] Whether or not this buffer is a top-level template,
|
60
|
+
# as opposed to a nested partial
|
51
61
|
def toplevel?
|
52
62
|
upper.nil?
|
53
63
|
end
|
54
64
|
|
55
|
-
#
|
56
|
-
#
|
65
|
+
# Whether or not this buffer is currently being used to render a Haml template.
|
66
|
+
# Returns `false` if a subtemplate is being rendered,
|
57
67
|
# even if it's a subtemplate of this buffer's template.
|
68
|
+
#
|
69
|
+
# @return [Boolean]
|
58
70
|
def active?
|
59
71
|
@active
|
60
72
|
end
|
61
73
|
|
62
|
-
#
|
74
|
+
# @return [Fixnum] The current indentation level of the document
|
63
75
|
def tabulation
|
64
76
|
@real_tabs + @tabulation
|
65
77
|
end
|
66
78
|
|
67
79
|
# Sets the current tabulation of the document.
|
80
|
+
#
|
81
|
+
# @param val [Fixnum] The new tabulation
|
68
82
|
def tabulation=(val)
|
69
83
|
val = val - @real_tabs
|
70
84
|
@tabulation = val > -1 ? val : 0
|
71
85
|
end
|
72
86
|
|
73
|
-
#
|
87
|
+
# @param upper [Buffer] The parent buffer
|
88
|
+
# @param options [Hash<Symbol, Object>] An options hash.
|
89
|
+
# See {Haml::Engine#options\_for\_buffer}
|
74
90
|
def initialize(upper = nil, options = {})
|
75
91
|
@active = true
|
76
92
|
@upper = upper
|
@@ -87,6 +103,13 @@ module Haml
|
|
87
103
|
@real_tabs = 0
|
88
104
|
end
|
89
105
|
|
106
|
+
# Appends text to the buffer, properly tabulated.
|
107
|
+
# Also modifies the document's indentation.
|
108
|
+
#
|
109
|
+
# @param text [String] The text to append
|
110
|
+
# @param tab_change [Fixnum] The number of tabs by which to increase
|
111
|
+
# or decrease the document's indentation
|
112
|
+
# @param dont_tab_up [Boolean] If true, don't indent the first line of `text`
|
90
113
|
def push_text(text, tab_change, dont_tab_up)
|
91
114
|
if @tabulation > 0
|
92
115
|
# Have to push every line in by the extra user set tabulation.
|
@@ -100,6 +123,10 @@ module Haml
|
|
100
123
|
@real_tabs += tab_change
|
101
124
|
end
|
102
125
|
|
126
|
+
# Modifies the indentation of the document.
|
127
|
+
#
|
128
|
+
# @param tab_change [Fixnum] The number of tabs by which to increase
|
129
|
+
# or decrease the document's indentation
|
103
130
|
def adjust_tabs(tab_change)
|
104
131
|
@real_tabs += tab_change
|
105
132
|
end
|
@@ -164,8 +191,8 @@ module Haml
|
|
164
191
|
<% end %>
|
165
192
|
RUBY
|
166
193
|
|
167
|
-
# Takes the various information about the opening tag for an
|
168
|
-
#
|
194
|
+
# Takes the various information about the opening tag for an element,
|
195
|
+
# formats it, and appends it to the buffer.
|
169
196
|
def open_tag(name, self_closing, try_one_line, preserve_tag, escape_html, class_id,
|
170
197
|
nuke_outer_whitespace, nuke_inner_whitespace, obj_ref, content, *attributes_hashes)
|
171
198
|
tabulation = @real_tabs
|
@@ -208,6 +235,18 @@ RUBY
|
|
208
235
|
buffer << buffer.slice!(capture_position..-1).rstrip
|
209
236
|
end
|
210
237
|
|
238
|
+
# Merges two attribute hashes.
|
239
|
+
# This is the same as `to.merge!(from)`,
|
240
|
+
# except that it merges id and class attributes.
|
241
|
+
#
|
242
|
+
# ids are concatenated with `"_"`,
|
243
|
+
# and classes are concatenated with `" "`.
|
244
|
+
#
|
245
|
+
# Destructively modifies both `to` and `from`.
|
246
|
+
#
|
247
|
+
# @param to [Hash<String, String>] The attribute hash to merge into
|
248
|
+
# @param from [Hash<String, String>] The attribute hash to merge from
|
249
|
+
# @return [Hash<String, String>] `to`, after being merged
|
211
250
|
def self.merge_attrs(to, from)
|
212
251
|
if to['id'] && from['id']
|
213
252
|
to['id'] << '_' << from.delete('id')
|
@@ -227,11 +266,8 @@ RUBY
|
|
227
266
|
|
228
267
|
private
|
229
268
|
|
230
|
-
# Some of these methods are exposed as public class methods
|
231
|
-
# so they can be re-used in helpers.
|
232
|
-
|
233
269
|
@@tab_cache = {}
|
234
|
-
# Gets
|
270
|
+
# Gets `count` tabs. Mostly for internal use.
|
235
271
|
def tabs(count = 0)
|
236
272
|
tabs = [count + @tabulation, 0].max
|
237
273
|
@@tab_cache[tabs] ||= ' ' * tabs
|
@@ -240,7 +276,7 @@ RUBY
|
|
240
276
|
# Takes an array of objects and uses the class and id of the first
|
241
277
|
# one to create an attributes hash.
|
242
278
|
# The second object, if present, is used as a prefix,
|
243
|
-
# just like you can do with dom_id() and dom_class() in Rails
|
279
|
+
# just like you can do with `dom_id()` and `dom_class()` in Rails
|
244
280
|
def parse_object_ref(ref)
|
245
281
|
prefix = ref[1]
|
246
282
|
ref = ref[0]
|
data/lib/haml/engine.rb
CHANGED
@@ -5,58 +5,62 @@ require 'haml/filters'
|
|
5
5
|
require 'haml/error'
|
6
6
|
|
7
7
|
module Haml
|
8
|
-
# This is the
|
9
|
-
#
|
10
|
-
# new instance and calling
|
8
|
+
# This is the frontend for using Haml programmatically.
|
9
|
+
# It can be directly used by the user by creating a
|
10
|
+
# new instance and calling \{#render} to render the template.
|
11
|
+
# For example:
|
11
12
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
13
|
+
# template = File.read('templates/really_cool_template.haml')
|
14
|
+
# haml_engine = Haml::Engine.new(template)
|
15
|
+
# output = haml_engine.render
|
16
|
+
# puts output
|
16
17
|
class Engine
|
17
18
|
include Precompiler
|
18
19
|
|
19
|
-
#
|
20
|
+
# The options hash.
|
21
|
+
# See [the Haml options documentation](../Haml.html#haml_options).
|
22
|
+
#
|
23
|
+
# @return [Hash<Symbol, Object>]
|
20
24
|
attr_accessor :options
|
21
25
|
|
22
|
-
#
|
23
|
-
#
|
26
|
+
# The source code that is evaluated to produce the Haml document.
|
27
|
+
#
|
28
|
+
# @return [String]
|
24
29
|
attr_accessor :precompiled
|
25
30
|
|
26
|
-
#
|
27
|
-
# nil if the indentation is ambiguous
|
31
|
+
# The indentation used in the Haml document,
|
32
|
+
# or `nil` if the indentation is ambiguous
|
28
33
|
# (for example, for a single-level document).
|
34
|
+
#
|
35
|
+
# @return [String]
|
29
36
|
attr_accessor :indentation
|
30
37
|
|
31
|
-
#
|
38
|
+
# @return [Boolean] Whether or not the format is XHTML.
|
32
39
|
def xhtml?
|
33
40
|
not html?
|
34
41
|
end
|
35
42
|
|
36
|
-
#
|
43
|
+
# @return [Boolean] Whether or not the format is any flavor of HTML.
|
37
44
|
def html?
|
38
45
|
html4? or html5?
|
39
46
|
end
|
40
47
|
|
41
|
-
#
|
48
|
+
# @return [Boolean] Whether or not the format is HTML4.
|
42
49
|
def html4?
|
43
50
|
@options[:format] == :html4
|
44
51
|
end
|
45
52
|
|
46
|
-
#
|
53
|
+
# @return [Boolean] Whether or not the format is HTML5.
|
47
54
|
def html5?
|
48
55
|
@options[:format] == :html5
|
49
56
|
end
|
50
57
|
|
51
|
-
#
|
52
|
-
# template string when <tt>render</tt> is called.
|
53
|
-
# See the Haml module documentation for available options.
|
54
|
-
#
|
55
|
-
#--
|
56
|
-
# When adding options, remember to add information about them
|
57
|
-
# to lib/haml.rb!
|
58
|
-
#++
|
58
|
+
# Precompiles the Haml template.
|
59
59
|
#
|
60
|
+
# @param template [String] The Haml template
|
61
|
+
# @param options [Hash<Symbol, Object>] An options hash;
|
62
|
+
# see [the Haml options documentation](../Haml.html#haml_options)
|
63
|
+
# @raise [Haml::Error] if there's a Haml syntax error in the template
|
60
64
|
def initialize(template, options = {})
|
61
65
|
@options = {
|
62
66
|
:suppress_eval => false,
|
@@ -108,39 +112,45 @@ END
|
|
108
112
|
|
109
113
|
# Processes the template and returns the result as a string.
|
110
114
|
#
|
111
|
-
#
|
112
|
-
# If it's a Binding or Proc object,
|
113
|
-
# Haml uses it as the second argument to Kernel#eval
|
114
|
-
# otherwise, Haml just uses its
|
115
|
+
# `scope` is the context in which the template is evaluated.
|
116
|
+
# If it's a `Binding` or `Proc` object,
|
117
|
+
# Haml uses it as the second argument to `Kernel#eval`;
|
118
|
+
# otherwise, Haml just uses its `#instance_eval` context.
|
115
119
|
#
|
116
120
|
# Note that Haml modifies the evaluation context
|
117
|
-
# (either the scope object or the
|
118
|
-
# It extends Haml::Helpers, and various instance variables are set
|
119
|
-
# (all prefixed with
|
121
|
+
# (either the scope object or the `self` object of the scope binding).
|
122
|
+
# It extends {Haml::Helpers}, and various instance variables are set
|
123
|
+
# (all prefixed with `haml_`).
|
120
124
|
# For example:
|
121
125
|
#
|
122
|
-
#
|
123
|
-
#
|
126
|
+
# s = "foobar"
|
127
|
+
# Haml::Engine.new("%p= upcase").render(s) #=> "<p>FOOBAR</p>"
|
124
128
|
#
|
125
|
-
#
|
126
|
-
#
|
129
|
+
# # s now extends Haml::Helpers
|
130
|
+
# s.responds_to?(:html_attrs) #=> true
|
127
131
|
#
|
128
|
-
#
|
132
|
+
# `locals` is a hash of local variables to make available to the template.
|
129
133
|
# For example:
|
130
134
|
#
|
131
|
-
#
|
135
|
+
# Haml::Engine.new("%p= foo").render(Object.new, :foo => "Hello, world!") #=> "<p>Hello, world!</p>"
|
132
136
|
#
|
133
137
|
# If a block is passed to render,
|
134
|
-
# that block is run when
|
138
|
+
# that block is run when `yield` is called
|
135
139
|
# within the template.
|
136
140
|
#
|
137
141
|
# Due to some Ruby quirks,
|
138
|
-
# if scope is a Binding or Proc object and a block is given,
|
142
|
+
# if `scope` is a `Binding` or `Proc` object and a block is given,
|
139
143
|
# the evaluation context may not be quite what the user expects.
|
140
|
-
# In particular, it's equivalent to passing
|
144
|
+
# In particular, it's equivalent to passing `eval("self", scope)` as `scope`.
|
141
145
|
# This won't have an effect in most cases,
|
142
|
-
# but if you're relying on local variables defined in the context of scope
|
146
|
+
# but if you're relying on local variables defined in the context of `scope`,
|
143
147
|
# they won't work.
|
148
|
+
#
|
149
|
+
# @param scope [Binding, Proc, Object] The context in which the template is evaluated
|
150
|
+
# @param locals [Hash<Symbol, Object>] Local variables that will be made available
|
151
|
+
# to the template
|
152
|
+
# @param block [#to_proc] A block that can be yielded to within the template
|
153
|
+
# @return [String] The rendered template
|
144
154
|
def render(scope = Object.new, locals = {}, &block)
|
145
155
|
buffer = Haml::Buffer.new(scope.instance_variable_get('@haml_buffer'), options_for_buffer)
|
146
156
|
|
@@ -173,24 +183,27 @@ END
|
|
173
183
|
# Returns a proc that, when called,
|
174
184
|
# renders the template and returns the result as a string.
|
175
185
|
#
|
176
|
-
#
|
186
|
+
# `scope` works the same as it does for render.
|
177
187
|
#
|
178
188
|
# The first argument of the returned proc is a hash of local variable names to values.
|
179
189
|
# However, due to an unfortunate Ruby quirk,
|
180
190
|
# the local variables which can be assigned must be pre-declared.
|
181
|
-
# This is done with the
|
191
|
+
# This is done with the `local_names` argument.
|
182
192
|
# For example:
|
183
193
|
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
194
|
+
# # This works
|
195
|
+
# Haml::Engine.new("%p= foo").render_proc(Object.new, :foo).call :foo => "Hello!"
|
196
|
+
# #=> "<p>Hello!</p>"
|
197
|
+
#
|
198
|
+
# # This doesn't
|
199
|
+
# Haml::Engine.new("%p= foo").render_proc.call :foo => "Hello!"
|
200
|
+
# #=> NameError: undefined local variable or method `foo'
|
187
201
|
#
|
188
|
-
#
|
189
|
-
# Haml::Engine.new("%p= foo").render_proc.call :foo => "Hello!"
|
190
|
-
# #=> NameError: undefined local variable or method `foo'
|
202
|
+
# The proc doesn't take a block; any yields in the template will fail.
|
191
203
|
#
|
192
|
-
# The
|
193
|
-
#
|
204
|
+
# @param scope [Binding, Proc, Object] The context in which the template is evaluated
|
205
|
+
# @param local_names [Array<Symbol>] The names of the locals that can be passed to the proc
|
206
|
+
# @return [Proc] The proc that will run the template
|
194
207
|
def render_proc(scope = Object.new, *local_names)
|
195
208
|
if scope.is_a?(Binding) || scope.is_a?(Proc)
|
196
209
|
scope_object = eval("self", scope)
|
@@ -203,41 +216,44 @@ END
|
|
203
216
|
precompiled_with_ambles(local_names) + "}\n", scope, @options[:filename], @options[:line])
|
204
217
|
end
|
205
218
|
|
206
|
-
# Defines a method on
|
207
|
-
# with the given name
|
219
|
+
# Defines a method on `object` with the given name
|
208
220
|
# that renders the template and returns the result as a string.
|
209
221
|
#
|
210
|
-
# If
|
222
|
+
# If `object` is a class or module,
|
211
223
|
# the method will instead by defined as an instance method.
|
212
224
|
# For example:
|
213
225
|
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
226
|
+
# t = Time.now
|
227
|
+
# Haml::Engine.new("%p\n Today's date is\n .date= self.to_s").def_method(t, :render)
|
228
|
+
# t.render #=> "<p>\n Today's date is\n <div class='date'>Fri Nov 23 18:28:29 -0800 2007</div>\n</p>\n"
|
217
229
|
#
|
218
|
-
#
|
219
|
-
#
|
230
|
+
# Haml::Engine.new(".upcased= upcase").def_method(String, :upcased_div)
|
231
|
+
# "foobar".upcased_div #=> "<div class='upcased'>FOOBAR</div>\n"
|
220
232
|
#
|
221
233
|
# The first argument of the defined method is a hash of local variable names to values.
|
222
234
|
# However, due to an unfortunate Ruby quirk,
|
223
235
|
# the local variables which can be assigned must be pre-declared.
|
224
|
-
# This is done with the
|
236
|
+
# This is done with the `local_names` argument.
|
225
237
|
# For example:
|
226
238
|
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
239
|
+
# # This works
|
240
|
+
# obj = Object.new
|
241
|
+
# Haml::Engine.new("%p= foo").def_method(obj, :render, :foo)
|
242
|
+
# obj.render(:foo => "Hello!") #=> "<p>Hello!</p>"
|
231
243
|
#
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
244
|
+
# # This doesn't
|
245
|
+
# obj = Object.new
|
246
|
+
# Haml::Engine.new("%p= foo").def_method(obj, :render)
|
247
|
+
# obj.render(:foo => "Hello!") #=> NameError: undefined local variable or method `foo'
|
236
248
|
#
|
237
249
|
# Note that Haml modifies the evaluation context
|
238
|
-
# (either the scope object or the
|
239
|
-
# It extends Haml::Helpers, and various instance variables are set
|
240
|
-
# (all prefixed with
|
250
|
+
# (either the scope object or the `self` object of the scope binding).
|
251
|
+
# It extends {Haml::Helpers}, and various instance variables are set
|
252
|
+
# (all prefixed with `haml_`).
|
253
|
+
#
|
254
|
+
# @param object [Object, Module] The object on which to define the method
|
255
|
+
# @param name [String, Symbol] The name of the method to define
|
256
|
+
# @param local_names [Array<Symbol>] The names of the locals that can be passed to the proc
|
241
257
|
def def_method(object, name, *local_names)
|
242
258
|
method = object.is_a?(Module) ? :module_eval : :instance_eval
|
243
259
|
|
@@ -245,16 +261,15 @@ END
|
|
245
261
|
@options[:filename], @options[:line])
|
246
262
|
end
|
247
263
|
|
248
|
-
|
249
|
-
|
250
|
-
def set_locals(locals, scope, scope_object)
|
251
|
-
scope_object.send(:instance_variable_set, '@_haml_locals', locals)
|
252
|
-
set_locals = locals.keys.map { |k| "#{k} = @_haml_locals[#{k.inspect}]" }.join("\n")
|
253
|
-
eval(set_locals, scope)
|
254
|
-
end
|
264
|
+
protected
|
255
265
|
|
256
|
-
# Returns a
|
257
|
-
#
|
266
|
+
# Returns a subset of \{#options}: those that {Haml::Buffer} cares about.
|
267
|
+
# All of the values here are such that when `#inspect` is called on the hash,
|
268
|
+
# it can be `Kernel#eval`ed to get the same result back.
|
269
|
+
#
|
270
|
+
# See [the Haml options documentation](../Haml.html#haml_options).
|
271
|
+
#
|
272
|
+
# @return [Hash<Symbol, Object>] The options hash
|
258
273
|
def options_for_buffer
|
259
274
|
{
|
260
275
|
:autoclose => @options[:autoclose],
|
@@ -264,5 +279,13 @@ END
|
|
264
279
|
:format => @options[:format]
|
265
280
|
}
|
266
281
|
end
|
282
|
+
|
283
|
+
private
|
284
|
+
|
285
|
+
def set_locals(locals, scope, scope_object)
|
286
|
+
scope_object.send(:instance_variable_set, '@_haml_locals', locals)
|
287
|
+
set_locals = locals.keys.map { |k| "#{k} = @_haml_locals[#{k.inspect}]" }.join("\n")
|
288
|
+
eval(set_locals, scope)
|
289
|
+
end
|
267
290
|
end
|
268
291
|
end
|
data/lib/haml/error.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
module Haml
|
2
2
|
# An exception raised by Haml code.
|
3
3
|
class Error < StandardError
|
4
|
-
#
|
5
|
-
|
6
|
-
#
|
7
|
-
# that was being processed when the exception was raised.
|
8
|
-
# However, if line is non-nil, it + 1 is used instead.
|
4
|
+
# The line of the template on which the error occurred.
|
5
|
+
#
|
6
|
+
# @return [Fixnum]
|
9
7
|
attr_reader :line
|
10
8
|
|
9
|
+
# @param message [String] The error message
|
10
|
+
# @param line [Fixnum] See \{#line}
|
11
11
|
def initialize(message = nil, line = nil)
|
12
12
|
super(message)
|
13
13
|
@line = line
|
14
14
|
end
|
15
|
-
# :startdoc:
|
16
15
|
end
|
17
16
|
|
18
17
|
# SyntaxError is the type of exception raised when Haml encounters an
|
19
18
|
# ill-formatted document.
|
20
|
-
# It's not particularly interesting,
|
19
|
+
# It's not particularly interesting,
|
20
|
+
# except in that it's a subclass of {Haml::Error}.
|
21
21
|
class SyntaxError < Haml::Error; end
|
22
22
|
end
|