faml 0.3.6 → 0.4.0

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: 71da312b9097d26800c2431adb5d01cc26252276
4
- data.tar.gz: acae87261e0f0650f0df3130eb8f97ba8326ae44
3
+ metadata.gz: f064e2ade70ffae1e981132413f02b123c6a80d8
4
+ data.tar.gz: b10afda81e0186e7c5c16f4ae74859f498cbbde7
5
5
  SHA512:
6
- metadata.gz: f7cbeb2dd1d2e326cb4540c30a50bc12440d760b2e618374aab624170585d0d8f7765ff07eb5781798f7341ce8e3fd44f13032e9f1f9e6250d45e3ace026f7b8
7
- data.tar.gz: 97ca3e26cd3493865f8300c2fa8b701ea854258849ac8eb99b90c493fdf9b5160ffd0e55d3d7e9cc5fb37120d42b3afe4063b34df7701a2de1474be41606a206
6
+ metadata.gz: 73e0d3b1457602502c81fcc6521a0596768a751a4f79af22e04c51003af7cebc4c93d9e47216867b6740240a7468014d09ef21c3f61e4731d86dc2f1e0a5e0b4
7
+ data.tar.gz: 201c731e3b02b14c0c92d2a0212790160cc5583e4984b8d6f08a07619147e4ba1c1d27ff6142496a0de5309457da125f98d0a6aff76fbd9ca5f95d5a909df3ee
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.4.0 (2015-11-15)
2
+ - Fix "end" insertion for empty else clause
3
+ = https://github.com/eagletmt/faml/pull/31
4
+ - It also requires haml_parser v0.2.0 or above.
5
+
1
6
  ## 0.3.6 (2015-11-06)
2
7
  - Fix attribute escape on forward slashes
3
8
  - https://github.com/eagletmt/faml/pull/30
data/faml.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.required_ruby_version = '>= 2.0.0'
22
22
 
23
23
  spec.add_dependency 'escape_utils'
24
- spec.add_dependency 'haml_parser', '>= 0.1.0'
24
+ spec.add_dependency 'haml_parser', '>= 0.2.0'
25
25
  spec.add_dependency 'parser'
26
26
  spec.add_dependency 'temple', '>= 0.7.0'
27
27
  spec.add_dependency 'tilt'
data/lib/faml/compiler.rb CHANGED
@@ -397,11 +397,17 @@ module Faml
397
397
  temple
398
398
  end
399
399
 
400
+ SKIP_END_KEYWORDS = %w[elsif else when].freeze
401
+
400
402
  def compile_silent_script(ast)
401
- temple = [:multi, [:code, ast.script], [:newline]]
403
+ temple = [:multi]
404
+ if SKIP_END_KEYWORDS.include?(ast.keyword)
405
+ temple << [:rmend]
406
+ end
407
+ temple << [:code, ast.script] << [:newline]
402
408
  compile_children(ast, temple)
403
- if !ast.children.empty? && !ast.mid_block_keyword
404
- temple << [:code, 'end']
409
+ if !ast.children.empty? || ast.keyword
410
+ temple << [:mkend]
405
411
  end
406
412
  temple
407
413
  end
data/lib/faml/engine.rb CHANGED
@@ -3,6 +3,7 @@ require 'temple'
3
3
  require_relative 'compiler'
4
4
  require_relative 'html'
5
5
  require_relative 'newline'
6
+ require_relative 'script_end'
6
7
 
7
8
  module Faml
8
9
  class Engine < Temple::Engine
@@ -18,6 +19,7 @@ module Faml
18
19
  filter :ControlFlow
19
20
  filter :MultiFlattener
20
21
  use Newline
22
+ use ScriptEnd
21
23
  filter :StaticMerger
22
24
  use :Generator do
23
25
  options[:generator].new(options.to_hash.reject { |k, _| !options[:generator].options.valid_key?(k) })
@@ -0,0 +1,27 @@
1
+ require 'temple'
2
+
3
+ module Faml
4
+ class ScriptEnd < Temple::Filter
5
+ def on_multi(*exprs)
6
+ i = exprs.size - 1
7
+ depth = 0
8
+ while i >= 0
9
+ case exprs[i]
10
+ when [:mkend]
11
+ if depth > 0
12
+ # Cancel :mkend
13
+ depth -= 1
14
+ exprs.delete_at(i)
15
+ else
16
+ exprs[i] = [:code, 'end'.freeze]
17
+ end
18
+ when [:rmend]
19
+ depth += 1
20
+ exprs.delete_at(i)
21
+ end
22
+ i -= 1
23
+ end
24
+ [:multi, *exprs]
25
+ end
26
+ end
27
+ end
data/lib/faml/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Faml
2
- VERSION = '0.3.6'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -84,6 +84,15 @@ HAML
84
84
  expect(render_string("%br\n-\n%br")).to eq("<br>\n<br>\n")
85
85
  end
86
86
 
87
+ it 'allows empty else body' do
88
+ expect(render_string(<<HAML)).to eq("ok\nfinish\n")
89
+ - if true
90
+ ok
91
+ - else
92
+ finish
93
+ HAML
94
+ end
95
+
87
96
  it 'checks indent levels' do
88
97
  expect(render_string(<<HAML)).to eq("<span>hello</span>\n")
89
98
  - if true
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.3.6
4
+ version: 0.4.0
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-11-06 00:00:00.000000000 Z
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.0
33
+ version: 0.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.0
40
+ version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: parser
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -375,6 +375,7 @@ files:
375
375
  - lib/faml/rails_helpers.rb
376
376
  - lib/faml/railtie.rb
377
377
  - lib/faml/ruby_syntax_checker.rb
378
+ - lib/faml/script_end.rb
378
379
  - lib/faml/static_hash_parser.rb
379
380
  - lib/faml/stats.rb
380
381
  - lib/faml/text_compiler.rb
@@ -511,7 +512,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
511
512
  version: '0'
512
513
  requirements: []
513
514
  rubyforge_project:
514
- rubygems_version: 2.5.0
515
+ rubygems_version: 2.4.5.1
515
516
  signing_key:
516
517
  specification_version: 4
517
518
  summary: Faster implementation of Haml template language.