faml 0.2.12 → 0.2.13
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/CHANGELOG.md +4 -0
- data/README.md +10 -0
- data/benchmark/compiling.rb +1 -1
- data/benchmark/rendering.rb +2 -2
- data/benchmark/slim.rb +1 -1
- data/ext/attribute_builder/attribute_builder.c +16 -10
- data/ext/attribute_builder/extconf.rb +1 -0
- data/faml.gemspec +1 -1
- data/lib/faml/engine.rb +0 -9
- data/lib/faml/html.rb +17 -7
- data/lib/faml/version.rb +1 -1
- data/spec/render/attribute_spec.rb +2 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13af244db12ca1e99e25c6f757a58390e966b37e
|
4
|
+
data.tar.gz: 9528efe51e42a8d73fa0eee94e831509b4f46912
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da4116520b13a085b7cebeb5ecc3a6a36787461db58fe5eb37cec1a3554de3a171494719e494eb64b9267e24fa765fa62311bbeceebb721d0ea745700d9e037f
|
7
|
+
data.tar.gz: bf0d92f3dde0f11aba126fa2f592429e149de0445f82a662589df132b462bea2b75adb959143fb82759c5258165e8f8f13009efc02e2a15774ac6c5bd12cb9d1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -23,6 +23,16 @@ Or install it yourself as:
|
|
23
23
|
$ gem install faml
|
24
24
|
|
25
25
|
## Usage
|
26
|
+
You can set several options via `Faml::Engine.options` .
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# Render in XHTML format
|
30
|
+
Faml::Engine.options[:format] = :xhtml
|
31
|
+
# Disable autoclose
|
32
|
+
Faml::Engine.options[:autoclose] = []
|
33
|
+
# Disable auto preserve
|
34
|
+
Faml::Engine.options[:preserve] = []
|
35
|
+
```
|
26
36
|
|
27
37
|
### Rails, sinatra
|
28
38
|
Just replace your `gem 'haml'` with `gem 'faml'` .
|
data/benchmark/compiling.rb
CHANGED
@@ -17,7 +17,7 @@ slim_code = ARGV[1] ? File.read(ARGV[1]) : nil
|
|
17
17
|
Benchmark.ips do |x|
|
18
18
|
x.report('Haml') { Haml::Engine.new(haml_code, ugly: true, escape_html: true) }
|
19
19
|
x.report('Faml') { Faml::Engine.new.call(haml_code) }
|
20
|
-
x.report('Hamlit') { Hamlit::Engine.new
|
20
|
+
x.report('Hamlit') { Hamlit::Engine.new.call(haml_code) }
|
21
21
|
if slim_code
|
22
22
|
x.report('Slim') { Slim::Engine.new.call(slim_code) }
|
23
23
|
end
|
data/benchmark/rendering.rb
CHANGED
@@ -21,8 +21,8 @@ Benchmark.ips do |x|
|
|
21
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
|
-
def hamlit_array; #{Hamlit::Engine.new
|
25
|
-
def hamlit_string; #{Hamlit::Engine.new(
|
24
|
+
def hamlit_array; #{Hamlit::Engine.new.call(haml_code)}; end
|
25
|
+
def hamlit_string; #{Hamlit::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(haml_code)}; end
|
26
26
|
}
|
27
27
|
if slim_code
|
28
28
|
obj.instance_eval %{
|
data/benchmark/slim.rb
CHANGED
@@ -15,7 +15,7 @@ context = Context.new
|
|
15
15
|
Haml::Engine.new(haml_code, ugly: true, escape_html: true).def_method(context, :haml)
|
16
16
|
context.instance_eval %{
|
17
17
|
def faml; #{Faml::Engine.new(generator: Temple::Generators::RailsOutputBuffer).call(haml_code)}; end
|
18
|
-
def hamlit; #{Hamlit::Engine.new(
|
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
|
|
@@ -161,7 +161,7 @@ put_attribute(VALUE attr_quote, VALUE key, VALUE value)
|
|
161
161
|
}
|
162
162
|
|
163
163
|
static VALUE
|
164
|
-
build_attribute(VALUE attr_quote, VALUE key, VALUE value)
|
164
|
+
build_attribute(VALUE attr_quote, int is_html, VALUE key, VALUE value)
|
165
165
|
{
|
166
166
|
const char *key_cstr = StringValueCStr(key);
|
167
167
|
if (strcmp(key_cstr, "class") == 0) {
|
@@ -199,10 +199,14 @@ build_attribute(VALUE attr_quote, VALUE key, VALUE value)
|
|
199
199
|
return put_attribute(attr_quote, key, rb_ary_join(ary, rb_str_new_cstr("_")));
|
200
200
|
}
|
201
201
|
} else if (RB_TYPE_P(value, T_TRUE)) {
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
202
|
+
if (is_html) {
|
203
|
+
VALUE attr = rb_str_buf_new(1 + RSTRING_LEN(key));
|
204
|
+
rb_str_buf_cat(attr, " ", 1);
|
205
|
+
rb_str_buf_append(attr, key);
|
206
|
+
return attr;
|
207
|
+
} else {
|
208
|
+
return put_attribute(attr_quote, key, key);
|
209
|
+
}
|
206
210
|
} else if (RB_TYPE_P(value, T_FALSE) || NIL_P(value)) {
|
207
211
|
return Qnil;
|
208
212
|
} else {
|
@@ -212,17 +216,19 @@ build_attribute(VALUE attr_quote, VALUE key, VALUE value)
|
|
212
216
|
}
|
213
217
|
|
214
218
|
static VALUE
|
215
|
-
m_build(int argc, VALUE *argv, VALUE self)
|
219
|
+
m_build(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
|
216
220
|
{
|
217
221
|
VALUE attr_quote, attributes, keys, buf;
|
222
|
+
int is_html;
|
218
223
|
long len, i;
|
219
224
|
|
220
|
-
rb_check_arity(argc,
|
225
|
+
rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
|
221
226
|
attr_quote = argv[0];
|
227
|
+
is_html = RTEST(argv[1]);
|
222
228
|
attributes = rb_hash_new();
|
223
229
|
rb_hash_aset(attributes, rb_str_new_cstr("id"), rb_ary_new());
|
224
230
|
rb_hash_aset(attributes, rb_str_new_cstr("class"), rb_ary_new());
|
225
|
-
merge(attributes, argc-
|
231
|
+
merge(attributes, argc-2, argv+2);
|
226
232
|
|
227
233
|
keys = rb_funcall(attributes, id_keys, 0);
|
228
234
|
rb_funcall(keys, id_sort_bang, 0);
|
@@ -230,14 +236,14 @@ m_build(int argc, VALUE *argv, VALUE self)
|
|
230
236
|
buf = rb_ary_new_capa(len);
|
231
237
|
for (i = 0; i < len; i++) {
|
232
238
|
VALUE k = RARRAY_AREF(keys, i);
|
233
|
-
rb_ary_push(buf, build_attribute(attr_quote, k, rb_hash_lookup(attributes, k)));
|
239
|
+
rb_ary_push(buf, build_attribute(attr_quote, is_html, k, rb_hash_lookup(attributes, k)));
|
234
240
|
}
|
235
241
|
|
236
242
|
return rb_ary_join(buf, Qnil);
|
237
243
|
}
|
238
244
|
|
239
245
|
static VALUE
|
240
|
-
m_normalize_data(VALUE self, VALUE data)
|
246
|
+
m_normalize_data(RB_UNUSED_VAR(VALUE self), VALUE data)
|
241
247
|
{
|
242
248
|
return normalize_data(data);
|
243
249
|
}
|
data/faml.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency "coffee-script"
|
30
30
|
spec.add_development_dependency "coveralls"
|
31
31
|
spec.add_development_dependency "haml" # for benchmark
|
32
|
-
spec.add_development_dependency "hamlit" # for benchmark
|
32
|
+
spec.add_development_dependency "hamlit", ">= 0.6.0" # for benchmark
|
33
33
|
spec.add_development_dependency "rake"
|
34
34
|
spec.add_development_dependency "rake-compiler"
|
35
35
|
spec.add_development_dependency "redcarpet"
|
data/lib/faml/engine.rb
CHANGED
data/lib/faml/html.rb
CHANGED
@@ -2,6 +2,10 @@ require 'faml/attribute_builder'
|
|
2
2
|
|
3
3
|
module Faml
|
4
4
|
class Html < Temple::HTML::Fast
|
5
|
+
# Override temple's default
|
6
|
+
self.options[:format] = :html
|
7
|
+
self.options[:attr_quote] = "'"
|
8
|
+
|
5
9
|
def on_haml_tag(name, self_closing, attrs, content = nil)
|
6
10
|
name = name.to_s
|
7
11
|
closed = self_closing && (!content || empty_exp?(content))
|
@@ -13,22 +17,18 @@ module Faml
|
|
13
17
|
end
|
14
18
|
|
15
19
|
def on_haml_attrs(code)
|
16
|
-
[:dynamic, "::Faml::AttributeBuilder.build(#{options[:attr_quote].inspect}, #{code})"]
|
20
|
+
[:dynamic, "::Faml::AttributeBuilder.build(#{options[:attr_quote].inspect}, #{options[:format] == :html}, #{code})"]
|
17
21
|
end
|
18
22
|
|
19
23
|
def on_haml_attr(name, value)
|
20
24
|
if empty_exp?(value)
|
21
|
-
|
22
|
-
[:static, " #{name}"]
|
23
|
-
else
|
24
|
-
[:static, " #{name}=#{options[:attr_quote]}#{name}#{options[:attr_quote]}"]
|
25
|
-
end
|
25
|
+
true_attribute(name)
|
26
26
|
elsif value[0] == :dvalue
|
27
27
|
sym = unique_name
|
28
28
|
[:multi,
|
29
29
|
[:code, "#{sym} = (#{value[1]})"],
|
30
30
|
[:case, sym,
|
31
|
-
['true',
|
31
|
+
['true', true_attribute(name)],
|
32
32
|
['false, nil', [:multi]],
|
33
33
|
[:else, [:multi,
|
34
34
|
[:static, " #{name}=#{options[:attr_quote]}"],
|
@@ -54,5 +54,15 @@ module Faml
|
|
54
54
|
def on_haml_preserve(sym)
|
55
55
|
[:dynamic, "::Faml::Compiler.find_and_preserve(#{sym}.to_s)"]
|
56
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def true_attribute(name)
|
61
|
+
if @format == :html
|
62
|
+
[:static, " #{name}"]
|
63
|
+
else
|
64
|
+
[:static, " #{name}=#{options[:attr_quote]}#{name}#{options[:attr_quote]}"]
|
65
|
+
end
|
66
|
+
end
|
57
67
|
end
|
58
68
|
end
|
data/lib/faml/version.rb
CHANGED
@@ -91,6 +91,8 @@ HAML
|
|
91
91
|
context 'with xhtml format' do
|
92
92
|
it 'renders name="name" if value is true' do
|
93
93
|
expect(render_string(%q|%span{foo: true, bar: 1} hello|, format: :xhtml)).to eq(%Q{<span bar='1' foo='foo'>hello</span>\n})
|
94
|
+
expect(render_string(%Q|- foo = true\n%span{foo: foo, bar: 1} hello|, format: :xhtml)).to eq(%Q{<span bar='1' foo='foo'>hello</span>\n})
|
95
|
+
expect(render_string(%Q|- h = {foo: true, bar: 1}\n%span{h} hello|, format: :xhtml)).to eq(%Q{<span bar='1' foo='foo'>hello</span>\n})
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
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.13
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 0.6.0
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 0.6.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rake
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|