fast_haml 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/fast_haml.gemspec +1 -0
- data/lib/fast_haml/compiler.rb +2 -0
- data/lib/fast_haml/filter_compilers.rb +1 -0
- data/lib/fast_haml/filter_compilers/base.rb +17 -5
- data/lib/fast_haml/filter_compilers/cdata.rb +1 -1
- data/lib/fast_haml/filter_compilers/coffee.rb +3 -1
- data/lib/fast_haml/filter_compilers/css.rb +1 -0
- data/lib/fast_haml/filter_compilers/escaped.rb +1 -0
- data/lib/fast_haml/filter_compilers/javascript.rb +1 -0
- data/lib/fast_haml/filter_compilers/markdown.rb +18 -0
- data/lib/fast_haml/filter_compilers/plain.rb +1 -7
- data/lib/fast_haml/filter_compilers/preserve.rb +2 -6
- data/lib/fast_haml/filter_compilers/ruby.rb +4 -0
- data/lib/fast_haml/filter_compilers/sass.rb +2 -1
- data/lib/fast_haml/filter_compilers/scss.rb +3 -1
- data/lib/fast_haml/filter_compilers/tilt_base.rb +1 -3
- data/lib/fast_haml/version.rb +1 -1
- data/spec/compiler_newline_spec.rb +24 -0
- data/spec/render/filters/markdown_spec.rb +19 -0
- data/spec/render/filters/ruby_spec.rb +1 -1
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2c83a5231d99ca247d8eb0a5ed441c0a5a3282d
|
4
|
+
data.tar.gz: e1f75102f999b5183b3158c4db6650c8f1756031
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70b442e2627fa2c24dd0aed0a07d20c558bc01522196847cf25ffb6d6a2ffde032b6c200ced597634efa535406611841bc3935784e291548c4f5801516a334d5
|
7
|
+
data.tar.gz: 4245abb4f80c88a8a48121de6b4d83e8eb3c009f24d9ab63526e9738194b5e6f5e406d098208063cb543e4ea01f06cafda4e943ab72f95e5f4dcb6d9f5167d8f
|
data/CHANGELOG.md
CHANGED
data/fast_haml.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "haml"
|
32
32
|
spec.add_development_dependency "rake"
|
33
33
|
spec.add_development_dependency "rake-compiler"
|
34
|
+
spec.add_development_dependency "redcarpet"
|
34
35
|
spec.add_development_dependency "rspec", ">= 3"
|
35
36
|
spec.add_development_dependency "sass"
|
36
37
|
spec.add_development_dependency "simplecov"
|
data/lib/fast_haml/compiler.rb
CHANGED
@@ -33,6 +33,7 @@ require 'fast_haml/filter_compilers/coffee'
|
|
33
33
|
require 'fast_haml/filter_compilers/css'
|
34
34
|
require 'fast_haml/filter_compilers/escaped'
|
35
35
|
require 'fast_haml/filter_compilers/javascript'
|
36
|
+
require 'fast_haml/filter_compilers/markdown'
|
36
37
|
require 'fast_haml/filter_compilers/plain'
|
37
38
|
require 'fast_haml/filter_compilers/preserve'
|
38
39
|
require 'fast_haml/filter_compilers/ruby'
|
@@ -3,15 +3,25 @@ require 'fast_haml/text_compiler'
|
|
3
3
|
module FastHaml
|
4
4
|
module FilterCompilers
|
5
5
|
class Base
|
6
|
+
def need_newline?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
6
10
|
protected
|
7
11
|
|
8
|
-
def compile_texts(temple, texts, tab_width: 0)
|
12
|
+
def compile_texts(temple, texts, tab_width: 0, keep_last_empty_lines: false)
|
9
13
|
tabs = ' ' * tab_width
|
10
|
-
|
14
|
+
n = 0
|
15
|
+
unless keep_last_empty_lines
|
16
|
+
texts, n = strip_last_empty_lines(texts)
|
17
|
+
end
|
11
18
|
texts.each do |text|
|
12
|
-
temple << [:static, tabs] << text_compiler.compile(text)
|
19
|
+
temple << [:static, tabs] << text_compiler.compile(text)
|
20
|
+
unless texts.last.equal?(text)
|
21
|
+
temple << [:static, "\n"] << [:newline]
|
22
|
+
end
|
13
23
|
end
|
14
|
-
temple.
|
24
|
+
temple.concat([[:newline]] * n)
|
15
25
|
nil
|
16
26
|
end
|
17
27
|
|
@@ -20,11 +30,13 @@ module FastHaml
|
|
20
30
|
end
|
21
31
|
|
22
32
|
def strip_last_empty_lines(texts)
|
33
|
+
n = 0
|
23
34
|
texts = texts.dup
|
24
35
|
while texts.last && texts.last.empty?
|
36
|
+
n += 1
|
25
37
|
texts.pop
|
26
38
|
end
|
27
|
-
texts
|
39
|
+
[texts, n]
|
28
40
|
end
|
29
41
|
end
|
30
42
|
end
|
@@ -4,7 +4,9 @@ module FastHaml
|
|
4
4
|
module FilterCompilers
|
5
5
|
class Coffee < TiltBase
|
6
6
|
def compile(texts)
|
7
|
-
temple =
|
7
|
+
temple = [:multi, [:static, "\n"], [:newline]]
|
8
|
+
compile_with_tilt(temple, 'coffee', texts)
|
9
|
+
temple << [:static, "\n"]
|
8
10
|
[:haml, :tag, 'script', false, [:html, :attrs], [:html, :js, temple]]
|
9
11
|
end
|
10
12
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'fast_haml/filter_compilers/tilt_base'
|
2
|
+
|
3
|
+
module FastHaml
|
4
|
+
module FilterCompilers
|
5
|
+
class Markdown < TiltBase
|
6
|
+
def need_newline?
|
7
|
+
false
|
8
|
+
end
|
9
|
+
|
10
|
+
def compile(texts)
|
11
|
+
temple = [:multi, [:newline]]
|
12
|
+
compile_with_tilt(temple, 'markdown', texts)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
register(:markdown, Markdown)
|
17
|
+
end
|
18
|
+
end
|
@@ -5,13 +5,7 @@ module FastHaml
|
|
5
5
|
class Plain < Base
|
6
6
|
def compile(texts)
|
7
7
|
temple = [:multi, [:newline]]
|
8
|
-
|
9
|
-
texts.each do |text|
|
10
|
-
temple << text_compiler.compile(text)
|
11
|
-
unless texts.last.equal?(text)
|
12
|
-
temple << [:static, "\n"] << [:newline]
|
13
|
-
end
|
14
|
-
end
|
8
|
+
compile_texts(temple, texts)
|
15
9
|
temple
|
16
10
|
end
|
17
11
|
end
|
@@ -7,12 +7,8 @@ module FastHaml
|
|
7
7
|
|
8
8
|
def compile(texts)
|
9
9
|
temple = [:multi, [:newline]]
|
10
|
-
|
11
|
-
|
12
|
-
unless texts.last.equal?(text)
|
13
|
-
temple << [:static, "\n"] << [:newline]
|
14
|
-
end
|
15
|
-
end
|
10
|
+
# I don't know why only :preserve filter keeps the last empty lines.
|
11
|
+
compile_texts(temple, texts, keep_last_empty_lines: true)
|
16
12
|
sym = unique_name
|
17
13
|
[:multi,
|
18
14
|
[:capture, sym, temple],
|
@@ -4,7 +4,8 @@ module FastHaml
|
|
4
4
|
module FilterCompilers
|
5
5
|
class Sass < TiltBase
|
6
6
|
def compile(texts)
|
7
|
-
temple =
|
7
|
+
temple = [:multi, [:static, "\n"], [:newline]]
|
8
|
+
compile_with_tilt(temple, 'sass', texts)
|
8
9
|
[:haml, :tag, 'style', false, [:html, :attrs], temple]
|
9
10
|
end
|
10
11
|
end
|
@@ -4,7 +4,9 @@ module FastHaml
|
|
4
4
|
module FilterCompilers
|
5
5
|
class Scss < TiltBase
|
6
6
|
def compile(texts)
|
7
|
-
temple =
|
7
|
+
temple = [:multi, [:static, "\n"], [:newline]]
|
8
|
+
compile_with_tilt(temple, 'scss', texts)
|
9
|
+
temple << [:static, "\n"]
|
8
10
|
[:haml, :tag, 'style', false, [:html, :attrs], temple]
|
9
11
|
end
|
10
12
|
end
|
@@ -14,16 +14,14 @@ module FastHaml
|
|
14
14
|
|
15
15
|
protected
|
16
16
|
|
17
|
-
def compile_with_tilt(name, texts)
|
17
|
+
def compile_with_tilt(temple, name, texts)
|
18
18
|
source = texts.join("\n")
|
19
|
-
temple = [:multi, [:static, "\n"], [:newline]]
|
20
19
|
if TextCompiler.contains_interpolation?(source)
|
21
20
|
text_temple = [:multi]
|
22
21
|
compile_texts(text_temple, texts)
|
23
22
|
sym = unique_name
|
24
23
|
temple << [:capture, sym, text_temple]
|
25
24
|
temple << [:dynamic, "::FastHaml::FilterCompilers::TiltBase.render_with_tilt(#{name.inspect}, #{sym})"]
|
26
|
-
temple << [:newline]
|
27
25
|
else
|
28
26
|
compiled = self.class.render_with_tilt(name, source)
|
29
27
|
temple << [:static, compiled]
|
data/lib/fast_haml/version.rb
CHANGED
@@ -95,6 +95,30 @@ HAML
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
context 'with filters' do
|
99
|
+
it do
|
100
|
+
expect { render_string(<<HAML) }.to raise_error(LineVerifier, raised_at(5))
|
101
|
+
:plain
|
102
|
+
hello
|
103
|
+
|
104
|
+
|
105
|
+
= raise LineVerifier
|
106
|
+
HAML
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'with interpolation' do
|
110
|
+
it do
|
111
|
+
expect { render_string(<<'HAML') }.to raise_error(LineVerifier, raised_at(5))
|
112
|
+
:plain
|
113
|
+
#{'hello'}
|
114
|
+
|
115
|
+
|
116
|
+
= raise LineVerifier
|
117
|
+
HAML
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
98
122
|
context 'with tilt filters' do
|
99
123
|
it 'keeps newlines in filter' do
|
100
124
|
expect { render_string(<<'HAML') }.to raise_error(LineVerifier, raised_at(4))
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Markdown filter rendering', type: :render do
|
4
|
+
it 'renders Markdown filter' do
|
5
|
+
expect(render_string(<<HAML)).to eq("<h1>hello</h1>\nworld\n")
|
6
|
+
:markdown
|
7
|
+
# hello
|
8
|
+
world
|
9
|
+
HAML
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'parses string interpolation' do
|
13
|
+
expect(render_string(<<'HAML')).to eq("<h1>hello</h1>\nworld\n")
|
14
|
+
:markdown
|
15
|
+
# #{'hello'}
|
16
|
+
world
|
17
|
+
HAML
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: redcarpet
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
181
195
|
- !ruby/object:Gem::Dependency
|
182
196
|
name: rspec
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -263,6 +277,7 @@ files:
|
|
263
277
|
- lib/fast_haml/filter_compilers/css.rb
|
264
278
|
- lib/fast_haml/filter_compilers/escaped.rb
|
265
279
|
- lib/fast_haml/filter_compilers/javascript.rb
|
280
|
+
- lib/fast_haml/filter_compilers/markdown.rb
|
266
281
|
- lib/fast_haml/filter_compilers/plain.rb
|
267
282
|
- lib/fast_haml/filter_compilers/preserve.rb
|
268
283
|
- lib/fast_haml/filter_compilers/ruby.rb
|
@@ -348,6 +363,7 @@ files:
|
|
348
363
|
- spec/render/filters/css_spec.rb
|
349
364
|
- spec/render/filters/escaped_spec.rb
|
350
365
|
- spec/render/filters/javascript_spec.rb
|
366
|
+
- spec/render/filters/markdown_spec.rb
|
351
367
|
- spec/render/filters/plain_spec.rb
|
352
368
|
- spec/render/filters/preserve_spec.rb
|
353
369
|
- spec/render/filters/ruby_spec.rb
|
@@ -453,6 +469,7 @@ test_files:
|
|
453
469
|
- spec/render/filters/css_spec.rb
|
454
470
|
- spec/render/filters/escaped_spec.rb
|
455
471
|
- spec/render/filters/javascript_spec.rb
|
472
|
+
- spec/render/filters/markdown_spec.rb
|
456
473
|
- spec/render/filters/plain_spec.rb
|
457
474
|
- spec/render/filters/preserve_spec.rb
|
458
475
|
- spec/render/filters/ruby_spec.rb
|