hamlit 0.1.1 → 0.1.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ac03a589d9cd0fe2450153fb7ec2f1b1b7ae4c8
|
4
|
+
data.tar.gz: f959a39fcf2966db4858b8beedd51b577e17ba08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f501dcaf6d1b0a3f3fdb49f748b99694e5de11e71c776b4f49505e20e84b3c5226cbe2400565db2531671559a8a6dbd6033a453da7608e1740b3f35558f6e71d
|
7
|
+
data.tar.gz: 08bfee10675d5192d0b0e3aabdaf6ded3db138cb02c037f2b17a7bd94e45dc95a0cf4a95865849a16ab2c68c490df67bca989fd3b0c6484356a5a54ad66ebd57
|
@@ -12,11 +12,13 @@ module Hamlit
|
|
12
12
|
include Concerns::Balanceable
|
13
13
|
include Concerns::Ripperable
|
14
14
|
|
15
|
+
IGNORED_EXPRESSIONS = %w[false nil].freeze
|
16
|
+
|
15
17
|
def compile_old_attribute(str)
|
16
18
|
return runtime_build(str) unless Ripper.sexp(str)
|
17
19
|
|
18
20
|
attrs = parse_old_attributes(str)
|
19
|
-
|
21
|
+
format_attributes(attrs).map do |key, value|
|
20
22
|
next true_attribute(key) if value == 'true'
|
21
23
|
[:html, :attr, key, [:dynamic, value]]
|
22
24
|
end
|
@@ -24,6 +26,18 @@ module Hamlit
|
|
24
26
|
|
25
27
|
private
|
26
28
|
|
29
|
+
def format_attributes(attributes)
|
30
|
+
attributes = flatten_attributes(attributes)
|
31
|
+
ignore_falsy_values(attributes)
|
32
|
+
end
|
33
|
+
|
34
|
+
def ignore_falsy_values(attributes)
|
35
|
+
attributes = attributes.dup
|
36
|
+
attributes.each do |key, value|
|
37
|
+
attributes.delete(key) if IGNORED_EXPRESSIONS.include?(value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
27
41
|
# Parse brace-balanced string and return the result as hash
|
28
42
|
def parse_old_attributes(str)
|
29
43
|
attributes = {}
|
@@ -8,10 +8,10 @@ module Hamlit
|
|
8
8
|
case value
|
9
9
|
when Hash
|
10
10
|
flatten_attributes(value).each do |k, v|
|
11
|
-
flattened["#{key}-#{k}"] = v
|
11
|
+
flattened["#{key}-#{k}"] = v if v
|
12
12
|
end
|
13
13
|
else
|
14
|
-
flattened[key] = value
|
14
|
+
flattened[key] = value if value
|
15
15
|
end
|
16
16
|
end
|
17
17
|
flattened
|
data/lib/hamlit/version.rb
CHANGED
@@ -40,7 +40,7 @@ describe Hamlit::Engine do
|
|
40
40
|
HTML
|
41
41
|
end
|
42
42
|
|
43
|
-
it 'renders attributes' do
|
43
|
+
it 'renders true attributes' do
|
44
44
|
assert_render(<<-'HAML', <<-HTML)
|
45
45
|
%span{ data: { disable: true } } bar
|
46
46
|
HAML
|
@@ -48,6 +48,19 @@ describe Hamlit::Engine do
|
|
48
48
|
HTML
|
49
49
|
end
|
50
50
|
|
51
|
+
it 'renders false or nil attributes' do
|
52
|
+
assert_render(<<-'HAML', <<-HTML)
|
53
|
+
- hash = { checked: false }
|
54
|
+
%input{ hash }
|
55
|
+
%input{ checked: false }
|
56
|
+
%input{ checked: nil }
|
57
|
+
HAML
|
58
|
+
<input>
|
59
|
+
<input>
|
60
|
+
<input>
|
61
|
+
HTML
|
62
|
+
end
|
63
|
+
|
51
64
|
it 'accepts even illegal input for haml' do
|
52
65
|
assert_render(<<-'HAML', <<-HTML)
|
53
66
|
%span{ class: '}}}', id: '{}}' } }{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
@@ -383,7 +383,6 @@ files:
|
|
383
383
|
- spec/rails/.gitignore
|
384
384
|
- spec/rails/.rspec
|
385
385
|
- spec/rails/Gemfile
|
386
|
-
- spec/rails/Gemfile.lock
|
387
386
|
- spec/rails/README.rdoc
|
388
387
|
- spec/rails/Rakefile
|
389
388
|
- spec/rails/app/assets/images/.keep
|
@@ -496,7 +495,6 @@ test_files:
|
|
496
495
|
- spec/rails/.gitignore
|
497
496
|
- spec/rails/.rspec
|
498
497
|
- spec/rails/Gemfile
|
499
|
-
- spec/rails/Gemfile.lock
|
500
498
|
- spec/rails/README.rdoc
|
501
499
|
- spec/rails/Rakefile
|
502
500
|
- spec/rails/app/assets/images/.keep
|