erbal 1.0.rc7 → 1.0.rc8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/erbal/erbal.c CHANGED
@@ -16,16 +16,14 @@ VALUE rb_erbal_alloc(VALUE klass) {
16
16
  }
17
17
 
18
18
  VALUE rb_erbal_initialize(int argc, VALUE *argv, VALUE self) {
19
- VALUE str, buffer_name, options;
19
+ VALUE str, options;
20
20
 
21
- rb_scan_args(argc, argv, "21", &str, &buffer_name, &options);
21
+ rb_scan_args(argc, argv, "11", &str, &options);
22
22
 
23
23
  Check_Type(str, T_STRING);
24
- Check_Type(buffer_name, T_STRING);
25
24
 
26
25
  erbal_parser *parser = NULL;
27
26
  Data_Get_Struct(self, erbal_parser, parser);
28
- parser->buffer_name = buffer_name;
29
27
  parser->str = str;
30
28
 
31
29
  if (NIL_P(options)) {
data/ext/erbal/parser.c CHANGED
@@ -168,16 +168,37 @@ void erbal_parser_init(erbal_parser *parser) {
168
168
  parser->chars_seen = 0;
169
169
  parser->in_buffer_shift = 0;
170
170
  parser->state = OUTSIDE_TAG;
171
- parser->debug = 0;
172
171
 
173
172
  if (rb_hash_aref(parser->options, ID2SYM(rb_intern("debug"))) == Qtrue) {
174
173
  parser->debug = 1;
174
+ } else {
175
+ parser->debug = 0;
176
+ }
177
+
178
+ VALUE buffer_name_val = rb_hash_aref(parser->options, ID2SYM(rb_intern("buffer")));
179
+
180
+ if (!NIL_P(buffer_name_val)) {
181
+ Check_Type(buffer_name_val, T_STRING);
182
+ parser->buffer_name = buffer_name_val;
183
+ } else {
184
+ parser->buffer_name = rb_str_new2("@output_buffer");
175
185
  }
176
186
 
177
187
  parser->src = rb_str_dup(parser->buffer_name);
178
- rb_str_buf_cat(parser->src, " = '';", 6);
188
+
189
+ VALUE buffer_init_val = rb_hash_aref(parser->options, ID2SYM(rb_intern("buffer_initial_value")));
190
+
191
+ if (!NIL_P(buffer_init_val)) {
192
+ Check_Type(buffer_init_val, T_STRING);
193
+ rb_str_buf_cat(parser->src, " = ", 3);
194
+ rb_str_concat(parser->src, buffer_init_val);
195
+ rb_str_buf_cat(parser->src, ";", 1);
196
+ } else {
197
+ rb_str_buf_cat(parser->src, " = '';", 6);
198
+ }
199
+
179
200
 
180
- #line 181 "parser.c"
201
+ #line 202 "parser.c"
181
202
  {
182
203
  cs = erbal_parser_start;
183
204
  ts = 0;
@@ -185,14 +206,14 @@ void erbal_parser_init(erbal_parser *parser) {
185
206
  act = 0;
186
207
  }
187
208
 
188
- #line 179 "parser.rl"
209
+ #line 200 "parser.rl"
189
210
  }
190
211
 
191
212
  void erbal_parser_exec(erbal_parser *parser) {
192
213
  p = RSTRING(parser->str)->ptr;
193
214
  pe = p + strlen(p);
194
215
 
195
- #line 196 "parser.c"
216
+ #line 217 "parser.c"
196
217
  {
197
218
  if ( p == pe )
198
219
  goto _test_eof;
@@ -242,7 +263,7 @@ st1:
242
263
  case 1:
243
264
  #line 1 "NONE"
244
265
  {ts = p;}
245
- #line 246 "parser.c"
266
+ #line 267 "parser.c"
246
267
  switch( (*p) ) {
247
268
  case 37: goto st2;
248
269
  case 45: goto tr4;
@@ -264,7 +285,7 @@ st3:
264
285
  if ( ++p == pe )
265
286
  goto _test_eof3;
266
287
  case 3:
267
- #line 268 "parser.c"
288
+ #line 289 "parser.c"
268
289
  if ( (*p) == 37 )
269
290
  goto st0;
270
291
  goto tr6;
@@ -314,6 +335,6 @@ case 5:
314
335
 
315
336
  }
316
337
 
317
- #line 185 "parser.rl"
338
+ #line 206 "parser.rl"
318
339
  erbal_parser_finish(parser);
319
340
  }
data/ext/erbal/parser.rl CHANGED
@@ -167,14 +167,35 @@ void erbal_parser_init(erbal_parser *parser) {
167
167
  parser->chars_seen = 0;
168
168
  parser->in_buffer_shift = 0;
169
169
  parser->state = OUTSIDE_TAG;
170
- parser->debug = 0;
171
170
 
172
171
  if (rb_hash_aref(parser->options, ID2SYM(rb_intern("debug"))) == Qtrue) {
173
172
  parser->debug = 1;
173
+ } else {
174
+ parser->debug = 0;
175
+ }
176
+
177
+ VALUE buffer_name_val = rb_hash_aref(parser->options, ID2SYM(rb_intern("buffer")));
178
+
179
+ if (!NIL_P(buffer_name_val)) {
180
+ Check_Type(buffer_name_val, T_STRING);
181
+ parser->buffer_name = buffer_name_val;
182
+ } else {
183
+ parser->buffer_name = rb_str_new2("@output_buffer");
174
184
  }
175
185
 
176
186
  parser->src = rb_str_dup(parser->buffer_name);
177
- rb_str_buf_cat(parser->src, " = '';", 6);
187
+
188
+ VALUE buffer_init_val = rb_hash_aref(parser->options, ID2SYM(rb_intern("buffer_initial_value")));
189
+
190
+ if (!NIL_P(buffer_init_val)) {
191
+ Check_Type(buffer_init_val, T_STRING);
192
+ rb_str_buf_cat(parser->src, " = ", 3);
193
+ rb_str_concat(parser->src, buffer_init_val);
194
+ rb_str_buf_cat(parser->src, ";", 1);
195
+ } else {
196
+ rb_str_buf_cat(parser->src, " = '';", 6);
197
+ }
198
+
178
199
  %% write init;
179
200
  }
180
201
 
data/lib/erbal/rails.rb CHANGED
@@ -1,8 +1,21 @@
1
1
  require 'erbal'
2
2
 
3
- class ErbalTemplateHandler < ActionView::TemplateHandler
4
- include ActionView::TemplateHandlers::Compilable
5
- def compile(template)
6
- ::Erbal.new("<% __in_erb_template=true %>#{template.source}", '@output_buffer').parse
3
+ if ActiveSupport.const_defined?('SafeBuffer')
4
+
5
+ class ErbalTemplateHandler < ActionView::TemplateHandler
6
+ include ActionView::TemplateHandlers::Compilable
7
+ def compile(template)
8
+ ::Erbal.new("<% __in_erb_template=true %>#{template.source}", {:buffer => '@output_buffer', :buffer_initial_value => 'ActiveSupport::SafeBuffer.new'}).parse
9
+ end
7
10
  end
11
+
12
+ else
13
+
14
+ class ErbalTemplateHandler < ActionView::TemplateHandler
15
+ include ActionView::TemplateHandlers::Compilable
16
+ def compile(template)
17
+ ::Erbal.new("<% __in_erb_template=true %>#{template.source}", {:buffer => '@output_buffer'}).parse
18
+ end
19
+ end
20
+
8
21
  end
data/spec/erbal_spec.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Erbal do
4
- def erbal_parse(str)
5
- Erbal.new(str, '@out').parse
4
+ def erbal_parse(str, options = {:buffer => '@out'})
5
+ Erbal.new(str, options).parse
6
6
  end
7
7
 
8
8
  def erubis_parse(str)
@@ -11,8 +11,28 @@ describe Erbal do
11
11
  Erubis::FastEruby.new.convert(str)
12
12
  end
13
13
 
14
- def compare(str)
15
- erbal_parse(str).should == erb_parse(str)
14
+ it "should default to @output_buffer if the :buffer option is not specified" do
15
+ erbal_parse("", :buffer => nil).should == "@output_buffer = '';@output_buffer"
16
+ end
17
+
18
+ it "should use the buffer specified via the :buffer option" do
19
+ erbal_parse("", :buffer => "_woot").should == "_woot = '';_woot"
20
+ end
21
+
22
+ it "should raise an error if the value given as the :buffer option is not a string" do
23
+ expect { erbal_parse("", :buffer => Class.new) }.should raise_error("wrong argument type Class (expected String)")
24
+ end
25
+
26
+ it "should default to an empty string as the initial buffer value if the :buffer_initial_value is not specified" do
27
+ erbal_parse("", :buffer_initial_value => nil).should == "@output_buffer = '';@output_buffer"
28
+ end
29
+
30
+ it "should use the initial value for the buffer specified by the :buffer_initial_value option" do
31
+ erbal_parse("", :buffer_initial_value => 'MyClass.new').should == "@output_buffer = MyClass.new;@output_buffer"
32
+ end
33
+
34
+ it "should raise an error if the value given as the :buffer_initial_value option is not a string" do
35
+ expect { erbal_parse("", :buffer_initial_value => Class.new) }.should raise_error("wrong argument type Class (expected String)")
16
36
  end
17
37
 
18
38
  it "should parse a blank string" do
data/tasks/gem.rake CHANGED
@@ -2,7 +2,7 @@ require 'rake/gempackagetask'
2
2
  require 'yaml'
3
3
 
4
4
  WIN_SUFFIX = ENV['WIN_SUFFIX'] || 'i386-mswin32'
5
- ERBAL_VERSION = '1.0.rc7'
5
+ ERBAL_VERSION = '1.0.rc8'
6
6
 
7
7
  task :clean => :clobber_package
8
8
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erbal
3
3
  version: !ruby/object:Gem::Version
4
- hash: 977940496
4
+ hash: 977940497
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - rc7
10
- version: 1.0.rc7
9
+ - rc8
10
+ version: 1.0.rc8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ian Leitch