renshi 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,16 +1,12 @@
1
1
  Renshi is a templating language for Ruby which is versatile and cooperative with HTML. It has a concise syntax and 'attribute expressions', which let you build and combine sets of inline Ruby instructions upon HTML elements.
2
2
 
3
- Renshi gives the Ruby dev. flexibility when templating; 'attribute expressions' create well-formed XHTML, $ interpretations can be used as a conciser ERB notation.
4
-
5
- Renshi integrates with Rails and Sinatra out of the box. Simply 'require renshi'! In Sinatra the helper method simply use 'ren' where you would have used 'erb'/'haml'.
6
-
7
- Renshi templates are appended with the suffix of .ren, e.g. index.html.ren or index.ren.
3
+ Renshi integrates with Rails and Sinatra transparently. Simply 'require renshi'. In Sinatra use 'ren' where you would have used the 'erb'/'haml' methods. Renshi templates are appended with the suffix of .ren, e.g. index.html.ren or index.ren.
8
4
 
9
5
  $ Ruby Interpretation
10
6
  =====================
11
7
  Like ERB, but less typing.
12
8
 
13
- Use $ or ${..} where you would use <%= ... %> . The single $ is used for one word phrases.
9
+ Use $ or ${..} where you would use <%= ... %> . The single $ is used for an unbroken phrase (see below).
14
10
 
15
11
  $foo[0], $1+1, $Time.now - ERB equiv. <%= foo[0] %>, <%= 1+1 %>, <%= Time.now %>
16
12
 
@@ -28,23 +24,22 @@ Attr. expressions are insertable into HTML elements as attributes.
28
24
 
29
25
  <p r:if="user.known?">Welcome $user.name</p>
30
26
 
31
- 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: if a variable is created by an attr. expression it can be used within its scope.
27
+ 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.
32
28
 
33
29
  <li r:each="@sphinx.results[:words], |k,v|" r:if="v[:hits].to_i > 0">
34
30
  $k - Hits $v[:hits] in $v[:docs] documents
35
31
  </li>
36
32
 
37
- If you use a variable within an attr. expression, the $ notation is not needed. It's only for insertion in regular HTML.
33
+ 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.
38
34
 
39
- Renshi will automatically guess the natural ending of boolean structures.
35
+ One more thing, Renshi will guess the expected ending of boolean structures.
40
36
 
41
37
  <td r:if="dataset.published?">...</td>
42
38
  <td r:else>...</td>
43
39
 
44
- You don't need to supply an 'end' element; it can be guessed by the structure of the HTML document (see r:if below in the library).
45
-
46
- None of the r:foo attr.expressions are rendered in the HTML source.
40
+ You don't need to supply an 'end' element; it is inferred by the HTML structure (see below).
47
41
 
42
+ None of the attr.expressions appear in the HTML rendered to the browser.
48
43
 
49
44
  Attribute Expression Library
50
45
  ============================
@@ -151,7 +146,7 @@ To print a $ use $$, e.g. $$10.95 comes out as $10.95
151
146
 
152
147
  Because the $foo evaluation can take all sorts of symbols to interpret a Ruby statement, if you are using a special symbol *immediately* before it, you'll have to use ${foo} instead. For example, because $greetings[0].upcase is interpretable, if you want to output "[HELLO]" where the brackets surround the string, you'd use [${greetings[0].upcase}]
153
148
 
154
- The $ parser *delimits* (splits) on any character which is not in this list - . " ' { } ( ) + = * / \ - @ [ ] : ? ! \w
149
+ The $ parser *delimits* (splits) on any character which is not in this list - . " ' { } ( ) + = * / \ - @ [ ] : ? ! % \w
155
150
 
156
151
  Installation
157
152
  ============
data/lib/renshi/parser.rb CHANGED
@@ -29,6 +29,10 @@ module Renshi
29
29
  parser = self.new(doc)
30
30
  out = parser.parse
31
31
 
32
+ if ENV['RENSHI_SHOW_SRC']
33
+ puts "Renshi src: \n#{out}"
34
+ end
35
+
32
36
  return out
33
37
  end
34
38
 
@@ -137,9 +141,8 @@ module Renshi
137
141
  raise SyntaxError, "No closing bracket: #{text}", caller
138
142
  end
139
143
  else #$foo
140
-
141
144
  #divide with a delimiter for anything which is not a name character - alpa-numeric and underscore
142
- words = text[(idx +1)..-1].split(/[^\w."'{}()+=*\/\-@\[\]:?!]/)
145
+ words = text[(idx +1)..-1].split(/[^\w."'{}()+=*\/\-@\[\]:?!%]/)
143
146
  words[0] = "'$'" if words[0] == "$"
144
147
  statement_str = words.first
145
148
  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.2.0"
12
+ VERSION="0.2.1"
13
13
 
14
14
  class SyntaxError < StandardError; end
15
15
  end
data/spec/parser_spec.rb CHANGED
@@ -212,4 +212,12 @@ end
212
212
 
213
213
  html.should eql "FOO"
214
214
  end
215
+
216
+ it "should interpret $Time.now.strftime('%I:%M')" do
217
+ raw = Renshi::Parser.parse("$Time.now.strftime('%I:%M')")
218
+ html = eval(raw, binding)
219
+
220
+ html.should =~ /:/
221
+ end
222
+
215
223
  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.2.0
4
+ version: 0.2.1
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-09-10 00:00:00 +10:00
12
+ date: 2009-09-21 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,7 +49,7 @@ files:
49
49
  - lib/renshi.rb
50
50
  - README
51
51
  has_rdoc: true
52
- homepage: http://treefallinginthewoods.com
52
+ homepage: http://github.com/biv/renshi/tree/master
53
53
  licenses: []
54
54
 
55
55
  post_install_message:
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  requirements: []
73
73
 
74
74
  rubyforge_project:
75
- rubygems_version: 1.3.5
75
+ rubygems_version: 1.3.4
76
76
  signing_key:
77
77
  specification_version: 3
78
78
  summary: Renshi is a templating language for Ruby which is versatile and cooperative with HTML.