renshi 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,15 +1,16 @@
1
- Renshi is a templating language for Ruby which is unobtrusive in HTML and XHTML structures.
1
+ Renshi is a templating language for Ruby which is unobtrusive in HTML and XHTML structures. It is conciser than ERB and offers 'attribute expressions', letting you build sets of inline Ruby instructions upon HTML elements. Renshi was designed to give the Ruby dev. flexibility when creating templates; the use of attribute expressions creates well-formed XHTML, $ interpretation can be used however the dev. wishes.
2
2
 
3
- $ Code
4
- ======
3
+ Renshi templates are appended with the suffix of .ren, e.g. index.html.ren or index.ren
4
+
5
+ $ Ruby Insertion
6
+ ================
5
7
  To output data on the page stick a $ in front of your var. or expression
6
8
 
7
- $foo
8
- $Time.now
9
+ $foo, $Time.now (ERB equivalent - <%= foo %>, <%= Time.now %>)
9
10
 
10
11
  If there's a space in your expression use ${}
11
12
 
12
- ${some_function "takes this string as input"}
13
+ ${some_function "takes this string as input"} (ERB equiv. - <%= some_function "takes this string as input" %>)
13
14
 
14
15
  To insert statements in your template use $[]
15
16
 
@@ -19,40 +20,36 @@ $[if foo]
19
20
  $foo
20
21
  $[end]
21
22
 
23
+ (The ERB equiv. should be obvious by now.)
24
+
22
25
  Attribute Expressions
23
26
  ===================
24
- The $ syntax will give you everything ERB does, with less typing. But Renshi also has 'attribute expressions', which can be inserted into a HTML element as an attribute - e.g. <span r:if="user.is_administrator">...</span>. After Renshi::Parser interprets an attribute expression it removes it from the HTML output; the code is unobtrusive.
25
-
26
- r:expression_name="expression" - the expression value is treated as a Ruby expression .
27
-
28
- Some expressions, such as r:each, use the quoted value to also hold parameter information.
29
-
30
- Current Attribute Expressions (see below for an explanation of each)
31
- * If
32
- * Unless
33
- * Elsif
34
- * Else
35
- * While
36
- * For
37
- * Each
27
+ Renshi has 'attribute expressions', which may be inserted into HTML elements as attributes.
38
28
 
39
- Combinations
40
- ============
41
- Attribute expressions can be combined on elements, and are interpreted in the order of appearance.
29
+ Attribute expressions can be combined on elements and are interpreted in the order of appearance and are cumulative, allowing you to build chunks of inline code which apply to the HTML element (and anything within it).
42
30
 
43
31
  For e.g.
44
-
45
32
  <ul>
46
- <li r:for="section in @section.sections" r:if="(section.groups & current_user.groups).any?">$section.name
33
+ <li r:for="section in @section.sections" r:if="authorized?(current_user, section)?" id="section_$section.name">$section.name
47
34
  <ul>
48
35
  <li r:for="page in section.pages">${link_to page.name, "#{page.path}"}</li>
49
36
  </ul>
50
37
  </li>
51
38
  </ul>
52
39
 
40
+ After Renshi interprets an attribute expression it removes it from the HTML output.
53
41
 
54
- Descriptions
55
- ============
42
+ $ symbols inside of attribute values are interpreted for regular HTML attributes (they're unneeded for renshi attributes).
43
+
44
+ Attribute Expression Library
45
+ ============================
46
+ * If
47
+ * Unless
48
+ * Elsif
49
+ * Else
50
+ * While
51
+ * For
52
+ * Each
56
53
 
57
54
  * If
58
55
  <span r:if="true">hello</span> would render "<span>hello</span>"
@@ -145,16 +142,8 @@ See renshi/lib/renshi/attribute_expressions for how they work.
145
142
 
146
143
  Other Rules
147
144
  ===========
148
- $ values inside of attributes are only interpreted as Renshi variables for regular attributes (not renshi attributes).
149
-
150
- 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.
151
-
152
145
  To print a $ use $$, e.g. $$10.95 comes out as $10.95
153
146
 
154
- Renshi documents are appended with the suffix of .ren
155
-
156
- e.g. index.html.ren or index.ren
157
-
158
147
  Installation
159
148
  ============
160
149
  Renshi is hosted on Rubyforge so 'sudo gem install renshi'. Alternatively, use github to do what you want with it.
data/lib/renshi/parser.rb CHANGED
@@ -132,7 +132,7 @@ module Renshi
132
132
  else #$foo
133
133
 
134
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
+ words = text[(idx +1)..-1].split(/[^\w."'{}()+=*\/\-]/)
136
136
  words[0] = "'$'" if words[0] == "$"
137
137
  statement_str = words.first
138
138
  statement = Statement.new(statement_str)
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.1.2"
12
+ VERSION="0.1.3"
13
13
 
14
14
  class SyntaxError < StandardError; end
15
15
  end
data/spec/parser_spec.rb CHANGED
@@ -109,5 +109,43 @@ describe Renshi::Parser do
109
109
  html = eval(raw, binding)
110
110
 
111
111
  html.should eql "hello world"
112
- end
112
+ end
113
+
114
+ class Test
115
+ def bar
116
+ return "hello world"
117
+ end
118
+ end
119
+
120
+ it "should interpret single $foo.bar using \W" do
121
+ raw = Renshi::Parser.parse("$foo.bar")
122
+ foo = Test.new
123
+ html = eval(raw, binding)
124
+
125
+ html.should eql "hello world"
126
+ end
127
+
128
+ it "should interpret single $1+1 and $2*2 and $3/3 and $4-4 using \W" do
129
+ raw = Renshi::Parser.parse("$1+1")
130
+ foo = Test.new
131
+ html = eval(raw, binding)
132
+ html.should eql "2"
133
+
134
+ raw = Renshi::Parser.parse("$2*2")
135
+ foo = Test.new
136
+ html = eval(raw, binding)
137
+ html.should eql "4"
138
+
139
+ raw = Renshi::Parser.parse("$3/3")
140
+ foo = Test.new
141
+ html = eval(raw, binding)
142
+ html.should eql "1"
143
+
144
+ raw = Renshi::Parser.parse("$4-4")
145
+ foo = Test.new
146
+ html = eval(raw, binding)
147
+ html.should eql "0"
148
+ end
149
+
150
+
113
151
  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.2
4
+ version: 0.1.3
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-15 00:00:00 +10:00
12
+ date: 2009-08-19 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency