faml 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/.travis.yml +0 -3
- data/Appraisals +5 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -1
- data/ext/attribute_builder/attribute_builder.c +63 -31
- data/ext/attribute_builder/extconf.rb +12 -0
- data/faml.gemspec +1 -1
- data/gemfiles/rails_4.0.gemfile +1 -1
- data/gemfiles/rails_4.1.gemfile +1 -1
- data/gemfiles/rails_4.2.gemfile +1 -1
- data/gemfiles/rails_edge.gemfile +2 -1
- data/incompatibilities/README.md +1 -1
- data/incompatibilities/spec/render/attribute_spec.md +0 -0
- data/lib/faml.rb +4 -4
- data/lib/faml/cli.rb +1 -1
- data/lib/faml/compiler.rb +7 -7
- data/lib/faml/engine.rb +4 -4
- data/lib/faml/filter_compilers.rb +12 -12
- data/lib/faml/filter_compilers/base.rb +1 -1
- data/lib/faml/filter_compilers/cdata.rb +1 -1
- data/lib/faml/filter_compilers/coffee.rb +1 -1
- data/lib/faml/filter_compilers/css.rb +1 -1
- data/lib/faml/filter_compilers/escaped.rb +1 -1
- data/lib/faml/filter_compilers/javascript.rb +1 -1
- data/lib/faml/filter_compilers/markdown.rb +1 -1
- data/lib/faml/filter_compilers/plain.rb +1 -1
- data/lib/faml/filter_compilers/preserve.rb +1 -1
- data/lib/faml/filter_compilers/ruby.rb +1 -1
- data/lib/faml/filter_compilers/sass.rb +1 -1
- data/lib/faml/filter_compilers/scss.rb +1 -1
- data/lib/faml/filter_compilers/tilt_base.rb +1 -2
- data/lib/faml/rails_helpers.rb +1 -1
- data/lib/faml/railtie.rb +1 -1
- data/lib/faml/text_compiler.rb +2 -2
- data/lib/faml/tilt.rb +1 -1
- data/lib/faml/version.rb +1 -1
- data/spec/render/attribute_spec.rb +13 -0
- data/vendor/houdini/.gitignore +3 -0
- data/vendor/houdini/COPYING +7 -0
- data/vendor/houdini/Makefile +79 -0
- data/vendor/houdini/README.md +59 -0
- data/vendor/houdini/buffer.c +249 -0
- data/vendor/houdini/buffer.h +113 -0
- data/vendor/houdini/houdini.h +46 -0
- data/vendor/houdini/houdini_href_e.c +115 -0
- data/vendor/houdini/houdini_html_e.c +90 -0
- data/vendor/houdini/houdini_html_u.c +122 -0
- data/vendor/houdini/houdini_js_e.c +90 -0
- data/vendor/houdini/houdini_js_u.c +60 -0
- data/vendor/houdini/houdini_uri_e.c +107 -0
- data/vendor/houdini/houdini_uri_u.c +68 -0
- data/vendor/houdini/houdini_xml_e.c +136 -0
- data/vendor/houdini/html_unescape.gperf +258 -0
- data/vendor/houdini/html_unescape.h +754 -0
- data/vendor/houdini/tools/build_table.py +13 -0
- data/vendor/houdini/tools/build_tables.c +51 -0
- data/vendor/houdini/tools/wikipedia_table.txt +2025 -0
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11898f802ec5a7c2db4ee3dddda380478dc5cbff
|
4
|
+
data.tar.gz: 4151d81c63cc375de89f7eb5f165cb63fa9388a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8917747df51adc7d2df2606657e659760eecab5ea673d1241c9acaa024edb6c88884d1e8560093b1faca4a3c5fec77fe345c5b6c3fbfbf713e98e9f7221c4ed
|
7
|
+
data.tar.gz: 3b667d9450d939a47690b906c3b25f1be9708914c07435f5485305374729a2a33ff9c366a1a278ed63fc710c846785d77900f42ab3416b081030a9442481d87f
|
data/.gitmodules
CHANGED
data/.travis.yml
CHANGED
@@ -19,9 +19,6 @@ matrix:
|
|
19
19
|
allow_failures:
|
20
20
|
- rvm: ruby-head
|
21
21
|
- gemfile: gemfiles/rails_edge.gemfile
|
22
|
-
# https://github.com/rspec/rspec-rails/pull/1264
|
23
|
-
- rvm: 2.2
|
24
|
-
gemfile: gemfiles/rails_4.0.gemfile
|
25
22
|
exclude:
|
26
23
|
# Rails 5 requires to run on Ruby 2.2.0 or newer.
|
27
24
|
- rvm: 2.0.0
|
data/Appraisals
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
appraise 'rails-4.0' do
|
2
2
|
gem 'rails', '~> 4.0.0'
|
3
|
-
gem 'rspec-rails'
|
3
|
+
gem 'rspec-rails', '>= 3.2.0'
|
4
4
|
gem 'sqlite3'
|
5
5
|
end
|
6
6
|
|
7
7
|
appraise 'rails-4.1' do
|
8
8
|
gem 'rails', '~> 4.1.0'
|
9
|
-
gem 'rspec-rails'
|
9
|
+
gem 'rspec-rails', '>= 3.2.0'
|
10
10
|
gem 'sqlite3'
|
11
11
|
end
|
12
12
|
|
13
13
|
appraise 'rails-4.2' do
|
14
14
|
gem 'rails', '~> 4.2.0'
|
15
|
-
gem 'rspec-rails'
|
15
|
+
gem 'rspec-rails', '>= 3.2.0'
|
16
16
|
gem 'sqlite3'
|
17
17
|
end
|
18
18
|
|
19
19
|
appraise 'rails-edge' do
|
20
20
|
gem 'rails', git: 'https://github.com/rails/rails'
|
21
21
|
gem 'arel', git: 'https://github.com/rails/arel'
|
22
|
-
gem '
|
22
|
+
gem 'rack', git: 'https://github.com/rack/rack'
|
23
|
+
gem 'rspec-rails', '>= 3.2.0'
|
23
24
|
gem 'sqlite3'
|
24
25
|
end
|
25
26
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 0.3.2 (2015-09-24)
|
2
|
+
- Fix illegal constant name
|
3
|
+
- Use `require_relative` if possible
|
4
|
+
- It improves loading performance a little especially when there's long
|
5
|
+
`$LOAD_PATH` by Bundler.
|
6
|
+
- Improve `Faml::AttributeBuilder.build` performance
|
7
|
+
- Call `escape_html` C-API (vmg/houdini) directly.
|
8
|
+
- Avoid `String#gsub` for performance
|
9
|
+
- Allow NUL characters in attribute keys
|
10
|
+
- You should not include NUL characters, of course.
|
11
|
+
|
1
12
|
## 0.3.1 (2015-09-20)
|
2
13
|
- Improve `Faml::AttributeBuilder.build` performance
|
3
14
|
- Reduce String allocations
|
data/Gemfile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#include <ruby.h>
|
2
|
+
#include <ruby/encoding.h>
|
2
3
|
#include <ruby/version.h>
|
4
|
+
#include "houdini.h"
|
3
5
|
|
4
6
|
#if (RUBY_API_VERSION_MAJOR > 2) || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR >= 1)
|
5
7
|
/* define nothing */
|
@@ -9,7 +11,7 @@
|
|
9
11
|
#endif
|
10
12
|
|
11
13
|
VALUE rb_mAttributeBuilder;
|
12
|
-
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, id_to_s;
|
13
15
|
static ID id_id, id_class, id_underscore, id_hyphen, id_space, id_equal;
|
14
16
|
|
15
17
|
static void
|
@@ -49,13 +51,39 @@ struct normalize_data_i2_arg {
|
|
49
51
|
VALUE key, normalized;
|
50
52
|
};
|
51
53
|
|
54
|
+
static VALUE
|
55
|
+
substitute_underscores(VALUE str)
|
56
|
+
{
|
57
|
+
int frozen;
|
58
|
+
long i, len;
|
59
|
+
|
60
|
+
/* gsub('_', '-') */
|
61
|
+
Check_Type(str, T_STRING);
|
62
|
+
len = RSTRING_LEN(str);
|
63
|
+
frozen = OBJ_FROZEN(str);
|
64
|
+
for (i = 0; i < len; i++) {
|
65
|
+
if (RSTRING_PTR(str)[i] == '_') {
|
66
|
+
if (frozen) {
|
67
|
+
str = rb_str_dup(str);
|
68
|
+
frozen = 0;
|
69
|
+
}
|
70
|
+
rb_str_update(str, i, 1, rb_const_get(rb_mAttributeBuilder, id_hyphen));
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
return str;
|
75
|
+
}
|
76
|
+
|
52
77
|
static int
|
53
78
|
normalize_data_i2(VALUE key, VALUE value, VALUE ptr)
|
54
79
|
{
|
55
80
|
struct normalize_data_i2_arg *arg = (struct normalize_data_i2_arg *)ptr;
|
56
81
|
VALUE k = rb_funcall(arg->key, id_to_s, 0);
|
57
82
|
|
58
|
-
k =
|
83
|
+
k = substitute_underscores(k);
|
84
|
+
if (OBJ_FROZEN(k)) {
|
85
|
+
k = rb_str_dup(k);
|
86
|
+
}
|
59
87
|
rb_str_cat(k, "-", 1);
|
60
88
|
rb_str_append(k, key);
|
61
89
|
rb_hash_aset(arg->normalized, k, value);
|
@@ -74,7 +102,7 @@ normalize_data_i(VALUE key, VALUE value, VALUE normalized)
|
|
74
102
|
rb_hash_foreach(normalize_data(value), normalize_data_i2, (VALUE)(&arg));
|
75
103
|
} else {
|
76
104
|
key = rb_funcall(key, id_to_s, 0);
|
77
|
-
key =
|
105
|
+
key = substitute_underscores(key);
|
78
106
|
rb_hash_aset(normalized, key, value);
|
79
107
|
}
|
80
108
|
return ST_CONTINUE;
|
@@ -91,6 +119,16 @@ normalize_data(VALUE data)
|
|
91
119
|
return normalized;
|
92
120
|
}
|
93
121
|
|
122
|
+
static int
|
123
|
+
put_data_attribute(VALUE key, VALUE val, VALUE hash)
|
124
|
+
{
|
125
|
+
VALUE k = rb_str_buf_new(5 + RSTRING_LEN(key));
|
126
|
+
rb_str_buf_cat(k, "data-", 5);
|
127
|
+
rb_str_buf_append(k, key);
|
128
|
+
rb_hash_aset(hash, k, val);
|
129
|
+
return ST_CONTINUE;
|
130
|
+
}
|
131
|
+
|
94
132
|
static void
|
95
133
|
normalize(VALUE hash)
|
96
134
|
{
|
@@ -99,26 +137,20 @@ normalize(VALUE hash)
|
|
99
137
|
long i;
|
100
138
|
for (i = 0; i < len; i++) {
|
101
139
|
VALUE key = RARRAY_AREF(keys, i);
|
102
|
-
const char *key_cstr = StringValueCStr(key);
|
103
140
|
VALUE value = rb_hash_lookup(hash, key);
|
104
|
-
|
105
|
-
|
106
|
-
|
141
|
+
VALUE key_str = key;
|
142
|
+
|
143
|
+
if (!RB_TYPE_P(key, T_STRING)) {
|
144
|
+
key_str = rb_funcall(key, id_to_s, 0);
|
145
|
+
}
|
146
|
+
if (RB_TYPE_P(value, T_HASH) && RSTRING_LEN(key_str) == 4 && memcmp(RSTRING_PTR(key_str), "data", 4) == 0) {
|
147
|
+
VALUE data;
|
107
148
|
|
108
149
|
rb_hash_delete(hash, key);
|
109
150
|
data = normalize_data(value);
|
110
|
-
|
111
|
-
rb_funcall(data_keys, id_sort_bang, 0);
|
112
|
-
data_len = RARRAY_LEN(data_keys);
|
113
|
-
for (j = 0; j < data_len; j++) {
|
114
|
-
VALUE data_key = RARRAY_AREF(data_keys, j);
|
115
|
-
VALUE k = rb_str_buf_new(5 + RSTRING_LEN(data_key));
|
116
|
-
rb_str_buf_cat(k, "data-", 5);
|
117
|
-
rb_str_buf_append(k, data_key);
|
118
|
-
rb_hash_aset(hash, k, rb_hash_lookup(data, data_key));
|
119
|
-
}
|
151
|
+
rb_hash_foreach(data, put_data_attribute, hash);
|
120
152
|
} else if (!(RB_TYPE_P(value, T_TRUE) || RB_TYPE_P(value, T_FALSE) || NIL_P(value))) {
|
121
|
-
rb_hash_aset(hash,
|
153
|
+
rb_hash_aset(hash, key_str, rb_funcall(value, id_to_s, 0));
|
122
154
|
}
|
123
155
|
}
|
124
156
|
}
|
@@ -143,11 +175,14 @@ merge(VALUE attributes, int argc, VALUE *argv)
|
|
143
175
|
static void
|
144
176
|
put_attribute(VALUE buf, VALUE attr_quote, VALUE key, VALUE value)
|
145
177
|
{
|
146
|
-
|
178
|
+
gh_buf ob = GH_BUF_INIT;
|
147
179
|
|
148
180
|
value = rb_funcall(value, id_to_s, 0);
|
149
|
-
|
150
|
-
|
181
|
+
Check_Type(value, T_STRING);
|
182
|
+
if (houdini_escape_html(&ob, (const uint8_t *)RSTRING_PTR(value), RSTRING_LEN(value))) {
|
183
|
+
value = rb_enc_str_new(ob.ptr, ob.size, rb_utf8_encoding());
|
184
|
+
gh_buf_free(&ob);
|
185
|
+
}
|
151
186
|
|
152
187
|
rb_ary_push(buf, rb_const_get(rb_mAttributeBuilder, id_space));
|
153
188
|
rb_ary_push(buf, key);
|
@@ -160,8 +195,11 @@ put_attribute(VALUE buf, VALUE attr_quote, VALUE key, VALUE value)
|
|
160
195
|
static void
|
161
196
|
build_attribute(VALUE buf, VALUE attr_quote, int is_html, VALUE key, VALUE value)
|
162
197
|
{
|
163
|
-
|
164
|
-
|
198
|
+
if (!RB_TYPE_P(key, T_STRING)) {
|
199
|
+
key = rb_funcall(key, id_to_s, 0);
|
200
|
+
}
|
201
|
+
Check_Type(key, T_STRING);
|
202
|
+
if (RSTRING_LEN(key) == 5 && memcmp(RSTRING_PTR(key), "class", 5) == 0) {
|
165
203
|
long len;
|
166
204
|
|
167
205
|
Check_Type(value, T_ARRAY);
|
@@ -177,7 +215,7 @@ build_attribute(VALUE buf, VALUE attr_quote, int is_html, VALUE key, VALUE value
|
|
177
215
|
rb_funcall(ary, id_uniq_bang, 0);
|
178
216
|
put_attribute(buf, attr_quote, key, rb_ary_join(ary, rb_const_get(rb_mAttributeBuilder, id_space)));
|
179
217
|
}
|
180
|
-
} else if (
|
218
|
+
} else if (RSTRING_LEN(key) == 2 && memcmp(RSTRING_PTR(key), "id", 2) == 0) {
|
181
219
|
long len = RARRAY_LEN(value);
|
182
220
|
|
183
221
|
Check_Type(value, T_ARRAY);
|
@@ -250,10 +288,6 @@ Init_attribute_builder(void)
|
|
250
288
|
id_sort_bang = rb_intern("sort!");
|
251
289
|
id_uniq_bang = rb_intern("uniq!");
|
252
290
|
id_merge_bang = rb_intern("merge!");
|
253
|
-
id_temple = rb_intern("Temple");
|
254
|
-
id_utils = rb_intern("Utils");
|
255
|
-
id_escape_html = rb_intern("escape_html");
|
256
|
-
id_gsub = rb_intern("gsub");
|
257
291
|
id_to_s = rb_intern("to_s");
|
258
292
|
|
259
293
|
id_id = rb_intern("ID");
|
@@ -261,7 +295,7 @@ Init_attribute_builder(void)
|
|
261
295
|
id_underscore = rb_intern("UNDERSCORE");
|
262
296
|
id_hyphen = rb_intern("HYPHEN");
|
263
297
|
id_space = rb_intern("SPACE");
|
264
|
-
id_equal = rb_intern("
|
298
|
+
id_equal = rb_intern("EQUAL");
|
265
299
|
|
266
300
|
rb_const_set(rb_mAttributeBuilder, id_id, rb_obj_freeze(rb_str_new_cstr("id")));
|
267
301
|
rb_const_set(rb_mAttributeBuilder, id_class, rb_obj_freeze(rb_str_new_cstr("class")));
|
@@ -269,6 +303,4 @@ Init_attribute_builder(void)
|
|
269
303
|
rb_const_set(rb_mAttributeBuilder, id_hyphen, rb_obj_freeze(rb_str_new_cstr("-")));
|
270
304
|
rb_const_set(rb_mAttributeBuilder, id_space, rb_obj_freeze(rb_str_new_cstr(" ")));
|
271
305
|
rb_const_set(rb_mAttributeBuilder, id_equal, rb_obj_freeze(rb_str_new_cstr("=")));
|
272
|
-
|
273
|
-
rb_require("temple");
|
274
306
|
}
|
@@ -1,4 +1,16 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
3
|
$CFLAGS << ' -Wall -W'
|
4
|
+
houdini_dir = File.expand_path('../../vendor/houdini', __dir__)
|
5
|
+
$INCFLAGS << " -I#{houdini_dir}"
|
6
|
+
|
7
|
+
$srcs = %w[attribute_builder.c]
|
8
|
+
%w[
|
9
|
+
buffer.c
|
10
|
+
houdini_html_e.c
|
11
|
+
].each do |c|
|
12
|
+
FileUtils.ln_s(File.join(houdini_dir, c), c, force: true)
|
13
|
+
$srcs << c
|
14
|
+
end
|
15
|
+
|
4
16
|
create_makefile('faml/attribute_builder')
|
data/faml.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/eagletmt/faml"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
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)/})
|
data/gemfiles/rails_4.0.gemfile
CHANGED
data/gemfiles/rails_4.1.gemfile
CHANGED
data/gemfiles/rails_4.2.gemfile
CHANGED
data/gemfiles/rails_edge.gemfile
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gem "rails", :git => "https://github.com/rails/rails"
|
6
|
-
gem "rspec-rails"
|
6
|
+
gem "rspec-rails", ">= 3.2.0"
|
7
7
|
gem "sqlite3"
|
8
8
|
gem "arel", :git => "https://github.com/rails/arel"
|
9
|
+
gem "rack", :git => "https://github.com/rack/rack"
|
9
10
|
|
10
11
|
gemspec :path => "../"
|
data/incompatibilities/README.md
CHANGED
Binary file
|
data/lib/faml.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative 'faml/engine'
|
2
|
+
require_relative 'faml/tilt'
|
3
|
+
require_relative 'faml/version'
|
4
4
|
|
5
5
|
begin
|
6
6
|
gem 'rails'
|
7
7
|
require 'rails'
|
8
|
-
|
8
|
+
require_relative 'faml/railtie'
|
9
9
|
rescue LoadError
|
10
10
|
end
|
data/lib/faml/cli.rb
CHANGED
data/lib/faml/compiler.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'ripper'
|
2
2
|
require 'temple'
|
3
3
|
require 'haml_parser/ast'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
require_relative 'error'
|
5
|
+
require_relative 'filter_compilers'
|
6
|
+
require_relative 'helpers'
|
7
|
+
require_relative 'rails_helpers'
|
8
|
+
require_relative 'ruby_syntax_checker'
|
9
|
+
require_relative 'static_hash_parser'
|
10
|
+
require_relative 'text_compiler'
|
11
11
|
|
12
12
|
module Faml
|
13
13
|
class Compiler < Temple::Parser
|
data/lib/faml/engine.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'temple'
|
2
|
-
require 'faml/compiler'
|
3
|
-
require 'faml/html'
|
4
|
-
require 'faml/newline'
|
5
1
|
require 'haml_parser/parser'
|
2
|
+
require 'temple'
|
3
|
+
require_relative 'compiler'
|
4
|
+
require_relative 'html'
|
5
|
+
require_relative 'newline'
|
6
6
|
|
7
7
|
module Faml
|
8
8
|
class Engine < Temple::Engine
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'error'
|
2
2
|
|
3
3
|
module Faml
|
4
4
|
module FilterCompilers
|
@@ -28,14 +28,14 @@ module Faml
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
31
|
+
require_relative 'filter_compilers/cdata'
|
32
|
+
require_relative 'filter_compilers/coffee'
|
33
|
+
require_relative 'filter_compilers/css'
|
34
|
+
require_relative 'filter_compilers/escaped'
|
35
|
+
require_relative 'filter_compilers/javascript'
|
36
|
+
require_relative 'filter_compilers/markdown'
|
37
|
+
require_relative 'filter_compilers/plain'
|
38
|
+
require_relative 'filter_compilers/preserve'
|
39
|
+
require_relative 'filter_compilers/ruby'
|
40
|
+
require_relative 'filter_compilers/sass'
|
41
|
+
require_relative 'filter_compilers/scss'
|