faml 0.2.14 → 0.2.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad03dfd0077214679b01a81f9f23e38681e5ba09
4
- data.tar.gz: 4f845eab154e7fefc437be4a4b6e7e9d781e7e5f
3
+ metadata.gz: 8ed579db6f39d551ff46f78f0407f8c239ac8b96
4
+ data.tar.gz: 7016eb2f48eccaaa9181ead1ef45f86f5c0e71d7
5
5
  SHA512:
6
- metadata.gz: 03eb904bc291e05ab14219d83c940a51c7b44c91cd42cd6b6b5b78a7d4774a0df35e5dadc84dc5fc92a324006c65681de3ebe0f6ca4ee95bbc26babff5fae0d0
7
- data.tar.gz: 9785e68c585d85301896f83e1b332d75423a6fa8b66194f2caa6384dccfe768ac52aa9860717776512ff3e933ce9a4f1c3e85c21dd0886007aa31cfea5923933
6
+ metadata.gz: f4eedb5026603869991eb3831d92ab71025152c1ab156a4bd96ca29bb925bf3abe80f7c73656f24c520b35ea11f5deb959b7603453c2b8955951e2f65b4d30fe
7
+ data.tar.gz: 0a5a7b8f98b4f9f5910e3296ec328e54bd394b7b75dfcd862f9b0902c08cea5aed51468f7db2812f3a44e6ac73d720203435cb899c39c075b30ad18146399aaf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.15 (2015-06-14)
2
+ - Improve compatibility of tilt filter indentations
3
+ - Raise error when ids or classes don't have values
4
+
1
5
  ## 0.2.14 (2015-06-11)
2
6
  - Check indent size consistency for compatibility with Haml
3
7
  - Intentionally prohibit indentations with hard tabs
@@ -1,8 +1,8 @@
1
1
  # Incompatibilities
2
2
  ## Versions
3
3
  - Haml 4.0.6
4
- - Faml 0.2.13
5
- - Hamlit 1.6.0
4
+ - Faml 0.2.15
5
+ - Hamlit 1.6.5
6
6
 
7
7
  ## Table of contents
8
8
  - [spec/compiler_newline_spec.md](spec/compiler_newline_spec.md)
@@ -11,14 +11,11 @@
11
11
  - [spec/render/doctype_spec.md](spec/render/doctype_spec.md)
12
12
  - [spec/render/element_spec.md](spec/render/element_spec.md)
13
13
  - [spec/render/filters/cdata_spec.md](spec/render/filters/cdata_spec.md)
14
- - [spec/render/filters/coffee_spec.md](spec/render/filters/coffee_spec.md)
15
14
  - [spec/render/filters/css_spec.md](spec/render/filters/css_spec.md)
16
15
  - [spec/render/filters/escaped_spec.md](spec/render/filters/escaped_spec.md)
17
16
  - [spec/render/filters/javascript_spec.md](spec/render/filters/javascript_spec.md)
18
17
  - [spec/render/filters/markdown_spec.md](spec/render/filters/markdown_spec.md)
19
18
  - [spec/render/filters/preserve_spec.md](spec/render/filters/preserve_spec.md)
20
- - [spec/render/filters/sass_spec.md](spec/render/filters/sass_spec.md)
21
- - [spec/render/filters/scss_spec.md](spec/render/filters/scss_spec.md)
22
19
  - [spec/render/helpers_spec.md](spec/render/helpers_spec.md)
23
20
  - [spec/render/indent_spec.md](spec/render/indent_spec.md)
24
21
  - [spec/render/multiline_spec.md](spec/render/multiline_spec.md)
@@ -89,24 +89,6 @@ Hamlit::SyntaxError
89
89
 
