faml 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/benchmark/compiling.rb +1 -0
- data/benchmark/context.rb +1 -0
- data/benchmark/rendering.rb +1 -0
- data/benchmark/slim.rb +1 -0
- data/ext/attribute_builder/extconf.rb +1 -0
- data/faml.gemspec +1 -1
- data/haml_spec_test.rb +1 -0
- data/incompatibilities/README.md +1 -1
- data/incompatibilities/spec/compiler_newline_spec.md +1 -1
- data/incompatibilities/spec/render/attribute_spec.md +314 -28
- data/incompatibilities/spec/render/comment_spec.md +1 -1
- data/incompatibilities/spec/render/doctype_spec.md +1 -1
- data/incompatibilities/spec/render/element_spec.md +1 -1
- data/incompatibilities/spec/render/filters/cdata_spec.md +1 -1
- data/incompatibilities/spec/render/filters/css_spec.md +1 -1
- data/incompatibilities/spec/render/filters/escaped_spec.md +1 -1
- data/incompatibilities/spec/render/filters/javascript_spec.md +1 -1
- data/incompatibilities/spec/render/filters/markdown_spec.md +1 -1
- data/incompatibilities/spec/render/filters/plain_spec.md +2 -2
- data/incompatibilities/spec/render/filters/preserve_spec.md +1 -1
- data/incompatibilities/spec/render/helpers_spec.md +2 -2
- data/incompatibilities/spec/render/multiline_spec.md +2 -2
- data/incompatibilities/spec/render/newline_spec.md +4 -4
- data/incompatibilities/spec/render/plain_spec.md +1 -1
- data/incompatibilities/spec/render/sanitize_spec.md +2 -2
- data/incompatibilities/spec/render/silent_script_spec.md +1 -1
- data/incompatibilities/spec/render/unescape_spec.md +3 -3
- data/lib/faml.rb +1 -0
- data/lib/faml/attribute_compiler.rb +1 -0
- data/lib/faml/attribute_optimizer.rb +14 -3
- data/lib/faml/cli.rb +1 -0
- data/lib/faml/compiler.rb +1 -0
- data/lib/faml/engine.rb +1 -0
- data/lib/faml/error.rb +1 -0
- data/lib/faml/filter_compilers.rb +1 -0
- data/lib/faml/filter_compilers/base.rb +1 -0
- data/lib/faml/filter_compilers/cdata.rb +1 -0
- data/lib/faml/filter_compilers/coffee.rb +1 -0
- data/lib/faml/filter_compilers/css.rb +1 -0
- data/lib/faml/filter_compilers/escaped.rb +1 -0
- data/lib/faml/filter_compilers/javascript.rb +1 -0
- data/lib/faml/filter_compilers/markdown.rb +1 -0
- data/lib/faml/filter_compilers/plain.rb +1 -0
- data/lib/faml/filter_compilers/preserve.rb +1 -0
- data/lib/faml/filter_compilers/ruby.rb +1 -0
- data/lib/faml/filter_compilers/sass.rb +1 -0
- data/lib/faml/filter_compilers/scss.rb +1 -0
- data/lib/faml/filter_compilers/tilt_base.rb +1 -0
- data/lib/faml/helpers.rb +1 -0
- data/lib/faml/html.rb +1 -0
- data/lib/faml/newline.rb +1 -0
- data/lib/faml/object_ref.rb +1 -0
- data/lib/faml/rails_handler.rb +1 -0
- data/lib/faml/rails_helpers.rb +1 -0
- data/lib/faml/railtie.rb +1 -0
- data/lib/faml/ruby_syntax_checker.rb +1 -0
- data/lib/faml/script_end.rb +1 -0
- data/lib/faml/static_hash_parser.rb +37 -13
- data/lib/faml/stats.rb +1 -0
- data/lib/faml/text_compiler.rb +1 -0
- data/lib/faml/tilt.rb +1 -0
- data/lib/faml/version.rb +2 -1
- data/spec/compiler_newline_spec.rb +1 -0
- data/spec/rails/app/controllers/application_controller.rb +1 -0
- data/spec/rails/app/controllers/books_controller.rb +1 -0
- data/spec/rails/app/helpers/application_helper.rb +1 -0
- data/spec/rails/app/models/book.rb +1 -0
- data/spec/rails/config/application.rb +1 -0
- data/spec/rails/config/boot.rb +1 -0
- data/spec/rails/config/environment.rb +1 -0
- data/spec/rails/config/environments/development.rb +1 -0
- data/spec/rails/config/environments/production.rb +1 -0
- data/spec/rails/config/environments/test.rb +1 -0
- data/spec/rails/config/initializers/assets.rb +1 -0
- data/spec/rails/config/initializers/backtrace_silencers.rb +1 -0
- data/spec/rails/config/initializers/cookies_serializer.rb +1 -0
- data/spec/rails/config/initializers/filter_parameter_logging.rb +1 -0
- data/spec/rails/config/initializers/inflections.rb +1 -0
- data/spec/rails/config/initializers/mime_types.rb +1 -0
- data/spec/rails/config/initializers/secret_key_base.rb +1 -0
- data/spec/rails/config/initializers/session_store.rb +1 -0
- data/spec/rails/config/initializers/wrap_parameters.rb +1 -0
- data/spec/rails/config/routes.rb +1 -0
- data/spec/rails/db/seeds.rb +1 -0
- data/spec/rails/spec/requests/faml_spec.rb +1 -0
- data/spec/rails_helper.rb +1 -0
- data/spec/render/attribute_spec.rb +33 -0
- data/spec/render/comment_spec.rb +1 -0
- data/spec/render/doctype_spec.rb +1 -0
- data/spec/render/element_spec.rb +1 -0
- data/spec/render/filters/cdata_spec.rb +1 -0
- data/spec/render/filters/coffee_spec.rb +1 -0
- data/spec/render/filters/css_spec.rb +1 -0
- data/spec/render/filters/escaped_spec.rb +1 -0
- data/spec/render/filters/javascript_spec.rb +1 -0
- data/spec/render/filters/markdown_spec.rb +1 -0
- data/spec/render/filters/plain_spec.rb +1 -0
- data/spec/render/filters/preserve_spec.rb +1 -0
- data/spec/render/filters/ruby_spec.rb +1 -0
- data/spec/render/filters/sass_spec.rb +1 -0
- data/spec/render/filters/scss_spec.rb +1 -0
- data/spec/render/filters_spec.rb +1 -0
- data/spec/render/haml_comment_spec.rb +1 -0
- data/spec/render/helpers_spec.rb +1 -0
- data/spec/render/multiline_spec.rb +1 -0
- data/spec/render/newline_spec.rb +1 -0
- data/spec/render/plain_spec.rb +1 -0
- data/spec/render/preserve_spec.rb +1 -0
- data/spec/render/sanitize_spec.rb +1 -0
- data/spec/render/script_spec.rb +1 -0
- data/spec/render/silent_script_spec.rb +1 -0
- data/spec/render/unescape_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/incompatibilities_generator.rb +2 -1
- data/spec/tilt_spec.rb +1 -0
- metadata +3 -3
@@ -1,4 +1,4 @@
|
|
1
|
-
# [./spec/render/filters/plain_spec.rb:
|
1
|
+
# [./spec/render/filters/plain_spec.rb:5](../../../../spec/render/filters/plain_spec.rb#L5)
|
2
2
|
## Input
|
3
3
|
```haml
|
4
4
|
%span
|
@@ -27,7 +27,7 @@ hello
|
|
27
27
|
|
28
28
|
```
|
29
29
|
|
30
|
-
# [./spec/render/filters/plain_spec.rb:
|
30
|
+
# [./spec/render/filters/plain_spec.rb:14](../../../../spec/render/filters/plain_spec.rb#L14)
|
31
31
|
## Input
|
32
32
|
```haml
|
33
33
|
%span
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# [./spec/render/helpers_spec.rb:
|
1
|
+
# [./spec/render/helpers_spec.rb:5](../../../spec/render/helpers_spec.rb#L5)
|
2
2
|
## Input (with options={:extend_helpers=>true})
|
3
3
|
```haml
|
4
4
|
%span!= preserve "hello\nworld !"
|
@@ -12,6 +12,6 @@
|
|
12
12
|
|
13
13
|
## Hamlit (Error)
|
14
14
|
```html
|
15
|
-
undefined method `preserve' for #<Object:
|
15
|
+
undefined method `preserve' for #<Object:0x000000047293c8>
|
16
16
|
```
|
17
17
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# [./spec/render/multiline_spec.rb:
|
1
|
+
# [./spec/render/multiline_spec.rb:23](../../../spec/render/multiline_spec.rb#L23)
|
2
2
|
## Input
|
3
3
|
```haml
|
4
4
|
%p
|
@@ -24,7 +24,7 @@ foo bar baz
|
|
24
24
|
|
25
25
|
```
|
26
26
|
|
27
|
-
# [./spec/render/multiline_spec.rb:
|
27
|
+
# [./spec/render/multiline_spec.rb:48](../../../spec/render/multiline_spec.rb#L48)
|
28
28
|
## Input
|
29
29
|
```haml
|
30
30
|
:javascript
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# [./spec/render/newline_spec.rb:
|
1
|
+
# [./spec/render/newline_spec.rb:20](../../../spec/render/newline_spec.rb#L20)
|
2
2
|
## Input
|
3
3
|
```haml
|
4
4
|
%div
|
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
```
|
22
22
|
|
23
|
-
# [./spec/render/newline_spec.rb:
|
23
|
+
# [./spec/render/newline_spec.rb:28](../../../spec/render/newline_spec.rb#L28)
|
24
24
|
## Input
|
25
25
|
```haml
|
26
26
|
%div
|
@@ -46,7 +46,7 @@
|
|
46
46
|
|
47
47
|
```
|
48
48
|
|
49
|
-
# [./spec/render/newline_spec.rb:
|
49
|
+
# [./spec/render/newline_spec.rb:37](../../../spec/render/newline_spec.rb#L37)
|
50
50
|
## Input
|
51
51
|
```haml
|
52
52
|
%div
|
@@ -72,7 +72,7 @@
|
|
72
72
|
|
73
73
|
```
|
74
74
|
|
75
|
-
# [./spec/render/newline_spec.rb:
|
75
|
+
# [./spec/render/newline_spec.rb:72](../../../spec/render/newline_spec.rb#L72)
|
76
76
|
## Input
|
77
77
|
```haml
|
78
78
|
%div(foo="bar") <b>hello</b>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# [./spec/render/sanitize_spec.rb:
|
1
|
+
# [./spec/render/sanitize_spec.rb:25](../../../spec/render/sanitize_spec.rb#L25)
|
2
2
|
## Input
|
3
3
|
```haml
|
4
4
|
&~ "<p>hello</p>"
|
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
```
|
18
18
|
|
19
|
-
# [./spec/render/sanitize_spec.rb:
|
19
|
+
# [./spec/render/sanitize_spec.rb:25](../../../spec/render/sanitize_spec.rb#L25)
|
20
20
|
## Input
|
21
21
|
```haml
|
22
22
|
%span&~ "<p>hello</p>"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# [./spec/render/unescape_spec.rb:
|
1
|
+
# [./spec/render/unescape_spec.rb:18](../../../spec/render/unescape_spec.rb#L18)
|
2
2
|
## Input
|
3
3
|
```haml
|
4
4
|
!<p>hello</p>
|
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
```
|
18
18
|
|
19
|
-
# [./spec/render/unescape_spec.rb:
|
19
|
+
# [./spec/render/unescape_spec.rb:34](../../../spec/render/unescape_spec.rb#L34)
|
20
20
|
## Input
|
21
21
|
```haml
|
22
22
|
!~ "<p>hello\n<pre>pre\nworld</pre></p>"
|
@@ -35,7 +35,7 @@
|
|
35
35
|
|
36
36
|
```
|
37
37
|
|
38
|
-
# [./spec/render/unescape_spec.rb:
|
38
|
+
# [./spec/render/unescape_spec.rb:34](../../../spec/render/unescape_spec.rb#L34)
|
39
39
|
## Input
|
40
40
|
```haml
|
41
41
|
%span!~ "<p>hello\n<pre>pre\nworld</pre></p>"
|
data/lib/faml.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen-string-literal: true
|
1
2
|
require_relative 'error'
|
2
3
|
require_relative 'ruby_syntax_checker'
|
3
4
|
require_relative 'static_hash_parser'
|
@@ -40,11 +41,21 @@ module Faml
|
|
40
41
|
|
41
42
|
def build_optimized_static_attributes(parser, static_id, static_class)
|
42
43
|
static_attributes = {}
|
44
|
+
class_list = []
|
45
|
+
id_list = []
|
43
46
|
parser.static_attributes.each do |k, v|
|
44
|
-
|
47
|
+
k = k.to_s
|
48
|
+
case k
|
49
|
+
when 'id'
|
50
|
+
id_list.concat(Array(v))
|
51
|
+
when 'class'
|
52
|
+
class_list.concat(Array(v))
|
53
|
+
else
|
54
|
+
static_attributes[k] = v
|
55
|
+
end
|
45
56
|
end
|
46
57
|
|
47
|
-
class_list =
|
58
|
+
class_list = class_list.select { |v| v }.flat_map { |c| c.to_s.split(/ +/) }
|
48
59
|
unless static_class.empty?
|
49
60
|
class_list.concat(static_class.split(/ +/))
|
50
61
|
end
|
@@ -52,7 +63,7 @@ module Faml
|
|
52
63
|
static_attributes['class'] = class_list.uniq.sort.join(' ')
|
53
64
|
end
|
54
65
|
|
55
|
-
id_list =
|
66
|
+
id_list = id_list.select { |v| v }
|
56
67
|
unless static_id.empty?
|
57
68
|
id_list = [static_id].concat(id_list)
|
58
69
|
end
|
data/lib/faml/cli.rb
CHANGED
data/lib/faml/compiler.rb
CHANGED
data/lib/faml/engine.rb
CHANGED
data/lib/faml/error.rb
CHANGED
data/lib/faml/helpers.rb
CHANGED
data/lib/faml/html.rb
CHANGED
data/lib/faml/newline.rb
CHANGED
data/lib/faml/object_ref.rb
CHANGED
data/lib/faml/rails_handler.rb
CHANGED
data/lib/faml/rails_helpers.rb
CHANGED
data/lib/faml/railtie.rb
CHANGED
data/lib/faml/script_end.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen-string-literal: true
|
1
2
|
require 'parser/current'
|
2
3
|
|
3
4
|
module Faml
|
@@ -65,24 +66,26 @@ module Faml
|
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
def try_static_value(key_static, node)
|
69
|
+
def try_static_value(key_static, node, force_static: false)
|
69
70
|
case node.type
|
70
71
|
when :sym, :int, :float, :str, :rational, :complex
|
71
|
-
|
72
|
+
set_static_attribute(key_static, node.children[0])
|
72
73
|
when :true
|
73
|
-
|
74
|
+
set_static_attribute(key_static, true)
|
74
75
|
when :false
|
75
|
-
|
76
|
+
set_static_attribute(key_static, false)
|
76
77
|
when :nil
|
77
|
-
|
78
|
+
set_static_attribute(key_static, nil)
|
78
79
|
when :dstr
|
79
|
-
|
80
|
+
if force_static
|
81
|
+
throw FAILURE_TAG
|
82
|
+
end
|
83
|
+
set_dynamic_attributes(key_static, node.location.expression.source)
|
80
84
|
when :send
|
81
|
-
if
|
85
|
+
if force_static
|
82
86
|
throw FAILURE_TAG
|
83
|
-
else
|
84
|
-
@dynamic_attributes[key_static] = node.location.expression.source
|
85
87
|
end
|
88
|
+
set_dynamic_attributes(key_static, node.location.expression.source)
|
86
89
|
when :hash
|
87
90
|
try_static_hash_value(key_static, node)
|
88
91
|
when :array
|
@@ -91,6 +94,7 @@ module Faml
|
|
91
94
|
throw FAILURE_TAG
|
92
95
|
end
|
93
96
|
end
|
97
|
+
protected :try_static_value
|
94
98
|
|
95
99
|
def try_static_hash_value(key_static, node)
|
96
100
|
parser = self.class.new
|
@@ -104,7 +108,7 @@ module Faml
|
|
104
108
|
|
105
109
|
def merge_attributes(key_static, parser)
|
106
110
|
unless parser.static_attributes.empty?
|
107
|
-
|
111
|
+
set_static_attribute(key_static, parser.static_attributes)
|
108
112
|
end
|
109
113
|
|
110
114
|
unless parser.dynamic_attributes.empty?
|
@@ -116,10 +120,30 @@ module Faml
|
|
116
120
|
end
|
117
121
|
|
118
122
|
def try_static_array_value(key_static, node)
|
119
|
-
|
120
|
-
|
123
|
+
parser = self.class.new
|
124
|
+
arr = node.children.map.with_index do |child, i|
|
125
|
+
# TODO: Support dynamic_attributes?
|
126
|
+
parser.try_static_value(i, child, force_static: true)
|
127
|
+
end
|
128
|
+
set_static_attribute(key_static, arr)
|
129
|
+
end
|
130
|
+
|
131
|
+
def set_static_attribute(key, val)
|
132
|
+
case key.to_s
|
133
|
+
when 'id', 'class'
|
134
|
+
@static_attributes[key] ||= []
|
135
|
+
@static_attributes[key].concat(Array(val))
|
136
|
+
else
|
137
|
+
@static_attributes[key] = val
|
138
|
+
end
|
139
|
+
val
|
140
|
+
end
|
141
|
+
|
142
|
+
def set_dynamic_attributes(key, val)
|
143
|
+
if SPECIAL_ATTRIBUTES.include?(key.to_s)
|
144
|
+
throw FAILURE_TAG
|
121
145
|
end
|
122
|
-
@
|
146
|
+
@dynamic_attributes[key] = val
|
123
147
|
end
|
124
148
|
end
|
125
149
|
end
|