trenni 2.1.0 → 3.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,69 @@
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'trenni/tag'
22
+
23
+ RSpec.describe Trenni::Tag.new("body", false, class: 'main') do
24
+ it "should have name" do
25
+ expect(subject.name).to be == "body"
26
+ end
27
+
28
+ it "should be open by default" do
29
+ expect(subject).to_not be_self_closed
30
+ end
31
+
32
+ it "should have an attribute" do
33
+ expect(subject.attributes).to include(:class)
34
+ expect(subject[:class]).to be == 'main'
35
+ expect(subject.to_s).to include('class="main"')
36
+ end
37
+ end
38
+
39
+ RSpec.describe Trenni::Tag.new("button", true, 'onclick' => 'javascript:alert("Hello World")') do
40
+ it "should have name" do
41
+ expect(subject.name).to be == "button"
42
+ end
43
+
44
+ it "should have an attribute" do
45
+ expect(subject.attributes).to include('onclick')
46
+ end
47
+
48
+ it "should generate valid string" do
49
+ expect(subject.to_s).to be == '<button onclick="javascript:alert(&quot;Hello World&quot;)"/>'
50
+ end
51
+ end
52
+
53
+ RSpec.describe Trenni::Tag.new("p", false, {}) do
54
+ it "should include content" do
55
+ expect(subject.to_s("Hello World")).to be == "<p>Hello World</p>"
56
+ end
57
+ end
58
+
59
+ RSpec.describe "namespace:name" do
60
+ it "should have namespace" do
61
+ expect(Trenni::Tag.split(subject)).to be == ['namespace', 'name']
62
+ end
63
+ end
64
+
65
+ RSpec.describe "name" do
66
+ it "should not have namespace" do
67
+ expect(Trenni::Tag.split(subject)).to be == [nil, 'name']
68
+ end
69
+ end
@@ -36,6 +36,24 @@ RSpec.describe Trenni::Template do
36
36
  # expect(object_time).to be < binding_time
37
37
  # end
38
38
 
39
+ let(:interpolations_path) {File.expand_path('template_spec/interpolations.trenni', __dir__)}
40
+
41
+ it "should be fast for lots of interpolations" do
42
+ trenni_template = Trenni::MarkupTemplate.new(Trenni::Buffer.load_file(interpolations_path))
43
+ model = Model.new
44
+
45
+ Benchmark.ips do |x|
46
+ x.report("Trenni") do |times|
47
+ i = 0
48
+
49
+ while i < times
50
+ trenni_template.to_string(model)
51
+
52
+ i += 1
53
+ end
54
+ end
55
+ end
56
+ end
39
57
 
40
58
  it "should be fast for basic templates" do
41
59
  trenni_template = Trenni::Template.new(Trenni::Buffer.load('Hi, #{name}!'))
@@ -0,0 +1,6 @@
1
+ <?r 1000.downto(1) do |i| ?>
2
+ <p>
3
+ #{i} bottles of beer on the wall, #{i} bottles of beer.</br>
4
+ Take one down and pass it around, #{i-1} bottles of beer on the wall.
5
+ </p>
6
+ <?r end ?>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trenni
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-13 00:00:00.000000000 Z
11
+ date: 2017-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,10 +74,14 @@ files:
74
74
  - benchmark/interpolation_vs_concat.rb
75
75
  - benchmark/io_vs_string.rb
76
76
  - entities.json
77
+ - ext/trenni/escape.c
78
+ - ext/trenni/escape.h
77
79
  - ext/trenni/extconf.rb
78
80
  - ext/trenni/markup.c
79
81
  - ext/trenni/markup.h
80
82
  - ext/trenni/markup.rl
83
+ - ext/trenni/tag.c
84
+ - ext/trenni/tag.h
81
85
  - ext/trenni/template.c
82
86
  - ext/trenni/template.h
83
87
  - ext/trenni/template.rl
