sal 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sal/compiler.rb +8 -16
- data/lib/sal/parser.rb +7 -9
- data/lib/sal/u.rb +3 -3
- data/lib/sal/version.rb +1 -1
- data/lib/sal/wrapper.rb +1 -1
- metadata +8 -8
data/lib/sal/compiler.rb
CHANGED
@@ -12,31 +12,23 @@ module Sal
|
|
12
12
|
[:html, :tag, tag, format_attrs(attrs), compile(content)]
|
13
13
|
end
|
14
14
|
|
15
|
-
def on_sal_text(
|
16
|
-
if
|
17
|
-
[:dynamic, "Sal::U.parse_for_html(_saldict, '#{text}')"]
|
15
|
+
def on_sal_text(text, code = nil)
|
16
|
+
if code
|
17
|
+
[:dynamic, "Sal::U.parse_for_html(_saldict, '#{code}', '#{text}')"]
|
18
18
|
else
|
19
19
|
[:static, text]
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def on_sal_code(code, tag, attrs, content)
|
24
|
-
tmp1
|
25
|
-
content = compile(content)
|
24
|
+
tmp1 = unique_name
|
26
25
|
if code == 'yield'
|
27
26
|
[:dynamic, code]
|
28
27
|
else
|
29
|
-
[:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
[:case, tmp1,
|
34
|
-
['Array',
|
35
|
-
[:block, "#{tmp1}.each do |_saldict|",
|
36
|
-
[:html, :tag, tag, ada(attrs), content]]],
|
37
|
-
[:else,
|
38
|
-
[:html, :tag, tag, ada(attrs), content]]],
|
39
|
-
[:code, "_saldict = #{tmp2}"]]]
|
28
|
+
[:multi,
|
29
|
+
[:if, "(#{tmp1} = _saldict['#{code}'])",
|
30
|
+
[:block, "Array(#{tmp1}).each do |_saldict|",
|
31
|
+
[:html, :tag, tag, ada(attrs), compile(content)]]]]
|
40
32
|
end
|
41
33
|
end
|
42
34
|
|
data/lib/sal/parser.rb
CHANGED
@@ -26,30 +26,28 @@ module Sal
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
def parse_nodeset(stacks, nodes,
|
29
|
+
def parse_nodeset(stacks, nodes, code = nil)
|
30
30
|
nodes.children.each do |node|
|
31
31
|
tag = node.name
|
32
|
-
|
32
|
+
@code = code
|
33
33
|
case node.type
|
34
34
|
when Nokogiri::XML::Node::ELEMENT_NODE
|
35
35
|
content = [:multi]
|
36
|
-
attrs, code = parse_attrs(node)
|
37
|
-
if code
|
38
|
-
|
39
|
-
stacks.last << [:sal, :code, code, tag, attrs, content]
|
36
|
+
attrs, @code = parse_attrs(node)
|
37
|
+
if @code
|
38
|
+
stacks.last << [:sal, :code, @code, tag, attrs, content]
|
40
39
|
else
|
41
|
-
incode = false
|
42
40
|
stacks.last << [:sal, :tag, tag, attrs, content]
|
43
41
|
end
|
44
42
|
stacks << content
|
45
|
-
parse_nodeset(stacks, node,
|
43
|
+
parse_nodeset(stacks, node, @code)
|
46
44
|
stacks.pop
|
47
45
|
when Nokogiri::XML::Node::TEXT_NODE
|
48
46
|
str = node.text
|
49
47
|
if str.strip.empty?
|
50
48
|
stacks.last << [:newline]
|
51
49
|
else
|
52
|
-
stacks.last << [:sal, :text,
|
50
|
+
stacks.last << [:sal, :text, str, @code]
|
53
51
|
end
|
54
52
|
when Nokogiri::XML::Node::DTD_NODE
|
55
53
|
stacks.last << [:static, node.to_s]
|
data/lib/sal/u.rb
CHANGED
@@ -7,8 +7,8 @@ module Sal
|
|
7
7
|
result = result.value if result.kind_of?(Sal::Wrapper)
|
8
8
|
|
9
9
|
return unless result.kind_of?(Hash)
|
10
|
-
|
11
10
|
result = stringify_keys(result)
|
11
|
+
return unless result['html']
|
12
12
|
|
13
13
|
# concat values on class attribute
|
14
14
|
if attrs['class'] && result['class']
|
@@ -18,12 +18,12 @@ module Sal
|
|
18
18
|
" #{result.collect{ |k,v| "#{k}='#{v}'" unless k.to_s == 'html' }.compact.join(' ')}"
|
19
19
|
end
|
20
20
|
|
21
|
-
def parse_for_html(result, text = '')
|
21
|
+
def parse_for_html(result, code, text = '')
|
22
22
|
result = result.value if result.kind_of?(Sal::Wrapper)
|
23
23
|
if result.kind_of?(String)
|
24
24
|
result
|
25
25
|
elsif result.kind_of?(Hash)
|
26
|
-
result
|
26
|
+
result[:html] || result[code.to_sym]
|
27
27
|
else
|
28
28
|
text unless text.strip.empty?
|
29
29
|
end
|
data/lib/sal/version.rb
CHANGED
data/lib/sal/wrapper.rb
CHANGED
@@ -20,11 +20,11 @@ module Sal
|
|
20
20
|
# go through the same steps on the parent object. This is useful when
|
21
21
|
# you are iterating over objects.
|
22
22
|
def [](name)
|
23
|
-
return wrap(value.send(name)) if value.respond_to?(name)
|
24
23
|
if value.respond_to?(:has_key?)
|
25
24
|
return wrap(value[name.to_sym]) if value.has_key?(name.to_sym)
|
26
25
|
return wrap(value[name.to_s]) if value.has_key?(name.to_s)
|
27
26
|
end
|
27
|
+
return wrap(value.send(name)) if value.respond_to?(name)
|
28
28
|
return wrap(value.instance_variable_get("@#{name}")) if value.instance_variable_defined?("@#{name}")
|
29
29
|
parent[name] if parent
|
30
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-22 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
17
|
-
requirement: &
|
17
|
+
requirement: &2164373500 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '1.4'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2164373500
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: temple
|
28
|
-
requirement: &
|
28
|
+
requirement: &2164372980 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0.3'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2164372980
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: tilt
|
39
|
-
requirement: &
|
39
|
+
requirement: &2164372500 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '1.2'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2164372500
|
48
48
|
description: sal.rb is an attribute language.
|
49
49
|
email:
|
50
50
|
- andy@stonean.com
|