opal-haml 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/lib/opal/haml/version.rb +1 -1
- data/opal/opal-haml.rb +24 -8
- data/spec/output_buffer_spec.rb +27 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a51df8f11890733b25009b477cd1858d435d23c
|
4
|
+
data.tar.gz: 9d1269a086e15e682d2ea661ffe5e780066ba77b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82c5a14a140dc07be2be3afbd300e339b67fa69ec293fc3c92178bad911b981c0e7421450a5423eeb32ba2d0b13bf1edf89216c94ad11873a1aa90fdff01ecfc
|
7
|
+
data.tar.gz: 794c500356aeb83d467ac1eff35aa79127f0996929ebe292443e72f1c99030e9663c4404a6908822984a463adf0cdedc50293e0e6e37e25f28654d5f563b907c
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
## 0.
|
1
|
+
## 0.4.1 2015-11-02
|
2
|
+
|
3
|
+
* Add support for nested attribute hashes: `%div{ data: { foo: 123 } }` now becomes `<div data-foo="123"></div>`.
|
4
|
+
|
5
|
+
* Attribute values are now properly escaped.
|
6
|
+
|
7
|
+
## 0.4.0 2015-08-07
|
2
8
|
|
3
9
|
* Add support for Opal 0.8.
|
4
10
|
|
data/lib/opal/haml/version.rb
CHANGED
data/opal/opal-haml.rb
CHANGED
@@ -9,20 +9,36 @@ class Template
|
|
9
9
|
attributes = class_id
|
10
10
|
|
11
11
|
attributes_hashes.each do |hash|
|
12
|
-
attributes.update hash
|
12
|
+
attributes.update hash do |_, oldval, newval|
|
13
|
+
Array(oldval) + Array(newval)
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
|
-
result =
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
result = []
|
18
|
+
_render_attributes attributes, result, ''
|
19
|
+
|
20
|
+
result.join
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def _render_attributes(attributes, out, prefix)
|
26
|
+
attributes.each do |attr, value|
|
27
|
+
attr_name = prefix + attr
|
28
|
+
|
29
|
+
case value
|
30
|
+
when true then out << " #{attr_name}"
|
31
|
+
when false, nil then next
|
32
|
+
when Hash then _render_attributes(value, out, attr_name + '-')
|
20
33
|
else
|
21
|
-
|
34
|
+
value = value.compact.join ' ' if value.is_a? Array
|
35
|
+
out << " #{attr_name}='#{_attribute_escape value}'"
|
22
36
|
end
|
23
37
|
end
|
38
|
+
end
|
24
39
|
|
25
|
-
|
40
|
+
def _attribute_escape(value)
|
41
|
+
value.to_s.gsub /['"&<>]/, '"' => '"', "'" => ''', '&' => '&', '<' => '<', '>' => '>'
|
26
42
|
end
|
27
43
|
end
|
28
44
|
end
|
data/spec/output_buffer_spec.rb
CHANGED
@@ -12,11 +12,38 @@ describe Template::OutputBuffer do
|
|
12
12
|
expect(result).to include("name='foo'", "height='100'")
|
13
13
|
end
|
14
14
|
|
15
|
+
it "can compile nested attributes" do
|
16
|
+
result = attributes(data: { foo: { bar: 'baz' }, another: 'one' })
|
17
|
+
expect(result).to include("data-foo-bar='baz'")
|
18
|
+
expect(result).to include("data-another='one'")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "combines input hashes" do
|
22
|
+
result = subject.attributes({ 'class' => 'foo' }, nil, { class: 'bar', data: 'baz' })
|
23
|
+
expect(result).to include("class='foo bar'")
|
24
|
+
expect(result).to include("data='baz'")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "removes nil from arrays" do
|
28
|
+
result = attributes(foo: [ 'bar', nil, 'baz' ])
|
29
|
+
expect(result).to include("foo='bar baz'")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "escapes attribute values" do
|
33
|
+
result = attributes(foo: 'a<>&"\'b')
|
34
|
+
expect(result).to include("foo='a<>&"'b'")
|
35
|
+
end
|
36
|
+
|
15
37
|
it "skips the attribute for false values" do
|
16
38
|
result = attributes(name: false)
|
17
39
|
expect(result).to_not include('name')
|
18
40
|
end
|
19
41
|
|
42
|
+
it "skips the attribute for nil values" do
|
43
|
+
result = attributes(name: nil)
|
44
|
+
expect(result).to_not include('name')
|
45
|
+
end
|
46
|
+
|
20
47
|
it "generates a simple named attribute for true values" do
|
21
48
|
result = attributes(closable: true)
|
22
49
|
expect(result).to include('closable')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Beynon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.4.
|
121
|
+
rubygems_version: 2.4.8
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Run Haml templates client-side with Opal
|