90
90
  ```
91
91
 
92
- # [./spec/render/attribute_spec.rb:65](../../../spec/render/attribute_spec.rb#L65)
93
- ## Input
94
- ```haml
95
- %span.foo{class: :foo}
96
- ```
97
-
98
- ## Faml, Haml
99
- ```html
100
- <span class='foo'></span>
101
-
102
- ```
103
-
104
- ## Hamlit
105
- ```html
106
- <span class='foo foo'></span>
107
-
108
- ```
109
-
110
92
  # [./spec/render/attribute_spec.rb:65](../../../spec/render/attribute_spec.rb#L65)
111
93
  ## Input
112
94
  ```haml
@@ -125,46 +107,6 @@ Hamlit::SyntaxError
125
107
 
126
108
  ```
127
109
 
128
- # [./spec/render/attribute_spec.rb:65](../../../spec/render/attribute_spec.rb#L65)
129
- ## Input
130
- ```haml
131
- %span.foo{class: %w[foo bar]}
132
- ```
133
-
134
- ## Faml, Haml
135
- ```html
136
- <span class='bar foo'></span>
137
-
138
- ```
139
-
140
- ## Hamlit
141
- ```html
142
- <span class='bar foo foo'></span>
143
-
144
- ```
145
-
146
- # [./spec/render/attribute_spec.rb:71](../../../spec/render/attribute_spec.rb#L71)
147
- ## Input
148
- ```haml
149
- %span.#foo{id: :bar} hello
150
- ```
151
-
152
- ## Faml
153
- ```html
154
- <span id='foo_bar'>hello</span>
155
-
156
- ```
157
-
158
- ## Haml (Error)
159
- ```html
160
- Illegal element: classes and ids must have values.
161
- ```
162
-
163
- ## Hamlit (Error)
164
- ```html
165
- Expected to scan (?-mix:[a-zA-Z0-9_-]+) but got nil
166
- ```
167
-
168
110
  # [./spec/render/attribute_spec.rb:75](../../../spec/render/attribute_spec.rb#L75)
169
111
  ## Input
170
112
  ```haml
@@ -1,26 +1,4 @@
1
- # [./spec/render/element_spec.rb:63](../../../spec/render/element_spec.rb#L63)
2
- ## Input
3
- ```haml
4
- %.foo
5
- ```
6
-
7
- ## Faml (Error)
8
- ```html
9
- Invalid element declaration
10
- ```
11
-
12
- ## Haml (Error)
13
- ```html
14
- Invalid tag: "%.foo".
15
- ```
16
-
17
- ## Hamlit
18
- ```html
19
- < class='foo'></>
20
-
21
- ```
22
-
23
- # [./spec/render/element_spec.rb:84](../../../spec/render/element_spec.rb#L84)
1
+ # [./spec/render/element_spec.rb:98](../../../spec/render/element_spec.rb#L98)
24
2
  ## Input
25
3
  ```haml
26
4
  - @var = '</span>'
@@ -45,51 +23,3 @@ hello <span> #@var </span>
45
23
 
46
24
  ```
47
25
 
48
- # [./spec/render/element_spec.rb:117](../../../spec/render/element_spec.rb#L117)
49
- ## Input
50
- ```haml
51
- %p/ hello
52
- ```
53
-
54
- ## Faml (Error)
55
- ```html
56
- Self-closing tags can't have content
57
- ```
58
-
59
- ## Haml (Error)
60
- ```html
61
- Self-closing tags can't have content.
62
- ```
63
-
64
- ## Hamlit
65
- ```html
66
- <p>
67
-
68
- ```
69
-
70
- # [./spec/render/element_spec.rb:121](../../../spec/render/element_spec.rb#L121)
71
- ## Input
72
- ```haml
73
- %p/
74
- hello
75
-
76
- ```
77
-
78
- ## Faml (Error)
79
- ```html
80
- Illegal nesting: nesting within a self-closing tag is illegal
81
- ```
82
-
83
- ## Haml (Error)
84
- ```html
85
- Illegal nesting: nesting within a self-closing tag is illegal.
86
- ```
87
-
88
- ## Hamlit
89
- ```html
90
- <p>
91
- hello
92
- </p>
93
-
94
- ```
95
-
@@ -12,6 +12,6 @@
12
12
 
