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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c8f17e5bb94d82ff20787118208ba1fd022e81920f9ba2bc5fd7200317dd53a
4
- data.tar.gz: 4744f42da1f657f6dd3cffa27492f9ade9f9e5e6ab89b6d4b4645eff7db7dc7c
3
+ metadata.gz: f24edb1470edcc84b9eb7fb5150344fa7a3ec52fb94ce828c008c9e8a5df2946
4
+ data.tar.gz: 9b61ea5087325c7d3a9cb8140d7a36f30a4a696443692710c37b44b5adc65114
5
5
  SHA512:
6
- metadata.gz: 27fcbafde0589969ec31561299701a415b71ce78fd459b29a237ba5e995ba7519c4eb6c140e74ee3302789d15b758b5e561b67c16dd36dad394618df0c4d8cc1
7
- data.tar.gz: 8cbfca9d51ae4fc88b790a83621b9e5d7d94a85a42ce7a5e63d8bb10e554e38d470350148d707a07cc486d80770ab1b828864d4829c989b8cff05e8bb652795a
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 execute:
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
- # More Examples
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
- ## Filenames
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
 
@@ -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 %{ (view = Class.new(ActionView::Base).new('.')).instance_variable_set(:@world, 'world!') }
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
@@ -2,8 +2,8 @@
2
2
 
3
3
  module StringTemplate
4
4
  class Handler
5
- def self.call(template)
6
- "%Q\0#{template.source}\0"
5
+ def self.call(template, source = nil)
6
+ "%Q\0#{source || template.source}\0"
7
7
  end
8
8
 
9
9
  def self.handles_encoding?
@@ -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.0'
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.0
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: 2017-12-28 00:00:00.000000000 Z
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: '0'
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: '0'
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.4
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