hmote 1.4.0 → 1.5.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 +4 -4
- data/LICENSE +2 -3
- data/README.md +47 -3
- data/lib/hmote/version.rb +1 -1
- data/lib/hmote.rb +36 -11
- data/test/helper.rb +4 -1
- data/test/{helpers.rb → helpers_test.rb} +6 -8
- data/test/{parsing.rb → parsing_test.rb} +1 -1
- metadata +44 -33
- data/.gems +0 -2
- data/benchmarks/.gems +0 -3
- data/benchmarks/escaping.rb +0 -11
- data/benchmarks/helpers/helper.rb +0 -8
- data/benchmarks/helpers/hmote_helper.rb +0 -7
- data/benchmarks/helpers/rails_helper.rb +0 -28
- data/benchmarks/memory.rb +0 -24
- data/benchmarks/safe.rb +0 -11
- data/benchmarks/templates/erb +0 -1
- data/benchmarks/templates/mote +0 -1
- data/hmote.gemspec +0 -17
- data/makefile +0 -8
- data/test/foo.mote +0 -1
- data/test/views/context.mote +0 -1
- data/test/views/home.mote +0 -1
- data/test/views/layout.mote +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19990b7d9d7fe577bc7dc27b2557f6ec928d5620
|
4
|
+
data.tar.gz: 81433bcbf7ddc6068bd41a75ec4e1df0c69a9833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67dc3c6016d0f8d3a94bb644f04cf8c1badec0347c70304e8cd3ac4f099f707ee6d5e5a6e3d5a22cb3a9d861096af80a2482487c3ca0a57c3e0cb774149228be
|
7
|
+
data.tar.gz: aa7a8f852a4d7220a273ef42f3924cea6155cccf1d834858c82de74cf04e63f126427de0345a415cc471f32b5ae5f665f28be9c9a553fdde8cb3bba2288256b7
|
data/LICENSE
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
Copyright (c)
|
2
|
-
Copyright (c)
|
3
|
-
Copyright (c) 2014-2015 Mayn Ektvedt Kjær
|
1
|
+
Copyright (c) 2014-2016 Francesco Rodríguez
|
2
|
+
Copyright (c) 2011-2015 Michel Martens
|
4
3
|
|
5
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
hmote
|
1
|
+
HMote [](https://travis-ci.org/frodsan/hmote)
|
2
2
|
=====
|
3
3
|
|
4
4
|
Minimal template engine with default escaping.
|
@@ -9,6 +9,27 @@ Description
|
|
9
9
|
HMote is a fork of [Mote][mote] that uses [Hache][hache]
|
10
10
|
to auto-escape HTML special characters.
|
11
11
|
|
12
|
+
Installation
|
13
|
+
------------
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem "hmote"
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
```
|
24
|
+
$ bundle
|
25
|
+
```
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
```
|
30
|
+
$ gem install hmote
|
31
|
+
```
|
32
|
+
|
12
33
|
Basic Usage
|
13
34
|
-----------
|
14
35
|
|
@@ -132,14 +153,37 @@ Related projects:
|
|
132
153
|
|
133
154
|
- [hmote-render][hmote-render]: HMote plugin for Cuba.
|
134
155
|
|
135
|
-
|
156
|
+
Contributing
|
136
157
|
------------
|
137
158
|
|
159
|
+
Fork the project with:
|
160
|
+
|
138
161
|
```
|
139
|
-
$
|
162
|
+
$ git clone git@github.com:frodsan/hmote.git
|
163
|
+
```
|
164
|
+
|
165
|
+
To install dependencies, use:
|
166
|
+
|
167
|
+
```
|
168
|
+
$ bundle install
|
140
169
|
```
|
141
170
|
|
171
|
+
To run the test suite, do:
|
172
|
+
|
173
|
+
```
|
174
|
+
$ rake test
|
175
|
+
```
|
176
|
+
|
177
|
+
For bug reports and pull requests use [GitHub][issues].
|
178
|
+
|
179
|
+
License
|
180
|
+
-------
|
181
|
+
|
182
|
+
HMote is released under the [MIT License][mit].
|
183
|
+
|
184
|
+
[mit]: http://www.opensource.org/licenses/MIT
|
142
185
|
[mote]: https://github.com/soveran/mote
|
143
186
|
[hache]: https://github.com/harmoni/hache
|
144
187
|
[hmote-render]: https://github.com/harmoni/hmote-render
|
188
|
+
[issues]: https://github.com/frodsan/hmote/issues
|
145
189
|
[xss]: http://en.wikipedia.org/wiki/Cross-Site_Scripting
|
data/lib/hmote/version.rb
CHANGED
data/lib/hmote.rb
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2011-2016 Francesco Rodríguez
|
4
|
+
# Copyright (c) 2011-2015 Michel Martens
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
# THE SOFTWARE.
|
23
|
+
|
1
24
|
require "hache"
|
2
25
|
|
3
26
|
class HMote
|
@@ -9,20 +32,12 @@ class HMote
|
|
9
32
|
|
10
33
|
def self.parse(template, context = self, vars = [])
|
11
34
|
terms = template.split(PATTERN)
|
12
|
-
parts = "Proc.new do |params, __o|\n params ||= {}; __o ||= ''\n"
|
35
|
+
parts = "Proc.new do |params, __o|\n params ||= {}; __o ||= ''\n".dup
|
13
36
|
|
14
|
-
vars.each
|
15
|
-
parts << sprintf("%s = params[%p]\n", var, var)
|
16
|
-
end
|
37
|
+
vars.each { |var| parts << format("%s = params[%p]\n", var, var) }
|
17
38
|
|
18
39
|
while (term = terms.shift)
|
19
|
-
|
20
|
-
when "<?" then parts << "#{terms.shift}\n"
|
21
|
-
when "%" then parts << "#{terms.shift}\n"
|
22
|
-
when "{{" then parts << "__o << Hache.h((#{terms.shift}).to_s)\n"
|
23
|
-
when "{{!" then parts << "__o << (#{terms.shift}).to_s\n"
|
24
|
-
else parts << "__o << #{term.dump}\n"
|
25
|
-
end
|
40
|
+
parts << parse_expression(terms, term)
|
26
41
|
end
|
27
42
|
|
28
43
|
parts << "__o; end"
|
@@ -30,6 +45,16 @@ class HMote
|
|
30
45
|
compile(context, parts)
|
31
46
|
end
|
32
47
|
|
48
|
+
def self.parse_expression(terms, term)
|
49
|
+
case term
|
50
|
+
when "<?" then terms.shift + "\n"
|
51
|
+
when "%" then terms.shift + "\n"
|
52
|
+
when "{{" then "__o << Hache.h((" + terms.shift + ").to_s)\n"
|
53
|
+
when "{{!" then "__o << (" + terms.shift + ").to_s\n"
|
54
|
+
else "__o << " + term.dump + "\n"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
33
58
|
def self.compile(context, parts)
|
34
59
|
context.instance_eval(parts)
|
35
60
|
end
|
data/test/helper.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
require_relative "helper"
|
2
2
|
|
3
|
-
class
|
3
|
+
class HelpersTest < Minitest::Test
|
4
4
|
include HMote::Helpers
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
setup do
|
7
|
+
hmote_cache.clear
|
8
8
|
end
|
9
|
-
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
hmote_cache.clear
|
10
|
+
def foo
|
11
|
+
"foo"
|
14
12
|
end
|
15
13
|
|
16
14
|
test "using functions in the context" do
|
@@ -18,7 +16,7 @@ scope("helpers") do
|
|
18
16
|
end
|
19
17
|
|
20
18
|
test "passing in a context" do
|
21
|
-
|
19
|
+
assert_raises(NameError) do
|
22
20
|
hmote("test/foo.mote", {}, TOPLEVEL_BINDING)
|
23
21
|
end
|
24
22
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hmote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodríguez
|
8
|
-
- Mayn Kjær
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: hache
|
@@ -26,52 +25,61 @@ dependencies:
|
|
26
25
|
- !ruby/object:Gem::Version
|
27
26
|
version: '1.1'
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
28
|
+
name: minitest
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
31
30
|
requirements:
|
32
31
|
- - "~>"
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
33
|
+
version: '5.8'
|
35
34
|
type: :development
|
36
35
|
prerelease: false
|
37
36
|
version_requirements: !ruby/object:Gem::Requirement
|
38
37
|
requirements:
|
39
38
|
- - "~>"
|
40
39
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
-
|
40
|
+
version: '5.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-sugar
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: A minimum operational template that escapes HTML tags by default
|
70
|
+
email: frodsan@protonmail.ch
|
47
71
|
executables: []
|
48
72
|
extensions: []
|
49
73
|
extra_rdoc_files: []
|
50
74
|
files:
|
51
|
-
- ".gems"
|
52
75
|
- LICENSE
|
53
76
|
- README.md
|
54
|
-
- benchmarks/.gems
|
55
|
-
- benchmarks/escaping.rb
|
56
|
-
- benchmarks/helpers/helper.rb
|
57
|
-
- benchmarks/helpers/hmote_helper.rb
|
58
|
-
- benchmarks/helpers/rails_helper.rb
|
59
|
-
- benchmarks/memory.rb
|
60
|
-
- benchmarks/safe.rb
|
61
|
-
- benchmarks/templates/erb
|
62
|
-
- benchmarks/templates/mote
|
63
|
-
- hmote.gemspec
|
64
77
|
- lib/hmote.rb
|
65
78
|
- lib/hmote/version.rb
|
66
|
-
- makefile
|
67
|
-
- test/foo.mote
|
68
79
|
- test/helper.rb
|
69
|
-
- test/
|
70
|
-
- test/
|
71
|
-
|
72
|
-
- test/views/home.mote
|
73
|
-
- test/views/layout.mote
|
74
|
-
homepage: https://github.com/harmoni/hmote
|
80
|
+
- test/helpers_test.rb
|
81
|
+
- test/parsing_test.rb
|
82
|
+
homepage: https://github.com/frodsan/hmote
|
75
83
|
licenses:
|
76
84
|
- MIT
|
77
85
|
metadata: {}
|
@@ -91,8 +99,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
99
|
version: '0'
|
92
100
|
requirements: []
|
93
101
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.5.1
|
95
103
|
signing_key:
|
96
104
|
specification_version: 4
|
97
|
-
summary: A minimum operational template that escapes HTML tags by default
|
98
|
-
test_files:
|
105
|
+
summary: A minimum operational template that escapes HTML tags by default
|
106
|
+
test_files:
|
107
|
+
- test/helper.rb
|
108
|
+
- test/helpers_test.rb
|
109
|
+
- test/parsing_test.rb
|
data/.gems
DELETED
data/benchmarks/.gems
DELETED
data/benchmarks/escaping.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require_relative "helpers/helper"
|
2
|
-
require_relative "helpers/hmote_helper"
|
3
|
-
require_relative "helpers/rails_helper"
|
4
|
-
|
5
|
-
text = %q(some < text > inside & these " escapable' characters/1234)
|
6
|
-
|
7
|
-
Benchmark.ips do |x|
|
8
|
-
x.report("hmote") { hmote(text: text) }
|
9
|
-
x.report("rails") { rails(text: text) }
|
10
|
-
x.compare!
|
11
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "action_view"
|
2
|
-
|
3
|
-
class Context
|
4
|
-
class LookupContext
|
5
|
-
def disable_cache
|
6
|
-
yield
|
7
|
-
end
|
8
|
-
|
9
|
-
def find_template(*args)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def lookup_context
|
14
|
-
@lookup_context ||= LookupContext.new
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
ACTIONVIEW_CONTEXT = Context.new
|
19
|
-
ACTIONVIEW_TEMPLATE = ActionView::Template.new(
|
20
|
-
File.read(ERB_TEMPLATE), "template",
|
21
|
-
ActionView::Template::Handlers::ERB.new,
|
22
|
-
format: :html, virtual_path: "template"
|
23
|
-
)
|
24
|
-
ACTIONVIEW_TEMPLATE.locals = [:text]
|
25
|
-
|
26
|
-
def rails(params)
|
27
|
-
ACTIONVIEW_TEMPLATE.render(ACTIONVIEW_CONTEXT, params)
|
28
|
-
end
|
data/benchmarks/memory.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative "helpers/helper"
|
2
|
-
require_relative "helpers/hmote_helper"
|
3
|
-
require "allocation_stats"
|
4
|
-
|
5
|
-
def benchmark(text)
|
6
|
-
stats = AllocationStats.new(burn: 5).trace do
|
7
|
-
hmote(text: text)
|
8
|
-
end
|
9
|
-
|
10
|
-
allocations = stats.allocations.all.size
|
11
|
-
memsize = stats.allocations.bytes.to_a.inject(&:+)
|
12
|
-
|
13
|
-
puts "total allocations: #{ allocations }"
|
14
|
-
puts "total memsize: #{ memsize }"
|
15
|
-
puts stats.allocations(alias_paths: true).to_text
|
16
|
-
end
|
17
|
-
|
18
|
-
puts "== Unsafe mode\n"
|
19
|
-
|
20
|
-
benchmark(%q(some < text > inside & these " escapable' characters/1234))
|
21
|
-
|
22
|
-
puts "\n== Safe mode\n"
|
23
|
-
|
24
|
-
benchmark(%q(some text without escapable characters))
|
data/benchmarks/safe.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require_relative "helpers/helper"
|
2
|
-
require_relative "helpers/hmote_helper"
|
3
|
-
require_relative "helpers/rails_helper"
|
4
|
-
|
5
|
-
text = %q(some text without escapable characters).html_safe
|
6
|
-
|
7
|
-
Benchmark.ips do |x|
|
8
|
-
x.report("hmote") { hmote(text: text) }
|
9
|
-
x.report("rails") { rails(text: text) }
|
10
|
-
x.compare!
|
11
|
-
end
|
data/benchmarks/templates/erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<%= text %>
|
data/benchmarks/templates/mote
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{{ text }}
|
data/hmote.gemspec
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require_relative "lib/hmote/version"
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "hmote"
|
5
|
-
s.version = HMote::VERSION
|
6
|
-
s.summary = "A minimum operational template that escapes HTML tags by default."
|
7
|
-
s.description = s.summary + " Inspired by mote."
|
8
|
-
s.authors = ["Francesco Rodríguez", "Mayn Kjær"]
|
9
|
-
s.email = ["frodsan@protonmail.ch", "mayn.kjaer@gmail.com"]
|
10
|
-
s.homepage = "https://github.com/harmoni/hmote"
|
11
|
-
s.license = "MIT"
|
12
|
-
|
13
|
-
s.files = `git ls-files`.split("\n")
|
14
|
-
|
15
|
-
s.add_dependency "hache", "~> 1.1"
|
16
|
-
s.add_development_dependency "cutest", "~> 1.2"
|
17
|
-
end
|
data/makefile
DELETED
data/test/foo.mote
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{{ foo }}
|
data/test/views/context.mote
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{{ app.name }}
|
data/test/views/home.mote
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<h1>Home</h1>
|
data/test/views/layout.mote
DELETED