@@ -98,19 +102,22 @@ files:
98
102
  - lib/trenni/parse_error.rb
99
103
  - lib/trenni/parsers.rb
100
104
  - lib/trenni/strings.rb
101
- - lib/trenni/substitutions.rb
105
+ - lib/trenni/tag.rb
102
106
  - lib/trenni/template.rb
103
107
  - lib/trenni/version.rb
104
108
  - parsers/trenni/entities.rl
105
109
  - parsers/trenni/markup.rl
106
110
  - parsers/trenni/template.rl
111
+ - spec/spec_helper.rb
107
112
  - spec/trenni/builder_spec.rb
108
113
  - spec/trenni/corpus/large.rb
109
114
  - spec/trenni/corpus/large.xhtml
110
115
  - spec/trenni/markup_parser_spec.rb
116
+ - spec/trenni/markup_performance_spec.rb
111
117
  - spec/trenni/markup_spec.rb
112
118
  - spec/trenni/parsers_performance_spec.rb
113
119
  - spec/trenni/strings_spec.rb
120
+ - spec/trenni/tag_spec.rb
114
121
  - spec/trenni/template_error_spec.rb
115
122
  - spec/trenni/template_performance_spec.rb
116
123
  - spec/trenni/template_spec.rb
@@ -119,6 +126,7 @@ files:
119
126
  - spec/trenni/template_spec/capture.trenni
120
127
  - spec/trenni/template_spec/error.trenni
121
128
  - spec/trenni/template_spec/escaped.trenni
129
+ - spec/trenni/template_spec/interpolations.trenni
122
130
  - spec/trenni/template_spec/large.trenni
123
131
  - spec/trenni/template_spec/nested.trenni
124
132
  - trenni.gemspec
@@ -141,18 +149,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
149
  version: '0'
142
150
  requirements: []
143
151
  rubyforge_project:
144
- rubygems_version: 2.5.2
152
+ rubygems_version: 2.6.10
145
153
  signing_key:
146
154
  specification_version: 4
147
155
  summary: A fast native templating system that compiles directly to Ruby code.
148
156
  test_files:
157
+ - spec/spec_helper.rb
149
158
  - spec/trenni/builder_spec.rb
150
159
  - spec/trenni/corpus/large.rb
151
160
  - spec/trenni/corpus/large.xhtml
152
161
  - spec/trenni/markup_parser_spec.rb
162
+ - spec/trenni/markup_performance_spec.rb
153
163
  - spec/trenni/markup_spec.rb
154
164
  - spec/trenni/parsers_performance_spec.rb
155
165
  - spec/trenni/strings_spec.rb
166
+ - spec/trenni/tag_spec.rb
156
167
  - spec/trenni/template_error_spec.rb
157
168
  - spec/trenni/template_performance_spec.rb
158
169
  - spec/trenni/template_spec.rb
@@ -161,5 +172,6 @@ test_files:
161
172
  - spec/trenni/template_spec/capture.trenni
162
173
  - spec/trenni/template_spec/error.trenni
163
174
  - spec/trenni/template_spec/escaped.trenni
175
+ - spec/trenni/template_spec/interpolations.trenni
164
176
  - spec/trenni/template_spec/large.trenni
165
177
  - spec/trenni/template_spec/nested.trenni
@@ -1,45 +0,0 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- module Trenni
22
- class Substitutions
23
- def initialize(tokens)
24
- @tokens = tokens
25
- end
26
-
27
- def patterns
28
- @tokens.keys
29
- end
30
-
31
- def pattern
32
- @pattern ||= Regexp.union(patterns)
33
- end
34
-
35
- attr :tokens
36
-
37
- def gsub!(string)
38
- string.gsub!(pattern) {|match| @tokens[match]}
39
- end
40
-
41
- def gsub(string)
42
- string.gsub(pattern) {|match| @tokens[match]}
43
- end
44
- end
45
- end