rubysl-erb 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0a309abd0a5fc4a4e438ea153e9afee2d4e185b
4
+ data.tar.gz: a303752e0095e1d345be42cc050ab9b303446bf2
5
+ SHA512:
6
+ metadata.gz: 97eadb1a9718c954ce185f2c1acb9a727b46cc606affbc4d427697fa871bc78eab65a5ed5bde2f90616102abb98e4be946d71f9da9353111ea55a537bf663ad1
7
+ data.tar.gz: 6cbb814906db25026a9ed99ad8b185d54e8de868c996ebe7e233f8a4e2c0594fc93150de2929ff1c05a2564bc765d247519f9be779bb38b0d7bc42ab9b8ef316
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system
4
+ - gem --version
5
+ - gem install rubysl-bundler
6
+ script: bundle exec mspec spec
7
+ rvm:
8
+ - rbx-nightly-18mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubysl-erb.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2013, Brian Shirai
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ 3. Neither the name of the library nor the names of its contributors may be
13
+ used to endorse or promote products derived from this software without
14
+ specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
20
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,29 @@
1
+ # Rubysl::Erb
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubysl-erb'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubysl-erb
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ require "rubysl-erb/version"
2
+
3
+ module RubySL
4
+ module Erb
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module RubySL
2
+ module Erb
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require './lib/rubysl/erb/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "rubysl-erb"
6
+ spec.version = RubySL::Erb::VERSION
7
+ spec.authors = ["Brian Shirai"]
8
+ spec.email = ["brixen@gmail.com"]
9
+ spec.description = %q{Ruby standard library erb.}
10
+ spec.summary = %q{Ruby standard library erb.}
11
+ spec.homepage = "https://github.com/rubysl/rubysl-erb"
12
+ spec.license = "BSD"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "mspec", "~> 1.5"
22
+ spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
23
+ end
@@ -0,0 +1,28 @@
1
+ require 'erb'
2
+
3
+ describe "ERB#def_class" do
4
+
5
+ it "return an unnamed class which has instance method to render eRuby script" do
6
+ input = <<'END'
7
+ @arg1=<%=@arg1.inspect%>
8
+ @arg2=<%=@arg2.inspect%>
9
+ END
10
+ expected = <<'END'
11
+ @arg1="foo"
12
+ @arg2=123
13
+ END
14
+ class MyClass1ForErb_
15
+ def initialize(arg1, arg2)
16
+ @arg1 = arg1; @arg2 = arg2
17
+ end
18
+ end
19
+ filename = 'example.rhtml'
20
+ #erb = ERB.new(File.read(filename))
21
+ erb = ERB.new(input)
22
+ erb.filename = filename
23
+ MyClass1ForErb = erb.def_class(MyClass1ForErb_, 'render()')
24
+ MyClass1ForErb.method_defined?(:render).should == true
25
+ MyClass1ForErb.new('foo', 123).render().should == expected
26
+ end
27
+
28
+ end
@@ -0,0 +1,25 @@
1
+ require 'erb'
2
+
3
+ describe "ERB#def_method" do
4
+
5
+ it "define module's instance method to render eRuby file" do
6
+ input = <<'END'
7
+ arg1=<%= arg1.inspect %>
8
+ arg2=<%= arg2.inspect %>
9
+ END
10
+ expected = <<'END'
11
+ arg1="foo"
12
+ arg2=123
13
+ END
14
+ #
15
+ filename = 'example.rhtml' # 'arg1' and 'arg2' are used in example.rhtml
16
+ #erb = ERB.new(File.read(filename))
17
+ erb = ERB.new(input)
18
+ class MyClass0ForErb
19
+ end
20
+ erb.def_method(MyClass0ForErb, 'render(arg1, arg2)', filename)
21
+ MyClass0ForErb.method_defined?(:render)
22
+ MyClass0ForErb.new.render('foo', 123).should == expected
23
+ end
24
+
25
+ end
@@ -0,0 +1,26 @@
1
+ require 'erb'
2
+
3
+ describe "ERB#def_module" do
4
+
5
+ it "return unnamed module which has instance method to render eRuby" do
6
+ input = <<'END'
7
+ arg1=<%= arg1.inspect %>
8
+ arg2=<%= arg2.inspect %>
9
+ END
10
+ expected = <<'END'
11
+ arg1="foo"
12
+ arg2=123
13
+ END
14
+ filename = 'example.rhtml'
15
+ #erb = ERB.new(File.read(filename))
16
+ erb = ERB.new(input)
17
+ erb.filename = filename
18
+ MyModule2ForErb = erb.def_module('render(arg1, arg2)')
19
+ MyModule2ForErb.method_defined?(':render')
20
+ class MyClass2ForErb
21
+ include MyModule2ForErb
22
+ end
23
+ MyClass2ForErb.new.render('foo', 123).should == expected
24
+ end
25
+
26
+ end
@@ -0,0 +1,62 @@
1
+ require 'erb'
2
+
3
+ describe "ERB::DefMethod.def_erb_method" do
4
+
5
+
6
+ input = <<'END'
7
+ <% for item in @items %>
8
+ <b><%= item %></b>
9
+ <% end %>
10
+ END
11
+
12
+
13
+ it "define method to render eRuby file as an instance method of current module" do
14
+ expected = <<'END'
15
+
16
+ <b>10</b>
17
+
18
+ <b>20</b>
19
+
20
+ <b>30</b>
21
+
22
+ END
23
+ #
24
+ begin
25
+ file = tmp('_example.rhtml')
26
+ File.open(file, 'w') {|f| f.write(input) }
27
+ klass = Class.new do
28
+ extend ERB::DefMethod
29
+ def_erb_method('render()', file)
30
+ def initialize(items)
31
+ @items = items
32
+ end
33
+ end
34
+ klass.new([10,20,30]).render().should == expected
35
+ ensure
36
+ rm_r file
37
+ end
38
+
39
+ end
40
+
41
+
42
+ it "define method to render eRuby object as an instance method of current module" do
43
+ expected = <<'END'
44
+ <b>10</b>
45
+ <b>20</b>
46
+ <b>30</b>
47
+ END
48
+ #
49
+ MY_INPUT4_FOR_ERB = input
50
+ class MyClass4ForErb
51
+ extend ERB::DefMethod
52
+ erb = ERB.new(MY_INPUT4_FOR_ERB, nil, '<>')
53
+ def_erb_method('render()', erb)
54
+ def initialize(items)
55
+ @items = items
56
+ end
57
+ end
58
+ MyClass4ForErb.new([10,20,30]).render().should == expected
59
+ end
60
+
61
+
62
+ end
@@ -0,0 +1,53 @@
1
+ require 'erb'
2
+
3
+ describe "ERB#filename" do
4
+ # TODO: why does this fail on rubinius?
5
+ it "raises an exception if there are errors processing content" do
6
+ filename = 'foobar.rhtml'
7
+ erb = ERB.new('<% if true %>') # will raise SyntaxError
8
+ erb.filename = filename
9
+ lambda {
10
+ begin
11
+ erb.result(binding)
12
+ rescue Exception => e
13
+ @ex = e
14
+ raise e
15
+ end
16
+ }.should raise_error(SyntaxError)
17
+ expected = filename
18
+
19
+ @ex.message =~ /^(.*?):(\d+): /
20
+ $1.should == expected
21
+ $2.to_i.should == 1
22
+
23
+ # TODO: why is this different on rubinius?
24
+ extended_on :rubinius do
25
+ @ex.file.should == expected
26
+ @ex.line.should == 1
27
+ end
28
+ end
29
+
30
+ # TODO: why does this fail on rubinius?
31
+ it "uses '(erb)' as filename when filename is not set" do
32
+ erb = ERB.new('<% if true %>') # will raise SyntaxError
33
+ lambda {
34
+ begin
35
+ erb.result(binding)
36
+ rescue Exception => e
37
+ @ex = e
38
+ raise e
39
+ end
40
+ }.should raise_error(SyntaxError)
41
+ expected = '(erb)'
42
+
43
+ @ex.message =~ /^(.*?):(\d+): /
44
+ $1.should == expected
45
+ $2.to_i.should == 1
46
+
47
+ # TODO: why is this different on rubinius?
48
+ extended_on :rubinius do
49
+ @ex.file.should == expected
50
+ @ex.line.should == 1
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,152 @@
1
+ require 'erb'
2
+
3
+ describe "ERB.new" do
4
+ before :all do
5
+ @eruby_str = <<'END'
6
+ <ul>
7
+ <% list = [1,2,3] %>
8
+ <% for item in list %>
9
+ <% if item %>
10
+ <li><%= item %></li>
11
+ <% end %>
12
+ <% end %>
13
+ </ul>
14
+ END
15
+
16
+ @eruby_str2 = <<'END'
17
+ <ul>
18
+ % list = [1,2,3]
19
+ %for item in list
20
+ % if item
21
+ <li><%= item %>
22
+ <% end %>
23
+ <% end %>
24
+ </ul>
25
+ %%%
26
+ END
27
+
28
+ end
29
+
30
+ it "compiles eRuby script into ruby code when trim mode is 0 or not specified" do
31
+ expected = "<ul>\n\n\n\n<li>1</li>\n\n\n\n<li>2</li>\n\n\n\n<li>3</li>\n\n\n</ul>\n"
32
+ [0, '', nil].each do |trim_mode|
33
+ ERB.new(@eruby_str, nil, trim_mode).result.should == expected
34
+ end
35
+ end
36
+
37
+ it "removes '\n' when trim_mode is 1 or '>'" do
38
+ expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
39
+ [1, '>'].each do |trim_mode|
40
+ ERB.new(@eruby_str, nil, trim_mode).result.should == expected
41
+ end
42
+ end
43
+
44
+ it "removes spaces at beginning of line and '\n' when trim_mode is 2 or '<>'" do
45
+ expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
46
+ [2, '<>'].each do |trim_mode|
47
+ ERB.new(@eruby_str, nil, trim_mode).result.should == expected
48
+ end
49
+ end
50
+
51
+ it "removes spaces around '<%- -%>' when trim_mode is '-'" do
52
+ expected = "<ul>\n <li>1 <li>2 <li>3</ul>\n"
53
+ input = <<'END'
54
+ <ul>
55
+ <%- for item in [1,2,3] -%>
56
+ <%- if item -%>
57
+ <li><%= item -%>
58
+ <%- end -%>
59
+ <%- end -%>
60
+ </ul>
61
+ END
62
+
63
+ ERB.new(input, nil, '-').result.should == expected
64
+ end
65
+
66
+
67
+ it "not support '<%-= expr %> even when trim_mode is '-'" do
68
+
69
+ input = <<'END'
70
+ <p>
71
+ <%= expr -%>
72
+ <%-= expr -%>
73
+ </p>
74
+ END
75
+
76
+ lambda { ERB.new(input, nil, '-').result }.should raise_error
77
+ end
78
+
79
+ ruby_bug "#213", "1.8.7" do
80
+ it "regards lines starting with '%' as '<% ... %>' when trim_mode is '%'" do
81
+ expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n\n</ul>\n%%\n"
82
+ ERB.new(@eruby_str2, nil, "%").result.should == expected
83
+ end
84
+ end
85
+ it "regards lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%>'" do
86
+ expected = "<ul>\n <li>1 <li>2 <li>3 </ul>\n%%\n"
87
+ ERB.new(@eruby_str2, nil, '%>').result.should == expected
88
+ end
89
+
90
+
91
+ it "regard lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%<>'" do
92
+ expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n</ul>\n%%\n"
93
+ ERB.new(@eruby_str2, nil, '%<>').result.should == expected
94
+ end
95
+
96
+
97
+ it "regard lines starting with '%' as '<% ... %>' and spaces around '<%- -%>' when trim_mode is '%-'" do
98
+
99
+ expected = "<ul>\n<li>1</li>\n<li>2</li>\n</ul>\n%%\n"
100
+ input = <<'END'
101
+ <ul>
102
+ %list = [1,2]
103
+ %for item in list
104
+ <li><%= item %></li>
105
+ <% end %></ul>
106
+ %%%
107
+ END
108
+
109
+ trim_mode = '%-'
110
+ ERB.new(input, nil, '%-').result.should == expected
111
+ end
112
+
113
+ not_compliant_on :rubinius do
114
+ it "accepts a safe level as second argument" do
115
+ input = "<b><%=- 2+2 %>"
116
+ safe_level = 3
117
+ lambda { ERB.new(input, safe_level).result }.should_not raise_error
118
+ end
119
+ end
120
+
121
+ it "changes '_erbout' variable name in the produced source" do
122
+ input = @eruby_str
123
+ match_erbout = ERB.new(input, nil, nil).src
124
+ match_buf = ERB.new(input, nil, nil, 'buf').src
125
+ match_erbout.gsub("_erbout", "buf").should == match_buf
126
+ end
127
+
128
+
129
+ it "ignores '<%# ... %>'" do
130
+ input = <<'END'
131
+ <%# for item in list %>
132
+ <b><%#= item %></b>
133
+ <%# end %>
134
+ END
135
+ ERB.new(input).result.should == "\n<b></b>\n\n"
136
+ ERB.new(input, nil, '<>').result.should == "<b></b>\n"
137
+ end
138
+
139
+ ruby_version_is ""..."2.0" do
140
+ it "remember local variables defined previous one" do
141
+ ERB.new(@eruby_str).result
142
+ ERB.new("<%= list.inspect %>").result.should == "[1, 2, 3]"
143
+ end
144
+ end
145
+
146
+ ruby_version_is "2.0" do
147
+ it "forget local variables defined previous one" do
148
+ ERB.new(@eruby_str).result
149
+ lambda{ ERB.new("<%= list %>").result }.should raise_error(NameError)
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,101 @@
1
+ require 'erb'
2
+
3
+ describe "ERB#result" do
4
+
5
+
6
+ it "return the result of compiled ruby code" do
7
+ input = <<'END'
8
+ <ul>
9
+ <% for item in list %>
10
+ <li><%= item %>
11
+ <% end %>
12
+ </ul>
13
+ END
14
+ expected = <<'END'
15
+ <ul>
16
+
17
+ <li>AAA
18
+
19
+ <li>BBB
20
+
21
+ <li>CCC
22
+
23
+ </ul>
24
+ END
25
+ erb = ERB.new(input)
26
+ list = %w[AAA BBB CCC]
27
+ actual = erb.result(binding)
28
+ actual.should == expected
29
+ end
30
+
31
+
32
+ it "share local variables" do
33
+ input = "<% var = 456 %>"
34
+ expected = 456
35
+ var = 123
36
+ ERB.new(input).result(binding)
37
+ var.should == expected
38
+ end
39
+
40
+
41
+ it "is not able to h() or u() unless including ERB::Util" do
42
+ input = "<%=h '<>' %>"
43
+ lambda {
44
+ ERB.new(input).result()
45
+ }.should raise_error(NameError)
46
+ end
47
+
48
+
49
+ it "is able to h() or u() if ERB::Util is included" do
50
+ class MyERB1
51
+ include ERB::Util
52
+ def main
53
+ input = "<%=h '<>' %>"
54
+ return ERB.new(input).result(binding)
55
+ end
56
+ end
57
+ expected = '&lt;&gt;'
58
+ actual = MyERB1.new.main()
59
+ actual.should == expected
60
+ end
61
+
62
+
63
+ it "use TOPLEVEL_BINDING if binding is not passed" do
64
+ class MyERB2
65
+ include ERB::Util
66
+ def main1
67
+ #input = "<%= binding.to_s %>"
68
+ input = "<%= _xxx_var_ %>"
69
+ return ERB.new(input).result()
70
+ end
71
+ def main2
72
+ input = "<%=h '<>' %>"
73
+ return ERB.new(input).result()
74
+ end
75
+ end
76
+
77
+ eval '_xxx_var_ = 123', TOPLEVEL_BINDING
78
+ expected = '123'
79
+ MyERB2.new.main1().should == expected
80
+
81
+ lambda {
82
+ actual = MyERB2.new.main2()
83
+ }.should raise_error(NameError)
84
+ end
85
+
86
+
87
+ #--
88
+ #it "does not change current $SAFE even if safe_level is specifiled at ERB#initialize" do
89
+ # input = "$SAFE=<%=$SAFE.inspect%>"
90
+ # expected = "$SAFE=2"
91
+ # safe_level = 2
92
+ # erb = ERB.new(input, safe_level)
93
+ # curr_safe_level = $SAFE
94
+ # erb.result(binding()).should == expected
95
+ # $SAFE.should == curr_safe_level # BUG: $SAFE will be changed in current Rubinius
96
+ #end
97
+ #++
98
+
99
+
100
+ end
101
+
@@ -0,0 +1,96 @@
1
+ require 'erb'
2
+
3
+ describe "ERB#run" do
4
+ # TODO: what is this? why does it not use
5
+ # lambda { ... }.should output
6
+ def _steal_stdout
7
+ orig = $stdout
8
+ s = ''
9
+ def s.write(arg); self << arg.to_s; end
10
+ $stdout = s
11
+ begin
12
+ yield
13
+ ensure
14
+ $stdout = orig
15
+ end
16
+ return s
17
+ end
18
+
19
+ it "print the result of compiled ruby code" do
20
+ input = <<END
21
+ <ul>
22
+ <% for item in list %>
23
+ <li><%= item %>
24
+ <% end %>
25
+ </ul>
26
+ END
27
+ expected = <<END
28
+ <ul>
29
+
30
+ <li>AAA
31
+
32
+ <li>BBB
33
+
34
+ <li>CCC
35
+
36
+ </ul>
37
+ END
38
+ erb = ERB.new(input)
39
+ list = %w[AAA BBB CCC]
40
+ actual = _steal_stdout { erb.run(binding) }
41
+ actual.should == expected
42
+ end
43
+
44
+ it "share local variables" do
45
+ input = "<% var = 456 %>"
46
+ expected = 456
47
+ var = 123
48
+ _steal_stdout { ERB.new(input).run(binding) }
49
+ var.should == expected
50
+ end
51
+
52
+ it "is not able to h() or u() unless including ERB::Util" do
53
+ input = "<%=h '<>' %>"
54
+ lambda {
55
+ _steal_stdout { ERB.new(input).run() }
56
+ }.should raise_error(NameError)
57
+ end
58
+
59
+ it "is able to h() or u() if ERB::Util is included" do
60
+ class MyERB1
61
+ include ERB::Util
62
+ def main
63
+ input = "<%=h '<>' %>"
64
+ ERB.new(input).run(binding)
65
+ end
66
+ end
67
+ expected = '&lt;&gt;'
68
+ actual = _steal_stdout { MyERB1.new.main() }
69
+ actual.should == expected
70
+ end
71
+
72
+ it "use TOPLEVEL_BINDING if binding is not passed" do
73
+ class MyERB2
74
+ include ERB::Util
75
+ def main1
76
+ #input = "<%= binding.to_s %>"
77
+ input = "<%= _xxx_var_ %>"
78
+ return ERB.new(input).run()
79
+ end
80
+ def main2
81
+ input = "<%=h '<>' %>"
82
+ return ERB.new(input).run()
83
+ end
84
+ end
85
+
86
+ eval '_xxx_var_ = 123', TOPLEVEL_BINDING
87
+ expected = '123'
88
+ actual = _steal_stdout { MyERB2.new.main1() }
89
+ actual.should == expected
90
+
91
+ lambda {
92
+ _steal_stdout { MyERB2.new.main2() }
93
+ }.should raise_error(NameError)
94
+ end
95
+ end
96
+
@@ -0,0 +1,32 @@
1
+ require 'erb'
2
+
3
+ describe "ERB#src" do
4
+
5
+ it "returns the compiled ruby code evaluated to a String" do
6
+ # note that what concrete code is emitted is not guaranteed.
7
+
8
+ input = <<'END'
9
+ <ul>
10
+ <% for item in list %>
11
+ <li><%= item %>
12
+ <% end %>
13
+ </ul>
14
+ END
15
+
16
+ expected = <<'END'
17
+ <ul>
18
+
19
+ <li>AAA
20
+
21
+ <li>BBB
22
+
23
+ <li>CCC
24
+
25
+ </ul>
26
+ END
27
+
28
+ list = %w[AAA BBB CCC]
29
+ eval(ERB.new(input).src).should == expected
30
+ end
31
+
32
+ end
@@ -0,0 +1,6 @@
1
+ require 'erb'
2
+ require File.expand_path('../shared/html_escape', __FILE__)
3
+
4
+ describe "ERB::Util.h" do
5
+ it_behaves_like :erb_util_html_escape, :h
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'erb'
2
+ require File.expand_path('../shared/html_escape', __FILE__)
3
+
4
+ describe "ERB::Util.html_escape" do
5
+ it_behaves_like :erb_util_html_escape, :html_escape
6
+ end
7
+
@@ -0,0 +1,58 @@
1
+ describe :erb_util_html_escape, :shared => true do
2
+ ruby_version_is ""..."2.0" do
3
+ it "escape '& < > \"' to '&amp; &lt; &gt; &quot;" do
4
+ input = '& < > "'
5
+ expected = '&amp; &lt; &gt; &quot;'
6
+ ERB::Util.__send__(@method, input).should == expected
7
+ end
8
+
9
+ it "not escape characters except '& < > \"'" do
10
+ input = (0x20..0x7E).to_a.collect {|ch| ch.chr}.join('')
11
+ expected = input.gsub(/&/,'&amp;').gsub(/</,'&lt;').gsub(/>/,'&gt;').gsub(/"/,'&quot;')
12
+ ERB::Util.__send__(@method, input).should == expected
13
+ end
14
+ end
15
+
16
+ ruby_version_is "2.0" do
17
+ it "escape (& < > \" ') to (&amp; &lt; &gt; &quot; &#39;)" do
18
+ input = '& < > " \''
19
+ expected = '&amp; &lt; &gt; &quot; &#39;'
20
+ ERB::Util.__send__(@method, input).should == expected
21
+ end
22
+
23
+ it "not escape characters except (& < > \" ')" do
24
+ input = (0x20..0x7E).to_a.collect {|ch| ch.chr}.join('')
25
+ expected = input.
26
+ gsub(/&/,'&amp;').
27
+ gsub(/</,'&lt;').
28
+ gsub(/>/,'&gt;').
29
+ gsub(/'/,'&#39;').
30
+ gsub(/"/,'&quot;')
31
+ ERB::Util.__send__(@method, input).should == expected
32
+ end
33
+ end
34
+
35
+ it "return empty string when argument is nil" do
36
+ input = nil
37
+ expected = ''
38
+ ERB::Util.__send__(@method, input).should == expected
39
+ end
40
+
41
+ it "returns string when argument is number" do
42
+ input = 123
43
+ expected = '123'
44
+ ERB::Util.__send__(@method, input).should == expected
45
+ input = 3.14159
46
+ expected = '3.14159'
47
+ ERB::Util.__send__(@method, input).should == expected
48
+ end
49
+
50
+ it "returns string when argument is boolean" do
51
+ input = true
52
+ expected = 'true'
53
+ ERB::Util.__send__(@method, input).should == expected
54
+ input = false
55
+ expected = 'false'
56
+ ERB::Util.__send__(@method, input).should == expected
57
+ end
58
+ end
@@ -0,0 +1,38 @@
1
+ describe :erb_util_url_encode, :shared => true do
2
+ it "encode characters" do
3
+ #input = (0x20..0x7E).to_a.collect{|ch| ch.chr}.join
4
+ input = " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
5
+ expected = "%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
6
+ ERB::Util.__send__(@method, input).should == expected
7
+ end
8
+
9
+ it "encode unicode string" do
10
+ input = "http://ja.wikipedia.org/wiki/\343\203\255\343\203\240\343\202\271\343\202\253\343\203\273\343\203\221\343\203\255\343\203\273\343\202\246\343\203\253\343\203\273\343\203\251\343\203\224\343\203\245\343\202\277"
11
+ expected = 'http%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%E3%83%AD%E3%83%A0%E3%82%B9%E3%82%AB%E3%83%BB%E3%83%91%E3%83%AD%E3%83%BB%E3%82%A6%E3%83%AB%E3%83%BB%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF'
12
+ ERB::Util.__send__(@method, input).should == expected
13
+ end
14
+
15
+ it "returns empty string when argument is nil" do
16
+ input = nil
17
+ expected = ''
18
+ ERB::Util.__send__(@method, input).should == expected
19
+ end
20
+
21
+ it "returns string when argument is number" do
22
+ input = 123
23
+ expected = '123'
24
+ ERB::Util.__send__(@method, input).should == expected
25
+ input = 3.14159
26
+ expected = '3.14159'
27
+ ERB::Util.__send__(@method, input).should == expected
28
+ end
29
+
30
+ it "returns string when argument is boolean" do
31
+ input = true
32
+ expected = 'true'
33
+ ERB::Util.__send__(@method, input).should == expected
34
+ input = false
35
+ expected = 'false'
36
+ ERB::Util.__send__(@method, input).should == expected
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ require 'erb'
2
+ require File.expand_path('../shared/url_encode', __FILE__)
3
+
4
+ describe "ERB::Util.u" do
5
+ it_behaves_like :erb_util_url_encode, :u
6
+ end
7
+
@@ -0,0 +1,6 @@
1
+ require 'erb'
2
+ require File.expand_path('../shared/url_encode', __FILE__)
3
+
4
+ describe "ERB::Util.url_encode" do
5
+ it_behaves_like :erb_util_url_encode, :url_encode
6
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubysl-erb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Shirai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubysl-prettyprint
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description: Ruby standard library erb.
70
+ email:
71
+ - brixen@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - lib/rubysl/erb.rb
83
+ - lib/rubysl/erb/version.rb
84
+ - rubysl-erb.gemspec
85
+ - spec/def_class_spec.rb
86
+ - spec/def_method_spec.rb
87
+ - spec/def_module_spec.rb
88
+ - spec/defmethod/def_erb_method_spec.rb
89
+ - spec/filename_spec.rb
90
+ - spec/new_spec.rb
91
+ - spec/result_spec.rb
92
+ - spec/run_spec.rb
93
+ - spec/src_spec.rb
94
+ - spec/util/h_spec.rb
95
+ - spec/util/html_escape_spec.rb
96
+ - spec/util/shared/html_escape.rb
97
+ - spec/util/shared/url_encode.rb
98
+ - spec/util/u_spec.rb
99
+ - spec/util/url_encode_spec.rb
100
+ homepage: https://github.com/rubysl/rubysl-erb
101
+ licenses:
102
+ - BSD
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.7
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Ruby standard library erb.
124
+ test_files:
125
+ - spec/def_class_spec.rb
126
+ - spec/def_method_spec.rb
127
+ - spec/def_module_spec.rb
128
+ - spec/defmethod/def_erb_method_spec.rb
129
+ - spec/filename_spec.rb
130
+ - spec/new_spec.rb
131
+ - spec/result_spec.rb
132
+ - spec/run_spec.rb
133
+ - spec/src_spec.rb
134
+ - spec/util/h_spec.rb
135
+ - spec/util/html_escape_spec.rb
136
+ - spec/util/shared/html_escape.rb
137
+ - spec/util/shared/url_encode.rb
138
+ - spec/util/u_spec.rb
139
+ - spec/util/url_encode_spec.rb