nokogiri 1.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- data/History.ja.txt +99 -0
- data/History.txt +99 -0
- data/Manifest.txt +141 -0
- data/README.ja.txt +100 -0
- data/README.txt +109 -0
- data/Rakefile +354 -0
- data/ext/nokogiri/extconf.rb +93 -0
- data/ext/nokogiri/html_document.c +86 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_sax_parser.c +36 -0
- data/ext/nokogiri/html_sax_parser.h +11 -0
- data/ext/nokogiri/native.c +41 -0
- data/ext/nokogiri/native.h +50 -0
- data/ext/nokogiri/xml_cdata.c +44 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +42 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +206 -0
- data/ext/nokogiri/xml_document.h +10 -0
- data/ext/nokogiri/xml_dtd.c +121 -0
- data/ext/nokogiri/xml_dtd.h +8 -0
- data/ext/nokogiri/xml_io.c +17 -0
- data/ext/nokogiri/xml_io.h +9 -0
- data/ext/nokogiri/xml_node.c +727 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +118 -0
- data/ext/nokogiri/xml_node_set.h +9 -0
- data/ext/nokogiri/xml_reader.c +465 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_sax_parser.c +201 -0
- data/ext/nokogiri/xml_sax_parser.h +10 -0
- data/ext/nokogiri/xml_syntax_error.c +199 -0
- data/ext/nokogiri/xml_syntax_error.h +11 -0
- data/ext/nokogiri/xml_text.c +40 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath.c +53 -0
- data/ext/nokogiri/xml_xpath.h +11 -0
- data/ext/nokogiri/xml_xpath_context.c +214 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +123 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/lib/action-nokogiri.rb +30 -0
- data/lib/nokogiri.rb +72 -0
- data/lib/nokogiri/css.rb +25 -0
- data/lib/nokogiri/css/generated_parser.rb +721 -0
- data/lib/nokogiri/css/generated_tokenizer.rb +159 -0
- data/lib/nokogiri/css/node.rb +97 -0
- data/lib/nokogiri/css/parser.rb +64 -0
- data/lib/nokogiri/css/parser.y +216 -0
- data/lib/nokogiri/css/syntax_error.rb +6 -0
- data/lib/nokogiri/css/tokenizer.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rex +63 -0
- data/lib/nokogiri/css/xpath_visitor.rb +168 -0
- data/lib/nokogiri/decorators.rb +2 -0
- data/lib/nokogiri/decorators/hpricot.rb +3 -0
- data/lib/nokogiri/decorators/hpricot/node.rb +56 -0
- data/lib/nokogiri/decorators/hpricot/node_set.rb +54 -0
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +28 -0
- data/lib/nokogiri/decorators/slop.rb +31 -0
- data/lib/nokogiri/hpricot.rb +51 -0
- data/lib/nokogiri/html.rb +105 -0
- data/lib/nokogiri/html/builder.rb +9 -0
- data/lib/nokogiri/html/document.rb +9 -0
- data/lib/nokogiri/html/sax/parser.rb +21 -0
- data/lib/nokogiri/version.rb +3 -0
- data/lib/nokogiri/xml.rb +83 -0
- data/lib/nokogiri/xml/after_handler.rb +18 -0
- data/lib/nokogiri/xml/attr.rb +10 -0
- data/lib/nokogiri/xml/before_handler.rb +33 -0
- data/lib/nokogiri/xml/builder.rb +84 -0
- data/lib/nokogiri/xml/cdata.rb +9 -0
- data/lib/nokogiri/xml/comment.rb +6 -0
- data/lib/nokogiri/xml/document.rb +55 -0
- data/lib/nokogiri/xml/dtd.rb +6 -0
- data/lib/nokogiri/xml/element.rb +6 -0
- data/lib/nokogiri/xml/entity_declaration.rb +9 -0
- data/lib/nokogiri/xml/node.rb +333 -0
- data/lib/nokogiri/xml/node_set.rb +197 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/reader.rb +20 -0
- data/lib/nokogiri/xml/sax.rb +9 -0
- data/lib/nokogiri/xml/sax/document.rb +59 -0
- data/lib/nokogiri/xml/sax/parser.rb +37 -0
- data/lib/nokogiri/xml/syntax_error.rb +21 -0
- data/lib/nokogiri/xml/text.rb +6 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +8 -0
- data/lib/nokogiri/xml/xpath_context.rb +14 -0
- data/lib/nokogiri/xslt.rb +28 -0
- data/lib/nokogiri/xslt/stylesheet.rb +6 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +237 -0
- data/test/css/test_tokenizer.rb +162 -0
- data/test/css/test_xpath_visitor.rb +64 -0
- data/test/files/dont_hurt_em_why.xml +422 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/helper.rb +78 -0
- data/test/hpricot/files/basic.xhtml +17 -0
- data/test/hpricot/files/boingboing.html +2266 -0
- data/test/hpricot/files/cy0.html +3653 -0
- data/test/hpricot/files/immob.html +400 -0
- data/test/hpricot/files/pace_application.html +1320 -0
- data/test/hpricot/files/tenderlove.html +16 -0
- data/test/hpricot/files/uswebgen.html +220 -0
- data/test/hpricot/files/utf8.html +1054 -0
- data/test/hpricot/files/week9.html +1723 -0
- data/test/hpricot/files/why.xml +19 -0
- data/test/hpricot/load_files.rb +11 -0
- data/test/hpricot/test_alter.rb +67 -0
- data/test/hpricot/test_builder.rb +27 -0
- data/test/hpricot/test_parser.rb +426 -0
- data/test/hpricot/test_paths.rb +15 -0
- data/test/hpricot/test_preserved.rb +77 -0
- data/test/hpricot/test_xml.rb +30 -0
- data/test/html/sax/test_parser.rb +27 -0
- data/test/html/test_builder.rb +89 -0
- data/test/html/test_document.rb +150 -0
- data/test/html/test_node.rb +21 -0
- data/test/test_convert_xpath.rb +185 -0
- data/test/test_css_cache.rb +57 -0
- data/test/test_gc.rb +15 -0
- data/test/test_memory_leak.rb +38 -0
- data/test/test_nokogiri.rb +97 -0
- data/test/test_reader.rb +222 -0
- data/test/test_xslt_transforms.rb +93 -0
- data/test/xml/sax/test_parser.rb +95 -0
- data/test/xml/test_attr.rb +15 -0
- data/test/xml/test_builder.rb +16 -0
- data/test/xml/test_cdata.rb +18 -0
- data/test/xml/test_comment.rb +16 -0
- data/test/xml/test_document.rb +195 -0
- data/test/xml/test_dtd.rb +43 -0
- data/test/xml/test_node.rb +394 -0
- data/test/xml/test_node_set.rb +143 -0
- data/test/xml/test_text.rb +13 -0
- data/test/xml/test_xpath.rb +105 -0
- data/vendor/hoe.rb +1020 -0
- metadata +233 -0
data/Rakefile
ADDED
@@ -0,0 +1,354 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
|
7
|
+
kind = Config::CONFIG['DLEXT']
|
8
|
+
windows = RUBY_PLATFORM =~ /mswin/i ? true : false
|
9
|
+
|
10
|
+
LIB_DIR = File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
|
11
|
+
$LOAD_PATH << LIB_DIR
|
12
|
+
|
13
|
+
require 'vendor/hoe'
|
14
|
+
|
15
|
+
GENERATED_PARSER = "lib/nokogiri/css/generated_parser.rb"
|
16
|
+
GENERATED_TOKENIZER = "lib/nokogiri/css/generated_tokenizer.rb"
|
17
|
+
|
18
|
+
EXT = "ext/nokogiri/native.#{kind}"
|
19
|
+
|
20
|
+
require 'nokogiri/version'
|
21
|
+
|
22
|
+
HOE = Hoe.new('nokogiri', Nokogiri::VERSION) do |p|
|
23
|
+
p.developer('Aaron Patterson', 'aaronp@rubyforge.org')
|
24
|
+
p.developer('Mike Dalessio', 'mike.dalessio@gmail.com')
|
25
|
+
p.clean_globs = [
|
26
|
+
'ext/nokogiri/Makefile',
|
27
|
+
'ext/nokogiri/*.{o,so,bundle,a,log,dll}',
|
28
|
+
'ext/nokogiri/conftest.dSYM',
|
29
|
+
GENERATED_PARSER,
|
30
|
+
GENERATED_TOKENIZER,
|
31
|
+
'cross',
|
32
|
+
]
|
33
|
+
p.spec_extras = { :extensions => ["ext/nokogiri/extconf.rb"] }
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace :gem do
|
37
|
+
namespace :dev do
|
38
|
+
task :spec do
|
39
|
+
File.open("#{HOE.name}.gemspec", 'w') do |f|
|
40
|
+
HOE.spec.version = "#{HOE.version}.#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
41
|
+
f.write(HOE.spec.to_ruby)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
namespace :win32 do
|
47
|
+
task :spec => ['build:win32'] do
|
48
|
+
File.open("#{HOE.name}.gemspec", 'w') do |f|
|
49
|
+
HOE.spec.files += Dir['ext/nokogiri/**.{dll,so}']
|
50
|
+
if windows
|
51
|
+
HOE.spec.platform = Gem::Platform::CURRENT
|
52
|
+
else
|
53
|
+
HOE.spec.platform = 'x86-mswin32-60'
|
54
|
+
end
|
55
|
+
HOE.spec.extensions = []
|
56
|
+
f.write(HOE.spec.to_ruby)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
namespace :jruby do
|
62
|
+
task :spec => ['build'] do
|
63
|
+
File.open("#{HOE.name}.gemspec", 'w') do |f|
|
64
|
+
HOE.spec.platform = 'java'
|
65
|
+
HOE.spec.files << GENERATED_PARSER
|
66
|
+
HOE.spec.files << GENERATED_TOKENIZER
|
67
|
+
HOE.spec.extensions = []
|
68
|
+
f.write(HOE.spec.to_ruby)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
namespace :unix do
|
74
|
+
task :spec do
|
75
|
+
File.open("#{HOE.name}.gemspec", 'w') do |f|
|
76
|
+
f.write(HOE.spec.to_ruby)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
task :spec => ['gem:dev:spec']
|
82
|
+
end
|
83
|
+
|
84
|
+
desc "Run code-coverage analysis"
|
85
|
+
task :coverage do
|
86
|
+
rm_rf "coverage"
|
87
|
+
sh "rcov -x Library -I lib:test #{Dir[*HOE.test_globs].join(' ')}"
|
88
|
+
end
|
89
|
+
|
90
|
+
file GENERATED_PARSER => "lib/nokogiri/css/parser.y" do |t|
|
91
|
+
begin
|
92
|
+
racc = `which racc`.strip
|
93
|
+
racc = "#{::Config::CONFIG['bindir']}/racc" if racc.empty?
|
94
|
+
sh "#{racc} -o #{t.name} #{t.prerequisites.first}"
|
95
|
+
rescue
|
96
|
+
abort "need racc, sudo gem install racc"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
file GENERATED_TOKENIZER => "lib/nokogiri/css/tokenizer.rex" do |t|
|
101
|
+
begin
|
102
|
+
sh "frex -i --independent -o #{t.name} #{t.prerequisites.first}"
|
103
|
+
rescue
|
104
|
+
abort "need frex, sudo gem install aaronp-frex -s http://gems.github.com"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
task 'ext/nokogiri/Makefile' do
|
109
|
+
Dir.chdir('ext/nokogiri') do
|
110
|
+
ruby "extconf.rb"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
task EXT => 'ext/nokogiri/Makefile' do
|
115
|
+
Dir.chdir('ext/nokogiri') do
|
116
|
+
sh 'make'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
if RUBY_PLATFORM == 'java'
|
121
|
+
task :build => [GENERATED_PARSER, GENERATED_TOKENIZER]
|
122
|
+
else
|
123
|
+
task :build => [EXT, GENERATED_PARSER, GENERATED_TOKENIZER]
|
124
|
+
end
|
125
|
+
|
126
|
+
namespace :build do
|
127
|
+
namespace :win32 do
|
128
|
+
file 'cross/bin/ruby.exe' => ['cross/ruby-1.8.6-p287'] do
|
129
|
+
Dir.chdir('cross/ruby-1.8.6-p287') do
|
130
|
+
str = ''
|
131
|
+
File.open('Makefile.in', 'rb') do |f|
|
132
|
+
f.each_line do |line|
|
133
|
+
if line =~ /^\s*ALT_SEPARATOR =/
|
134
|
+
str += "\t\t " + 'ALT_SEPARATOR = "\\\\\"; \\'
|
135
|
+
str += "\n"
|
136
|
+
else
|
137
|
+
str += line
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
File.open('Makefile.in', 'wb') { |f| f.write str }
|
142
|
+
buildopts = if File.exists?('/usr/bin/i586-mingw32msvc-gcc')
|
143
|
+
"--host=i586-mingw32msvc --target=i386-mingw32 --build=i686-linux"
|
144
|
+
else
|
145
|
+
"--host=i386-mingw32 --target=i386-mingw32"
|
146
|
+
end
|
147
|
+
sh(<<-eocommand)
|
148
|
+
env ac_cv_func_getpgrp_void=no \
|
149
|
+
ac_cv_func_setpgrp_void=yes \
|
150
|
+
rb_cv_negative_time_t=no \
|
151
|
+
ac_cv_func_memcmp_working=yes \
|
152
|
+
rb_cv_binary_elf=no \
|
153
|
+
./configure \
|
154
|
+
#{buildopts} \
|
155
|
+
--prefix=#{File.expand_path(File.join(Dir.pwd, '..'))}
|
156
|
+
eocommand
|
157
|
+
sh 'make'
|
158
|
+
sh 'make install'
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
desc 'build cross compiled ruby'
|
163
|
+
task :ruby => 'cross/bin/ruby.exe'
|
164
|
+
end
|
165
|
+
|
166
|
+
desc 'build nokogiri for win32'
|
167
|
+
task :win32 => [GENERATED_PARSER, GENERATED_TOKENIZER, 'build:externals', 'build:win32:ruby'] do
|
168
|
+
dash_i = File.expand_path(
|
169
|
+
File.join(File.dirname(__FILE__), 'cross/lib/ruby/1.8/i386-mingw32/')
|
170
|
+
)
|
171
|
+
Dir.chdir('ext/nokogiri') do
|
172
|
+
ruby " -I #{dash_i} extconf.rb"
|
173
|
+
sh 'make'
|
174
|
+
end
|
175
|
+
dlls = Dir[File.join(File.dirname(__FILE__), 'cross', '**/*.dll')]
|
176
|
+
dlls.each do |dll|
|
177
|
+
next if dll =~ /ruby/
|
178
|
+
cp dll, 'ext/nokogiri'
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
libs = %w{
|
183
|
+
iconv-1.9.2.win32
|
184
|
+
zlib-1.2.3.win32
|
185
|
+
libxml2-2.7.2.win32
|
186
|
+
libxslt-1.1.24.win32
|
187
|
+
}
|
188
|
+
|
189
|
+
libs.each do |lib|
|
190
|
+
file "stash/#{lib}.zip" do |t|
|
191
|
+
puts "downloading #{lib}"
|
192
|
+
FileUtils.mkdir_p('stash')
|
193
|
+
Dir.chdir('stash') do
|
194
|
+
url = "http://www.zlatkovic.com/pub/libxml/#{lib}.zip"
|
195
|
+
system("wget #{url} || curl -O #{url}")
|
196
|
+
end
|
197
|
+
end
|
198
|
+
file "cross/#{lib}" => ["stash/#{lib}.zip"] do |t|
|
199
|
+
puts "unzipping #{lib}.zip"
|
200
|
+
FileUtils.mkdir_p('cross')
|
201
|
+
Dir.chdir('cross') do
|
202
|
+
sh "unzip ../stash/#{lib}.zip"
|
203
|
+
sh "touch #{lib}"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
file "stash/ruby-1.8.6-p287.tar.gz" do |t|
|
209
|
+
puts "downloading ruby"
|
210
|
+
FileUtils.mkdir_p('stash')
|
211
|
+
Dir.chdir('stash') do
|
212
|
+
url = ("ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p287.tar.gz")
|
213
|
+
system("wget #{url} || curl -O #{url}")
|
214
|
+
end
|
215
|
+
end
|
216
|
+
file 'cross/ruby-1.8.6-p287' => ["stash/ruby-1.8.6-p287.tar.gz"] do |t|
|
217
|
+
puts "unzipping ruby"
|
218
|
+
FileUtils.mkdir_p('cross')
|
219
|
+
Dir.chdir('cross') do
|
220
|
+
sh "tar zxvf ../stash/ruby-1.8.6-p287.tar.gz"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
task :externals => libs.map { |x| "cross/#{x}" } + ['cross/ruby-1.8.6-p287']
|
225
|
+
end
|
226
|
+
|
227
|
+
desc "set environment variables to build and/or test with debug options"
|
228
|
+
task :debug do
|
229
|
+
ENV['NOKOGIRI_DEBUG'] = "true"
|
230
|
+
ENV['CFLAGS'] ||= ""
|
231
|
+
ENV['CFLAGS'] += " -DDEBUG"
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_suite_cmdline
|
235
|
+
require 'find'
|
236
|
+
match = ENV['MATCH'] ? /#{ENV['MATCH']}/ : /./
|
237
|
+
|
238
|
+
files = []
|
239
|
+
Find.find("test") do |f|
|
240
|
+
basename = File.basename(f)
|
241
|
+
|
242
|
+
files << f if basename =~ /.*test.*\.rb$/ && basename =~ match
|
243
|
+
end
|
244
|
+
cmdline = "ruby -w -I.:lib:ext:test -rtest/unit -e '%w[#{files.join(' ')}].each {|f| require f}'"
|
245
|
+
end
|
246
|
+
|
247
|
+
class ValgrindTestTask < Rake::TestTask
|
248
|
+
def initialize *args
|
249
|
+
super
|
250
|
+
%w[ ext lib bin test ].each do |dir|
|
251
|
+
self.libs << dir
|
252
|
+
end
|
253
|
+
self.test_files = FileList['test/**/test_*.rb'] +
|
254
|
+
FileList['test/**/*_test.rb']
|
255
|
+
self.verbose = true
|
256
|
+
self.warning = true
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
VALGRIND_BASIC_OPTS = "--num-callers=50 --error-limit=no --partial-loads-ok=yes --undef-value-errors=no"
|
261
|
+
|
262
|
+
desc "run test suite under valgrind with basic ruby options"
|
263
|
+
ValgrindTestTask.new('test:valgrind').extend(Module.new {
|
264
|
+
def ruby *args
|
265
|
+
cmd = "valgrind #{VALGRIND_BASIC_OPTS} #{RUBY} #{args.join(' ')}"
|
266
|
+
puts cmd
|
267
|
+
system cmd
|
268
|
+
end
|
269
|
+
})
|
270
|
+
Rake::Task['test:valgrind'].prerequisites << :build
|
271
|
+
|
272
|
+
namespace :test do
|
273
|
+
# partial-loads-ok and undef-value-errors necessary to ignore
|
274
|
+
# spurious (and eminently ignorable) warnings from the ruby
|
275
|
+
# interpreter
|
276
|
+
|
277
|
+
desc "run test suite under valgrind with memory-fill ruby options"
|
278
|
+
task :valgrind_mem => :build do
|
279
|
+
# fill malloced memory with "m" and freed memory with "f"
|
280
|
+
cmdline = "valgrind #{VALGRIND_BASIC_OPTS} --freelist-vol=100000000 --malloc-fill=6D --free-fill=66 #{test_suite_cmdline}"
|
281
|
+
puts cmdline
|
282
|
+
system cmdline
|
283
|
+
end
|
284
|
+
|
285
|
+
desc "run test suite under valgrind with memory-zero ruby options"
|
286
|
+
task :valgrind_mem0 => :build do
|
287
|
+
# fill malloced and freed memory with 0
|
288
|
+
cmdline = "valgrind #{VALGRIND_BASIC_OPTS} --freelist-vol=100000000 --malloc-fill=00 --free-fill=00 #{test_suite_cmdline}"
|
289
|
+
puts cmdline
|
290
|
+
system cmdline
|
291
|
+
end
|
292
|
+
|
293
|
+
desc "run test suite under gdb"
|
294
|
+
task :gdb => :build do
|
295
|
+
cmdline = "gdb --args #{test_suite_cmdline}"
|
296
|
+
puts cmdline
|
297
|
+
system cmdline
|
298
|
+
end
|
299
|
+
|
300
|
+
desc "run test suite with aggressive GC"
|
301
|
+
task :gc => :build do
|
302
|
+
ENV['NOKOGIRI_GC'] = "true"
|
303
|
+
Rake::Task["test"].invoke
|
304
|
+
end
|
305
|
+
|
306
|
+
desc "find call-seq in the rdoc"
|
307
|
+
task :rdoc => 'docs' do
|
308
|
+
Dir['doc/**/*.html'].each { |docfile|
|
309
|
+
next if docfile =~ /\.src/
|
310
|
+
puts "FAIL: #{docfile}" if File.read(docfile) =~ /call-seq/
|
311
|
+
}
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
namespace :install do
|
316
|
+
desc "Install frex and racc for development"
|
317
|
+
task :deps => %w(frex racc)
|
318
|
+
|
319
|
+
directory "stash"
|
320
|
+
|
321
|
+
file "stash/racc-1.4.5-all.tar.gz" => "stash" do |t|
|
322
|
+
puts "Downloading racc to #{t.name}..."
|
323
|
+
|
324
|
+
Dir.chdir File.dirname(t.name) do
|
325
|
+
url = "http://i.loveruby.net/archive/racc/racc-1.4.5-all.tar.gz"
|
326
|
+
system "wget #{url} || curl -O #{url}"
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
task :racc => "stash/racc-1.4.5-all.tar.gz" do |t|
|
331
|
+
sh "tar xvf #{t.prerequisites.first} -C stash"
|
332
|
+
|
333
|
+
Dir.chdir "stash/#{File.basename(t.prerequisites.first, ".tar.gz")}" do
|
334
|
+
sh "ruby setup.rb config"
|
335
|
+
sh "ruby setup.rb setup"
|
336
|
+
sh "sudo ruby setup.rb install"
|
337
|
+
end
|
338
|
+
|
339
|
+
puts "The racc binary is likely in #{::Config::CONFIG["bindir"]}."
|
340
|
+
end
|
341
|
+
|
342
|
+
task :frex do
|
343
|
+
sh "sudo gem install aaronp-frex -s http://gems.github.com"
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
# Only do this on unix, since we can't build on windows
|
348
|
+
unless windows
|
349
|
+
Rake::Task[:test].prerequisites << :build
|
350
|
+
Rake::Task[:check_manifest].prerequisites << GENERATED_PARSER
|
351
|
+
Rake::Task[:check_manifest].prerequisites << GENERATED_TOKENIZER
|
352
|
+
end
|
353
|
+
|
354
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,93 @@
|
|
1
|
+
ENV["ARCHFLAGS"] = "-arch #{`uname -p` =~ /powerpc/ ? 'ppc' : 'i386'}"
|
2
|
+
|
3
|
+
require 'mkmf'
|
4
|
+
|
5
|
+
ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
6
|
+
LIBDIR = Config::CONFIG['libdir']
|
7
|
+
INCLUDEDIR = Config::CONFIG['includedir']
|
8
|
+
|
9
|
+
use_macports = !(defined?(RUBY_ENGINE) && RUBY_ENGINE != 'ruby')
|
10
|
+
|
11
|
+
$CFLAGS << " #{ENV["CFLAGS"]}"
|
12
|
+
if Config::CONFIG['target_os'] == 'mingw32'
|
13
|
+
$CFLAGS << " -DXP_WIN -DXP_WIN32"
|
14
|
+
else
|
15
|
+
$CFLAGS << " -g -DXP_UNIX"
|
16
|
+
end
|
17
|
+
|
18
|
+
$LIBPATH << "/opt/local/lib" if use_macports
|
19
|
+
|
20
|
+
$CFLAGS << " -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
|
21
|
+
|
22
|
+
if Config::CONFIG['target_os'] == 'mingw32'
|
23
|
+
header = File.join(ROOT, 'cross', 'libxml2-2.7.2.win32', 'include')
|
24
|
+
unless find_header('libxml/xmlversion.h', header)
|
25
|
+
abort "need libxml"
|
26
|
+
end
|
27
|
+
|
28
|
+
header = File.join(ROOT, 'cross', 'libxslt-1.1.24.win32', 'include')
|
29
|
+
unless find_header('libxslt/libxslt.h', header)
|
30
|
+
abort "need libxslt"
|
31
|
+
end
|
32
|
+
unless find_header('libexslt/libexslt.h', header)
|
33
|
+
abort "need libexslt"
|
34
|
+
end
|
35
|
+
|
36
|
+
header = File.join(ROOT, 'cross', 'iconv-1.9.2.win32', 'include')
|
37
|
+
unless find_header('iconv.h', header)
|
38
|
+
abort "need iconv"
|
39
|
+
end
|
40
|
+
else
|
41
|
+
HEADER_DIRS = [
|
42
|
+
File.join(INCLUDEDIR, "libxml2"),
|
43
|
+
INCLUDEDIR,
|
44
|
+
'/usr/include/libxml2',
|
45
|
+
'/usr/local/include/libxml2'
|
46
|
+
]
|
47
|
+
|
48
|
+
[
|
49
|
+
'/opt/local/include/libxml2',
|
50
|
+
'/opt/local/include',
|
51
|
+
].each { |x| HEADER_DIRS.unshift(x) } if use_macports
|
52
|
+
|
53
|
+
unless find_header('libxml/xmlversion.h', *HEADER_DIRS)
|
54
|
+
abort "need libxml"
|
55
|
+
end
|
56
|
+
|
57
|
+
unless find_header('libxslt/xslt.h', *HEADER_DIRS)
|
58
|
+
abort "need libxslt"
|
59
|
+
end
|
60
|
+
unless find_header('libexslt/exslt.h', *HEADER_DIRS)
|
61
|
+
abort "need libxslt"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if Config::CONFIG['target_os'] == 'mingw32'
|
66
|
+
find_library('xml2', 'xmlParseDoc',
|
67
|
+
File.join(ROOT, 'cross', 'libxml2-2.7.2.win32', 'bin'))
|
68
|
+
find_library('xslt', 'xsltParseStylesheetDoc',
|
69
|
+
File.join(ROOT, 'cross', 'libxslt-1.1.24.win32', 'bin'))
|
70
|
+
find_library('exslt', 'exsltFuncRegister',
|
71
|
+
File.join(ROOT, 'cross', 'libxslt-1.1.24.win32', 'bin'))
|
72
|
+
else
|
73
|
+
find_library('xml2', 'xmlParseDoc',
|
74
|
+
LIBDIR,
|
75
|
+
'/opt/local/lib',
|
76
|
+
'/usr/local/lib',
|
77
|
+
'/usr/lib'
|
78
|
+
)
|
79
|
+
find_library('xslt', 'xsltParseStylesheetDoc',
|
80
|
+
LIBDIR,
|
81
|
+
'/opt/local/lib',
|
82
|
+
'/usr/local/lib',
|
83
|
+
'/usr/lib'
|
84
|
+
)
|
85
|
+
find_library('exslt', 'exsltFuncRegister',
|
86
|
+
LIBDIR,
|
87
|
+
'/opt/local/lib',
|
88
|
+
'/usr/local/lib',
|
89
|
+
'/usr/lib'
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
create_makefile('nokogiri/native')
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#include <html_document.h>
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* serialize
|
6
|
+
*
|
7
|
+
* Serialize this document
|
8
|
+
*/
|
9
|
+
static VALUE serialize(VALUE self)
|
10
|
+
{
|
11
|
+
xmlDocPtr doc;
|
12
|
+
xmlChar *buf;
|
13
|
+
int size;
|
14
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
15
|
+
|
16
|
+
htmlDocDumpMemory(doc, &buf, &size);
|
17
|
+
VALUE rb_str = rb_str_new((char *)buf, (long)size);
|
18
|
+
xmlFree(buf);
|
19
|
+
return rb_str;
|
20
|
+
}
|
21
|
+
|
22
|
+
/*
|
23
|
+
* call-seq:
|
24
|
+
* read_memory(string, url, encoding, options)
|
25
|
+
*
|
26
|
+
* Read the HTML document contained in +string+ with given +url+, +encoding+,
|
27
|
+
* and +options+. See Nokogiri::HTML.parse
|
28
|
+
*/
|
29
|
+
static VALUE read_memory( VALUE klass,
|
30
|
+
VALUE string,
|
31
|
+
VALUE url,
|
32
|
+
VALUE encoding,
|
33
|
+
VALUE options )
|
34
|
+
{
|
35
|
+
const char * c_buffer = StringValuePtr(string);
|
36
|
+
const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url);
|
37
|
+
const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding);
|
38
|
+
int len = NUM2INT(rb_funcall(string, rb_intern("length"), 0));
|
39
|
+
|
40
|
+
htmlDocPtr doc = htmlReadMemory(c_buffer, len, c_url, c_enc, NUM2INT(options));
|
41
|
+
|
42
|
+
if(doc == NULL) {
|
43
|
+
xmlFreeDoc(doc);
|
44
|
+
rb_raise(rb_eRuntimeError, "Couldn't create a document");
|
45
|
+
return Qnil;
|
46
|
+
}
|
47
|
+
|
48
|
+
return Nokogiri_wrap_xml_document(klass, doc);
|
49
|
+
}
|
50
|
+
|
51
|
+
/*
|
52
|
+
* call-seq:
|
53
|
+
* type
|
54
|
+
*
|
55
|
+
* The type for this document
|
56
|
+
*/
|
57
|
+
static VALUE type(VALUE self)
|
58
|
+
{
|
59
|
+
htmlDocPtr doc;
|
60
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
61
|
+
return INT2NUM((int)doc->type);
|
62
|
+
}
|
63
|
+
|
64
|
+
VALUE cNokogiriHtmlDocument ;
|
65
|
+
void init_html_document()
|
66
|
+
{
|
67
|
+
/*
|
68
|
+
* HACK. This is so that rdoc will work with this C file.
|
69
|
+
*/
|
70
|
+
/*
|
71
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
72
|
+
VALUE html = rb_define_module_under(nokogiri, "HTML");
|
73
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
74
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
75
|
+
VALUE xml_doc = rb_define_class_under(xml, "Document", node);
|
76
|
+
VALUE klass = rb_define_class_under(html, "Document", xml_doc);
|
77
|
+
*/
|
78
|
+
|
79
|
+
VALUE klass ;
|
80
|
+
klass = cNokogiriHtmlDocument = rb_const_get(mNokogiriHtml, rb_intern("Document"));
|
81
|
+
|
82
|
+
rb_define_singleton_method(klass, "read_memory", read_memory, 4);
|
83
|
+
|
84
|
+
rb_define_method(klass, "type", type, 0);
|
85
|
+
rb_define_method(klass, "serialize", serialize, 0);
|
86
|
+
}
|