Skip to content

Commit

Permalink
Inline HtmlTokenizer in this gem
Browse files Browse the repository at this point in the history
This gem is the only user of that library, so it is better to inline
here than to depend on a separate gem that we also have to maintain.
  • Loading branch information
rafaelfranca committed Aug 11, 2022
1 parent d4b9efe commit bddb2cc
Show file tree
Hide file tree
Showing 20 changed files with 2,692 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ bower.json

# Ignore pow environment settings
.powenv

*.so
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ gemspec

gem 'actionview'
gem 'rake'
gem 'rake-compiler'
gem 'minitest'
gem 'html_tokenizer'
gem 'mocha'

group :deployment, :test do
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ PATH
activesupport (>= 4.0)
ast (~> 2.0)
erubi (~> 1.4)
html_tokenizer (~> 0.0.6)
parser (>= 2.4)
smart_properties

Expand All @@ -31,7 +30,6 @@ GEM
concurrent-ruby (1.0.5)
crass (1.0.6)
erubi (1.6.1)
html_tokenizer (0.0.6)
i18n (0.8.6)
loofah (2.18.0)
crass (~> 1.0.2)
Expand Down Expand Up @@ -60,6 +58,8 @@ GEM
rails-html-sanitizer (1.4.3)
loofah (~> 2.3)
rake (13.0.6)
rake-compiler (1.2.0)
rake
smart_properties (1.15.0)
thread_safe (0.3.6)
tzinfo (1.2.10)
Expand All @@ -71,11 +71,11 @@ PLATFORMS
DEPENDENCIES
actionview
better_html!
html_tokenizer
minitest
mocha
pry-byebug
rake
rake-compiler

BUNDLED WITH
2.2.22
1 change: 1 addition & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Copyright 2022-present Shopify Inc.
Copyright 2016 Francois Chagnon

Permission is hereby granted, free of charge, to any person obtaining
Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require 'rake/extensiontask'

Rake::ExtensionTask.new("better_html_ext")

require 'rdoc/task'

RDoc::Task.new(:rdoc) do |rdoc|
Expand All @@ -25,4 +29,4 @@ Rake::TestTask.new(:test) do |t|
end


task default: :test
task default: [:compile, :test]
4 changes: 2 additions & 2 deletions better_html.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ Gem::Specification.new do |s|
"allowed_push_host" => "https://rubygems.org"
}

s.extensions = ['ext/better_html_ext/extconf.rb']
s.files = Dir["{app,config,db,lib,ext}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.require_paths = ["lib"]
s.require_paths = ["lib", "ext"]

s.add_dependency 'ast', '~> 2.0'
s.add_dependency 'erubi', '~> 1.4'
s.add_dependency 'activesupport', '>= 4.0'
s.add_dependency 'actionview', '>= 4.0'
s.add_dependency 'parser', '>= 2.4'
s.add_dependency 'smart_properties'
s.add_dependency 'html_tokenizer', '~> 0.0.6'

s.add_development_dependency 'rake', '~> 13'
end
2 changes: 2 additions & 0 deletions ext/better_html_ext/better_html.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <ruby.h>
#include "html_tokenizer.h"
12 changes: 12 additions & 0 deletions ext/better_html_ext/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'mkmf'

$CXXFLAGS += " -std=c++11 "
$CXXFLAGS += " -g -O1 -ggdb "
$CFLAGS += " -g -O1 -ggdb "

if ENV['DEBUG']
$CXXFLAGS += " -DDEBUG "
$CFLAGS += " -DDEBUG "
end

create_makefile('better_html_ext')
12 changes: 12 additions & 0 deletions ext/better_html_ext/html_tokenizer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <ruby.h>
#include "tokenizer.h"
#include "parser.h"

static VALUE mHtmlTokenizer = Qnil;

void Init_better_html_ext()
{
mHtmlTokenizer = rb_define_module("HtmlTokenizer");
Init_html_tokenizer_tokenizer(mHtmlTokenizer);
Init_html_tokenizer_parser(mHtmlTokenizer);
}
7 changes: 7 additions & 0 deletions ext/better_html_ext/html_tokenizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#ifdef DEBUG
#define DBG_PRINT(msg, arg...) printf("%s:%u: " msg "\n", __FUNCTION__, __LINE__, arg);
#else
#define DBG_PRINT(msg, arg...) ((void)0);
#endif
Loading

0 comments on commit bddb2cc

Please sign in to comment.