renshi 0.1.0 → 0.1.2
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.
- data/README +21 -3
- data/lib/renshi/parser.rb +3 -2
- data/lib/renshi.rb +1 -1
- data/spec/data/example1.ren +4 -0
- data/spec/parser_spec.rb +73 -63
- metadata +2 -2
data/README
CHANGED
@@ -7,9 +7,9 @@ To output data on the page stick a $ in front of your var. or expression
|
|
7
7
|
$foo
|
8
8
|
$Time.now
|
9
9
|
|
10
|
-
If there's a space in your expression
|
10
|
+
If there's a space in your expression use ${}
|
11
11
|
|
12
|
-
${
|
12
|
+
${some_function "takes this string as input"}
|
13
13
|
|
14
14
|
To insert statements in your template use $[]
|
15
15
|
|
@@ -27,7 +27,7 @@ r:expression_name="expression" - the expression value is treated as a Ruby expre
|
|
27
27
|
|
28
28
|
Some expressions, such as r:each, use the quoted value to also hold parameter information.
|
29
29
|
|
30
|
-
Current Attribute Expressions
|
30
|
+
Current Attribute Expressions (see below for an explanation of each)
|
31
31
|
* If
|
32
32
|
* Unless
|
33
33
|
* Elsif
|
@@ -36,6 +36,24 @@ Current Attribute Expressions
|
|
36
36
|
* For
|
37
37
|
* Each
|
38
38
|
|
39
|
+
Combinations
|
40
|
+
============
|
41
|
+
Attribute expressions can be combined on elements, and are interpreted in the order of appearance.
|
42
|
+
|
43
|
+
For e.g.
|
44
|
+
|
45
|
+
<ul>
|
46
|
+
<li r:for="section in @section.sections" r:if="(section.groups & current_user.groups).any?">$section.name
|
47
|
+
<ul>
|
48
|
+
<li r:for="page in section.pages">${link_to page.name, "#{page.path}"}</li>
|
49
|
+
</ul>
|
50
|
+
</li>
|
51
|
+
</ul>
|
52
|
+
|
53
|
+
|
54
|
+
Descriptions
|
55
|
+
============
|
56
|
+
|
39
57
|
* If
|
40
58
|
<span r:if="true">hello</span> would render "<span>hello</span>"
|
41
59
|
|
data/lib/renshi/parser.rb
CHANGED
@@ -120,7 +120,6 @@ module Renshi
|
|
120
120
|
#$[...]
|
121
121
|
elsif next_char == "["
|
122
122
|
begin
|
123
|
-
|
124
123
|
# closing_brace_idx = text.rindex("]")
|
125
124
|
closing_brace_idx = close_of_phrase_ending_with("]", text, idx)
|
126
125
|
statement_str = text[(idx + 2)..(closing_brace_idx -1)]
|
@@ -131,7 +130,9 @@ module Renshi
|
|
131
130
|
raise SyntaxError, "No closing bracket: #{text}", caller
|
132
131
|
end
|
133
132
|
else #$foo
|
134
|
-
|
133
|
+
|
134
|
+
#divide with a delimiter for anything which is not a name character - alpa-numeric and underscore
|
135
|
+
words = text[(idx +1)..-1].split(/\W/)
|
135
136
|
words[0] = "'$'" if words[0] == "$"
|
136
137
|
statement_str = words.first
|
137
138
|
statement = Statement.new(statement_str)
|
data/lib/renshi.rb
CHANGED
data/spec/data/example1.ren
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -6,72 +6,72 @@ def N(str)
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe Renshi::Parser do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
9
|
+
it "should parse a $foo var in elements" do
|
10
|
+
title = "hello world"
|
11
|
+
out = interpret("data/hello_world1.ren", binding)
|
12
|
+
|
13
|
+
doc = Nokogiri::XML(out)
|
14
|
+
(doc/"title").text.should eql "hello world"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should interpret vars surrounded by whitespace" do
|
18
|
+
foo = "in space no one can hear you scream"
|
19
|
+
out = interpret("data/white_space.ren", binding)
|
20
|
+
doc = N(out)
|
21
|
+
(doc/"div[@id='content']").text.strip.should eql "in space no one can hear you scream"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should ignore $(..)" do
|
25
|
+
doc = Nokogiri::HTML.fragment("$(foo)")
|
26
|
+
node = doc.children.first
|
27
|
+
eval(deliver_compiled(node), binding).should eql "$(foo)"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should parse attribute values - e.g. <div id='content$i'>" do
|
31
|
+
i = 1
|
32
|
+
html = interpret("data/attribute_values_parsed.ren", binding)
|
33
|
+
html = N(html)
|
34
|
+
(html/"div[@id='content1']").text.strip.should =~ /hello/
|
35
|
+
end
|
36
|
+
|
37
37
|
def foo(one, two = "", three = {})
|
38
38
|
"#{one}, #{two}"
|
39
39
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
40
|
+
|
41
|
+
it "should understand double quotations marks within ruby code!" do
|
42
|
+
#${link_to "alter this template", edit_cms_page_template_path(PageTemplate.find_by_file_name("default.html.erb"))}
|
43
|
+
raw = compile_file("data/quots.ren")
|
44
|
+
html = eval(raw, binding)
|
45
|
+
html = N(html)
|
46
|
+
(html/"div[@id='content']").text.strip.should =~ /1, 2/
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should understand double quotations marks within ruby code!" do
|
50
|
+
#${link_to "alter this template", edit_cms_page_template_path(PageTemplate.find_by_file_name("default.html.erb"))}
|
51
|
+
raw = compile_file("data/quots2.ren")
|
52
|
+
html = eval(raw, binding)
|
53
|
+
html = N(html)
|
54
|
+
(html/"div[@id='content']").text.strip.should =~ /1, 2/
|
55
|
+
(html/"div[@id='content2']").text.strip.should =~ /a, 2/
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should understand double quotations marks within ruby code! 2" do
|
59
|
+
doc = Nokogiri::HTML(%Q!<p>${foo "1", foo("3", "4")}</p>!)
|
60
|
+
|
61
|
+
puts doc.root
|
62
|
+
|
63
|
+
body = doc.root.children.first
|
64
|
+
node = body.children.first
|
65
|
+
eval(deliver_compiled(node), binding).should eql "1, 3, 4"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should understand multiple statements on the same line" do
|
69
|
+
raw = compile_file("data/multiple_statements.ren")
|
70
|
+
html = eval(raw, binding)
|
71
|
+
html = N(html)
|
72
|
+
(html/"div[@id='content']").text.strip.should =~ /1, 2, 3, 4/
|
73
|
+
(html/"div[@id='content2']").text.strip.should =~ /1, 2/
|
74
|
+
end
|
75
75
|
|
76
76
|
|
77
77
|
# STRING_END = "^R_END" #maybe replace this with a funky unicode char
|
@@ -100,4 +100,14 @@ describe Renshi::Parser do
|
|
100
100
|
|
101
101
|
html.should =~/head/
|
102
102
|
end
|
103
|
+
|
104
|
+
it "should interpret single $foos using \W, i.e. $foo$bar should render" do
|
105
|
+
raw = Renshi::Parser.parse("$foo$bar")
|
106
|
+
foo = "hello"
|
107
|
+
bar = " world"
|
108
|
+
|
109
|
+
html = eval(raw, binding)
|
110
|
+
|
111
|
+
html.should eql "hello world"
|
112
|
+
end
|
103
113
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: renshi
|
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
|
- Nicholas Faiz
|
@@ -9,7 +9,7 @@ autorequire: renshi
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-15 00:00:00 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|