fast_haml 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/ext/attribute_builder/attribute_builder.c +3 -1
- data/lib/fast_haml/ast.rb +0 -5
- data/lib/fast_haml/compiler.rb +3 -1
- data/lib/fast_haml/html.rb +14 -0
- data/lib/fast_haml/version.rb +1 -1
- data/spec/render/attribute_spec.rb +12 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 435825826b3948fd94accaf5eaafc29e1d7ea4f1
|
4
|
+
data.tar.gz: 3b0ad21919d9a8ec7bccee42f39740431acd2b8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c03f60242ffe2650685d696c1e1cc36d3561d28b31aaa86feee6412154551c938d76f3406948527a5b959122d846bc5cd827a85f11558e79dab8e02e453f1f2
|
7
|
+
data.tar.gz: d5a8252b40bfd94d5f2748870add6eda2cda54579b50aee5dc91de16f46e61c3bf22e6dd4e77ed3f90c2ce20ff2b08c25fabd15b5fe588d67e63b9e9c0e175f5
|
data/CHANGELOG.md
CHANGED
@@ -116,7 +116,7 @@ normalize(VALUE hash)
|
|
116
116
|
rb_str_buf_append(k, data_key);
|
117
117
|
rb_hash_aset(hash, k, rb_hash_lookup(data, data_key));
|
118
118
|
}
|
119
|
-
} else if (!RB_TYPE_P(value, T_TRUE)) {
|
119
|
+
} else if (!(RB_TYPE_P(value, T_TRUE) || RB_TYPE_P(value, T_FALSE) || NIL_P(value))) {
|
120
120
|
rb_hash_aset(hash, key, rb_funcall(value, id_to_s, 0));
|
121
121
|
}
|
122
122
|
}
|
@@ -202,6 +202,8 @@ build_attribute(VALUE attr_quote, VALUE key, VALUE value)
|
|
202
202
|
rb_str_buf_cat(attr, " ", 1);
|
203
203
|
rb_str_buf_append(attr, key);
|
204
204
|
return attr;
|
205
|
+
} else if (RB_TYPE_P(value, T_FALSE) || NIL_P(value)) {
|
206
|
+
return Qnil;
|
205
207
|
} else {
|
206
208
|
return put_attribute(attr_quote, key, value);
|
207
209
|
}
|
data/lib/fast_haml/ast.rb
CHANGED
data/lib/fast_haml/compiler.rb
CHANGED
@@ -302,6 +302,8 @@ module FastHaml
|
|
302
302
|
case
|
303
303
|
when value == true
|
304
304
|
[[:haml, :attr, key, [:multi]]]
|
305
|
+
when value == false || value == nil
|
306
|
+
[[:multi]]
|
305
307
|
when value.is_a?(Hash) && key == 'data'
|
306
308
|
data = AttributeBuilder.normalize_data(value)
|
307
309
|
data.keys.sort.map do |k|
|
@@ -313,7 +315,7 @@ module FastHaml
|
|
313
315
|
end
|
314
316
|
|
315
317
|
def compile_dynamic_attribute(key, value)
|
316
|
-
[[:haml, :attr, key, [:
|
318
|
+
[[:haml, :attr, key, [:dvalue, value]]]
|
317
319
|
end
|
318
320
|
|
319
321
|
def compile_script(ast)
|
data/lib/fast_haml/html.rb
CHANGED
@@ -23,6 +23,20 @@ module FastHaml
|
|
23
23
|
else
|
24
24
|
[:static, " #{name}=#{options[:attr_quote]}#{name}#{options[:attr_quote]}"]
|
25
25
|
end
|
26
|
+
elsif value[0] == :dvalue
|
27
|
+
sym = unique_name
|
28
|
+
[:multi,
|
29
|
+
[:code, "#{sym} = (#{value[1]})"],
|
30
|
+
[:case, sym,
|
31
|
+
['true', [:static, " #{name}"]],
|
32
|
+
['false, nil', [:multi]],
|
33
|
+
[:else, [:multi,
|
34
|
+
[:static, " #{name}=#{options[:attr_quote]}"],
|
35
|
+
[:escape, true, [:dynamic, sym]],
|
36
|
+
[:static, options[:attr_quote]],
|
37
|
+
]],
|
38
|
+
],
|
39
|
+
]
|
26
40
|
else
|
27
41
|
[:multi,
|
28
42
|
[:static, " #{name}=#{options[:attr_quote]}"],
|
data/lib/fast_haml/version.rb
CHANGED
@@ -22,6 +22,18 @@ RSpec.describe 'Attributes rendering', type: :render do
|
|
22
22
|
expect(render_string('%span.c2{class: ["c1", "c3"]}')).to eq("<span class='c1 c2 c3'></span>\n")
|
23
23
|
end
|
24
24
|
|
25
|
+
it "renders boolean attributes" do
|
26
|
+
expect(render_string('%input{checked: true}')).to eq("<input checked>\n")
|
27
|
+
expect(render_string('%input{checked: false}')).to eq("<input>\n")
|
28
|
+
expect(render_string('%input{checked: nil}')).to eq("<input>\n")
|
29
|
+
expect(render_string('%input{checked: "a" == "a"}')).to eq("<input checked>\n")
|
30
|
+
expect(render_string('%input{checked: "a" != "a"}')).to eq("<input>\n")
|
31
|
+
expect(render_string("- x = nil\n%input{checked: x}")).to eq("<input>\n")
|
32
|
+
expect(render_string("- h = {checked: true}\n%input{h}")).to eq("<input checked>\n")
|
33
|
+
expect(render_string("- h = {checked: false}\n%input{h}")).to eq("<input>\n")
|
34
|
+
expect(render_string("- h = {checked: nil}\n%input{h}")).to eq("<input>\n")
|
35
|
+
end
|
36
|
+
|
25
37
|
it 'merges classes' do
|
26
38
|
expect(render_string(<<HAML)).to eq("<span class='c1 c2 content {}' id='main_id1_id3_id2'>hello</span>\n")
|
27
39
|
- h1 = {class: 'c1', id: ['id1', 'id3']}
|
@@ -197,7 +209,6 @@ HAML
|
|
197
209
|
expect(render_string(%q|%span(foo=1 bar='baz#{1 + 2}') hello|)).to eq("<span bar='baz3' foo='1'>hello</span>\n")
|
198
210
|
end
|
199
211
|
|
200
|
-
|
201
212
|
it 'parses escapes' do
|
202
213
|
expect(render_string(%q|%span(foo=1 bar="ba\"z") hello|)).to eq("<span bar='ba"z' foo='1'>hello</span>\n")
|
203
214
|
expect(render_string(%q|%span(foo=1 bar='ba\'z') hello|)).to eq("<span bar='ba'z' foo='1'>hello</span>\n")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|