fast_haml 0.1.2 → 0.1.3
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/CHANGELOG.md +4 -0
- data/lib/fast_haml/compiler.rb +14 -7
- data/lib/fast_haml/version.rb +1 -1
- data/spec/compiler_newline_spec.rb +46 -0
- data/spec/render/element_spec.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82e5ebff407e25bb08be2e8130a90cca37e0bfc6
|
4
|
+
data.tar.gz: ac737189d9a874166e57300520d1f58179420e03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9afecde05c50d903af4ef9fa480fbc89e8bfacc41256311a2a754a4acaa382128551ed2c9d20d57137db7747a66957230abd0ec4cda9e0c02a4aac88d49b941
|
7
|
+
data.tar.gz: 2fc94f166bbf3b2830fa123968c995bf73e96ee23b75a2b933ce789f3b5fe056274b9af01db342d7a62fd9e3a1662f5df15b66b723657822c69c248cb26dc68e
|
data/CHANGELOG.md
CHANGED
data/lib/fast_haml/compiler.rb
CHANGED
@@ -87,12 +87,15 @@ module FastHaml
|
|
87
87
|
if c.is_a?(Ast::Element) && c.nuke_outer_whitespace && was_newline
|
88
88
|
# pop newline
|
89
89
|
x = temple.pop
|
90
|
-
if x
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
if x == [:newline]
|
91
|
+
x = temple.pop
|
92
|
+
if x != [:static, "\n"]
|
93
|
+
raise "InternalError: Unexpected pop (expected [:static, \\n]): #{x}"
|
94
|
+
end
|
95
|
+
elsif x == [:static, "\n"]
|
96
|
+
# nothing
|
97
|
+
else
|
98
|
+
raise "InternalError: Unexpected pop (expected [:newline] or [:static, \\n]): #{x}"
|
96
99
|
end
|
97
100
|
unless suppress_code_newline?(c.oneline_child)
|
98
101
|
temple << [:newline]
|
@@ -125,7 +128,10 @@ module FastHaml
|
|
125
128
|
end
|
126
129
|
|
127
130
|
def suppress_code_newline?(ast)
|
128
|
-
ast.is_a?(Ast::Script) ||
|
131
|
+
ast.is_a?(Ast::Script) ||
|
132
|
+
ast.is_a?(Ast::SilentScript) ||
|
133
|
+
(ast.is_a?(Ast::Element) && suppress_code_newline?(ast.oneline_child)) ||
|
134
|
+
(ast.is_a?(Ast::Element) && !ast.children.empty?)
|
129
135
|
end
|
130
136
|
|
131
137
|
def compile_text(ast)
|
@@ -185,6 +191,7 @@ module FastHaml
|
|
185
191
|
unless nuke_inner_whitespace?(ast)
|
186
192
|
children << [:static, "\n"]
|
187
193
|
end
|
194
|
+
children << [:newline]
|
188
195
|
compile_children(ast, children)
|
189
196
|
temple << children
|
190
197
|
end
|
data/lib/fast_haml/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class LineVerifier < StandardError
|
4
|
+
def initialize
|
5
|
+
super("raised at #{caller_locations(1, 1)[0].lineno}")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module LineVerifierHelper
|
10
|
+
extend RSpec::Matchers::DSL
|
11
|
+
|
12
|
+
matcher :raised_at do |expected|
|
13
|
+
match do |actual|
|
14
|
+
actual == "raised at #{expected}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.describe 'FastHaml::Compiler newline generation', type: :render do
|
20
|
+
include LineVerifierHelper
|
21
|
+
|
22
|
+
it do
|
23
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(3))
|
24
|
+
%div
|
25
|
+
%span= 1
|
26
|
+
%span>= raise LineVerifier
|
27
|
+
HAML
|
28
|
+
end
|
29
|
+
|
30
|
+
it do
|
31
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(2))
|
32
|
+
%img
|
33
|
+
%img{href: raise(LineVerifier)}>
|
34
|
+
%img
|
35
|
+
HAML
|
36
|
+
end
|
37
|
+
|
38
|
+
it do
|
39
|
+
expect { render_string(<<'HAML') }.to raise_error(LineVerifier, raised_at(3))
|
40
|
+
%div
|
41
|
+
%span hello
|
42
|
+
%span #{raise LineVerifier}
|
43
|
+
%span world
|
44
|
+
HAML
|
45
|
+
end
|
46
|
+
end
|
data/spec/render/element_spec.rb
CHANGED
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.
|
4
|
+
version: 0.1.3
|
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-
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -251,6 +251,7 @@ files:
|
|
251
251
|
- lib/fast_haml/text_compiler.rb
|
252
252
|
- lib/fast_haml/tilt.rb
|
253
253
|
- lib/fast_haml/version.rb
|
254
|
+
- spec/compiler_newline_spec.rb
|
254
255
|
- spec/rails/Rakefile
|
255
256
|
- spec/rails/app/assets/images/.keep
|
256
257
|
- spec/rails/app/assets/javascripts/application.js
|
@@ -351,6 +352,7 @@ signing_key:
|
|
351
352
|
specification_version: 4
|
352
353
|
summary: Faster implementation of Haml template language.
|
353
354
|
test_files:
|
355
|
+
- spec/compiler_newline_spec.rb
|
354
356
|
- spec/rails/Rakefile
|
355
357
|
- spec/rails/app/assets/images/.keep
|
356
358
|
- spec/rails/app/assets/javascripts/application.js
|