fast_haml 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b27cfffdd8647b6badef2bce9bc9696c5fabdac
4
- data.tar.gz: bd9776dd0a37157e8fabfcfb1d81a90d7f84f341
3
+ metadata.gz: e396fc6a76d932fc231a39783109c56be41fd5d2
4
+ data.tar.gz: 637ffb6b8faa7caf60cf8be200826740da3d521a
5
5
  SHA512:
6
- metadata.gz: 268d5ce19f97c7b2c5fdd6ef20fa2f4e5ac490ef2b974f4c8ea3db50d59fecd5c661f49fc2966bd432fa44c77126495f71c0ec1452f6ab0db2f905b79609c07c
7
- data.tar.gz: 71dbcabdf836323d3a23070ec9d443f9e94912b05b6715fa455640f70a698741337105442e3692a0436de2a8cc2f208b950fcfef7d0513170c98ff906b3c8c7e
6
+ metadata.gz: 6a9bbe7b0da60b072fb9c5eab60d8292e549e5b78989b6ff5e109de846e0321dd5425f5f92bcb85c534a3153e2889953950384d68d896cad01db5d73d362976c
7
+ data.tar.gz: fcb46c42e9801024c85e1232c92222f079c37c60694796b4ec682c4dd72a97499508aef4fc4584348b9dba9f71c6902b01a2b098871e552cc6bd79b7bd224aab
@@ -1,3 +1,6 @@
1
+ ## 0.1.2 (2015-02-24)
2
+ - Keep newlines for better backtrace (#4)
3
+
1
4
  ## 0.1.1 (2015-02-23)
2
5
  - Fix attribute parsing with `%span {foo}` or `%span (foo)` cases.
3
6
  - Fix comparison with statically-compilable class attributes like `%span.foo{class: bar}` .
@@ -1,6 +1,19 @@
1
1
  module FastHaml
2
2
  module Ast
3
- module Construct
3
+ module LineCounter
4
+ def initialize(*)
5
+ super
6
+ @trailing_empty_lines = 0
7
+ end
8
+
9
+ def trailing_empty_lines
10
+ @trailing_empty_lines
11
+ end
12
+
13
+ def increment_trailing_empty_lines
14
+ @trailing_empty_lines += 1
15
+ nil
16
+ end
4
17
  end
5
18
 
6
19
  module HasChildren
@@ -15,10 +28,12 @@ module FastHaml
15
28
  end
16
29
 
17
30
  class Root < Struct.new(:children)
31
+ include LineCounter
18
32
  include HasChildren
19
33
  end
20
34
 
21
35
  class Doctype < Struct.new(:doctype)
36
+ include LineCounter
22
37
  end
23
38
 
24
39
  class Element < Struct.new(
@@ -32,6 +47,7 @@ module FastHaml
32
47
  :nuke_inner_whitespace,
33
48
  :nuke_outer_whitespace,
34
49
  )
50
+ include LineCounter
35
51
  include HasChildren
36
52
 
37
53
  def initialize(*)
@@ -52,6 +68,7 @@ module FastHaml
52
68
  :preserve,
53
69
  :mid_block_keyword,
54
70
  )
71
+ include LineCounter
55
72
  include HasChildren
56
73
 
57
74
  def initialize(*)
@@ -69,6 +86,7 @@ module FastHaml
69
86
  end
70
87
 
71
88
  class SilentScript < Struct.new(:children, :script, :mid_block_keyword)
89
+ include LineCounter
72
90
  include HasChildren
73
91
 
74
92
  def initialize(*)
@@ -80,6 +98,7 @@ module FastHaml
80
98
  end
81
99
 
82
100
  class HtmlComment < Struct.new(:children, :comment, :conditional)
101
+ include LineCounter
83
102
  include HasChildren
84
103
 
85
104
  def initialize(*)
@@ -90,10 +109,13 @@ module FastHaml
90
109
  end
91
110
 
92
111
  class HamlComment < Struct.new(:children)
112
+ include LineCounter
93
113
  include HasChildren
94
114
  end
95
115
 
96
116
  class Text < Struct.new(:text, :escape_html)
117
+ include LineCounter
118
+
97
119
  def initialize(*)
98
120
  super
99
121
  if self.escape_html.nil?
@@ -103,6 +125,8 @@ module FastHaml
103
125
  end
104
126
 
105
127
  class Filter < Struct.new(:name, :texts)
128
+ include LineCounter
129
+
106
130
  def initialize(*)
107
131
  super
108
132
  self.texts ||= []
@@ -44,32 +44,39 @@ module FastHaml
44
44
  private
45
45
 
46
46
  def compile(ast)
47
- case ast
48
- when Ast::Root
49
- compile_root(ast)
50
- when Ast::Doctype
51
- compile_doctype(ast)
52
- when Ast::HtmlComment
53
- compile_html_comment(ast)
54
- when Ast::HamlComment
55
- [:multi]
56
- when Ast::Element
57
- compile_element(ast)
58
- when Ast::Script
59
- compile_script(ast)
60
- when Ast::SilentScript
61
- compile_silent_script(ast)
62
- when Ast::Text
63
- compile_text(ast)
64
- when Ast::Filter
65
- compile_filter(ast)
47
+ temple =
48
+ case ast
49
+ when Ast::Root
50
+ compile_root(ast)
51
+ when Ast::Doctype
52
+ compile_doctype(ast)
53
+ when Ast::HtmlComment
54
+ compile_html_comment(ast)
55
+ when Ast::HamlComment
56
+ [:multi]
57
+ when Ast::Element
58
+ compile_element(ast)
59
+ when Ast::Script
60
+ compile_script(ast)
61
+ when Ast::SilentScript
62
+ compile_silent_script(ast)
63
+ when Ast::Text
64
+ compile_text(ast)
65
+ when Ast::Filter
66
+ compile_filter(ast)
67
+ else
68
+ raise "InternalError: Unknown AST node #{ast.class}: #{ast.inspect}"
69
+ end
70
+
71
+ if ast.trailing_empty_lines > 0
72
+ [:multi, temple].concat([[:newline]] * ast.trailing_empty_lines)
66
73
  else
67
- raise "InternalError: Unknown AST node #{ast.class}: #{ast.inspect}"
74
+ temple
68
75
  end
69
76
  end
70
77
 
71
78
  def compile_root(ast)
72
- [:multi, [:newline]].tap do |temple|
79
+ [:multi].tap do |temple|
73
80
  compile_children(ast, temple)
74
81
  end
75
82
  end
@@ -87,10 +94,15 @@ module FastHaml
87
94
  if x != [:static, "\n"]
88
95
  raise "InternalError: Unexpected pop (expected [:static, newline]): #{x}"
89
96
  end
97
+ unless suppress_code_newline?(c.oneline_child)
98
+ temple << [:newline]
99
+ end
90
100
  end
91
101
  temple << compile(c)
92
102
  if was_newline = need_newline?(ast, c)
93
103
  temple << [:static, "\n"]
104
+ end
105
+ unless suppress_code_newline?(c)
94
106
  temple << [:newline]
95
107
  end
96
108
  end
@@ -112,6 +124,10 @@ module FastHaml
112
124
  end
113
125
  end
114
126
 
127
+ def suppress_code_newline?(ast)
128
+ ast.is_a?(Ast::Script) || ast.is_a?(Ast::SilentScript) || (ast.is_a?(Ast::Element) && suppress_code_newline?(ast.oneline_child))
129
+ end
130
+
115
131
  def compile_text(ast)
116
132
  @text_compiler.compile(ast.text, escape_html: ast.escape_html)
117
133
  end
@@ -169,7 +185,6 @@ module FastHaml
169
185
  unless nuke_inner_whitespace?(ast)
170
186
  children << [:static, "\n"]
171
187
  end
172
- children << [:newline]
173
188
  compile_children(ast, children)
174
189
  temple << children
175
190
  end
@@ -8,7 +8,7 @@ module FastHaml
8
8
  def compile_texts(temple, texts, tab_width: 0)
9
9
  tabs = ' ' * tab_width
10
10
  texts.each do |text|
11
- temple << [:static, tabs] << text_compiler.compile(text) << [:static, "\n"]
11
+ temple << [:static, tabs] << text_compiler.compile(text) << [:static, "\n"] << [:newline]
12
12
  end
13
13
  nil
14
14
  end
@@ -7,7 +7,7 @@ module FastHaml
7
7
  temple = [:multi]
8
8
  texts = strip_last_empty_lines(texts)
9
9
  compile_texts(temple, texts[0 .. -2])
10
- temple << text_compiler.compile(texts[-1])
10
+ temple << text_compiler.compile(texts[-1]) << [:newline]
11
11
  temple
12
12
  end
13
13
  end
@@ -12,6 +12,7 @@ module FastHaml
12
12
  unless texts.last.equal?(text)
13
13
  temple << [:static, "\n"]
14
14
  end
15
+ temple << [:newline]
15
16
  end
16
17
  sym = unique_name
17
18
  [:multi,
@@ -59,6 +59,7 @@ module FastHaml
59
59
  text, indent = @indent_tracker.process(line, @line_parser.lineno)
60
60
 
61
61
  if text.empty?
62
+ @ast.increment_trailing_empty_lines
62
63
  return
63
64
  end
64
65
 
@@ -2,11 +2,6 @@ module FastHaml
2
2
  class Railtie < ::Rails::Railtie
3
3
  initializer :fast_haml do |app|
4
4
  require 'fast_haml/rails_handler'
5
- begin
6
- # Load Haml::Plugin earlier to overwrite template handler with fast_haml.
7
- require 'haml/plugin'
8
- rescue LoadError
9
- end
10
5
  ActionView::Template.register_template_handler(:haml, FastHaml::RailsHandler.new)
11
6
  end
12
7
  end
@@ -1,3 +1,3 @@
1
1
  module FastHaml
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils