hamlit 0.1.2 → 0.1.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5197e691717bb214cdad95076a339e333b5dd792
|
4
|
+
data.tar.gz: 9c7c54d9caa52e82fc0b530a2e56a4ced80279f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da4d38596e82c4810fbdf9d89c5e4ea1e41f296b14bc515eba50e1ae23f3393ea9621750c89cad01a5b0e98afe26797b3aba14a1ea5136a1e34f79312a8e34b2
|
7
|
+
data.tar.gz: 32c52ed264090db9a982b64f552e691c75fb74d28a7d4e542c98348e04fd639c86014aad59c8d70a9a98f0621abb94ecd4503b31a3524cf14cc59a89f4c5642e
|
data/lib/hamlit/attribute.rb
CHANGED
@@ -22,6 +22,11 @@ module Hamlit
|
|
22
22
|
def build(attributes)
|
23
23
|
result = ''
|
24
24
|
flatten_attributes(attributes).each do |key, value|
|
25
|
+
if value == true
|
26
|
+
result += " #{key}"
|
27
|
+
next
|
28
|
+
end
|
29
|
+
|
25
30
|
escaped = Temple::Utils.escape_html(value)
|
26
31
|
result += " #{key}=#{@quote}#{escaped}#{@quote}"
|
27
32
|
end
|
@@ -6,22 +6,32 @@ require 'hamlit/concerns/ripperable'
|
|
6
6
|
# This module compiles only old-style attribute, which is
|
7
7
|
# surrounded by brackets.
|
8
8
|
module Hamlit
|
9
|
+
# This error is raised when hamlit copmiler decide to
|
10
|
+
# copmile the attributes on runtime.
|
11
|
+
class RuntimeBuild < StandardError; end
|
12
|
+
|
9
13
|
module Compilers
|
10
14
|
module OldAttribute
|
11
15
|
include Concerns::AttributeBuilder
|
12
16
|
include Concerns::Balanceable
|
13
17
|
include Concerns::Ripperable
|
14
18
|
|
19
|
+
# For performance, only data can be nested.
|
20
|
+
NESTABLE_ATTRIBUTES = %w[data].freeze
|
15
21
|
IGNORED_EXPRESSIONS = %w[false nil].freeze
|
16
22
|
|
17
23
|
def compile_old_attribute(str)
|
18
|
-
|
24
|
+
raise RuntimeBuild unless Ripper.sexp(str)
|
19
25
|
|
20
26
|
attrs = parse_old_attributes(str)
|
21
27
|
format_attributes(attrs).map do |key, value|
|
22
28
|
next true_attribute(key) if value == 'true'
|
29
|
+
assert_static_value!(value) if NESTABLE_ATTRIBUTES.include?(key)
|
30
|
+
|
23
31
|
[:html, :attr, key, [:dynamic, value]]
|
24
32
|
end
|
33
|
+
rescue RuntimeBuild
|
34
|
+
return runtime_build(str)
|
25
35
|
end
|
26
36
|
|
27
37
|
private
|
@@ -38,6 +48,14 @@ module Hamlit
|
|
38
48
|
end
|
39
49
|
end
|
40
50
|
|
51
|
+
# Give up static copmile when variables are detected.
|
52
|
+
def assert_static_value!(value)
|
53
|
+
tokens = Ripper.lex(value)
|
54
|
+
tokens.each do |(row, col), type, str|
|
55
|
+
raise RuntimeBuild if type == :on_ident
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
41
59
|
# Parse brace-balanced string and return the result as hash
|
42
60
|
def parse_old_attributes(str)
|
43
61
|
attributes = {}
|
data/lib/hamlit/version.rb
CHANGED
@@ -48,6 +48,15 @@ describe Hamlit::Engine do
|
|
48
48
|
HTML
|
49
49
|
end
|
50
50
|
|
51
|
+
it 'renders nested hash whose value is variable' do
|
52
|
+
assert_render(<<-'HAML', <<-HTML)
|
53
|
+
- hash = { disable: true }
|
54
|
+
%span{ data: hash } bar
|
55
|
+
HAML
|
56
|
+
<span data-disable>bar</span>
|
57
|
+
HTML
|
58
|
+
end
|
59
|
+
|
51
60
|
it 'renders false or nil attributes' do
|
52
61
|
assert_render(<<-'HAML', <<-HTML)
|
53
62
|
- hash = { checked: false }
|