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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8aa3367427fc4d33e2ff57ba8f1988f31be1047
4
- data.tar.gz: da9216a9d2cc12bfdc92b90a9df75f1912876459
3
+ metadata.gz: a2c83a5231d99ca247d8eb0a5ed441c0a5a3282d
4
+ data.tar.gz: e1f75102f999b5183b3158c4db6650c8f1756031
5
5
  SHA512:
6
- metadata.gz: 53802e8411247cecffb2987fde99ec569dfea66b73a1240ee9a33361f4c2e4ba7a2b13892f1952be33e8b84b75b56de75f93be0c93c40e2029eeeb2df7211a28
7
- data.tar.gz: 8ec843e6e5946ae0fefcd3d04c3d7c62649a042a038641c716fc498ae60bdc163645f99503424e4a0191ae4ced649f8c276327671d1f579b478bdc298d319eb1
6
+ metadata.gz: 70b442e2627fa2c24dd0aed0a07d20c558bc01522196847cf25ffb6d6a2ffde032b6c200ced597634efa535406611841bc3935784e291548c4f5801516a334d5
7
+ data.tar.gz: 4245abb4f80c88a8a48121de6b4d83e8eb3c009f24d9ab63526e9738194b5e6f5e406d098208063cb543e4ea01f06cafda4e943ab72f95e5f4dcb6d9f5167d8f
@@ -1,3 +1,7 @@
1
+ ## 0.1.10 (2015-03-19)
2
+ - Fix ruby filter to not generate newlines
3
+ - Support markdown filter
4
+
1
5
  ## 0.1.9 (2015-03-18)
2
6
  - Refactor script parser (internal)
3
7
  - Fix newline generation with filters
@@ -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"
@@ -100,6 +100,8 @@ module FastHaml
100
100
  false
101
101
  when Ast::Element
102
102
  !child.nuke_outer_whitespace
103
+ when Ast::Filter
104
+ FilterCompilers.find(child.name).need_newline?
103
105
  else
104
106
  true
105
107
  end
@@ -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
- texts = strip_last_empty_lines(texts)
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) << [:static, "\n"] << [:newline]
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.pop # discard last [:newline]
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
@@ -6,7 +6,7 @@ module FastHaml
6
6
  def compile(texts)
7
7
  temple = [:multi, [:static, "<![CDATA[\n"], [:newline]]
8
8
  compile_texts(temple, texts, tab_width: 4)
9
- temple << [:static, "]]>"]
9
+ temple << [:static, "\n]]>"]
10
10
  end
11
11
  end
12
12
 
@@ -4,7 +4,9 @@ module FastHaml
4
4
  module FilterCompilers
5
5
  class Coffee < TiltBase
6
6
  def compile(texts)
7
- temple = compile_with_tilt('coffee', texts)
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
@@ -6,6 +6,7 @@ module FastHaml
6
6
  def compile(texts)
7
7
  temple = [:multi, [:static, "\n"], [:newline]]
8
8
  compile_texts(temple, texts, tab_width: 2)
9
+ temple << [:static, "\n"]
9
10
  [:haml, :tag, 'style', false, [:html, :attrs], temple]
10
11
  end
11
12
  end
@@ -8,6 +8,7 @@ module FastHaml
8
8
  def compile(texts)
9
9
  temple = [:multi, [:newline]]
10
10
  compile_texts(temple, texts)
11
+ temple << [:static, "\n"]
11
12
  escape_code = Temple::Filters::Escapable.new.instance_variable_get(:@escape_code)
12
13
  sym = unique_name
13
14
  [:multi,
@@ -6,6 +6,7 @@ module FastHaml
6
6
  def compile(texts)
7
7
  temple = [:multi, [:static, "\n"], [:newline]]
8
8
  compile_texts(temple, texts, tab_width: 2)
9
+ temple << [:static, "\n"]
9
10
  [:haml, :tag, 'script', false, [:html, :attrs], [:html, :js, temple]]
10
11
  end
11
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
- texts = strip_last_empty_lines(texts)
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
- texts.each do |text|
11
- temple << text_compiler.compile(text)
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],
@@ -3,6 +3,10 @@ require 'fast_haml/filter_compilers/base'
3
3
  module FastHaml
4
4
  module FilterCompilers
5
5
  class Ruby < Base
6
+ def need_newline?
7
+ false
8
+ end
9
+
6
10
  def compile(texts)
7
11
  [:multi, [:newline], [:code, strip_last_empty_lines(texts).join("\n")]]
8
12
  end
@@ -4,7 +4,8 @@ module FastHaml
4
4
  module FilterCompilers
5
5
  class Sass < TiltBase
6
6
  def compile(texts)
7
- temple = compile_with_tilt('sass', texts)
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 = compile_with_tilt('scss', texts)
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]
@@ -1,3 +1,3 @@
1
1
  module FastHaml
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
@@ -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
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe 'Ruby filter rendering', type: :render do
4
4
  it 'renders ruby filter' do
5
- expect(render_string(<<HAML)).to eq("\n3\n")
5
+ expect(render_string(<<HAML)).to eq("3\n")
6
6
  :ruby
7
7
  hash = {
8
8
  a: 3,
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.9
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