string_template 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -9
- data/benchmark.rb +9 -7
- data/lib/string_template/handler.rb +2 -2
- data/string_template.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f24edb1470edcc84b9eb7fb5150344fa7a3ec52fb94ce828c008c9e8a5df2946
|
4
|
+
data.tar.gz: 9b61ea5087325c7d3a9cb8140d7a36f30a4a696443692710c37b44b5adc65114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f51f25e054ea2607c6b2f7d1cf4925c3d7dbd2db2ef583184ee5367a44134c1128d4c4ea7249bb381d8c9332674c8797aca39a6d4bad30c8a51feb633a265b4
|
7
|
+
data.tar.gz: 16ba86b238e8d32317a7d7ab95012ffffab688e6f988f9793458d23fb8865452b017c1e416d8479e3f955ee59fcaa2609b2252c9bf950a4c1506abcf6e5321c5
|
data/README.md
CHANGED
@@ -12,15 +12,13 @@ Why don't we use this for the view files in our apps?
|
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
15
|
-
Add this line to your application's Gemfile:
|
15
|
+
Add this line to your Rails application's Gemfile:
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
gem 'string_template'
|
19
19
|
```
|
20
20
|
|
21
|
-
And then
|
22
|
-
|
23
|
-
% bundle
|
21
|
+
And then bundle.
|
24
22
|
|
25
23
|
|
26
24
|
## Syntax
|
@@ -51,33 +49,38 @@ ERB:
|
|
51
49
|
|
52
50
|
string\_template:
|
53
51
|
```
|
54
|
-
<p id="notice">#{ notice }</p>
|
52
|
+
<p id="notice">#{h notice }</p>
|
55
53
|
|
56
54
|
<p>
|
57
55
|
<strong>Title:</strong>
|
58
|
-
#{ @post.title }
|
56
|
+
#{h @post.title }
|
59
57
|
</p>
|
60
58
|
|
61
59
|
<p>
|
62
60
|
<strong>Body:</strong>
|
63
|
-
#{ @post.body }
|
61
|
+
#{h @post.body }
|
64
62
|
</p>
|
65
63
|
|
66
64
|
#{ link_to 'Edit', "/posts/#{@post.id}/edit" } |
|
67
65
|
#{ link_to 'Back', '/posts' }
|
68
66
|
```
|
69
67
|
|
70
|
-
|
68
|
+
### More Examples
|
71
69
|
Please take a look at [the tests](https://github.com/amatsuda/string_template/blob/master/test/string_template_test.rb) for actual examples.
|
72
70
|
|
73
71
|
|
74
|
-
##
|
72
|
+
## File Names
|
75
73
|
By default, string\_template renders view files with `.string` extension, e.g. `app/views/posts/show.html.string`
|
76
74
|
|
77
75
|
|
76
|
+
## Security
|
77
|
+
string\_template does not automatically `html_escape`. Don't forget to explicitly call `h()` when interpolating possibly HTML unsafe strings, like we used to do in pre Rails 3 era.
|
78
|
+
|
79
|
+
|
78
80
|
## So, Should We Rewrite Everything with This?
|
79
81
|
string\_template may not be the best choice as a general purpose template engine.
|
80
82
|
It may sometimes be hard to express your template in a simple and maintainable code, especially when the template includes some business logic.
|
83
|
+
You need to care about security.
|
81
84
|
So this template engine is recommended to use only for performance hotspots.
|
82
85
|
For other templates, you might better use your favorite template engine such as haml, or haml, or haml.
|
83
86
|
|
data/benchmark.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
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
3
|
require 'benchmark_driver'
|
9
4
|
|
10
5
|
Benchmark.driver do |x|
|
11
|
-
x.prelude %{
|
6
|
+
x.prelude %{
|
7
|
+
require 'rails'
|
8
|
+
require 'action_view'
|
9
|
+
require 'string_template'
|
10
|
+
StringTemplate::Railtie.run_initializers
|
11
|
+
require 'action_view/base'
|
12
|
+
|
13
|
+
(view = Class.new(ActionView::Base).new('.')).instance_variable_set(:@world, 'world!')
|
14
|
+
}
|
12
15
|
x.report 'erb', %{ view.render(template: 'hello', handlers: 'erb') }
|
13
16
|
x.report 'string', %{ view.render(template: 'hello', handlers: 'string') }
|
14
|
-
x.compare!
|
15
17
|
end
|
data/string_template.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "string_template"
|
6
|
-
spec.version = '0.2.
|
6
|
+
spec.version = '0.2.1'
|
7
7
|
spec.authors = ["Akira Matsuda"]
|
8
8
|
spec.email = ["ronnie@dio.jp"]
|
9
9
|
|
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'bundler'
|
25
25
|
spec.add_development_dependency 'rake'
|
26
26
|
spec.add_development_dependency 'minitest'
|
27
|
-
spec.add_development_dependency 'benchmark_driver'
|
27
|
+
spec.add_development_dependency 'benchmark_driver', '>= 0.9.0'
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string_template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.9.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.9.0
|
83
83
|
description: string_template is a Rails plugin that adds an Action View handler for
|
84
84
|
.string template that accepts Ruby's String literal that uses notation for interpolating
|
85
85
|
dynamic variables
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.7.
|
127
|
+
rubygems_version: 2.7.8
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: A template engine for Rails, focusing on speed, using Ruby's String interpolation
|