renshi 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -14,18 +14,20 @@ e.g. you can do this
14
14
  $stylesheet_link_tag "atsida"
15
15
 
16
16
  e.g. or this
17
- <p>$foo $bar</p>
17
+ <p>$foo $translator("welcome human") $Time.now</p>
18
18
 
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.
19
24
 
20
- ${} delimits where the ruby begins and ends, for insertions within a line of HTML
25
+
26
+ ${} 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).
21
27
 
22
28
  e.g.
23
29
  <p>this is normal HTML but ${some_function "takes this string as input"} and now this is normal HTML</p>
24
30
 
25
- $= is used for inplace insertion:
26
-
27
- e.g.
28
- <p>What are you doing up at $=Time.now when you should be asleep?</p>
29
31
 
30
32
  $[] allows ruby src code to be embedded. It's a bad practice (use helpers or something) but we let you do it.
31
33
 
data/lib/renshi/parser.rb CHANGED
@@ -106,9 +106,7 @@ module Renshi
106
106
  while idx != nil do
107
107
  next_char = text[(idx + 1)..(idx + 1)]
108
108
 
109
- if next_char == " "
110
- raise SyntaxError, "Floating $ - use $$ to output '$': #{text[(idx +1)..-1]}", caller
111
- elsif next_char == "("
109
+ if next_char == "("
112
110
  #this may be jquery, etc. $(...)
113
111
  end_statement_idx = (idx + 2)
114
112
  bits << text[idx..(idx + 1)]
@@ -148,6 +146,9 @@ module Renshi
148
146
  statement = Statement.new(statement_str)
149
147
  bits << statement.compile_to_print!
150
148
  end_statement_idx = (words.first.length) + 2 + idx
149
+ elsif next_char =~/\s/ #the empty $ acting as a delimiter
150
+ end_statement_idx = (idx + 2)
151
+ bits << "\s"
151
152
  else #$foo
152
153
  #divide with a delimiter on \n or $ or assume ruby until the end of element
153
154
  words = text[(idx +1)..-1].split(/[\n$]/)
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.6"
12
+ VERSION="0.2.7"
13
13
 
14
14
  class SyntaxError < StandardError; end
15
15
  end
data/spec/parser_spec.rb CHANGED
@@ -231,18 +231,26 @@ end
231
231
  html.should =~ /goodbye/
232
232
  end
233
233
 
234
- it "should interpret $foo until \n or end of element as ruby to string" do
235
- raw = Renshi::Parser.parse("$'this should output as a string'")
236
- html = eval(raw, binding)
237
-
238
- html.should =~ /this should output as a string/
239
- end
240
-
241
- it "should interpret $=foo as the single phrase" do
242
- raw = Renshi::Parser.parse("this should $=foo 'hello'")
243
- foo = "say"
244
- html = eval(raw, binding)
245
-
246
- html.should =~ /this should say 'hello'/
247
- end
234
+ it "should interpret $foo until \n or end of element as ruby to string" do
235
+ raw = Renshi::Parser.parse("$'this should output as a string'")
236
+ html = eval(raw, binding)
237
+
238
+ html.should =~ /this should output as a string/
239
+ end
240
+
241
+ it "should interpret $=foo as the single phrase" do
242
+ raw = Renshi::Parser.parse("this should $=foo 'hello'")
243
+ foo = "say"
244
+ html = eval(raw, binding)
245
+
246
+ html.should =~ /this should say 'hello'/
247
+ end
248
+
249
+ it "should interpret $ as a delimiter " do
250
+ raw = Renshi::Parser.parse("this should $foo$ 'hello'")
251
+ foo = "say"
252
+ html = eval(raw, binding)
253
+
254
+ html.should =~ /this should say 'hello'/
255
+ end
248
256
  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.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Faiz