Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call escape_html C-API directly #27

Merged
merged 1 commit into from
Sep 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "haml-spec"]
path = haml-spec
url = https://github.com/haml/haml-spec
[submodule "vendor/houdini"]
path = vendor/houdini
url = https://github.com/vmg/houdini
18 changes: 9 additions & 9 deletions ext/attribute_builder/attribute_builder.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <ruby.h>
#include <ruby/encoding.h>
#include <ruby/version.h>
#include "houdini.h"

#if (RUBY_API_VERSION_MAJOR > 2) || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR >= 1)
/* define nothing */
Expand All @@ -9,7 +11,7 @@
#endif

VALUE rb_mAttributeBuilder;
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;
static ID id_keys, id_sort_bang, id_uniq_bang, id_merge_bang, id_gsub, id_to_s;
static ID id_id, id_class, id_underscore, id_hyphen, id_space, id_equal;

static void
Expand Down Expand Up @@ -143,11 +145,14 @@ merge(VALUE attributes, int argc, VALUE *argv)
static void
put_attribute(VALUE buf, VALUE attr_quote, VALUE key, VALUE value)
{
VALUE utils_class;
gh_buf ob = GH_BUF_INIT;

value = rb_funcall(value, id_to_s, 0);
utils_class = rb_const_get(rb_const_get(rb_cObject, id_temple), id_utils);
value = rb_funcall(utils_class, id_escape_html, 1, value);
Check_Type(value, T_STRING);
if (houdini_escape_html(&ob, (const uint8_t *)RSTRING_PTR(value), RSTRING_LEN(value))) {
value = rb_enc_str_new(ob.ptr, ob.size, rb_utf8_encoding());
gh_buf_free(&ob);
}

rb_ary_push(buf, rb_const_get(rb_mAttributeBuilder, id_space));
rb_ary_push(buf, key);
Expand Down Expand Up @@ -250,9 +255,6 @@ Init_attribute_builder(void)
id_sort_bang = rb_intern("sort!");
id_uniq_bang = rb_intern("uniq!");
id_merge_bang = rb_intern("merge!");
id_temple = rb_intern("Temple");
id_utils = rb_intern("Utils");
id_escape_html = rb_intern("escape_html");
id_gsub = rb_intern("gsub");
id_to_s = rb_intern("to_s");

Expand All @@ -269,6 +271,4 @@ Init_attribute_builder(void)
rb_const_set(rb_mAttributeBuilder, id_hyphen, rb_obj_freeze(rb_str_new_cstr("-")));
rb_const_set(rb_mAttributeBuilder, id_space, rb_obj_freeze(rb_str_new_cstr(" ")));
rb_const_set(rb_mAttributeBuilder, id_equal, rb_obj_freeze(rb_str_new_cstr("=")));

rb_require("temple");
}
12 changes: 12 additions & 0 deletions ext/attribute_builder/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
require 'mkmf'

$CFLAGS << ' -Wall -W'
houdini_dir = File.expand_path('../../vendor/houdini', __dir__)
$INCFLAGS << " -I#{houdini_dir}"

$srcs = %w[attribute_builder.c]
%w[
buffer.c
houdini_html_e.c
].each do |c|
FileUtils.ln_s(File.join(houdini_dir, c), c, force: true)
$srcs << c
end

create_makefile('faml/attribute_builder')
2 changes: 1 addition & 1 deletion faml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/eagletmt/faml"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.files = `git ls-files -z`.split("\x0") + `git -C vendor/houdini ls-files -z`.split("\x0").map { |path| "vendor/houdini/#{path}" }
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.extensions = ['ext/attribute_builder/extconf.rb']
spec.test_files = spec.files.grep(%r{^(test|spec|features|incompatibilities)/})
Expand Down
1 change: 1 addition & 0 deletions vendor/houdini
Submodule houdini added at 59727b