renshi 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +14 -27
  2. data/lib/renshi/parser.rb +14 -6
  3. data/lib/renshi.rb +1 -1
  4. metadata +2 -2
data/README CHANGED
@@ -7,7 +7,7 @@ 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 or you need formatting it use ${}
10
+ If there's a space in your expression or you need formatting use ${}
11
11
 
12
12
  ${foo},$Time.now
13
13
 
@@ -15,10 +15,14 @@ To insert statements in your template use $[]
15
15
 
16
16
  $[foo = "hello world"]
17
17
 
18
+ $[if foo]
19
+ $foo
20
+ $[end]
21
+
18
22
  Attribute Expressions
19
23
  ===================
20
- Renshi has a small library of expressions which can be inserted into HTML or XML elements as attributes.
21
- Attribute expressions generally follow the form of
24
+ The $ syntax will give you everything ERB does, with less typing. But Renshi also has 'attribute expressions',
25
+ which can be inserted into a HTML element as an attribute - e.g. <span r:if="user.is_administrator">...</span>.
22
26
 
23
27
  r:expression_name="expression" - the expression value is treated as a Ruby expression .
24
28
 
@@ -34,16 +38,12 @@ Current Attribute Expressions
34
38
  * Each
35
39
 
36
40
  * If
37
- <span r:if="true">hello</span>
38
- would render "<span>hello</span>"
41
+ <span r:if="true">hello</span> would render "<span>hello</span>"
39
42
 
40
43
  <span r:if="false">goodbye!</span> will render "".
41
44
 
42
45
  * Unless
43
- <span r:unless="false">hello</span>
44
- would render "<span>hello</span>"
45
-
46
- <span r:unless="true">goodbye!</span> will render "".
46
+ e.g. <span r:unless="false">hello</span>
47
47
 
48
48
  * Elsif
49
49
 
@@ -58,7 +58,6 @@ would render "<span>hello</span>"
58
58
 
59
59
  r:elsif and r:else must be adjacent (a sibling) to the element.
60
60
 
61
-
62
61
  For example, the below is fine, because the if and else statements are adjacent siblings in the tree of elements.
63
62
 
64
63
  <div id="menu" r:if="user.is_administrator?">
@@ -67,16 +66,6 @@ For example, the below is fine, because the if and else statements are adjacent
67
66
  <div id="user_menu"> ... </div>
68
67
  </div>
69
68
 
70
- but this is not:
71
-
72
- <div id="menu" r:if="user.is_administrator?">
73
- <div id="admin_menu"> ... </div>
74
- <div id="register">
75
- <div id="register"> ... </div>
76
- </div>
77
- <div id="menu" r:else>
78
- <div id="user_menu"> ... </div>
79
- </div>
80
69
 
81
70
  * While
82
71
 
@@ -138,9 +127,6 @@ $ values inside of attributes are only interpreted as Renshi variables for regul
138
127
 
139
128
  E.g. <div r:if="'abc' =~ /$abc/" id="content$foo"> the r:if statement would treat $ exactly as Ruby does, while the id attribute value is transformed.
140
129
 
141
-
142
- Miscellaneous
143
- =============
144
130
  To print a $ use $$, e.g. $$10.95 comes out as $10.95
145
131
 
146
132
  Renshi documents are appended with the suffix of .ren
@@ -176,11 +162,12 @@ Firstly, it doesn't need a reason. It's a fun project.
176
162
 
177
163
  But ...
178
164
 
179
- I've always found ERB to be a bit cumbersome - <%= is quite tiring to type out when you realise it could be much shorter. I used to think that Velocity, in Java,
180
- was the most fun templating language I'd used, and I had wanted something equally as concise for Ruby.
165
+ I've always found ERB to be a bit cumbersome - <%= is quite tiring to type out when you realise it could be much shorter. I used to think that Velocity, in Java, was the most fun templating language I'd used, and I had wanted something equally as concise for Ruby.
166
+
167
+ A real need for it emerged in a project which relied upon an external design house handing us HTML. Converting it incessantly into HAML was nightmarish. A colleague mentioned Genshi in Python as ideal, which was when the idea of Renshi was conceived.
181
168
 
182
- A real need for it emerged in a project which relied upon an external design house handing us HTML. Converting it incessantly into HAML was nightmarish. A colleague
183
- mentioned Genshi in Python as ideal, which was when the idea of Renshi was conceived.
169
+ It should give the developer power to do what they want, without being restrictive. You can throw $ statements around the place in a document
170
+ or use attribute expressions to preserve a strict xhtml layout.
184
171
 
185
172
  English to Japanese
186
173
  ===================
data/lib/renshi/parser.rb CHANGED
@@ -63,13 +63,21 @@ module Renshi
63
63
 
64
64
  bits = []
65
65
  bits << text[0..(idx -1)] if idx != 0
66
+
66
67
  while idx != nil do
67
- if text[(idx + 1)..(idx + 1)] == "("
68
- #this may be jquery, etc. $(...)
69
- return text
68
+ next_char = text[(idx + 1)..(idx + 1)]
69
+
70
+ if next_char == "("
71
+ #this may be jquery, etc. $(...)
72
+ end_statement_idx = (idx + 2)
73
+ bits << text[idx..(idx + 1)]
74
+ elsif next_char == "$"
75
+ #an escaped $ - i.e. '$$'
76
+ end_statement_idx = (idx + 2)
77
+ bits << "$"
70
78
 
71
79
  #${...}
72
- elsif text[(idx + 1)..(idx + 1)] == "{"
80
+ elsif next_char == "{"
73
81
  begin
74
82
  closing_brace_idx = text.rindex("}")
75
83
  statement_str = text[(idx + 2)..(closing_brace_idx -1)]
@@ -81,7 +89,7 @@ module Renshi
81
89
  end
82
90
 
83
91
  #$[...]
84
- elsif text[(idx + 1)..(idx + 1)] == "["
92
+ elsif next_char == "["
85
93
  begin
86
94
  closing_brace_idx = text.rindex("]")
87
95
  statement_str = text[(idx + 2)..(closing_brace_idx -1)]
@@ -101,7 +109,7 @@ module Renshi
101
109
  end
102
110
 
103
111
  next_statement_idx = text.index("$", end_statement_idx)
104
-
112
+
105
113
  if next_statement_idx
106
114
  gap = text[end_statement_idx..(next_statement_idx -1)]
107
115
  bits << gap
data/lib/renshi.rb CHANGED
@@ -9,7 +9,7 @@ require 'renshi/attribute_expressions'
9
9
  require 'renshi/frameworks'
10
10
 
11
11
  module Renshi
12
- VERSION="0.0.7"
12
+ VERSION="0.0.8"
13
13
 
14
14
  class SyntaxError < StandardError; end
15
15
  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.0.7
4
+ version: 0.0.8
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-07-10 00:00:00 +10:00
12
+ date: 2009-07-13 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency