faml 0.2.11 → 0.2.12
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/ext/attribute_builder/attribute_builder.c +3 -1
- data/lib/faml/cli.rb +20 -5
- data/lib/faml/compiler.rb +2 -1
- data/lib/faml/version.rb +1 -1
- data/spec/render/attribute_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7a063fee1f2806cfe4b482c790ec377b5870653
|
4
|
+
data.tar.gz: 60fe5ca8e1aa9a9c3b5dc2d6fd5e52583f49ab11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eb70dba3088438ee8139cdfdcda59b572c4bc2fa6ea9f858d4b621bebfe6e909e0ac24bd2623d1932a5d70a95699cd073f9e7eedf1fc663dcf5d232f4f7736d
|
7
|
+
data.tar.gz: dc3cffec0d339450dc104958de8e3aed251660f1d1b0e75cb76af6214325a4e70ed334783c9606f563ee1e0f2a50cef05e7ab80c984cc30b31bf2e7f7370a00b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.2.12 (2015-04-12)
|
2
|
+
- Remove duplicated class values
|
3
|
+
- For compatibility
|
4
|
+
- Add `version` subcommand
|
5
|
+
- Add `--format` option to cli
|
6
|
+
|
1
7
|
## 0.2.11 (2015-04-07)
|
2
8
|
- Keep code newlines within multiline in HTML-style attribute list
|
3
9
|
- https://github.com/eagletmt/faml/issues/19
|
@@ -9,7 +9,7 @@
|
|
9
9
|
#endif
|
10
10
|
|
11
11
|
VALUE rb_mAttributeBuilder;
|
12
|
-
static ID id_keys, id_sort_bang, id_merge_bang, id_temple, id_utils, id_escape_html, id_gsub, id_to_s;
|
12
|
+
static ID id_keys, id_sort_bang, id_uniq_bang, id_merge_bang, id_temple, id_utils, id_escape_html, id_gsub, id_to_s;
|
13
13
|
|
14
14
|
static void
|
15
15
|
concat_array_attribute(VALUE attributes, VALUE hash, VALUE key)
|
@@ -179,6 +179,7 @@ build_attribute(VALUE attr_quote, VALUE key, VALUE value)
|
|
179
179
|
rb_ary_push(ary, rb_funcall(v, id_to_s, 0));
|
180
180
|
}
|
181
181
|
rb_funcall(ary, id_sort_bang, 0);
|
182
|
+
rb_funcall(ary, id_uniq_bang, 0);
|
182
183
|
return put_attribute(attr_quote, key, rb_ary_join(ary, rb_str_new_cstr(" ")));
|
183
184
|
}
|
184
185
|
} else if (strcmp(key_cstr, "id") == 0) {
|
@@ -251,6 +252,7 @@ Init_attribute_builder(void)
|
|
251
252
|
|
252
253
|
id_keys = rb_intern("keys");
|
253
254
|
id_sort_bang = rb_intern("sort!");
|
255
|
+
id_uniq_bang = rb_intern("uniq!");
|
254
256
|
id_merge_bang = rb_intern("merge!");
|
255
257
|
id_temple = rb_intern("Temple");
|
256
258
|
id_utils = rb_intern("Utils");
|
data/lib/faml/cli.rb
CHANGED
@@ -3,15 +3,19 @@ require 'thor'
|
|
3
3
|
|
4
4
|
module Faml
|
5
5
|
class CLI < Thor
|
6
|
+
package_name 'faml'
|
7
|
+
|
6
8
|
desc 'render FILE', 'Render haml template'
|
9
|
+
option :format, type: :string, default: :html, desc: 'HTML format'
|
7
10
|
def render(file)
|
8
|
-
code = compile_file(file)
|
11
|
+
code = compile_file(file, format: options[:format].to_sym)
|
9
12
|
puts instance_eval(code, file)
|
10
13
|
end
|
11
14
|
|
12
15
|
desc 'compile FILE', 'Compile haml template'
|
16
|
+
option :format, type: :string, default: :html, desc: 'HTML format'
|
13
17
|
def compile(file)
|
14
|
-
puts compile_file(file)
|
18
|
+
puts compile_file(file, format: options[:format].to_sym)
|
15
19
|
end
|
16
20
|
|
17
21
|
desc 'parse FILE', 'Render faml AST'
|
@@ -21,15 +25,26 @@ module Faml
|
|
21
25
|
end
|
22
26
|
|
23
27
|
desc 'temple FILE', 'Render temple AST'
|
28
|
+
option :format, type: :string, default: :html, desc: 'HTML format'
|
24
29
|
def temple(file)
|
25
30
|
require 'pp'
|
26
|
-
pp Faml::Compiler.new(filename: file).call(parse_file(file))
|
31
|
+
pp Faml::Compiler.new(filename: file, format: options[:format].to_sym).call(parse_file(file))
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'version', 'Print version'
|
35
|
+
option :numeric, type: :boolean, default: false, desc: 'Print version number only'
|
36
|
+
def version
|
37
|
+
if options[:numeric]
|
38
|
+
puts VERSION
|
39
|
+
else
|
40
|
+
puts "faml #{VERSION}"
|
41
|
+
end
|
27
42
|
end
|
28
43
|
|
29
44
|
private
|
30
45
|
|
31
|
-
def compile_file(file)
|
32
|
-
Faml::Engine.new(filename: file).call(File.read(file))
|
46
|
+
def compile_file(file, opts)
|
47
|
+
Faml::Engine.new(opts.merge(filename: file)).call(File.read(file))
|
33
48
|
end
|
34
49
|
|
35
50
|
def parse_file(file)
|
data/lib/faml/compiler.rb
CHANGED
@@ -321,7 +321,8 @@ module Faml
|
|
321
321
|
static_attributes[k.to_s] = v
|
322
322
|
end
|
323
323
|
unless static_class.empty?
|
324
|
-
|
324
|
+
class_list = static_attributes.fetch('class', '').to_s.split(/ +/)
|
325
|
+
static_attributes['class'] = static_class.split(/ +/).concat(class_list).uniq.sort.join(' ')
|
325
326
|
end
|
326
327
|
unless static_id.empty?
|
327
328
|
static_attributes['id'] = [static_id, static_attributes['id']].compact.join('_')
|
data/lib/faml/version.rb
CHANGED
@@ -62,6 +62,12 @@ HAML
|
|
62
62
|
expect(render_string('%span.foo{class: 1} hello')).to eq("<span class='1 foo'>hello</span>\n")
|
63
63
|
end
|
64
64
|
|
65
|
+
it 'remove duplicated classes' do
|
66
|
+
expect(render_string('%span.foo{class: :foo}')).to eq("<span class='foo'></span>\n")
|
67
|
+
expect(render_string('%span.foo{class: "foo bar"}')).to eq("<span class='bar foo'></span>\n")
|
68
|
+
expect(render_string('%span.foo{class: %w[foo bar]}')).to eq("<span class='bar foo'></span>\n")
|
69
|
+
end
|
70
|
+
|
65
71
|
it 'strigify non-string ids' do
|
66
72
|
expect(render_string('%span.#foo{id: :bar} hello')).to eq("<span id='foo_bar'>hello</span>\n")
|
67
73
|
end
|
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.
|
4
|
+
version: 0.2.12
|
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-04-
|
11
|
+
date: 2015-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -447,7 +447,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
447
447
|
version: '0'
|
448
448
|
requirements: []
|
449
449
|
rubyforge_project:
|
450
|
-
rubygems_version: 2.
|
450
|
+
rubygems_version: 2.4.5
|
451
451
|
signing_key:
|
452
452
|
specification_version: 4
|
453
453
|
summary: Faster implementation of Haml template language.
|