renshi 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README +11 -8
- data/lib/renshi/parser.rb +1 -1
- data/lib/renshi.rb +1 -1
- metadata +1 -1
data/README
CHANGED
@@ -7,7 +7,9 @@ index.html.ren means you're working with a Renshi file!
|
|
7
7
|
|
8
8
|
$ Ruby Interpretation
|
9
9
|
=====================
|
10
|
-
$
|
10
|
+
The $ symbol is designed to let you drop into ruby code or go back to regular HTML, without having to cursor back and forth as you build your templates.
|
11
|
+
|
12
|
+
$ interprets everything after it as ruby which will be to_stringed until the next $, a newline character, or the end of the element. Leave a $ with a space after it to switch back into writing regular HTML.
|
11
13
|
|
12
14
|
e.g. you can do this
|
13
15
|
|
@@ -16,17 +18,18 @@ e.g. you can do this
|
|
16
18
|
e.g. or this
|
17
19
|
<p>$foo $translator("welcome human") $Time.now</p>
|
18
20
|
|
19
|
-
e.g. or this
|
20
|
-
|
21
|
-
<p>$foo $translator("welcome human") $Time.now $ now this is normal html, the final $$ signaled where the last expression ended ... </p>
|
22
|
-
|
23
|
-
The $ symbol is the most flexible, designed to let you drop into inserting ruby code or go back to regular HTML, without having to cursor back and forth as you create templates.
|
21
|
+
e.g. or this (contrived) example
|
24
22
|
|
23
|
+
<p>$Page.find_by_text("this is the way world ends, \ not with a bang but a whimper).full_text$ A poem by T.S. Eliot, which we thought you'd like $current_user.name</p>
|
25
24
|
|
26
25
|
${} delimits where the ruby begins and ends, for insertions within a line of HTML where you need to include characters the single $ can't handle (such as $, \n).
|
27
26
|
|
28
27
|
e.g.
|
29
|
-
<p>this is normal HTML but ${some_function "takes this string as input"} and now this is normal HTML</p>
|
28
|
+
<p>this is normal HTML but ${some_function "takes this string as input or uses a \n or /foo$/ regex"} and now this is normal HTML</p>
|
29
|
+
|
30
|
+
$^ allows you to insert single phrases, as an alternative to surrounding your ruby with on each side.
|
31
|
+
e.g.
|
32
|
+
<p>It has been $^current_user.days_absent since we last saw you.</p>
|
30
33
|
|
31
34
|
|
32
35
|
$[] allows ruby src code to be embedded. It's a bad practice (use helpers or something) but we let you do it.
|
@@ -44,7 +47,7 @@ Attribute expressions are insertable into HTML elements.
|
|
44
47
|
They can be combined on elements and are interpreted in the order of appearance and are cumulative, allowing you to program inline on the HTML structure.
|
45
48
|
|
46
49
|
<li r:each="@sphinx.results[:words], |k,v|" r:if="v[:hits].to_i > 0">
|
47
|
-
$^k - Hits
|
50
|
+
$^k - Hits $v[:hits]$ in $v[:docs]$ documents
|
48
51
|
</li>
|
49
52
|
|
50
53
|
In the above, you can see that the if statement is scoped within the preceding each block, so you can reference variables between attr. expressions. Variables within an attr. expression don't need the $ symbol. That's only for setting up Ruby insertions within regular HTML.
|
data/lib/renshi/parser.rb
CHANGED
@@ -138,7 +138,7 @@ module Renshi
|
|
138
138
|
rescue StandardError
|
139
139
|
raise SyntaxError, "No closing bracket: #{text}", caller
|
140
140
|
end
|
141
|
-
elsif next_char == "
|
141
|
+
elsif next_char == "^" #$^foo
|
142
142
|
#divide with a delimiter for anything which is not a name character - alpa-numeric and underscore
|
143
143
|
words = text[(idx + 2)..-1].split(/[^\w."'{}()+=*\/\-@\[\]:?!%]/)
|
144
144
|
words[0] = "'$'" if words[0] == "$"
|
data/lib/renshi.rb
CHANGED