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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82c2cd008b3cb7f86bf02d80ad69ae0655bd88b6
4
- data.tar.gz: a06febaeb2ccf36598a2d612f8dd9de3e367f8c3
3
+ metadata.gz: 435825826b3948fd94accaf5eaafc29e1d7ea4f1
4
+ data.tar.gz: 3b0ad21919d9a8ec7bccee42f39740431acd2b8d
5
5
  SHA512:
6
- metadata.gz: 26b7a473dd89a20eb8dcef16c14b435157ea054ae8aac72bd19782959bc8de54d010c119580f6c5bd6a1617f19e1d0b20354e2d5691a2f2428df173a52bfb0c5
7
- data.tar.gz: 15431eb000c43add9ab90cfd19167c52a5c23f0cee9fdc56b84bbcdbd7d40b1fbbdfd12bf5ddd89df5e102f861d6621550a28d4e8d98e8a404c02d9f10d858b7
6
+ metadata.gz: 3c03f60242ffe2650685d696c1e1cc36d3561d28b31aaa86feee6412154551c938d76f3406948527a5b959122d846bc5cd827a85f11558e79dab8e02e453f1f2
7
+ data.tar.gz: d5a8252b40bfd94d5f2748870add6eda2cda54579b50aee5dc91de16f46e61c3bf22e6dd4e77ed3f90c2ce20ff2b08c25fabd15b5fe588d67e63b9e9c0e175f5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.7 (2015-03-16)
2
+ - Fix attribute rendering with falsey values
3
+ - https://github.com/eagletmt/fast_haml/pull/11
4
+
1
5
  ## 0.1.6 (2015-03-11)
2
6
  - Fix render error with comment-only script
3
7
  - https://github.com/eagletmt/fast_haml/issues/6
@@ -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
@@ -19,11 +19,6 @@ module FastHaml
19
19
  super
20
20
  @leading_empty_lines = 0
21
21
  end
22
-
23
- def increment_leading_empty_lines
24
- @leading_empty_lines +=1
25
- nil
26
- end
27
22
  end
28
23
 
29
24
  class Doctype < Struct.new(:doctype)
@@ -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, [:escape, true, [:dynamic, value]]]]
318
+ [[:haml, :attr, key, [:dvalue, value]]]
317
319
  end
318
320
 
319
321
  def compile_script(ast)
@@ -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]}"],
@@ -1,3 +1,3 @@
1
1
  module FastHaml
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -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&quot;z' foo='1'>hello</span>\n")
203
214
  expect(render_string(%q|%span(foo=1 bar='ba\'z') hello|)).to eq("<span bar='ba&#39;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.6
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 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils