hamlit 1.6.1 → 1.6.2

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
  SHA1:
3
- metadata.gz: 4848cd3ee1ccb8ba77acac4389eaadeca802b145
4
- data.tar.gz: 13c163d9c67e46d506686337b09979a65020cf62
3
+ metadata.gz: 3f85fe19ae942cdfef4ed10ea87a021b5603d915
4
+ data.tar.gz: cec640d9203032acf294e118fa737724d89c0952
5
5
  SHA512:
6
- metadata.gz: babb6f83c927734400646d758cf9c2e412ceeb416e77613031b97465b93cf71158d5f0549c940e81c58bec086634e7968d23b3d2b8649bb6b1f32cc48b3a6e94
7
- data.tar.gz: a7afb822afce6b75d1fffd69d292146c3d2b86edc0b66a57ff3b865a9847d8f1eab291fe733f9216a8e39ce6fa5ec18b819244eef8234852b858ca9377a931c4
6
+ metadata.gz: c668671bcbea79462a605a52b934fa1ec86c81f2ba665abcdc5a1f1667a8b18548896f0069646a8318713d708a2cd241aa10dc28db0b03e4aa167110d679672a
7
+ data.tar.gz: 5879b98703b9a549bee394304a1d34c3686c72a84bc7bb0b4d8da135e0674d3077e753009770da9a72d033ee3417970ef150200d1b362807b4c999c79025c628
data/.travis.yml CHANGED
@@ -14,9 +14,11 @@ env:
14
14
  - TASK=spec
15
15
  - TASK=rails:spec
16
16
  - TASK=bench TIME=20
17
+ - TASK=bench TIME=20 HTML_ESCAPE=1
17
18
  matrix:
18
19
  allow_failures:
19
20
  - env: TASK=bench TIME=20
21
+ - env: TASK=bench TIME=20 HTML_ESCAPE=1
20
22
  exclude:
21
23
  - env: TASK=spec
22
24
  gemfile: spec/rails/Gemfile
@@ -24,11 +26,17 @@ matrix:
24
26
  gemfile: Gemfile
25
27
  - env: TASK=bench TIME=20
26
28
  gemfile: spec/rails/Gemfile
29
+ - env: TASK=bench TIME=20 HTML_ESCAPE=1
30
+ gemfile: spec/rails/Gemfile
27
31
  - rvm: 2.1
28
32
  env: TASK=rails:spec
29
33
  - rvm: 2.1
30
34
  env: TASK=bench TIME=20
35
+ - rvm: 2.1
36
+ env: TASK=bench TIME=20 HTML_ESCAPE=1
31
37
  - rvm: 2.0.0
32
38
  env: TASK=rails:spec
33
39
  - rvm: 2.0.0
34
40
  env: TASK=bench TIME=20
41
+ - rvm: 2.0.0
42
+ env: TASK=bench TIME=20 HTML_ESCAPE=1
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
+ ## v1.6.2
2
+
3
+ - Reject a content for self-closing tags
4
+ - Reject nesing within self-closing tags
5
+
1
6
  ## v1.6.1
2
7
 
3
8
  - Parse N-space indentation
9
+ - https://github.com/k0kubun/hamlit/issues/26
10
+ - Thanks to @eagletmt
4
11
 
5
12
  ## v1.6.0
6
13
 
@@ -16,15 +16,38 @@ class Benchmarks
16
16
  @time = time
17
17
  @benches = []
18
18
  @versions = {}
19
+ end
19
20
 
20
- @erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
21
- @haml_code = File.read(File.dirname(__FILE__) + '/view.haml')
22
- @slim_code = File.read(File.dirname(__FILE__) + '/view.slim')
21
+ def init_compiled_benches(escape_enabled)
22
+ if escape_enabled
23
+ @erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
24
+ @haml_code = File.read(File.dirname(__FILE__) + '/view.haml')
25
+ @slim_code = File.read(File.dirname(__FILE__) + '/view.escaped.slim')
26
+ init_escaped_benches
27
+ else
28
+ @erb_code = File.read(File.dirname(__FILE__) + '/view.erb')
29
+ @haml_code = File.read(File.dirname(__FILE__) + '/view.haml')
30
+ @slim_code = File.read(File.dirname(__FILE__) + '/view.slim')
31
+ init_plain_benches
32
+ end
33
+ end
23
34
 
24
- init_compiled_benches
35
+ def run
36
+ show_versions
37
+ result = Benchmark.ips do |x|
38
+ x.config(time: @time, warmup: 2)
39
+ @benches.each do |name, block|
40
+ x.report(name, &block)
41
+ end
42
+ x.compare!
43
+ end
25
44
  end
26
45
 
27
- def init_compiled_benches
46
+ private
47
+
48
+ # Totally the same as slim-template/slim's compiled bench.
49
+ def init_plain_benches
50
+ puts 'Compiled rendering benchmarks without HTML escape'
28
51
  context = Context.new
29
52
 
30
53
  haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true)
@@ -32,29 +55,36 @@ class Benchmarks
32
55
  context.instance_eval %{
33
56
  def run_erubis; #{Erubis::Eruby.new(@erb_code).src}; end
34
57
  def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
35
- def run_faml; #{Faml::Engine.new.call @haml_code}; end
36
- def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end
58
+ def run_hamlit; #{Hamlit::Engine.new(escape_html: false).call @haml_code}; end
37
59
  }
38
60
 
39
61
  bench('hamlit', Hamlit::VERSION) { context.run_hamlit }
40
62
  bench('erubis', Erubis::VERSION) { context.run_erubis }
41
63
  bench('slim', Slim::VERSION) { context.run_slim_ugly }
42
- bench('faml', Faml::VERSION) { context.run_faml }
43
64
  bench('haml', Haml::VERSION) { context.run_haml_ugly }
44
65
  end
45
66
 
46
- def run
47
- show_versions
48
- result = Benchmark.ips do |x|
49
- x.config(time: @time, warmup: 2)
50
- @benches.each do |name, block|
51
- x.report(name, &block)
52
- end
53
- x.compare!
54
- end
55
- end
67
+ # slim-template/slim's compiled bench with HTML escaping.
68
+ def init_escaped_benches
69
+ puts 'Compiled rendering benchmarks with HTML escape'
70
+ context = Context.new
71
+ context.instance_eval("def header; '<script>'; end")
56
72
 
57
- private
73
+ haml_ugly = Haml::Engine.new(@haml_code, format: :html5, ugly: true, escape_html: true)
74
+ haml_ugly.def_method(context, :run_haml_ugly)
75
+ context.instance_eval %{
76
+ def run_erubis; #{Erubis::EscapedEruby.new(@erb_code).src}; end
77
+ def run_slim_ugly; #{Slim::Engine.new.call @slim_code}; end
78
+ def run_faml; #{Faml::Engine.new.call @haml_code}; end
79
+ def run_hamlit; #{Hamlit::Engine.new.call @haml_code}; end
80
+ }
81
+
82
+ bench('hamlit', Hamlit::VERSION) { context.run_hamlit }
83
+ bench('slim', Slim::VERSION) { context.run_slim_ugly }
84
+ bench('faml', Faml::VERSION) { context.run_faml }
85
+ bench('erubis', Erubis::VERSION) { context.run_erubis }
86
+ bench('haml', Haml::VERSION) { context.run_haml_ugly }
87
+ end
58
88
 
59
89
  def bench(name, version, &block)
60
90
  @benches.push([name, block])
@@ -70,4 +100,6 @@ class Benchmarks
70
100
  end
71
101
 
72
102
  time = (ENV['TIME'] || 5).to_i
73
- Benchmarks.new(time).run
103
+ bench = Benchmarks.new(time)
104
+ bench.init_compiled_benches(ENV['HTML_ESCAPE'])
105
+ bench.run
@@ -0,0 +1,17 @@
1
+ doctype html
2
+ html
3
+ head
4
+ title Simple Benchmark
5
+ body
6
+ h1 = header
7
+ - unless item.empty?
8
+ ul
9
+ - for i in item
10
+ - if i[:current]
11
+ li
12
+ strong = i[:name]
13
+ - else
14
+ li
15
+ a href==i[:url] = i[:name]
16
+ - else
17
+ p The list is empty.
data/doc/engine/indent.md CHANGED
@@ -17,9 +17,7 @@
17
17
 
18
18
  ### Faml
19
19
  ```html
20
- <p></p>
21
- %a
22
-
20
+ Faml::IndentTracker::HardTabNotAllowed: Indentation with hard tabs are not allowed :-p
23
21
  ```
24
22
 
25
23
 
@@ -45,9 +43,6 @@ foo
45
43
 
46
44
  ### Faml
47
45
  ```html
48
- <p></p>
49
- %span
50
- foo
51
-
46
+ Faml::IndentTracker::HardTabNotAllowed: Indentation with hard tabs are not allowed :-p
52
47
  ```
53
48
 
@@ -9,9 +9,7 @@
9
9
  ## Output
10
10
  ### Faml
11
11
  ```html
12
- <p></p>
13
- %a
14
-
12
+ Faml::IndentTracker::HardTabNotAllowed: Indentation with hard tabs are not allowed :-p
15
13
  ```
16
14
 
17
15
  ### Hamlit
@@ -35,10 +33,7 @@
35
33
  ## Output
36
34
  ### Faml
37
35
  ```html
38
- <p></p>
39
- %span
40
- foo
41
-
36
+ Faml::IndentTracker::HardTabNotAllowed: Indentation with hard tabs are not allowed :-p
42
37
  ```
43
38
 
44
39
  ### Hamlit
@@ -19,10 +19,6 @@ module Hamlit
19
19
  count_indent(next_line)
20
20
  end
21
21
 
22
- def next_width
23
- count_width(next_line)
24
- end
25
-
26
22
  def with_indented(&block)
27
23
  @current_indent += 1
28
24
  block.call
@@ -37,11 +33,6 @@ module Hamlit
37
33
  line.match(/\A[ \t]+/).to_s.length / indent_rule
38
34
  end
39
35
 
40
- def count_width(line)
41
- return EOF unless line
42
- line[/\A[ \t]+/].to_s.length
43
- end
44
-
45
36
  def same_indent?(line)
46
37
  return false unless line
47
38
  count_indent(line) == @current_indent
@@ -65,6 +56,15 @@ module Hamlit
65
56
  next_indent != @current_indent
66
57
  end
67
58
 
59
+ def has_block?
60
+ return false unless next_line
61
+ return fetch_indent(next_line).length > 0 unless @indent_space
62
+
63
+ next_indent > @current_indent
64
+ end
65
+
66
+ private
67
+
68
68
  # Validate the template is using consitent indentation, 2 spaces or a tab.
69
69
  def validate_indentation_consistency!(indent)
70
70
  return false if indent.empty?
@@ -85,37 +85,6 @@ module Hamlit
85
85
  "#{length} #{label}#{'s' if length > 1}"
86
86
  end
87
87
 
88
- def has_block?
89
- return false unless next_line
90
- return fetch_indent(next_line).length > 0 unless @indent_space
91
-
92
- next_indent > @current_indent
93
- end
94
-
95
- private
96
-
97
- def indent_label(indent)
98
- return %Q{"#{indent}"} if indent.include?(' ') && indent.include?("\t")
99
-
100
- label = indent.include?(' ') ? 'space' : 'tab'
101
- length = indent.match(/[ \t]+/).to_s.length
102
-
103
- "#{length} #{label}#{'s' if length > 1}"
104
- end
105
-
106
- def count_width(line)
107
- return EOF unless line
108
- line[/\A +/].to_s.length
109
- end
110
-
111
- def next_space
112
- next_line[/\A +/].to_s
113
- end
114
-
115
- def next_width
116
- count_width(next_line)
117
- end
118
-
119
88
  def indent_rule
120
89
  (@indent_space || '').length
121
90
  end
@@ -26,8 +26,11 @@ module Hamlit
26
26
  inner_removal = parse_whitespace_removal(scanner)
27
27
 
28
28
  if !has_block? || scanner.match?(/=|&=|!=/)
29
+ return syntax_error("Self-closing tags can't have content.") if scanner.scan(/\/ *[^ ]/)
29
30
  return ast if scanner.scan(/\//)
30
31
  return ast << parse_line(scanner, inline: true)
32
+ elsif scanner.match?(/\//)
33
+ return syntax_error("Illegal nesting: nesting within a self-closing tag is illegal.")
31
34
  end
32
35
 
33
36
  content = [:multi, [:static, "\n"]]
@@ -1,3 +1,3 @@
1
1
  module Hamlit
2
- VERSION = "1.6.1"
2
+ VERSION = "1.6.2"
3
3
  end
@@ -69,5 +69,20 @@ describe Hamlit::Engine do
69
69
  HAML
70
70
  to raise_error(Hamlit::SyntaxError, "Indentation can't use both tabs and spaces.")
71
71
  end
72
+
73
+ it 'raises syntax error for an inconsistent indentation' do
74
+ expect { render_string(<<-HAML.unindent) }.
75
+ %div/ foo
76
+ HAML
77
+ to raise_error(Hamlit::SyntaxError, "Self-closing tags can't have content.")
78
+ end
79
+
80
+ it 'raises syntax error for an inconsistent indentation' do
81
+ expect { render_string(<<-HAML.unindent) }.
82
+ %div/
83
+ foo
84
+ HAML
85
+ to raise_error(Hamlit::SyntaxError, "Illegal nesting: nesting within a self-closing tag is illegal.")
86
+ end
72
87
  end
73
88
  end
@@ -1,7 +1,7 @@
1
1
  describe Hamlit::Engine do
2
2
  describe 'tab indent' do
3
3
  it 'accepts tab indentation' do
4
- assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
4
+ assert_render(<<-HAML, <<-HTML, compatible_only: :haml, error_with: :faml)
5
5
  %p
6
6
  \t%a
7
7
  HAML
@@ -26,7 +26,7 @@ describe Hamlit::Engine do
26
26
  end
27
27
 
28
28
  it 'accepts N-tab indentation' do
29
- assert_render(<<-HAML, <<-HTML, compatible_only: :haml)
29
+ assert_render(<<-HAML, <<-HTML, compatible_only: :haml, error_with: :faml)
30
30
  %p
31
31
  \t%span
32
32
  \t\tfoo
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamlit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
@@ -295,6 +295,7 @@ files:
295
295
  - benchmarks/benchmark.rb
296
296
  - benchmarks/context.rb
297
297
  - benchmarks/view.erb
298
+ - benchmarks/view.escaped.slim
298
299
  - benchmarks/view.haml
299
300
  - benchmarks/view.slim
300
301
  - bin/hamlit
@@ -603,4 +604,3 @@ test_files:
603
604
  - spec/spec_helper/document_generator.rb
604
605
  - spec/spec_helper/render_helper.rb
605
606
  - spec/spec_helper/test_case.rb
606
- has_rdoc: