faml 0.2.10 → 0.2.11
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/README.md +2 -0
- data/lib/faml/element_parser.rb +8 -14
- data/lib/faml/version.rb +1 -1
- data/spec/compiler_newline_spec.rb +8 -0
- data/spec/render/attribute_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4090ae5210da7fc60d6ed8e2837ab25f846a8271
|
4
|
+
data.tar.gz: 60d7ddcb1e8fd8f87fc97de7341e97e5e3e6c81a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3840b30af5a7e5edcf48918d91046fcd34b2982672770a5b29afca3f05833676f30dbed78fe00e5807fbe3b8ffa58fd6a2e737509e307ee544c6769cf63c93bc
|
7
|
+
data.tar.gz: 1afc3e04ae4fb23a20b9e0fb316bf5cf336c162df281165c726f2f240e494639dadc8e197d70e41bb44d0a4424de0fe6ed3b7d640f1603c0fe4819cb4448784f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -27,6 +27,8 @@ Or install it yourself as:
|
|
27
27
|
### Rails, sinatra
|
28
28
|
Just replace your `gem 'haml'` with `gem 'faml'` .
|
29
29
|
|
30
|
+
faml is only tested with Rails >= 4.0.
|
31
|
+
|
30
32
|
### middleman
|
31
33
|
Since middleman has its own renderers, there's no easy way to use faml with middleman currently.
|
32
34
|
|
data/lib/faml/element_parser.rb
CHANGED
@@ -77,11 +77,10 @@ module Faml
|
|
77
77
|
|
78
78
|
attributes = old_attributes
|
79
79
|
unless new_attributes.empty?
|
80
|
-
t = to_old_syntax(new_attributes)
|
81
80
|
if attributes.empty?
|
82
|
-
attributes =
|
81
|
+
attributes = new_attributes
|
83
82
|
else
|
84
|
-
attributes << ", " <<
|
83
|
+
attributes << ", " << new_attributes
|
85
84
|
end
|
86
85
|
end
|
87
86
|
[attributes, rest]
|
@@ -112,14 +111,12 @@ module Faml
|
|
112
111
|
s = StringScanner.new(text)
|
113
112
|
s.pos = 1
|
114
113
|
depth = 1
|
115
|
-
new_attributes = []
|
116
114
|
loop do
|
117
115
|
pre_pos = s.pos
|
118
116
|
depth = ParserUtils.balance(s, '(', ')', depth)
|
119
117
|
if depth == 0
|
120
118
|
t = s.string.byteslice(pre_pos ... s.pos-1)
|
121
|
-
|
122
|
-
return [new_attributes, s.rest]
|
119
|
+
return [parse_new_attribute_list(t), s.rest]
|
123
120
|
else
|
124
121
|
if @line_parser.has_next?
|
125
122
|
text << "\n" << @line_parser.next_line
|
@@ -132,7 +129,7 @@ module Faml
|
|
132
129
|
|
133
130
|
def parse_new_attribute_list(text)
|
134
131
|
s = StringScanner.new(text)
|
135
|
-
|
132
|
+
attributes = []
|
136
133
|
until s.eos?
|
137
134
|
name = scan_key(s)
|
138
135
|
s.skip(/\s*/)
|
@@ -143,11 +140,12 @@ module Faml
|
|
143
140
|
else
|
144
141
|
value = 'true'
|
145
142
|
end
|
146
|
-
s.
|
143
|
+
spaces = s.scan(/\s*/)
|
144
|
+
line_count = spaces.count("\n")
|
147
145
|
|
148
|
-
|
146
|
+
attributes << "#{name.inspect} => #{value},#{"\n" * line_count}"
|
149
147
|
end
|
150
|
-
|
148
|
+
attributes.join
|
151
149
|
end
|
152
150
|
|
153
151
|
def scan_key(scanner)
|
@@ -201,10 +199,6 @@ module Faml
|
|
201
199
|
end
|
202
200
|
end
|
203
201
|
|
204
|
-
def to_old_syntax(new_attributes)
|
205
|
-
new_attributes.map { |k, v| "#{k.inspect} => #{v}" }.join(', ')
|
206
|
-
end
|
207
|
-
|
208
202
|
def parse_nuke_whitespace(rest)
|
209
203
|
m = rest.match(/\A(><|<>|[><])(.*)\z/)
|
210
204
|
if m
|
data/lib/faml/version.rb
CHANGED
@@ -168,6 +168,14 @@ HAML
|
|
168
168
|
HAML
|
169
169
|
end
|
170
170
|
|
171
|
+
it 'keeps newlines in static HTML-style attributes' do
|
172
|
+
expect(render_string(<<HAML)).to eq("<span a='1' b='2'></span>\n3\n")
|
173
|
+
%span(a=1
|
174
|
+
b=2)
|
175
|
+
= __LINE__
|
176
|
+
HAML
|
177
|
+
end
|
178
|
+
|
171
179
|
it 'keeps newlines in dynamic attributes' do
|
172
180
|
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(2))
|
173
181
|
%span{a: 1,
|
@@ -259,5 +259,12 @@ HAML
|
|
259
259
|
it 'raises error when string interpolation is unterminated' do
|
260
260
|
expect { render_string('%span(foo=1 bar="ba#{1") hello') }.to raise_error(Faml::SyntaxError)
|
261
261
|
end
|
262
|
+
|
263
|
+
it 'renders __LINE__ correctly' do
|
264
|
+
expect(render_string(<<HAML)).to eq("<span a='2' b='1'></span>\n")
|
265
|
+
%span(b=__LINE__
|
266
|
+
a=__LINE__)
|
267
|
+
HAML
|
268
|
+
end
|
262
269
|
end
|
263
270
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
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-04-
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|