string_template 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/MIT-LICENSE +21 -0
- data/README.md +69 -0
- data/Rakefile +10 -0
- data/benchmark.rb +15 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hello.erb +50 -0
- data/hello.string +50 -0
- data/lib/string_template.rb +4 -0
- data/lib/string_template/handler.rb +13 -0
- data/lib/string_template/railtie.rb +11 -0
- data/string_template.gemspec +28 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1676affa8a6c17cb3a067f44f136d486175eb9929991cb45eff8f6f2cc6a5866
|
4
|
+
data.tar.gz: 74fde3634a89fd89673b511c7498450127ca4e4a28217e1a13be4d616d4d9d45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ae08e930afd613d01ad6a6ca0fffc7283a30c9ab43f5b2b60c32cfe5890f0d768583d794e8e2abdbacc82618f42fd7a01e72f2107c6424a425f2b0c1ae77d1b
|
7
|
+
data.tar.gz: 1f53eef7a9caa329b86df4f25523e9d08a8380d30aac46c991d0d6bf45a48ba803d17d29dacb9d95ab425f11c53d218f0d4acd9c03280f777d23f2294fadaa27
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Akira Matsuda
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# StringTemplate
|
2
|
+
|
3
|
+
The fastest template engine for Rails.
|
4
|
+
|
5
|
+
|
6
|
+
## Concept
|
7
|
+
|
8
|
+
Ruby's String literal has such a powerful interpolation mechanism.
|
9
|
+
It's almost a template engine, it's the fastest way to compose a String, and the syntax is already very well known by every Ruby programmer.
|
10
|
+
Why don't we use this for the view files in our apps?
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'string_template'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
% bundle
|
24
|
+
|
25
|
+
|
26
|
+
## Syntax
|
27
|
+
|
28
|
+
StringTemplate's syntax is based on Ruby's String interpolation.
|
29
|
+
Plus, you can use Action View features.
|
30
|
+
Please take a look at the tests for actual examples.
|
31
|
+
|
32
|
+
|
33
|
+
## Filenames
|
34
|
+
By default, string\_template renders view files with `.string` extension, e.g. `app/views/posts/show.html.string`
|
35
|
+
|
36
|
+
|
37
|
+
## So, Should We Rewrite Everything with This?
|
38
|
+
string\_template may not be the best choice as a general purpose template engine.
|
39
|
+
It may sometimes be hard to express your template in a simple and maintainable code, especially when the template includes some business logic.
|
40
|
+
So this template engine is recommended to use only for performance hotspots.
|
41
|
+
For other templates, you might better use your favorite template engine such as haml, or haml, or haml.
|
42
|
+
|
43
|
+
|
44
|
+
## Benchmark
|
45
|
+
Following is the benchmark result showing how string\_template is faster than ERB, executed on Ruby trunk (2.6).
|
46
|
+
This repo includes [this actual benchmarking script](https://github.com/amatsuda/string_template/blob/master/benchmark.rb) so that you can try it on your machine.
|
47
|
+
|
48
|
+
```
|
49
|
+
% ruby benchmark.rb
|
50
|
+
Warming up --------------------------------------
|
51
|
+
erb 986.519 i/100ms
|
52
|
+
string 1.614k i/100ms
|
53
|
+
Calculating -------------------------------------
|
54
|
+
erb 10.598k i/s - 49.325k in 4.654229s
|
55
|
+
string 19.550k i/s - 80.686k in 4.127156s
|
56
|
+
|
57
|
+
Comparison:
|
58
|
+
string: 19550.0 i/s
|
59
|
+
erb: 10597.9 i/s - 1.84x slower
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/amatsuda/string_template.
|
66
|
+
|
67
|
+
## License
|
68
|
+
|
69
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/benchmark.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
require 'action_view'
|
5
|
+
require_relative 'lib/string_template'
|
6
|
+
StringTemplate::Railtie.run_initializers
|
7
|
+
require 'action_view/base'
|
8
|
+
require 'benchmark_driver'
|
9
|
+
|
10
|
+
Benchmark.driver do |x|
|
11
|
+
x.prelude %{ (view = Class.new(ActionView::Base).new('.')).instance_variable_set(:@world, 'world!') }
|
12
|
+
x.report 'erb', %{ view.render(template: 'hello', handlers: 'erb') }
|
13
|
+
x.report 'string', %{ view.render(template: 'hello', handlers: 'string') }
|
14
|
+
x.compare!
|
15
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "string_template"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/hello.erb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
hello, <%= @world %>
|
2
|
+
hello, <%= @world %>
|
3
|
+
hello, <%= @world %>
|
4
|
+
hello, <%= @world %>
|
5
|
+
hello, <%= @world %>
|
6
|
+
hello, <%= @world %>
|
7
|
+
hello, <%= @world %>
|
8
|
+
hello, <%= @world %>
|
9
|
+
hello, <%= @world %>
|
10
|
+
hello, <%= @world %>
|
11
|
+
hello, <%= @world %>
|
12
|
+
hello, <%= @world %>
|
13
|
+
hello, <%= @world %>
|
14
|
+
hello, <%= @world %>
|
15
|
+
hello, <%= @world %>
|
16
|
+
hello, <%= @world %>
|
17
|
+
hello, <%= @world %>
|
18
|
+
hello, <%= @world %>
|
19
|
+
hello, <%= @world %>
|
20
|
+
hello, <%= @world %>
|
21
|
+
hello, <%= @world %>
|
22
|
+
hello, <%= @world %>
|
23
|
+
hello, <%= @world %>
|
24
|
+
hello, <%= @world %>
|
25
|
+
hello, <%= @world %>
|
26
|
+
hello, <%= @world %>
|
27
|
+
hello, <%= @world %>
|
28
|
+
hello, <%= @world %>
|
29
|
+
hello, <%= @world %>
|
30
|
+
hello, <%= @world %>
|
31
|
+
hello, <%= @world %>
|
32
|
+
hello, <%= @world %>
|
33
|
+
hello, <%= @world %>
|
34
|
+
hello, <%= @world %>
|
35
|
+
hello, <%= @world %>
|
36
|
+
hello, <%= @world %>
|
37
|
+
hello, <%= @world %>
|
38
|
+
hello, <%= @world %>
|
39
|
+
hello, <%= @world %>
|
40
|
+
hello, <%= @world %>
|
41
|
+
hello, <%= @world %>
|
42
|
+
hello, <%= @world %>
|
43
|
+
hello, <%= @world %>
|
44
|
+
hello, <%= @world %>
|
45
|
+
hello, <%= @world %>
|
46
|
+
hello, <%= @world %>
|
47
|
+
hello, <%= @world %>
|
48
|
+
hello, <%= @world %>
|
49
|
+
hello, <%= @world %>
|
50
|
+
hello, <%= @world %>
|
data/hello.string
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
hello, #{ @world }
|
2
|
+
hello, #{ @world }
|
3
|
+
hello, #{ @world }
|
4
|
+
hello, #{ @world }
|
5
|
+
hello, #{ @world }
|
6
|
+
hello, #{ @world }
|
7
|
+
hello, #{ @world }
|
8
|
+
hello, #{ @world }
|
9
|
+
hello, #{ @world }
|
10
|
+
hello, #{ @world }
|
11
|
+
hello, #{ @world }
|
12
|
+
hello, #{ @world }
|
13
|
+
hello, #{ @world }
|
14
|
+
hello, #{ @world }
|
15
|
+
hello, #{ @world }
|
16
|
+
hello, #{ @world }
|
17
|
+
hello, #{ @world }
|
18
|
+
hello, #{ @world }
|
19
|
+
hello, #{ @world }
|
20
|
+
hello, #{ @world }
|
21
|
+
hello, #{ @world }
|
22
|
+
hello, #{ @world }
|
23
|
+
hello, #{ @world }
|
24
|
+
hello, #{ @world }
|
25
|
+
hello, #{ @world }
|
26
|
+
hello, #{ @world }
|
27
|
+
hello, #{ @world }
|
28
|
+
hello, #{ @world }
|
29
|
+
hello, #{ @world }
|
30
|
+
hello, #{ @world }
|
31
|
+
hello, #{ @world }
|
32
|
+
hello, #{ @world }
|
33
|
+
hello, #{ @world }
|
34
|
+
hello, #{ @world }
|
35
|
+
hello, #{ @world }
|
36
|
+
hello, #{ @world }
|
37
|
+
hello, #{ @world }
|
38
|
+
hello, #{ @world }
|
39
|
+
hello, #{ @world }
|
40
|
+
hello, #{ @world }
|
41
|
+
hello, #{ @world }
|
42
|
+
hello, #{ @world }
|
43
|
+
hello, #{ @world }
|
44
|
+
hello, #{ @world }
|
45
|
+
hello, #{ @world }
|
46
|
+
hello, #{ @world }
|
47
|
+
hello, #{ @world }
|
48
|
+
hello, #{ @world }
|
49
|
+
hello, #{ @world }
|
50
|
+
hello, #{ @world }
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StringTemplate
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
initializer 'string_template' do
|
6
|
+
ActiveSupport.on_load :action_view do
|
7
|
+
ActionView::Template.register_template_handler :string, StringTemplate::Handler
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "string_template"
|
6
|
+
spec.version = '0.1.0'
|
7
|
+
spec.authors = ["Akira Matsuda"]
|
8
|
+
spec.email = ["ronnie@dio.jp"]
|
9
|
+
|
10
|
+
spec.summary = "A template engine for Rails, focusing on speed, using Ruby's String interpolation syntax"
|
11
|
+
spec.description = 'String is your template engine'
|
12
|
+
spec.homepage = 'https://github.com/amatsuda/string_template'
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'rails'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'minitest'
|
27
|
+
spec.add_development_dependency 'benchmark_driver'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: string_template
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akira Matsuda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: benchmark_driver
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: String is your template engine
|
84
|
+
email:
|
85
|
+
- ronnie@dio.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- MIT-LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- benchmark.rb
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- hello.erb
|
100
|
+
- hello.string
|
101
|
+
- lib/string_template.rb
|
102
|
+
- lib/string_template/handler.rb
|
103
|
+
- lib/string_template/railtie.rb
|
104
|
+
- string_template.gemspec
|
105
|
+
homepage: https://github.com/amatsuda/string_template
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.7.4
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A template engine for Rails, focusing on speed, using Ruby's String interpolation
|
129
|
+
syntax
|
130
|
+
test_files: []
|