faml 0.3.2 → 0.3.3
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 +4 -4
- data/.rubocop.yml +44 -0
- data/.rubocop_todo.yml +43 -0
- data/CHANGELOG.md +7 -0
- data/Rakefile +1 -1
- data/benchmark/compiling.rb +1 -1
- data/benchmark/context.rb +3 -3
- data/benchmark/rendering.rb +5 -5
- data/benchmark/slim.rb +2 -2
- data/ext/attribute_builder/attribute_builder.c +30 -30
- data/faml.gemspec +29 -28
- data/haml_spec_test.rb +4 -4
- data/incompatibilities/spec/render/attribute_spec.md +0 -0
- data/lib/faml/cli.rb +6 -0
- data/lib/faml/compiler.rb +23 -16
- data/lib/faml/engine.rb +1 -1
- data/lib/faml/filter_compilers.rb +1 -1
- data/lib/faml/filter_compilers/escaped.rb +2 -2
- data/lib/faml/filter_compilers/preserve.rb +2 -2
- data/lib/faml/html.rb +16 -16
- data/lib/faml/newline.rb +1 -1
- data/lib/faml/railtie.rb +1 -1
- data/lib/faml/static_hash_parser.rb +2 -2
- data/lib/faml/stats.rb +148 -0
- data/lib/faml/text_compiler.rb +4 -4
- data/lib/faml/tilt.rb +1 -1
- data/lib/faml/version.rb +1 -1
- data/spec/rails/bin/setup +8 -8
- data/spec/rails/spec/requests/faml_spec.rb +1 -1
- data/spec/rails_helper.rb +2 -2
- data/spec/render/attribute_spec.rb +13 -3
- data/spec/render/filters/escaped_spec.rb +1 -1
- data/spec/render/filters/plain_spec.rb +2 -2
- data/spec/render/filters/sass_spec.rb +1 -1
- data/spec/render/filters/scss_spec.rb +1 -1
- data/spec/render/newline_spec.rb +1 -1
- data/spec/support/incompatibilities_generator.rb +5 -5
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f188aeb028e6438b455033f6f2efe701297ad13
|
4
|
+
data.tar.gz: cac035f6c7671aef877c83ff47d7e772941b2d1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e9c2a21ca2ad84c4cb9c219bfbf971c11e85bc07fa02910a177a9f081a82a18ea37a9e4b0ecf900f84150eb41f369f65ed14c1b6b5c3ea8dc5791500c9da58e
|
7
|
+
data.tar.gz: 2f0873cb28c9d275e2c11ca00d2ff3b0ca3d37d794ab2c76c747eaf82cd8f780a7dc376f615dccbaf736f8a6e32c510516c790002e544fed70d0696bb260d961
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- 'haml-spec/**/*'
|
6
|
+
|
7
|
+
Lint/HandleExceptions:
|
8
|
+
Exclude:
|
9
|
+
# Ignore LoadError
|
10
|
+
- 'lib/faml.rb'
|
11
|
+
- 'lib/faml/tilt.rb'
|
12
|
+
Lint/Eval:
|
13
|
+
Exclude:
|
14
|
+
- 'lib/faml/static_hash_parser.rb'
|
15
|
+
- 'spec/spec_helper.rb'
|
16
|
+
|
17
|
+
Style/BarePercentLiterals:
|
18
|
+
EnforcedStyle: percent_q
|
19
|
+
Style/CaseEquality:
|
20
|
+
Enabled: false
|
21
|
+
Style/GlobalVars:
|
22
|
+
Exclude:
|
23
|
+
- '**/extconf.rb'
|
24
|
+
Style/GuardClause:
|
25
|
+
Enabled: false
|
26
|
+
Style/HashSyntax:
|
27
|
+
Exclude:
|
28
|
+
- 'Rakefile'
|
29
|
+
Style/IfUnlessModifier:
|
30
|
+
Enabled: false
|
31
|
+
Style/PercentLiteralDelimiters:
|
32
|
+
Enabled: false
|
33
|
+
Style/RaiseArgs:
|
34
|
+
EnforcedStyle: compact
|
35
|
+
Style/SignalException:
|
36
|
+
Enabled: false
|
37
|
+
Style/TrailingComma:
|
38
|
+
Enabled: false
|
39
|
+
Style/TrailingWhitespace:
|
40
|
+
Exclude:
|
41
|
+
- 'spec/render/multiline_spec.rb'
|
42
|
+
|
43
|
+
Style/UnneededPercentQ:
|
44
|
+
Enabled: false # buggy
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2015-10-06 23:31:05 +0900 using RuboCop version 0.34.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 17
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 32
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
Metrics/BlockNesting:
|
15
|
+
Max: 4
|
16
|
+
|
17
|
+
# Offense count: 4
|
18
|
+
# Configuration parameters: CountComments.
|
19
|
+
Metrics/ClassLength:
|
20
|
+
Max: 341
|
21
|
+
|
22
|
+
# Offense count: 7
|
23
|
+
Metrics/CyclomaticComplexity:
|
24
|
+
Max: 12
|
25
|
+
|
26
|
+
# Offense count: 214
|
27
|
+
# Configuration parameters: AllowURI, URISchemes.
|
28
|
+
Metrics/LineLength:
|
29
|
+
Max: 199
|
30
|
+
|
31
|
+
# Offense count: 20
|
32
|
+
# Configuration parameters: CountComments.
|
33
|
+
Metrics/MethodLength:
|
34
|
+
Max: 29
|
35
|
+
|
36
|
+
# Offense count: 5
|
37
|
+
Metrics/PerceivedComplexity:
|
38
|
+
Max: 13
|
39
|
+
|
40
|
+
# Offense count: 45
|
41
|
+
# Configuration parameters: Exclude.
|
42
|
+
Style/Documentation:
|
43
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.3.3 (2015-10-07)
|
2
|
+
- Improve `Faml::AttributeBuilder.build` performance
|
3
|
+
- Optimize string conversions
|
4
|
+
- Fix handling true/false/nil values in data attribute
|
5
|
+
- Add `stats` subcommand
|
6
|
+
- Currently, it shows AST ratio and element attribute's ratio.
|
7
|
+
|
1
8
|
## 0.3.2 (2015-09-24)
|
2
9
|
- Fix illegal constant name
|
3
10
|
- Use `require_relative` if possible
|
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ namespace :benchmark do
|
|
22
22
|
sh 'ruby', 'benchmark/rendering.rb', standard_haml_path
|
23
23
|
end
|
24
24
|
|
25
|
-
desc
|
25
|
+
desc 'Run rendering benchmark for attribute builder'
|
26
26
|
task :attributes do
|
27
27
|
sh 'ruby', 'benchmark/rendering.rb', 'benchmark/attribute_builder.haml', 'benchmark/attribute_builder.slim'
|
28
28
|
end
|
data/benchmark/compiling.rb
CHANGED
data/benchmark/context.rb
CHANGED
@@ -4,8 +4,8 @@ class Context
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def item
|
7
|
-
[
|
8
|
-
|
9
|
-
|
7
|
+
[{ name: 'red', current: true, url: '#red' },
|
8
|
+
{ name: 'green', current: false, url: '#green' },
|
9
|
+
{ name: 'blue', current: false, url: '#blue' }]
|
10
10
|
end
|
11
11
|
end
|
data/benchmark/rendering.rb
CHANGED
@@ -7,7 +7,7 @@ require 'slim'
|
|
7
7
|
require 'escape_utils/html/haml'
|
8
8
|
|
9
9
|
unless ARGV[0]
|
10
|
-
$stderr.puts "Usage: #{$
|
10
|
+
$stderr.puts "Usage: #{$PROGRAM_NAME} template.haml [template.slim]"
|
11
11
|
exit 1
|
12
12
|
end
|
13
13
|
|
@@ -18,17 +18,17 @@ Benchmark.ips do |x|
|
|
18
18
|
obj = Object.new
|
19
19
|
|
20
20
|
Haml::Engine.new(haml_code, ugly: true, escape_html: true).def_method(obj, :haml)
|
21
|
-
obj.instance_eval
|
21
|
+
obj.instance_eval "
|
22
22
|
def faml_array; #{Faml::Engine.new.call(haml_code)}; end
|
23
23
|
def faml_string; #{Faml::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(haml_code)}; end
|
24
24
|
def hamlit_array; #{Hamlit::Engine.new.call(haml_code)}; end
|
25
25
|
def hamlit_string; #{Hamlit::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(haml_code)}; end
|
26
|
-
|
26
|
+
"
|
27
27
|
if slim_code
|
28
|
-
obj.instance_eval
|
28
|
+
obj.instance_eval "
|
29
29
|
def slim_array; #{Slim::Engine.new.call(slim_code)}; end
|
30
30
|
def slim_string; #{Slim::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(slim_code)}; end
|
31
|
-
|
31
|
+
"
|
32
32
|
end
|
33
33
|
|
34
34
|
x.report('Haml') { obj.haml }
|
data/benchmark/slim.rb
CHANGED
@@ -13,11 +13,11 @@ slim_code = File.read(File.join(__dir__, 'view.slim'))
|
|
13
13
|
|
14
14
|
context = Context.new
|
15
15
|
Haml::Engine.new(haml_code, ugly: true, escape_html: true).def_method(context, :haml)
|
16
|
-
context.instance_eval
|
16
|
+
context.instance_eval "
|
17
17
|
def faml; #{Faml::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(haml_code)}; end
|
18
18
|
def hamlit; #{Hamlit::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(haml_code)}; end
|
19
19
|
def slim; #{Slim::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(slim_code)}; end
|
20
|
-
|
20
|
+
"
|
21
21
|
|
22
22
|
Benchmark.ips do |x|
|
23
23
|
x.report('Haml') { context.haml }
|
@@ -11,7 +11,7 @@
|
|
11
11
|
#endif
|
12
12
|
|
13
13
|
VALUE rb_mAttributeBuilder;
|
14
|
-
static ID id_keys, id_sort_bang, id_uniq_bang, id_merge_bang
|
14
|
+
static ID id_keys, id_sort_bang, id_uniq_bang, id_merge_bang;
|
15
15
|
static ID id_id, id_class, id_underscore, id_hyphen, id_space, id_equal;
|
16
16
|
|
17
17
|
static void
|
@@ -34,7 +34,7 @@ concat_array_attribute(VALUE attributes, VALUE hash, VALUE key)
|
|
34
34
|
static int
|
35
35
|
stringify_keys_i(VALUE key, VALUE value, VALUE arg)
|
36
36
|
{
|
37
|
-
key =
|
37
|
+
key = rb_convert_type(key, T_STRING, "String", "to_s");
|
38
38
|
rb_hash_aset(arg, key, value);
|
39
39
|
return ST_CONTINUE;
|
40
40
|
}
|
@@ -77,16 +77,15 @@ substitute_underscores(VALUE str)
|
|
77
77
|
static int
|
78
78
|
normalize_data_i2(VALUE key, VALUE value, VALUE ptr)
|
79
79
|
{
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
k
|
80
|
+
if (!(RB_TYPE_P(value, T_FALSE) || NIL_P(value))) {
|
81
|
+
struct normalize_data_i2_arg *arg = (struct normalize_data_i2_arg *)ptr;
|
82
|
+
VALUE k = rb_str_dup(arg->key);
|
83
|
+
|
84
|
+
k = rb_str_dup(arg->key);
|
85
|
+
rb_str_cat(k, "-", 1);
|
86
|
+
rb_str_append(k, key);
|
87
|
+
rb_hash_aset(arg->normalized, k, value);
|
86
88
|
}
|
87
|
-
rb_str_cat(k, "-", 1);
|
88
|
-
rb_str_append(k, key);
|
89
|
-
rb_hash_aset(arg->normalized, k, value);
|
90
89
|
return ST_CONTINUE;
|
91
90
|
}
|
92
91
|
|
@@ -95,15 +94,21 @@ static VALUE normalize_data(VALUE data);
|
|
95
94
|
static int
|
96
95
|
normalize_data_i(VALUE key, VALUE value, VALUE normalized)
|
97
96
|
{
|
97
|
+
key = rb_convert_type(key, T_STRING, "String", "to_s");
|
98
|
+
key = substitute_underscores(key);
|
99
|
+
|
98
100
|
if (RB_TYPE_P(value, T_HASH)) {
|
99
101
|
struct normalize_data_i2_arg arg;
|
100
102
|
arg.key = key;
|
101
103
|
arg.normalized = normalized;
|
102
104
|
rb_hash_foreach(normalize_data(value), normalize_data_i2, (VALUE)(&arg));
|
103
|
-
} else {
|
104
|
-
|
105
|
-
key = substitute_underscores(key);
|
105
|
+
} else if (RB_TYPE_P(value, T_TRUE)) {
|
106
|
+
/* Keep Qtrue value */
|
106
107
|
rb_hash_aset(normalized, key, value);
|
108
|
+
} else if (RB_TYPE_P(value, T_FALSE) || NIL_P(value)) {
|
109
|
+
/* Delete falsey values */
|
110
|
+
} else {
|
111
|
+
rb_hash_aset(normalized, key, rb_convert_type(value, T_STRING, "String", "to_s"));
|
107
112
|
}
|
108
113
|
return ST_CONTINUE;
|
109
114
|
}
|
@@ -138,19 +143,21 @@ normalize(VALUE hash)
|
|
138
143
|
for (i = 0; i < len; i++) {
|
139
144
|
VALUE key = RARRAY_AREF(keys, i);
|
140
145
|
VALUE value = rb_hash_lookup(hash, key);
|
141
|
-
VALUE key_str = key;
|
142
146
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
if (RB_TYPE_P(value, T_HASH) && RSTRING_LEN(key_str) == 4 && memcmp(RSTRING_PTR(key_str), "data", 4) == 0) {
|
147
|
+
/* key must be String because it is already stringified by stringify_keys */
|
148
|
+
Check_Type(key, T_STRING);
|
149
|
+
if (RB_TYPE_P(value, T_HASH) && RSTRING_LEN(key) == 4 && memcmp(RSTRING_PTR(key), "data", 4) == 0) {
|
147
150
|
VALUE data;
|
148
151
|
|
149
152
|
rb_hash_delete(hash, key);
|
150
153
|
data = normalize_data(value);
|
151
154
|
rb_hash_foreach(data, put_data_attribute, hash);
|
152
|
-
} else if (
|
153
|
-
|
155
|
+
} else if (RB_TYPE_P(value, T_TRUE)) {
|
156
|
+
/* Keep Qtrue value */
|
157
|
+
} else if (RB_TYPE_P(value, T_FALSE) || NIL_P(value)) {
|
158
|
+
rb_hash_delete(hash, key);
|
159
|
+
} else {
|
160
|
+
rb_hash_aset(hash, key, rb_convert_type(value, T_STRING, "String", "to_s"));
|
154
161
|
}
|
155
162
|
}
|
156
163
|
}
|
@@ -177,7 +184,6 @@ put_attribute(VALUE buf, VALUE attr_quote, VALUE key, VALUE value)
|
|
177
184
|
{
|
178
185
|
gh_buf ob = GH_BUF_INIT;
|
179
186
|
|
180
|
-
value = rb_funcall(value, id_to_s, 0);
|
181
187
|
Check_Type(value, T_STRING);
|
182
188
|
if (houdini_escape_html(&ob, (const uint8_t *)RSTRING_PTR(value), RSTRING_LEN(value))) {
|
183
189
|
value = rb_enc_str_new(ob.ptr, ob.size, rb_utf8_encoding());
|
@@ -195,9 +201,6 @@ put_attribute(VALUE buf, VALUE attr_quote, VALUE key, VALUE value)
|
|
195
201
|
static void
|
196
202
|
build_attribute(VALUE buf, VALUE attr_quote, int is_html, VALUE key, VALUE value)
|
197
203
|
{
|
198
|
-
if (!RB_TYPE_P(key, T_STRING)) {
|
199
|
-
key = rb_funcall(key, id_to_s, 0);
|
200
|
-
}
|
201
204
|
Check_Type(key, T_STRING);
|
202
205
|
if (RSTRING_LEN(key) == 5 && memcmp(RSTRING_PTR(key), "class", 5) == 0) {
|
203
206
|
long len;
|
@@ -209,7 +212,7 @@ build_attribute(VALUE buf, VALUE attr_quote, int is_html, VALUE key, VALUE value
|
|
209
212
|
VALUE ary = rb_ary_new_capa(len);
|
210
213
|
for (i = 0; i < len; i++) {
|
211
214
|
VALUE v = RARRAY_AREF(value, i);
|
212
|
-
rb_ary_push(ary,
|
215
|
+
rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
|
213
216
|
}
|
214
217
|
rb_funcall(ary, id_sort_bang, 0);
|
215
218
|
rb_funcall(ary, id_uniq_bang, 0);
|
@@ -225,7 +228,7 @@ build_attribute(VALUE buf, VALUE attr_quote, int is_html, VALUE key, VALUE value
|
|
225
228
|
VALUE ary = rb_ary_new_capa(len);
|
226
229
|
for (i = 0; i < len; i++) {
|
227
230
|
VALUE v = RARRAY_AREF(value, i);
|
228
|
-
rb_ary_push(ary,
|
231
|
+
rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
|
229
232
|
}
|
230
233
|
put_attribute(buf, attr_quote, key, rb_ary_join(ary, rb_const_get(rb_mAttributeBuilder, id_underscore)));
|
231
234
|
}
|
@@ -236,8 +239,6 @@ build_attribute(VALUE buf, VALUE attr_quote, int is_html, VALUE key, VALUE value
|
|
236
239
|
} else {
|
237
240
|
put_attribute(buf, attr_quote, key, key);
|
238
241
|
}
|
239
|
-
} else if (RB_TYPE_P(value, T_FALSE) || NIL_P(value)) {
|
240
|
-
/* do nothing */
|
241
242
|
} else {
|
242
243
|
put_attribute(buf, attr_quote, key, value);
|
243
244
|
}
|
@@ -288,7 +289,6 @@ Init_attribute_builder(void)
|
|
288
289
|
id_sort_bang = rb_intern("sort!");
|
289
290
|
id_uniq_bang = rb_intern("uniq!");
|
290
291
|
id_merge_bang = rb_intern("merge!");
|
291
|
-
id_to_s = rb_intern("to_s");
|
292
292
|
|
293
293
|
id_id = rb_intern("ID");
|
294
294
|
id_class = rb_intern("CLASS");
|
data/faml.gemspec
CHANGED
@@ -4,39 +4,40 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'faml/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'faml'
|
8
8
|
spec.version = Faml::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Kohei Suzuki']
|
10
|
+
spec.email = ['eagletmt@gmail.com']
|
11
|
+
spec.summary = 'Faster implementation of Haml template language.'
|
12
|
+
spec.description = 'Faster implementation of Haml template language.'
|
13
|
+
spec.homepage = 'https://github.com/eagletmt/faml'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0") + `git -C vendor/houdini ls-files -z`.split("\x0").map { |path| "vendor/houdini/#{path}" }
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.extensions = ['ext/attribute_builder/extconf.rb']
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features|incompatibilities)/})
|
20
|
-
spec.require_paths = [
|
21
|
-
spec.required_ruby_version =
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.required_ruby_version = '>= 2.0.0'
|
22
22
|
|
23
|
-
spec.add_dependency
|
24
|
-
spec.add_dependency
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency
|
27
|
-
spec.add_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency
|
40
|
-
spec.add_development_dependency
|
41
|
-
spec.add_development_dependency
|
23
|
+
spec.add_dependency 'escape_utils'
|
24
|
+
spec.add_dependency 'haml_parser', '>= 0.1.0'
|
25
|
+
spec.add_dependency 'parser'
|
26
|
+
spec.add_dependency 'temple', '>= 0.7.0'
|
27
|
+
spec.add_dependency 'tilt'
|
28
|
+
spec.add_development_dependency 'appraisal'
|
29
|
+
spec.add_development_dependency 'benchmark-ips'
|
30
|
+
spec.add_development_dependency 'bundler'
|
31
|
+
spec.add_development_dependency 'coffee-script'
|
32
|
+
spec.add_development_dependency 'coveralls'
|
33
|
+
spec.add_development_dependency 'haml' # for benchmark
|
34
|
+
spec.add_development_dependency 'hamlit', '>= 0.6.0' # for benchmark
|
35
|
+
spec.add_development_dependency 'rake'
|
36
|
+
spec.add_development_dependency 'rake-compiler'
|
37
|
+
spec.add_development_dependency 'redcarpet'
|
38
|
+
spec.add_development_dependency 'rspec', '>= 3'
|
39
|
+
spec.add_development_dependency 'rubocop'
|
40
|
+
spec.add_development_dependency 'sass'
|
41
|
+
spec.add_development_dependency 'simplecov'
|
42
|
+
spec.add_development_dependency 'slim' # for benchmark
|
42
43
|
end
|
data/haml_spec_test.rb
CHANGED
@@ -7,10 +7,10 @@ class HamlTest < Minitest::Test
|
|
7
7
|
contexts.each do |context|
|
8
8
|
context[1].each do |name, test|
|
9
9
|
define_method("test_spec: #{name} (#{context[0]})") do
|
10
|
-
html = test[
|
11
|
-
haml = test[
|
12
|
-
locals = Hash[(test[
|
13
|
-
options = Hash[(test[
|
10
|
+
html = test['html']
|
11
|
+
haml = test['haml']
|
12
|
+
locals = Hash[(test['locals'] || {}).map { |x, y| [x.to_sym, y] }]
|
13
|
+
options = Hash[(test['config'] || {}).map { |x, y| [x.to_sym, y] }]
|
14
14
|
options[:format] = options[:format].to_sym if options.key?(:format)
|
15
15
|
tilt = Tilt.new("#{name}.haml", nil, options) { haml }
|
16
16
|
result = tilt.render(Object.new, locals)
|
Binary file
|
data/lib/faml/cli.rb
CHANGED
@@ -25,6 +25,12 @@ module Faml
|
|
25
25
|
pp Faml::Compiler.new(filename: file, format: options[:format].to_sym).call(parse_file(file))
|
26
26
|
end
|
27
27
|
|
28
|
+
desc 'stats FILE/DIR ...', 'Show statistics'
|
29
|
+
def stats(*paths)
|
30
|
+
require_relative 'stats'
|
31
|
+
Stats.new(*paths).report
|
32
|
+
end
|
33
|
+
|
28
34
|
desc 'version', 'Print version'
|
29
35
|
option :numeric, type: :boolean, default: false, desc: 'Print version number only'
|
30
36
|
def version
|
data/lib/faml/compiler.rb
CHANGED
@@ -45,10 +45,10 @@ module Faml
|
|
45
45
|
|
46
46
|
def self.find_and_preserve(input)
|
47
47
|
# Taken from the original haml code
|
48
|
-
re =
|
48
|
+
re = %r{<(#{options[:preserve].map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)}im
|
49
49
|
input.to_s.gsub(re) do |s|
|
50
|
-
|
51
|
-
"<#{
|
50
|
+
m = s.match(re) # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible
|
51
|
+
"<#{m[1]}#{m[2]}>#{Helpers.preserve(m[3])}</#{m[1]}>"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -166,7 +166,7 @@ module Faml
|
|
166
166
|
end
|
167
167
|
compile_children(ast, temple)
|
168
168
|
unless ast.conditional.empty?
|
169
|
-
temple << [:static,
|
169
|
+
temple << [:static, '<![endif]']
|
170
170
|
end
|
171
171
|
[:multi, [:html, :comment, temple]]
|
172
172
|
end
|
@@ -228,7 +228,8 @@ module Faml
|
|
228
228
|
return compile_static_id_and_class(static_id, static_class)
|
229
229
|
end
|
230
230
|
|
231
|
-
|
231
|
+
attrs = try_optimize_attributes(text, static_id, static_class)
|
232
|
+
if attrs
|
232
233
|
line_count = text.count("\n")
|
233
234
|
return [:multi, [:html, :attrs, *attrs]].concat([[:newline]] * line_count)
|
234
235
|
end
|
@@ -275,7 +276,7 @@ module Faml
|
|
275
276
|
return nil
|
276
277
|
end
|
277
278
|
|
278
|
-
if dynamic_attributes.
|
279
|
+
if dynamic_attributes.key?('data')
|
279
280
|
# XXX: Quit optimization...
|
280
281
|
return nil
|
281
282
|
end
|
@@ -287,7 +288,7 @@ module Faml
|
|
287
288
|
end
|
288
289
|
|
289
290
|
(static_attributes.keys + dynamic_attributes.keys).sort.flat_map do |k|
|
290
|
-
if static_attributes.
|
291
|
+
if static_attributes.key?(k)
|
291
292
|
compile_static_attribute(k, static_attributes[k])
|
292
293
|
else
|
293
294
|
compile_dynamic_attribute(k, dynamic_attributes[k])
|
@@ -331,7 +332,7 @@ module Faml
|
|
331
332
|
dynamic_attributes = {}
|
332
333
|
parser.dynamic_attributes.each do |k, v|
|
333
334
|
k = k.to_s
|
334
|
-
if static_attributes.
|
335
|
+
if static_attributes.key?(k)
|
335
336
|
if StaticHashParser::SPECIAL_ATTRIBUTES.include?(k)
|
336
337
|
# XXX: Quit optimization
|
337
338
|
return nil
|
@@ -343,18 +344,24 @@ module Faml
|
|
343
344
|
end
|
344
345
|
|
345
346
|
def compile_static_attribute(key, value)
|
346
|
-
|
347
|
-
when value == true
|
348
|
-
[[:haml, :attr, key, [:multi]]]
|
349
|
-
when value == false || value == nil
|
350
|
-
[[:multi]]
|
351
|
-
when value.is_a?(Hash) && key == 'data'
|
347
|
+
if value.is_a?(Hash) && key == 'data'
|
352
348
|
data = AttributeBuilder.normalize_data(value)
|
353
349
|
data.keys.sort.map do |k|
|
354
|
-
|
350
|
+
compile_static_simple_attribute("data-#{k}", data[k])
|
355
351
|
end
|
356
352
|
else
|
357
|
-
[
|
353
|
+
[compile_static_simple_attribute(key, value)]
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
def compile_static_simple_attribute(key, value)
|
358
|
+
case
|
359
|
+
when value == true
|
360
|
+
[:haml, :attr, key, [:multi]]
|
361
|
+
when value == false || value.nil?
|
362
|
+
[:multi]
|
363
|
+
else
|
364
|
+
[:haml, :attr, key, [:static, Temple::Utils.escape_html(value)]]
|
358
365
|
end
|
359
366
|
end
|
360
367
|
|
data/lib/faml/engine.rb
CHANGED
@@ -20,7 +20,7 @@ module Faml
|
|
20
20
|
use Newline
|
21
21
|
filter :StaticMerger
|
22
22
|
use :Generator do
|
23
|
-
options[:generator].new(options.to_hash.reject {|k,
|
23
|
+
options[:generator].new(options.to_hash.reject { |k, _| !options[:generator].options.valid_key?(k) })
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -12,8 +12,8 @@ module Faml
|
|
12
12
|
escape_code = Temple::Filters::Escapable.new(use_html_safe: false).instance_variable_get(:@escape_code)
|
13
13
|
sym = unique_name
|
14
14
|
[:multi,
|
15
|
-
|
16
|
-
|
15
|
+
[:capture, sym, temple],
|
16
|
+
[:dynamic, escape_code % sym],
|
17
17
|
]
|
18
18
|
end
|
19
19
|
end
|
@@ -11,8 +11,8 @@ module Faml
|
|
11
11
|
compile_texts(temple, ast.lineno, ast.texts, keep_last_empty_lines: true)
|
12
12
|
sym = unique_name
|
13
13
|
[:multi,
|
14
|
-
|
15
|
-
|
14
|
+
[:capture, sym, temple],
|
15
|
+
[:dynamic, "::Faml::FilterCompilers::Preserve.preserve(#{sym})"],
|
16
16
|
]
|
17
17
|
end
|
18
18
|
|
data/lib/faml/html.rb
CHANGED
@@ -3,8 +3,8 @@ require 'faml/attribute_builder'
|
|
3
3
|
module Faml
|
4
4
|
class Html < Temple::HTML::Fast
|
5
5
|
# Override temple's default
|
6
|
-
|
7
|
-
|
6
|
+
options[:format] = :html
|
7
|
+
options[:attr_quote] = "'"
|
8
8
|
|
9
9
|
def on_haml_tag(name, self_closing, attrs, content = nil)
|
10
10
|
name = name.to_s
|
@@ -12,7 +12,7 @@ module Faml
|
|
12
12
|
result = [:multi, [:static, "<#{name}"], compile(attrs)]
|
13
13
|
result << [:static, (closed && @format != :html ? ' /' : '') + '>']
|
14
14
|
result << compile(content) if content
|
15
|
-
result << [:static, "</#{name}>"]
|
15
|
+
result << [:static, "</#{name}>"] unless closed
|
16
16
|
result
|
17
17
|
end
|
18
18
|
|
@@ -26,22 +26,22 @@ module Faml
|
|
26
26
|
elsif value[0] == :dvalue
|
27
27
|
sym = unique_name
|
28
28
|
[:multi,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
[:code, "#{sym} = (#{value[1]})"],
|
30
|
+
[:case, sym,
|
31
|
+
['true', true_attribute(name)],
|
32
|
+
['false, nil', [:multi]],
|
33
|
+
[:else, [:multi,
|
34
|
+
[:static, " #{name}=#{options[:attr_quote]}"],
|
35
|
+
[:escape, true, [:dynamic, sym]],
|
36
|
+
[:static, options[:attr_quote]],
|
37
|
+
]],
|
38
|
+
],
|
39
39
|
]
|
40
40
|
else
|
41
41
|
[:multi,
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
[:static, " #{name}=#{options[:attr_quote]}"],
|
43
|
+
compile(value),
|
44
|
+
[:static, options[:attr_quote]]]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
data/lib/faml/newline.rb
CHANGED
data/lib/faml/railtie.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Faml
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
|
-
initializer :faml do
|
3
|
+
initializer :faml do
|
4
4
|
require_relative 'rails_handler'
|
5
5
|
ActionView::Template.register_template_handler(:haml, Faml::RailsHandler.new)
|
6
6
|
ActionView::Template.register_template_handler(:faml, Faml::RailsHandler.new)
|
data/lib/faml/stats.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'find'
|
2
|
+
require 'pathname'
|
3
|
+
require 'haml_parser/parser'
|
4
|
+
require_relative 'static_hash_parser'
|
5
|
+
|
6
|
+
module Faml
|
7
|
+
class Stats
|
8
|
+
Info = Struct.new(
|
9
|
+
:empty_attribute_count,
|
10
|
+
:static_attribute_count,
|
11
|
+
:dynamic_attribute_count,
|
12
|
+
:dynamic_attribute_with_data_count,
|
13
|
+
:dynamic_attribute_with_newline_count,
|
14
|
+
:ruby_attribute_count,
|
15
|
+
:ast_types
|
16
|
+
) do
|
17
|
+
def initialize(*)
|
18
|
+
super
|
19
|
+
self.ast_types ||= Hash.new { |h, k| h[k] = 0 }
|
20
|
+
members.each do |k|
|
21
|
+
self[k] ||= 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(*paths)
|
27
|
+
@files = find_files(paths)
|
28
|
+
end
|
29
|
+
|
30
|
+
def report
|
31
|
+
info = Info.new
|
32
|
+
@files.each do |file|
|
33
|
+
collect_info(info, file)
|
34
|
+
end
|
35
|
+
|
36
|
+
report_attribute_stats(info)
|
37
|
+
report_ast_stats(info)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def find_files(paths)
|
43
|
+
paths.flat_map do |path|
|
44
|
+
if File.directory?(path)
|
45
|
+
find_haml_files(path)
|
46
|
+
else
|
47
|
+
[path.to_s]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_haml_files(dir)
|
53
|
+
files = []
|
54
|
+
Find.find(dir) do |file|
|
55
|
+
if File.extname(file) == '.haml'
|
56
|
+
files << file
|
57
|
+
end
|
58
|
+
end
|
59
|
+
files
|
60
|
+
end
|
61
|
+
|
62
|
+
def collect_info(info, file)
|
63
|
+
ast = HamlParser::Parser.new(filename: file).call(File.read(file))
|
64
|
+
walk_ast(info, ast)
|
65
|
+
end
|
66
|
+
|
67
|
+
def walk_ast(info, ast)
|
68
|
+
info.ast_types[ast.class.to_s.sub(/\A.*::(.+)\z/, '\1')] += 1
|
69
|
+
case ast
|
70
|
+
when HamlParser::Ast::Root
|
71
|
+
ast.children.each { |c| walk_ast(info, c) }
|
72
|
+
when HamlParser::Ast::Doctype
|
73
|
+
:noop
|
74
|
+
when HamlParser::Ast::Element
|
75
|
+
collect_attribute_info(info, ast)
|
76
|
+
if ast.oneline_child
|
77
|
+
walk_ast(info, ast.oneline_child)
|
78
|
+
end
|
79
|
+
ast.children.each { |c| walk_ast(info, c) }
|
80
|
+
when HamlParser::Ast::Script
|
81
|
+
ast.children.each { |c| walk_ast(info, c) }
|
82
|
+
when HamlParser::Ast::SilentScript
|
83
|
+
ast.children.each { |c| walk_ast(info, c) }
|
84
|
+
when HamlParser::Ast::HtmlComment
|
85
|
+
ast.children.each { |c| walk_ast(info, c) }
|
86
|
+
when HamlParser::Ast::HamlComment
|
87
|
+
ast.children.each { |c| walk_ast(info, c) }
|
88
|
+
when HamlParser::Ast::Text
|
89
|
+
:noop
|
90
|
+
when HamlParser::Ast::Filter
|
91
|
+
:noop
|
92
|
+
when HamlParser::Ast::Empty
|
93
|
+
:noop
|
94
|
+
else
|
95
|
+
raise "InternalError: Unknown ast #{ast.class}: #{ast.inspect}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def collect_attribute_info(info, ast)
|
100
|
+
if ast.attributes.empty?
|
101
|
+
if ast.static_class.empty? && ast.static_id.empty?
|
102
|
+
info.empty_attribute_count += 1
|
103
|
+
else
|
104
|
+
info.static_attribute_count += 1
|
105
|
+
end
|
106
|
+
else
|
107
|
+
static_hash_parser = StaticHashParser.new
|
108
|
+
if static_hash_parser.parse("{#{ast.attributes}}")
|
109
|
+
if static_hash_parser.dynamic_attributes.empty?
|
110
|
+
info.static_attribute_count += 1
|
111
|
+
else
|
112
|
+
if static_hash_parser.dynamic_attributes.key?('data')
|
113
|
+
info.dynamic_attribute_with_data_count += 1
|
114
|
+
elsif ast.attributes.include?("\n")
|
115
|
+
info.dynamic_attribute_with_newline_count += 1
|
116
|
+
else
|
117
|
+
info.dynamic_attribute_count += 1
|
118
|
+
end
|
119
|
+
end
|
120
|
+
else
|
121
|
+
info.ruby_attribute_count += 1
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def report_attribute_stats(info)
|
127
|
+
static = info.static_attribute_count
|
128
|
+
dynamic = info.dynamic_attribute_count + info.dynamic_attribute_with_data_count + info.dynamic_attribute_with_newline_count
|
129
|
+
ruby = info.ruby_attribute_count
|
130
|
+
total = static + dynamic + ruby
|
131
|
+
puts 'Attribute stats'
|
132
|
+
printf(" Static attributes: %d (%.2f%%)\n", static, static * 100.0 / total)
|
133
|
+
printf(" Dynamic attributes: %d (%.2f%%)\n", dynamic, dynamic * 100.0 / total)
|
134
|
+
printf(" with data: %d\n", info.dynamic_attribute_with_data_count)
|
135
|
+
printf(" with newline: %d\n", info.dynamic_attribute_with_newline_count)
|
136
|
+
printf(" Ruby attributes: %d (%.2f%%)\n", ruby, ruby * 100.0 / total)
|
137
|
+
end
|
138
|
+
|
139
|
+
def report_ast_stats(info)
|
140
|
+
total = info.ast_types.values.inject(0, :+)
|
141
|
+
puts 'AST stats'
|
142
|
+
info.ast_types.keys.sort.each do |type|
|
143
|
+
v = info.ast_types[type]
|
144
|
+
printf(" %s: %d (%.2f%%)\n", type, v, v * 100.0 / total)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/lib/faml/text_compiler.rb
CHANGED
@@ -33,9 +33,9 @@ module Faml
|
|
33
33
|
pos = s.pos
|
34
34
|
while s.scan_until(INTERPOLATION_BEGIN)
|
35
35
|
escapes = s[1].size
|
36
|
-
pre = s.string.byteslice(pos
|
37
|
-
temple << [:static, pre] << [:static,
|
38
|
-
if escapes
|
36
|
+
pre = s.string.byteslice(pos...(s.pos - s.matched.size))
|
37
|
+
temple << [:static, pre] << [:static, '\\' * (escapes / 2)]
|
38
|
+
if escapes.even?
|
39
39
|
# perform interpolation
|
40
40
|
if s[2] == '#{'
|
41
41
|
temple << [:escape, escape_html, [:dynamic, find_close_brace(s, lineno)]]
|
@@ -63,7 +63,7 @@ module Faml
|
|
63
63
|
if depth != 0
|
64
64
|
raise InvalidInterpolation.new(scanner.string, lineno)
|
65
65
|
else
|
66
|
-
scanner.string.byteslice(pos
|
66
|
+
scanner.string.byteslice(pos...(scanner.pos - 1))
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/lib/faml/tilt.rb
CHANGED
data/lib/faml/version.rb
CHANGED
data/spec/rails/bin/setup
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
require 'pathname'
|
3
3
|
|
4
4
|
# path to your application root.
|
5
|
-
APP_ROOT = Pathname.new File.expand_path('../../',
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
6
|
|
7
7
|
Dir.chdir APP_ROOT do
|
8
8
|
# This script is a starting point to setup your application.
|
9
9
|
# Add necessary setup steps to this file:
|
10
10
|
|
11
|
-
puts
|
12
|
-
system
|
13
|
-
system
|
11
|
+
puts '== Installing dependencies =='
|
12
|
+
system 'gem install bundler --conservative'
|
13
|
+
system 'bundle check || bundle install'
|
14
14
|
|
15
15
|
# puts "\n== Copying sample files =="
|
16
16
|
# unless File.exist?("config/database.yml")
|
@@ -18,12 +18,12 @@ Dir.chdir APP_ROOT do
|
|
18
18
|
# end
|
19
19
|
|
20
20
|
puts "\n== Preparing database =="
|
21
|
-
system
|
21
|
+
system 'bin/rake db:setup'
|
22
22
|
|
23
23
|
puts "\n== Removing old logs and tempfiles =="
|
24
|
-
system
|
25
|
-
system
|
24
|
+
system 'rm -f log/*'
|
25
|
+
system 'rm -rf tmp/cache'
|
26
26
|
|
27
27
|
puts "\n== Restarting application server =="
|
28
|
-
system
|
28
|
+
system 'touch tmp/restart.txt'
|
29
29
|
end
|
@@ -42,7 +42,7 @@ RSpec.describe 'Faml with Rails', type: :request do
|
|
42
42
|
it 'works with :escaped filter' do
|
43
43
|
get '/books/escaped'
|
44
44
|
expect(response).to be_ok
|
45
|
-
expect(response.body).to include(
|
45
|
+
expect(response.body).to include('<marquee>escape me</marquee>')
|
46
46
|
end
|
47
47
|
|
48
48
|
describe 'preserve helper' do
|
data/spec/rails_helper.rb
CHANGED
@@ -17,9 +17,9 @@ RSpec.describe 'Attributes rendering', type: :render do
|
|
17
17
|
|
18
18
|
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
|
19
19
|
it 'renders attributes with 2.2-style symbol literals' do
|
20
|
-
expect(render_string(%
|
20
|
+
expect(render_string(%q|%span{"foo": 'bar'}|)).to eq("<span foo='bar'></span>\n")
|
21
21
|
expect(render_string(%Q|- x = 'bar'\n%span{"foo": x}|)).to eq("<span foo='bar'></span>\n")
|
22
|
-
expect(render_string(%
|
22
|
+
expect(render_string(%q|%span{'foo': 'bar'}|)).to eq("<span foo='bar'></span>\n")
|
23
23
|
expect(render_string(%Q|- x = 'bar'\n%span{'foo': x}|)).to eq("<span foo='bar'></span>\n")
|
24
24
|
end
|
25
25
|
end
|
@@ -33,7 +33,7 @@ RSpec.describe 'Attributes rendering', type: :render do
|
|
33
33
|
expect(render_string('%span.c2{class: ["c1", "c3"]}')).to eq("<span class='c1 c2 c3'></span>\n")
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'renders boolean attributes' do
|
37
37
|
expect(render_string('%input{checked: true}')).to eq("<input checked>\n")
|
38
38
|
expect(render_string('%input{checked: false}')).to eq("<input>\n")
|
39
39
|
expect(render_string('%input{checked: nil}')).to eq("<input>\n")
|
@@ -153,6 +153,16 @@ HAML
|
|
153
153
|
%span{data: data} hello
|
154
154
|
HAML
|
155
155
|
end
|
156
|
+
|
157
|
+
it 'skips falsey data attributes' do
|
158
|
+
expect(render_string('%span{data: { foo: nil }}')).to eq("<span></span>\n")
|
159
|
+
expect(render_string("- v = nil\n%span{data: { foo: v }}")).to eq("<span></span>\n")
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'renders true data attributes' do
|
163
|
+
expect(render_string('%span{data: { foo: true }}')).to eq("<span data-foo></span>\n")
|
164
|
+
expect(render_string("- v = true\n%span{data: { foo: v }}")).to eq("<span data-foo></span>\n")
|
165
|
+
end
|
156
166
|
end
|
157
167
|
|
158
168
|
it 'renders __LINE__ correctly' do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe 'Escaped filter rendering', type: :render do
|
4
|
-
it' renders escaped filter' do
|
4
|
+
it ' renders escaped filter' do
|
5
5
|
expect(render_string(<<'HAML')).to eq("<span>start</span>\nhello\n <p>world</p>\n<span>hello</span>\n\n<span>end</span>\n")
|
6
6
|
%span start
|
7
7
|
:escaped
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe 'Plain filter rendering', type: :render do
|
4
4
|
it 'renders plain filter' do
|
5
|
-
expect(render_string(<<HAML)).to eq("<span>\nhello\n<span>world</span>\n</span>\n")
|
5
|
+
expect(render_string(<<'HAML')).to eq("<span>\nhello\n<span>world</span>\n</span>\n")
|
6
6
|
%span
|
7
7
|
:plain
|
8
8
|
he#{'llo'}
|
@@ -11,7 +11,7 @@ HAML
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'strips last empty lines' do
|
14
|
-
expect(render_string(<<HAML)).to eq("<span>\nhello\n\nabc\n<span>world</span>\n</span>\n")
|
14
|
+
expect(render_string(<<'HAML')).to eq("<span>\nhello\n\nabc\n<span>world</span>\n</span>\n")
|
15
15
|
%span
|
16
16
|
:plain
|
17
17
|
he#{'llo'}
|
data/spec/render/newline_spec.rb
CHANGED
@@ -6,7 +6,7 @@ require 'hamlit/version'
|
|
6
6
|
class IncompatibilitiesGenerator
|
7
7
|
include Singleton
|
8
8
|
|
9
|
-
|
9
|
+
Record = Struct.new(:template, :options, :spec_path, :line_number, :faml_result, :haml_result, :hamlit_result) do
|
10
10
|
def incompatible?
|
11
11
|
!all_error? && (faml_result != haml_result || faml_result != hamlit_result || haml_result != hamlit_result)
|
12
12
|
end
|
@@ -70,9 +70,9 @@ class IncompatibilitiesGenerator
|
|
70
70
|
|
71
71
|
def render_haml(template, options)
|
72
72
|
obj = Object.new
|
73
|
-
Haml::Engine.new(template, {ugly: true, escape_html: true}.merge(options)).def_method(obj, :haml)
|
73
|
+
Haml::Engine.new(template, { ugly: true, escape_html: true }.merge(options)).def_method(obj, :haml)
|
74
74
|
obj.haml
|
75
|
-
rescue
|
75
|
+
rescue => e
|
76
76
|
e
|
77
77
|
end
|
78
78
|
|
@@ -80,7 +80,7 @@ class IncompatibilitiesGenerator
|
|
80
80
|
obj = Object.new
|
81
81
|
obj.instance_eval "def hamlit; #{Hamlit::Engine.new(options).call(template)}; end"
|
82
82
|
obj.hamlit
|
83
|
-
rescue
|
83
|
+
rescue => e
|
84
84
|
e
|
85
85
|
end
|
86
86
|
|
@@ -99,7 +99,7 @@ EOS
|
|
99
99
|
|
100
100
|
def render_input_title(options)
|
101
101
|
title = 'Input'
|
102
|
-
|
102
|
+
unless options.empty?
|
103
103
|
title << " (with options=#{options.inspect})"
|
104
104
|
end
|
105
105
|
title
|
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.
|
4
|
+
version: 0.3.3
|
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
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -234,6 +234,20 @@ dependencies:
|
|
234
234
|
- - ">="
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: '3'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: rubocop
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
237
251
|
- !ruby/object:Gem::Dependency
|
238
252
|
name: sass
|
239
253
|
requirement: !ruby/object:Gem::Requirement
|
@@ -288,6 +302,8 @@ files:
|
|
288
302
|
- ".gitignore"
|
289
303
|
- ".gitmodules"
|
290
304
|
- ".rspec"
|
305
|
+
- ".rubocop.yml"
|
306
|
+
- ".rubocop_todo.yml"
|
291
307
|
- ".travis.yml"
|
292
308
|
- Appraisals
|
293
309
|
- CHANGELOG.md
|
@@ -359,6 +375,7 @@ files:
|
|
359
375
|
- lib/faml/railtie.rb
|
360
376
|
- lib/faml/ruby_syntax_checker.rb
|
361
377
|
- lib/faml/static_hash_parser.rb
|
378
|
+
- lib/faml/stats.rb
|
362
379
|
- lib/faml/text_compiler.rb
|
363
380
|
- lib/faml/tilt.rb
|
364
381
|
- lib/faml/version.rb
|