renshi 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,12 +1,12 @@
1
- Renshi is a templating language for Ruby which is unobtrusive in HTML and XHTML structures. It has a conciser syntax than ERB and an 'attribute expression' library which lets you build and combine sets of inline Ruby instructions upon HTML elements.
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
3
  Renshi templates are appended with the suffix of .ren, e.g. index.html.ren or index.ren
4
4
 
5
- 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.
5
+ 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. It's especially useful when working alongside a HTML designer.
6
6
 
7
- $ Ruby Insertion
8
- ================
9
- Very much like ERB.
7
+ $ Ruby Interpretation
8
+ =====================
9
+ Very much like ERB with less typing.
10
10
 
11
11
  Use $ or ${..} where you would use <%= ... %> . The single $ is used for one word phrases.
12
12
 
@@ -24,7 +24,7 @@ Attribute Expressions
24
24
  ===================
25
25
  Renshi has 'attribute expressions', which may be inserted into HTML elements as attributes.
26
26
 
27
- Attribute expressions 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 (the element and everything within it).
27
+ Attribute expressions 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 (the element and everything within it).
28
28
 
29
29
  For e.g.
30
30
  <ul>
@@ -35,6 +35,17 @@ For e.g.
35
35
  </li>
36
36
  </ul>
37
37
 
38
+ Another e.g.
39
+ <li r:each="@sphinx.results[:words], |k,v|" r:if="v[:hits].to_i > 0">
40
+ $k - Hits $v[:hits] in $v[:docs] documents
41
+ </li>
42
+
43
+ Another e.g.
44
+ <td r:if="dataset.published?">${link_to 'Hide', hide_cms_dataset_path(dataset)}</td>
45
+ <td r:else>${link_to 'Publish', publish_cms_dataset_path(dataset)}</td>
46
+
47
+ 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).
48
+
38
49
  After Renshi interprets an attribute expression it removes it from the HTML output.
39
50
 
40
51
  $ symbols inside of attribute values are interpreted for regular HTML attributes (they're unneeded for renshi attributes).
@@ -142,9 +153,9 @@ Other Rules
142
153
  ===========
143
154
  To print a $ use $$, e.g. $$10.95 comes out as $10.95
144
155
 
145
- 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.
156
+ 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}]
146
157
 
147
- For example, because $"hello".upcase works, if you want to do "$"hello".upcase" to produce "HELLO" you'll need to use "${"hello".upcase}" instead.
158
+ The $ character accepts the following characters as legitmate ruby characters - " ' { } ( ) + = * / \ - @ [ ] : ? along with the ^\w (any character which is not a Ruby word character).
148
159
 
149
160
  Installation
150
161
  ============
@@ -0,0 +1,21 @@
1
+
2
+ # module Renshi
3
+ # module Frameworks
4
+ # module Sinatra
5
+ #
6
+
7
+ module Sinatra
8
+ module Templates
9
+ def ren(template, options={}, locals={})
10
+ render :ren, template, options, locals
11
+ end
12
+
13
+ private
14
+ def render_ren(data, options, locals, &block)
15
+ # ::Haml::Engine.new(data, options).render(self, locals, &block)
16
+ #
17
+ out = Renshi::Parser.parse(source)
18
+ return eval(out, binding)
19
+ end
20
+ end
21
+ end
@@ -3,6 +3,7 @@ module Renshi
3
3
  #framework integrations can be loaded within notice by checking the environment
4
4
  def self.notice
5
5
  require 'renshi/frameworks/rails' if defined? ENV['RAILS_ENV']
6
+ # require 'renshi/frameworks/sinatra' if defined? Sinatra
6
7
  end
7
8
  end
8
9
  end
data/lib/renshi/parser.rb CHANGED
@@ -139,7 +139,7 @@ module Renshi
139
139
  else #$foo
140
140
 
141
141
  #divide with a delimiter for anything which is not a name character - alpa-numeric and underscore
142
- words = text[(idx +1)..-1].split(/[^\w."'{}()+=*\/\-@\[\]:]/)
142
+ words = text[(idx +1)..-1].split(/[^\w."'{}()+=*\/\-@\[\]:?!]/)
143
143
  words[0] = "'$'" if words[0] == "$"
144
144
  statement_str = words.first
145
145
  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.8"
12
+ VERSION="0.1.9"
13
13
 
14
14
  class SyntaxError < StandardError; end
15
15
  end
data/spec/if_spec.rb CHANGED
@@ -28,4 +28,12 @@ describe Renshi::Parser do
28
28
  (doc/"div[@id='content']").text.strip.should =~ /hello/
29
29
  (doc/"div[@id='inner_content']").text.strip.should eql "world"
30
30
  end
31
+
32
+ # it "trying to replicate a problem ..." do
33
+ # @foos = [1, 2]
34
+ # raw = Renshi::Parser.parse("<p r:if='@foos.empty?'>hello</p>")
35
+ # html = eval(raw, binding)
36
+ #
37
+ # html.should eql ""
38
+ # end
31
39
  end
data/spec/parser_spec.rb CHANGED
@@ -181,4 +181,35 @@ end
181
181
 
182
182
  html.should eql "<a href=\"#{r.path}\">hello</a>"
183
183
  end
184
+
185
+ it "should interpret $foo.nil?" do
186
+ foo = nil
187
+ raw = Renshi::Parser.parse("$foo.nil?")
188
+ html = eval(raw, binding)
189
+
190
+ html.should eql true.to_s
191
+ end
192
+
193
+ it "should interpret $@foo.nil?" do
194
+ @foo = nil
195
+ raw = Renshi::Parser.parse("$@foo.nil?")
196
+ html = eval(raw, binding)
197
+
198
+ html.should eql true.to_s
199
+ end
200
+
201
+ it "should interpret $a$b$c" do
202
+ a = 'a'; b = 'b'; c = 'c';
203
+ raw = Renshi::Parser.parse("$a$b$c")
204
+ html = eval(raw, binding)
205
+
206
+ html.should eql "abc"
207
+ end
208
+
209
+ it "should interpret $'foo'.upcase!" do
210
+ raw = Renshi::Parser.parse("$'foo'.upcase!")
211
+ html = eval(raw, binding)
212
+
213
+ html.should eql "FOO"
214
+ end
184
215
  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.8
4
+ version: 0.1.9
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-26 00:00:00 +10:00
12
+ date: 2009-09-09 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,6 +41,7 @@ files:
41
41
  - lib/renshi/attribute_expressions.rb
42
42
  - lib/renshi/frameworks/generic.rb
43
43
  - lib/renshi/frameworks/rails.rb
44
+ - lib/renshi/frameworks/sinatra.rb
44
45
  - lib/renshi/frameworks.rb
45
46
  - lib/renshi/node.rb
46
47
  - lib/renshi/parser.rb