13
13
  ## Hamlit (Error)
14
14
  ```html
15
- undefined method `preserve' for #<Object:0x00000003ec3a58>
15
+ undefined method `preserve' for #<Object:0x0000000436a0c0>
16
16
  ```
17
17
 
@@ -39,12 +39,16 @@ module Faml
39
39
  def parse_class_and_id(class_and_id)
40
40
  classes = []
41
41
  id = ''
42
- class_and_id.scan(/([#.])([-:_a-zA-Z0-9]+)/) do |type, prop|
43
- case type
42
+ scanner = StringScanner.new(class_and_id)
43
+ until scanner.eos?
44
+ unless scanner.scan(/([#.])([-:_a-zA-Z0-9]+)/)
45
+ syntax_error!('Illegal element: classes and ids must have values.')
46
+ end
47
+ case scanner[1]
44
48
  when '.'
45
- classes << prop
49
+ classes << scanner[2]
46
50
  when '#'
47
- id = prop
51
+ id = scanner[2]
48
52
  end
49
53
  end
50
54
 
@@ -5,7 +5,7 @@ module Faml
5
5
  class Coffee < TiltBase
6
6
  def compile(ast)
7
7
  temple = [:multi, [:static, "\n"], [:newline]]
8
- compile_with_tilt(temple, 'coffee', ast)
8
+ compile_with_tilt(temple, 'coffee', ast, indent_width: 2)
9
9
  temple << [:static, "\n"]
10
10
  [:haml, :tag, 'script', false, [:html, :attrs], [:html, :js, temple]]
11
11
  end
@@ -10,6 +10,7 @@ module Faml
10
10
  def compile(ast)
11
11
  temple = [:multi, [:newline]]
12
12
  compile_with_tilt(temple, 'markdown', ast)
13
+ temple << [:static, "\n"]
13
14
  end
14
15
  end
15
16
 
@@ -5,7 +5,8 @@ module Faml
5
5
  class Sass < TiltBase
6
6
  def compile(ast)
7
7
  temple = [:multi, [:static, "\n"], [:newline]]
8
- compile_with_tilt(temple, 'sass', ast)
8
+ compile_with_tilt(temple, 'sass', ast, indent_width: 2)
9
+ temple << [:static, "\n"]
9
10
  [:haml, :tag, 'style', false, [:html, :attrs], temple]
10
11
  end
11
12
  end
@@ -5,7 +5,7 @@ module Faml
5
5
  class Scss < TiltBase
6
6
  def compile(ast)
7
7
  temple = [:multi, [:static, "\n"], [:newline]]
8
- compile_with_tilt(temple, 'scss', ast)
8
+ compile_with_tilt(temple, 'scss', ast, indent_width: 2)
9
9
  temple << [:static, "\n"]
10
10
  [:haml, :tag, 'style', false, [:html, :attrs], temple]
11
11
  end
@@ -8,22 +8,24 @@ module Faml
8
8
  class TiltBase < Base
9
9
  include Temple::Utils
10
10
 
11
- def self.render_with_tilt(name, source)
12
- ::Tilt["t.#{name}"].new { source }.render
11
+ def self.render_with_tilt(name, source, indent_width: 0)
12
+ text = ::Tilt["t.#{name}"].new { source }.render
13
+ indent = ' ' * indent_width
14
+ "#{indent}#{text.rstrip.gsub("\n", "\n#{indent}")}"
13
15
  end
14
16
 
15
17
  protected
16
18
 
17
- def compile_with_tilt(temple, name, ast)
19
+ def compile_with_tilt(temple, name, ast, indent_width: 0)
18
20
  source = ast.texts.join("\n")
19
21
  if TextCompiler.contains_interpolation?(source)
20
22
  text_temple = [:multi]
21
23
  compile_texts(text_temple, ast.lineno, ast.texts)
22
24
  sym = unique_name
23
25
  temple << [:capture, sym, text_temple]
24
- temple << [:dynamic, "::Faml::FilterCompilers::TiltBase.render_with_tilt(#{name.inspect}, #{sym})"]
26
+ temple << [:dynamic, "::Faml::FilterCompilers::TiltBase.render_with_tilt(#{name.inspect}, #{sym}, indent_width: #{indent_width})"]
25
27
  else
26
- compiled = self.class.render_with_tilt(name, source)
28
+ compiled = self.class.render_with_tilt(name, source, indent_width: indent_width)
27
29
  temple << [:static, compiled]
28
30
  temple.concat([[:newline]] * (ast.texts.size - 1))
29
31
  end
data/lib/faml/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Faml
2
- VERSION = "0.2.14"
2
+ VERSION = "0.2.15"
3
3
  end
@@ -69,7 +69,7 @@ HAML
69
69
  end
70
70
 
71
71
  it 'strigify non-string ids' do
72
- expect(render_string('%span.#foo{id: :bar} hello')).to eq("<span id='foo_bar'>hello</span>\n")
72
+ expect(render_string('%span#foo{id: :bar} hello')).to eq("<span id='foo_bar'>hello</span>\n")
73
73
  end
74
74
 
75
75
  it 'escapes' do
@@ -65,6 +65,20 @@ HAML
65
65
  end
66
66
  end
67
67
 
68
+ context 'with invalid classes' do
69
+ it 'raises error' do
70
+ expect { render_string('%span. hello') }.to raise_error(Faml::SyntaxError)
71
+ expect { render_string('%span.{foo: "bar"} hello') }.to raise_error(Faml::SyntaxError)
72
+ end
73
+ end
74
+
75
+ context 'with invalid ids' do
76
+ it 'raises error' do
77
+ expect { render_string('%span# hello') }.to raise_error(Faml::SyntaxError)
78
+ expect { render_string('%span#{foo: "bar"} hello') }.to raise_error(Faml::SyntaxError)
79
+ end
80
+ end
81
+
68
82
  it 'parses #' do
69
83
  expect(render_string('#main')).to eq(%Q{<div id='main'></div>\n})
70
84
  end
@@ -7,6 +7,28 @@ class IncompatibilitiesGenerator
7
7
  include Singleton
8
8
 
9
9
  class Record < Struct.new(:template, :options, :spec_path, :line_number, :faml_result, :haml_result, :hamlit_result)
10
+ def incompatible?
11
+ !all_error? && (faml_result != haml_result || faml_result != hamlit_result || haml_result != hamlit_result)
12
+ end
13
+
14
+ def grouped_difference
15
+ case
16
+ when faml_result != haml_result && faml_result != hamlit_result && haml_result != hamlit_result
17
+ { 'Faml' => faml_result, 'Haml' => haml_result, 'Hamlit' => hamlit_result }
18
+ when faml_result == haml_result
19
+ { 'Faml, Haml' => faml_result, 'Hamlit' => hamlit_result }
20
+ when faml_result == hamlit_result
21
+ { 'Faml, Hamlit' => faml_result, 'Haml' => haml_result }
22
+ else
23
+ { 'Faml' => faml_result, 'Haml, Hamlit' => haml_result }
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def all_error?
30
+ [faml_result, haml_result, hamlit_result].all? { |r| r.is_a?(Exception) }
31
+ end
10
32
  end
11
33
 
12
34
  def initialize
@@ -23,9 +45,7 @@ class IncompatibilitiesGenerator
23
45
 
24
46
  incompatibilities = Hash.new { |h, k| h[k] = [] }
25
47
  @records.each do |record|
26
- if record.faml_result.is_a?(Exception) && record.haml_result.is_a?(Exception) && record.hamlit_result.is_a?(Exception)
27
- # All errored, not an incompatibility.
28
- elsif record.faml_result != record.haml_result || record.faml_result != record.hamlit_result || record.haml_result != record.hamlit_result
48
+ if record.incompatible?
29
49
  incompatibilities[record.spec_path] << record
30
50
  end
31
51
  end
@@ -70,15 +90,7 @@ class IncompatibilitiesGenerator
70
90
  ```
71
91
 
72
92
  EOS
73
- if record.faml_result != record.haml_result && record.faml_result != record.hamlit_result && record.haml_result != record.hamlit_result
74
- render_grouped_difference(file, 'Faml' => record.faml_result, 'Haml' => record.haml_result, 'Hamlit' => record.hamlit_result)
75
- elsif record.faml_result == record.haml_result
76
- render_grouped_difference(file, 'Faml, Haml' => record.faml_result, 'Hamlit' => record.hamlit_result)
77
- elsif record.faml_result == record.hamlit_result
78
- render_grouped_difference(file, 'Faml, Hamlit' => record.faml_result, 'Haml' => record.haml_result)
79
- else
80
- render_grouped_difference(file, 'Faml' => record.faml_result, 'Haml, Hamlit' => record.haml_result)
81
- end
93
+ render_grouped_difference(file, record.grouped_difference)
82
94
  end
83
95
 
84
96
  def render_input_title(options)
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.14
4
+ version: 0.2.15
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-06-11 00:00:00.000000000 Z
11
+ date: 2015-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils
@@ -305,14 +305,11 @@ files:
305
305
  - incompatibilities/spec/render/doctype_spec.md
306
306
  - incompatibilities/spec/render/element_spec.md
307
307
  - incompatibilities/spec/render/filters/cdata_spec.md
308
- - incompatibilities/spec/render/filters/coffee_spec.md
309
308
  - incompatibilities/spec/render/filters/css_spec.md
310
309
  - incompatibilities/spec/render/filters/escaped_spec.md
311
310
  - incompatibilities/spec/render/filters/javascript_spec.md
312
311
  - incompatibilities/spec/render/filters/markdown_spec.md
313
312
  - incompatibilities/spec/render/filters/preserve_spec.md
314
- - incompatibilities/spec/render/filters/sass_spec.md
315
- - incompatibilities/spec/render/filters/scss_spec.md
316
313
  - incompatibilities/spec/render/helpers_spec.md
317
314
  - incompatibilities/spec/render/indent_spec.md
318
315
  - incompatibilities/spec/render/multiline_spec.md
@@ -484,14 +481,11 @@ test_files:
484
481
  - incompatibilities/spec/render/doctype_spec.md
485
482
  - incompatibilities/spec/render/element_spec.md
486
483
  - incompatibilities/spec/render/filters/cdata_spec.md
487
- - incompatibilities/spec/render/filters/coffee_spec.md
488
484
  - incompatibilities/spec/render/filters/css_spec.md
489
485
  - incompatibilities/spec/render/filters/escaped_spec.md
490
486
  - incompatibilities/spec/render/filters/javascript_spec.md
491
487
  - incompatibilities/spec/render/filters/markdown_spec.md
492
488
  - incompatibilities/spec/render/filters/preserve_spec.md
493
- - incompatibilities/spec/render/filters/sass_spec.md
494
- - incompatibilities/spec/render/filters/scss_spec.md
495
489
  - incompatibilities/spec/render/helpers_spec.md
496
490
  - incompatibilities/spec/render/indent_spec.md
497
491
  - incompatibilities/spec/render/multiline_spec.md
@@ -1,88 +0,0 @@
1
- # [./spec/render/filters/coffee_spec.rb:4](../../../../spec/render/filters/coffee_spec.rb#L4)
2
- ## Input
3
- ```haml
4
- :coffee
5
- square = (x) -> x * x
6
- square(3)
7
-
8
- ```
9
-
10
- ## Faml
11
- ```html
12
- <script>
13
- (function() {
14
- var square;
15
-
16
- square = function(x) {
17
- return x * x;
18
- };
19
-
20
- square(3);
21
-
22
- }).call(this);
23
-
24
- </script>
25
-
26
- ```
27
-
28
- ## Haml, Hamlit
29
- ```html
30
- <script>
31
- (function() {
32
- var square;
33
-
34
- square = function(x) {
35
- return x * x;
36
- };
37
-
38
- square(3);
39
-
40
- }).call(this);
41
- </script>
42
-
43
- ```
44
-
45
- # [./spec/render/filters/coffee_spec.rb:15](../../../../spec/render/filters/coffee_spec.rb#L15)
46
- ## Input
47
- ```haml
48
- :coffee
49
- square = (x) -> x * x
50
- square(#{1 + 2})
51
-
52
- ```
53
-
54
- ## Faml
55
- ```html
56
- <script>
57
- (function() {
58
- var square;
59
-
60
- square = function(x) {
61
- return x * x;
62
- };
63
-
64
- square(3);
65
-
66
- }).call(this);
67
-
68
- </script>
69
-
70
- ```
71
-
72
- ## Haml, Hamlit
73
- ```html
74
- <script>
75
- (function() {
76
- var square;
77
-
78
- square = function(x) {
79
- return x * x;
80
- };
81
-
82
- square(3);
83
-
84
- }).call(this);
85
- </script>
86
-
87
- ```
88
-
@@ -1,59 +0,0 @@
1
- # [./spec/render/filters/sass_spec.rb:4](../../../../spec/render/filters/sass_spec.rb#L4)
2
- ## Input
3
- ```haml
4
- :sass
5
- nav
6
- ul
7
- margin: 0
8
- content: "hello"
9
-
10
- ```
11
-
12
- ## Faml
13
- ```html
14
- <style>
15
- nav ul {
16
- margin: 0;
17
- content: "hello"; }
18
- </style>
19
-
20
- ```
21
-
22
- ## Haml, Hamlit
23
- ```html
24
- <style>
25
- nav ul {
26
- margin: 0;
27
- content: "hello"; }
28
- </style>
29
-
30
- ```
31
-
32
- # [./spec/render/filters/sass_spec.rb:17](../../../../spec/render/filters/sass_spec.rb#L17)
33
- ## Input
34
- ```haml
35
- :sass
36
- nav
37
- ul
38
- margin: #{0 + 5}px
39
-
40
- ```
41
-
42
- ## Faml
43
- ```html
44
- <style>
45
- nav ul {
46
- margin: 5px; }
47
- </style>
48
-
49
- ```
50
-
51
- ## Haml, Hamlit
52
- ```html
53
- <style>
54
- nav ul {
55
- margin: 5px; }
56
- </style>
57
-
58
- ```
59
-
@@ -1,65 +0,0 @@
1
- # [./spec/render/filters/scss_spec.rb:4](../../../../spec/render/filters/scss_spec.rb#L4)
2
- ## Input
3
- ```haml
4
- :scss
5
- nav {
6
- ul {
7
- margin: 0;
8
- content: "hello";
9
- }
10
- }
11
-
12
- ```
13
-
14
- ## Faml
15
- ```html
16
- <style>
17
- nav ul {
18
- margin: 0;
19
- content: "hello"; }
20
-
21
- </style>
22
-
23
- ```
24
-
25
- ## Haml, Hamlit
26
- ```html
27
- <style>
28
- nav ul {
29
- margin: 0;
30
- content: "hello"; }
31
- </style>
32
-
33
- ```
34
-
35
- # [./spec/render/filters/scss_spec.rb:19](../../../../spec/render/filters/scss_spec.rb#L19)
36
- ## Input
37
- ```haml
38
- :scss
39
- nav {
40
- ul {
41
- margin: #{0 + 5}px;
42
- }
43
- }
44
-
45
- ```
46
-
47
- ## Faml
48
- ```html
49
- <style>
50
- nav ul {
51
- margin: 5px; }
52
-
53
- </style>
54
-
55
- ```
56
-
57
- ## Haml, Hamlit
58
- ```html
59
- <style>
60
- nav ul {
61
- margin: 5px; }
62
- </style>
63
-
64
- ```
65
-