hamlit 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +9 -2
- data/lib/hamlit/compilers/attributes.rb +4 -1
- data/lib/hamlit/compilers/script.rb +10 -1
- data/lib/hamlit/concerns/escapable.rb +17 -0
- data/lib/hamlit/engine.rb +1 -0
- data/lib/hamlit/parser.rb +1 -1
- data/lib/hamlit/parsers/script.rb +9 -2
- data/lib/hamlit/railtie.rb +1 -0
- data/lib/hamlit/version.rb +1 -1
- data/spec/Rakefile +2 -10
- data/spec/hamlit/engine/script_spec.rb +2 -2
- data/spec/hamlit/haml_spec.rb +2 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89250564d274169193ab2b990498777705b31cf9
|
4
|
+
data.tar.gz: 154fd04373a7b7d574cb203187bd4c7f21172ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92799f8c4f1bea17c85e5e2911c9430f2193226c3a835deb77acd348b21240eb5bb837351760ae1eeb426312bda7bf8e9c574bd89c7c25585c4dcc9635646a39
|
7
|
+
data.tar.gz: b0381cb98e2987dff4574e707a181bfc97d5261b1e3e071d9f336f2914ab89df2d5a0cf681a94c43d6a5b8b6fe5f467338d0119459db6e3ab5ffdc1e7a59d1e8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -49,9 +49,16 @@ Hamlit is used on [githubranking.com](http://githubranking.com/).
|
|
49
49
|
Basically the same as [haml](https://github.com/haml/haml).
|
50
50
|
Check out the [reference documentation](http://haml.info/docs/yardoc/file.REFERENCE.html) for details.
|
51
51
|
|
52
|
-
### Rails
|
52
|
+
### Rails
|
53
|
+
Just update Gemfile.
|
53
54
|
|
54
|
-
|
55
|
+
### Sinatra
|
56
|
+
Update Gemfile. Html escaping is enabled by default.
|
57
|
+
If you want to disable it, add following code.
|
58
|
+
|
59
|
+
```rb
|
60
|
+
set :haml, { escape_html: false }
|
61
|
+
```
|
55
62
|
|
56
63
|
## Why high performance?
|
57
64
|
### Less work on runtime
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'hamlit/compilers/new_attribute'
|
2
2
|
require 'hamlit/compilers/old_attribute'
|
3
3
|
require 'hamlit/compilers/runtime_attribute'
|
4
|
+
require 'hamlit/concerns/escapable'
|
4
5
|
require 'hamlit/concerns/included'
|
5
6
|
|
6
7
|
module Hamlit
|
@@ -12,6 +13,8 @@ module Hamlit
|
|
12
13
|
include Compilers::RuntimeAttribute
|
13
14
|
|
14
15
|
included do
|
16
|
+
include Concerns::Escapable
|
17
|
+
|
15
18
|
define_options :format, :attr_quote
|
16
19
|
end
|
17
20
|
|
@@ -38,7 +41,7 @@ module Hamlit
|
|
38
41
|
type, arg = value
|
39
42
|
next attr unless name && type && type && arg
|
40
43
|
|
41
|
-
[:html, :attr, name,
|
44
|
+
[:html, :attr, name, escape_html(value, true)]
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
@@ -1,11 +1,20 @@
|
|
1
|
+
require 'hamlit/concerns/escapable'
|
2
|
+
require 'hamlit/concerns/included'
|
3
|
+
|
1
4
|
module Hamlit
|
2
5
|
module Compilers
|
3
6
|
module Script
|
7
|
+
extend Concerns::Included
|
8
|
+
|
9
|
+
included do
|
10
|
+
include Concerns::Escapable
|
11
|
+
end
|
12
|
+
|
4
13
|
def on_haml_script(code, options, *exps)
|
5
14
|
variable = result_identifier
|
6
15
|
|
7
16
|
assign = [:code, "#{variable} = #{code}"]
|
8
|
-
result = [:
|
17
|
+
result = escape_html([:dynamic, variable], options[:force_escape])
|
9
18
|
result = [:dynamic, variable] if options[:disable_escape]
|
10
19
|
[:multi, assign, *exps.map { |exp| compile(exp) }, compile(result)]
|
11
20
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'hamlit/concerns/included'
|
2
|
+
|
3
|
+
module Hamlit
|
4
|
+
module Concerns
|
5
|
+
module Escapable
|
6
|
+
extend Included
|
7
|
+
|
8
|
+
included do
|
9
|
+
define_options escape_html: false
|
10
|
+
end
|
11
|
+
|
12
|
+
def escape_html(exp, force_escape = false)
|
13
|
+
[:escape, force_escape || @options[:escape_html], exp]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/hamlit/engine.rb
CHANGED
data/lib/hamlit/parser.rb
CHANGED
@@ -86,7 +86,7 @@ module Hamlit
|
|
86
86
|
if scanner.scan(/\\/) || scanner.match?(/\#{/)
|
87
87
|
return parse_text(scanner)
|
88
88
|
elsif scanner.match?(/&=/)
|
89
|
-
return parse_script(scanner)
|
89
|
+
return parse_script(scanner, force_escape: true)
|
90
90
|
elsif scanner.match?(/!=/)
|
91
91
|
return parse_script(scanner, disable_escape: true)
|
92
92
|
elsif scanner.match?(/[.#](\Z|[^a-zA-Z0-9_-])/)
|
@@ -1,14 +1,21 @@
|
|
1
|
+
require 'hamlit/concerns/escapable'
|
1
2
|
require 'hamlit/concerns/error'
|
3
|
+
require 'hamlit/concerns/included'
|
2
4
|
require 'hamlit/concerns/indentable'
|
3
5
|
|
4
6
|
module Hamlit
|
5
7
|
module Parsers
|
6
8
|
module Script
|
9
|
+
extend Concerns::Included
|
7
10
|
include Concerns::Error
|
8
11
|
include Concerns::Indentable
|
9
12
|
|
10
13
|
INTERNAL_STATEMENTS = %w[else elsif when].freeze
|
11
|
-
DEFAULT_SCRIPT_OPTIONS = { disable_escape: false }.freeze
|
14
|
+
DEFAULT_SCRIPT_OPTIONS = { force_escape: false, disable_escape: false }.freeze
|
15
|
+
|
16
|
+
included do
|
17
|
+
include Concerns::Escapable
|
18
|
+
end
|
12
19
|
|
13
20
|
def parse_script(scanner, options = {})
|
14
21
|
assert_scan!(scanner, /=|&=|!=|~/)
|
@@ -18,7 +25,7 @@ module Hamlit
|
|
18
25
|
return syntax_error("There's no Ruby code for = to evaluate.") if code.empty? && !with_comment
|
19
26
|
unless has_block?
|
20
27
|
return [:dynamic, code] if options[:disable_escape]
|
21
|
-
return [:
|
28
|
+
return escape_html([:dynamic, code], options[:force_escape])
|
22
29
|
end
|
23
30
|
|
24
31
|
ast = [:haml, :script, code, options]
|
data/lib/hamlit/railtie.rb
CHANGED
data/lib/hamlit/version.rb
CHANGED
data/spec/Rakefile
CHANGED
@@ -10,23 +10,15 @@ def generate_spec(mode)
|
|
10
10
|
|
11
11
|
# This is a spec converted by haml-spec.
|
12
12
|
# See: https://github.com/haml/haml-spec
|
13
|
-
describe "haml #{mode} mode with
|
13
|
+
describe "haml #{mode} mode with ecape_html" do
|
14
14
|
DEFAULT_OPTIONS = { ugly: true, escape_html: true }.freeze
|
15
15
|
|
16
16
|
def assert_haml(haml, locals, options)
|
17
17
|
engine = Haml::Engine.new(haml, DEFAULT_OPTIONS.merge(options))
|
18
|
-
hamlit = Hamlit::Template.new(
|
18
|
+
hamlit = Hamlit::Template.new(options) { haml }
|
19
19
|
expect(hamlit.render(Object.new, locals)).to eq(engine.render(Object.new, locals))
|
20
20
|
end
|
21
21
|
|
22
|
-
# NOTE: Hamlit only supports escape_html mode.
|
23
|
-
# Thus the option is not supporeted and prints noisy warnings.
|
24
|
-
def suppress_warnings(options)
|
25
|
-
options = options.dup
|
26
|
-
options.delete(:escape_html)
|
27
|
-
options
|
28
|
-
end
|
29
|
-
|
30
22
|
SPEC
|
31
23
|
|
32
24
|
url = 'https://raw.githubusercontent.com/haml/haml-spec/master/tests.json'
|
@@ -76,7 +76,7 @@ describe Hamlit::Engine do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'renders !=' do
|
79
|
-
assert_render(<<-HAML, <<-HTML)
|
79
|
+
assert_render(<<-HAML, <<-HTML, escape_html: true)
|
80
80
|
!= '<"&>'
|
81
81
|
!= '<"&>'.tap do |str|
|
82
82
|
-# no operation
|
@@ -87,7 +87,7 @@ describe Hamlit::Engine do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'renders &=' do
|
90
|
-
assert_render(<<-HAML, <<-HTML)
|
90
|
+
assert_render(<<-HAML, <<-HTML, escape_html: false)
|
91
91
|
&= '<"&>'
|
92
92
|
&= '<"&>'.tap do |str|
|
93
93
|
-# no operation
|
data/spec/hamlit/haml_spec.rb
CHANGED
@@ -2,23 +2,15 @@ require "haml"
|
|
2
2
|
|
3
3
|
# This is a spec converted by haml-spec.
|
4
4
|
# See: https://github.com/haml/haml-spec
|
5
|
-
describe "haml ugly mode with
|
5
|
+
describe "haml ugly mode with ecape_html" do
|
6
6
|
DEFAULT_OPTIONS = { ugly: true, escape_html: true }.freeze
|
7
7
|
|
8
8
|
def assert_haml(haml, locals, options)
|
9
9
|
engine = Haml::Engine.new(haml, DEFAULT_OPTIONS.merge(options))
|
10
|
-
hamlit = Hamlit::Template.new(
|
10
|
+
hamlit = Hamlit::Template.new(options) { haml }
|
11
11
|
expect(hamlit.render(Object.new, locals)).to eq(engine.render(Object.new, locals))
|
12
12
|
end
|
13
13
|
|
14
|
-
# NOTE: Hamlit only supports escape_html mode.
|
15
|
-
# Thus the option is not supporeted and prints noisy warnings.
|
16
|
-
def suppress_warnings(options)
|
17
|
-
options = options.dup
|
18
|
-
options.delete(:escape_html)
|
19
|
-
options
|
20
|
-
end
|
21
|
-
|
22
14
|
context "headers" do
|
23
15
|
specify "an XHTML XML prolog" do
|
24
16
|
haml = %q{!!! XML}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -332,6 +332,7 @@ files:
|
|
332
332
|
- lib/hamlit/concerns/balanceable.rb
|
333
333
|
- lib/hamlit/concerns/deprecation.rb
|
334
334
|
- lib/hamlit/concerns/error.rb
|
335
|
+
- lib/hamlit/concerns/escapable.rb
|
335
336
|
- lib/hamlit/concerns/included.rb
|
336
337
|
- lib/hamlit/concerns/indentable.rb
|
337
338
|
- lib/hamlit/concerns/line_reader.rb
|