nokogiri 1.0.0

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.

Files changed (121) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +120 -0
  3. data/README.ja.txt +86 -0
  4. data/README.txt +87 -0
  5. data/Rakefile +264 -0
  6. data/ext/nokogiri/extconf.rb +59 -0
  7. data/ext/nokogiri/html_document.c +83 -0
  8. data/ext/nokogiri/html_document.h +10 -0
  9. data/ext/nokogiri/html_sax_parser.c +32 -0
  10. data/ext/nokogiri/html_sax_parser.h +11 -0
  11. data/ext/nokogiri/native.c +40 -0
  12. data/ext/nokogiri/native.h +51 -0
  13. data/ext/nokogiri/xml_cdata.c +52 -0
  14. data/ext/nokogiri/xml_cdata.h +9 -0
  15. data/ext/nokogiri/xml_document.c +159 -0
  16. data/ext/nokogiri/xml_document.h +10 -0
  17. data/ext/nokogiri/xml_dtd.c +117 -0
  18. data/ext/nokogiri/xml_dtd.h +8 -0
  19. data/ext/nokogiri/xml_node.c +709 -0
  20. data/ext/nokogiri/xml_node.h +15 -0
  21. data/ext/nokogiri/xml_node_set.c +124 -0
  22. data/ext/nokogiri/xml_node_set.h +9 -0
  23. data/ext/nokogiri/xml_reader.c +429 -0
  24. data/ext/nokogiri/xml_reader.h +10 -0
  25. data/ext/nokogiri/xml_sax_parser.c +174 -0
  26. data/ext/nokogiri/xml_sax_parser.h +10 -0
  27. data/ext/nokogiri/xml_syntax_error.c +194 -0
  28. data/ext/nokogiri/xml_syntax_error.h +11 -0
  29. data/ext/nokogiri/xml_text.c +29 -0
  30. data/ext/nokogiri/xml_text.h +9 -0
  31. data/ext/nokogiri/xml_xpath.c +46 -0
  32. data/ext/nokogiri/xml_xpath.h +11 -0
  33. data/ext/nokogiri/xml_xpath_context.c +81 -0
  34. data/ext/nokogiri/xml_xpath_context.h +9 -0
  35. data/ext/nokogiri/xslt_stylesheet.c +108 -0
  36. data/ext/nokogiri/xslt_stylesheet.h +9 -0
  37. data/lib/nokogiri.rb +51 -0
  38. data/lib/nokogiri/css.rb +6 -0
  39. data/lib/nokogiri/css/generated_parser.rb +653 -0
  40. data/lib/nokogiri/css/generated_tokenizer.rb +159 -0
  41. data/lib/nokogiri/css/node.rb +95 -0
  42. data/lib/nokogiri/css/parser.rb +24 -0
  43. data/lib/nokogiri/css/parser.y +198 -0
  44. data/lib/nokogiri/css/tokenizer.rb +9 -0
  45. data/lib/nokogiri/css/tokenizer.rex +63 -0
  46. data/lib/nokogiri/css/xpath_visitor.rb +165 -0
  47. data/lib/nokogiri/decorators.rb +1 -0
  48. data/lib/nokogiri/decorators/hpricot.rb +3 -0
  49. data/lib/nokogiri/decorators/hpricot/node.rb +58 -0
  50. data/lib/nokogiri/decorators/hpricot/node_set.rb +14 -0
  51. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +17 -0
  52. data/lib/nokogiri/hpricot.rb +47 -0
  53. data/lib/nokogiri/html.rb +95 -0
  54. data/lib/nokogiri/html/builder.rb +9 -0
  55. data/lib/nokogiri/html/document.rb +9 -0
  56. data/lib/nokogiri/html/sax/parser.rb +21 -0
  57. data/lib/nokogiri/version.rb +3 -0
  58. data/lib/nokogiri/xml.rb +67 -0
  59. data/lib/nokogiri/xml/after_handler.rb +18 -0
  60. data/lib/nokogiri/xml/before_handler.rb +32 -0
  61. data/lib/nokogiri/xml/builder.rb +79 -0
  62. data/lib/nokogiri/xml/cdata.rb +9 -0
  63. data/lib/nokogiri/xml/document.rb +30 -0
  64. data/lib/nokogiri/xml/dtd.rb +6 -0
  65. data/lib/nokogiri/xml/element.rb +6 -0
  66. data/lib/nokogiri/xml/entity_declaration.rb +9 -0
  67. data/lib/nokogiri/xml/node.rb +195 -0
  68. data/lib/nokogiri/xml/node_set.rb +183 -0
  69. data/lib/nokogiri/xml/notation.rb +6 -0
  70. data/lib/nokogiri/xml/reader.rb +14 -0
  71. data/lib/nokogiri/xml/sax.rb +9 -0
  72. data/lib/nokogiri/xml/sax/document.rb +59 -0
  73. data/lib/nokogiri/xml/sax/parser.rb +33 -0
  74. data/lib/nokogiri/xml/syntax_error.rb +21 -0
  75. data/lib/nokogiri/xml/text.rb +6 -0
  76. data/lib/nokogiri/xml/xpath.rb +6 -0
  77. data/lib/nokogiri/xml/xpath_context.rb +14 -0
  78. data/lib/nokogiri/xslt.rb +11 -0
  79. data/lib/nokogiri/xslt/stylesheet.rb +6 -0
  80. data/nokogiri.gemspec +34 -0
  81. data/test/css/test_nthiness.rb +159 -0
  82. data/test/css/test_parser.rb +224 -0
  83. data/test/css/test_tokenizer.rb +162 -0
  84. data/test/css/test_xpath_visitor.rb +54 -0
  85. data/test/files/staff.xml +59 -0
  86. data/test/files/staff.xslt +32 -0
  87. data/test/files/tlm.html +850 -0
  88. data/test/helper.rb +70 -0
  89. data/test/hpricot/files/basic.xhtml +17 -0
  90. data/test/hpricot/files/boingboing.html +2266 -0
  91. data/test/hpricot/files/cy0.html +3653 -0
  92. data/test/hpricot/files/immob.html +400 -0
  93. data/test/hpricot/files/pace_application.html +1320 -0
  94. data/test/hpricot/files/tenderlove.html +16 -0
  95. data/test/hpricot/files/uswebgen.html +220 -0
  96. data/test/hpricot/files/utf8.html +1054 -0
  97. data/test/hpricot/files/week9.html +1723 -0
  98. data/test/hpricot/files/why.xml +19 -0
  99. data/test/hpricot/load_files.rb +7 -0
  100. data/test/hpricot/test_alter.rb +67 -0
  101. data/test/hpricot/test_builder.rb +27 -0
  102. data/test/hpricot/test_parser.rb +423 -0
  103. data/test/hpricot/test_paths.rb +15 -0
  104. data/test/hpricot/test_preserved.rb +78 -0
  105. data/test/hpricot/test_xml.rb +30 -0
  106. data/test/html/sax/test_parser.rb +27 -0
  107. data/test/html/test_builder.rb +78 -0
  108. data/test/html/test_document.rb +86 -0
  109. data/test/test_convert_xpath.rb +180 -0
  110. data/test/test_nokogiri.rb +36 -0
  111. data/test/test_reader.rb +222 -0
  112. data/test/test_xslt_transforms.rb +29 -0
  113. data/test/xml/sax/test_parser.rb +93 -0
  114. data/test/xml/test_builder.rb +16 -0
  115. data/test/xml/test_cdata.rb +18 -0
  116. data/test/xml/test_document.rb +171 -0
  117. data/test/xml/test_dtd.rb +43 -0
  118. data/test/xml/test_node.rb +223 -0
  119. data/test/xml/test_node_set.rb +116 -0
  120. data/test/xml/test_text.rb +13 -0
  121. metadata +211 -0
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-07-13
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,120 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.ja.txt
4
+ README.txt
5
+ Rakefile
6
+ ext/nokogiri/extconf.rb
7
+ ext/nokogiri/html_document.c
8
+ ext/nokogiri/html_document.h
9
+ ext/nokogiri/html_sax_parser.c
10
+ ext/nokogiri/html_sax_parser.h
11
+ ext/nokogiri/native.c
12
+ ext/nokogiri/native.h
13
+ ext/nokogiri/xml_cdata.c
14
+ ext/nokogiri/xml_cdata.h
15
+ ext/nokogiri/xml_document.c
16
+ ext/nokogiri/xml_document.h
17
+ ext/nokogiri/xml_dtd.c
18
+ ext/nokogiri/xml_dtd.h
19
+ ext/nokogiri/xml_node.c
20
+ ext/nokogiri/xml_node.h
21
+ ext/nokogiri/xml_node_set.c
22
+ ext/nokogiri/xml_node_set.h
23
+ ext/nokogiri/xml_reader.c
24
+ ext/nokogiri/xml_reader.h
25
+ ext/nokogiri/xml_sax_parser.c
26
+ ext/nokogiri/xml_sax_parser.h
27
+ ext/nokogiri/xml_syntax_error.c
28
+ ext/nokogiri/xml_syntax_error.h
29
+ ext/nokogiri/xml_text.c
30
+ ext/nokogiri/xml_text.h
31
+ ext/nokogiri/xml_xpath.c
32
+ ext/nokogiri/xml_xpath.h
33
+ ext/nokogiri/xml_xpath_context.c
34
+ ext/nokogiri/xml_xpath_context.h
35
+ ext/nokogiri/xslt_stylesheet.c
36
+ ext/nokogiri/xslt_stylesheet.h
37
+ lib/nokogiri.rb
38
+ lib/nokogiri/css.rb
39
+ lib/nokogiri/css/generated_parser.rb
40
+ lib/nokogiri/css/generated_tokenizer.rb
41
+ lib/nokogiri/css/node.rb
42
+ lib/nokogiri/css/parser.rb
43
+ lib/nokogiri/css/parser.y
44
+ lib/nokogiri/css/tokenizer.rb
45
+ lib/nokogiri/css/tokenizer.rex
46
+ lib/nokogiri/css/xpath_visitor.rb
47
+ lib/nokogiri/decorators.rb
48
+ lib/nokogiri/decorators/hpricot.rb
49
+ lib/nokogiri/decorators/hpricot/node.rb
50
+ lib/nokogiri/decorators/hpricot/node_set.rb
51
+ lib/nokogiri/decorators/hpricot/xpath_visitor.rb
52
+ lib/nokogiri/hpricot.rb
53
+ lib/nokogiri/html.rb
54
+ lib/nokogiri/html/builder.rb
55
+ lib/nokogiri/html/document.rb
56
+ lib/nokogiri/html/sax/parser.rb
57
+ lib/nokogiri/version.rb
58
+ lib/nokogiri/xml.rb
59
+ lib/nokogiri/xml/after_handler.rb
60
+ lib/nokogiri/xml/before_handler.rb
61
+ lib/nokogiri/xml/builder.rb
62
+ lib/nokogiri/xml/cdata.rb
63
+ lib/nokogiri/xml/document.rb
64
+ lib/nokogiri/xml/dtd.rb
65
+ lib/nokogiri/xml/element.rb
66
+ lib/nokogiri/xml/entity_declaration.rb
67
+ lib/nokogiri/xml/node.rb
68
+ lib/nokogiri/xml/node_set.rb
69
+ lib/nokogiri/xml/notation.rb
70
+ lib/nokogiri/xml/reader.rb
71
+ lib/nokogiri/xml/sax.rb
72
+ lib/nokogiri/xml/sax/document.rb
73
+ lib/nokogiri/xml/sax/parser.rb
74
+ lib/nokogiri/xml/syntax_error.rb
75
+ lib/nokogiri/xml/text.rb
76
+ lib/nokogiri/xml/xpath.rb
77
+ lib/nokogiri/xml/xpath_context.rb
78
+ lib/nokogiri/xslt.rb
79
+ lib/nokogiri/xslt/stylesheet.rb
80
+ nokogiri.gemspec
81
+ test/css/test_nthiness.rb
82
+ test/css/test_parser.rb
83
+ test/css/test_tokenizer.rb
84
+ test/css/test_xpath_visitor.rb
85
+ test/files/staff.xml
86
+ test/files/staff.xslt
87
+ test/files/tlm.html
88
+ test/helper.rb
89
+ test/hpricot/files/basic.xhtml
90
+ test/hpricot/files/boingboing.html
91
+ test/hpricot/files/cy0.html
92
+ test/hpricot/files/immob.html
93
+ test/hpricot/files/pace_application.html
94
+ test/hpricot/files/tenderlove.html
95
+ test/hpricot/files/uswebgen.html
96
+ test/hpricot/files/utf8.html
97
+ test/hpricot/files/week9.html
98
+ test/hpricot/files/why.xml
99
+ test/hpricot/load_files.rb
100
+ test/hpricot/test_alter.rb
101
+ test/hpricot/test_builder.rb
102
+ test/hpricot/test_parser.rb
103
+ test/hpricot/test_paths.rb
104
+ test/hpricot/test_preserved.rb
105
+ test/hpricot/test_xml.rb
106
+ test/html/sax/test_parser.rb
107
+ test/html/test_builder.rb
108
+ test/html/test_document.rb
109
+ test/test_convert_xpath.rb
110
+ test/test_nokogiri.rb
111
+ test/test_reader.rb
112
+ test/test_xslt_transforms.rb
113
+ test/xml/sax/test_parser.rb
114
+ test/xml/test_builder.rb
115
+ test/xml/test_cdata.rb
116
+ test/xml/test_document.rb
117
+ test/xml/test_dtd.rb
118
+ test/xml/test_node.rb
119
+ test/xml/test_node_set.rb
120
+ test/xml/test_text.rb
@@ -0,0 +1,86 @@
1
+ = Nokogiri (鋸)
2
+
3
+ * http://nokogiri.rubyforge.org/
4
+ * http://github.com/tenderlove/nokogiri/wikis
5
+ * http://github.com/tenderlove/nokogiri/tree/master
6
+
7
+ == DESCRIPTION:
8
+
9
+ Nokogiri はHTMLやXMLやSAXやXSLTやReaderのパーサーです。
10
+
11
+ == FEATURES:
12
+
13
+ * XPath で探せる
14
+ * CSS3 のセレクターで探せる
15
+ * XML/HTMLのビルダーはある
16
+
17
+ NokogiriはHpricotより早くパーサーし、検索出来たり、
18
+ 正確にCSS3とXPathをサポート出来たりする。
19
+
20
+ * http://gist.github.com/18533
21
+
22
+ NokogiriはHpricotの代わりに使用出来る。
23
+ その互換性は簡単に正しいCSSとXPathを使用する事が出来る。
24
+
25
+ == SYNOPSIS:
26
+
27
+ require 'nokogiri'
28
+ require 'open-uri'
29
+
30
+ doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
31
+
32
+ ####
33
+ # Search for nodes by css
34
+ doc.css('h3.r a.l').each do |link|
35
+ puts link.content
36
+ end
37
+
38
+ ####
39
+ # Search for nodes by xpath
40
+ doc.xpath('//h3/a[@class="l"]').each do |link|
41
+ puts link.content
42
+ end
43
+
44
+ ####
45
+ # Or mix and match.
46
+ doc.search('h3.r a.l', '//h3/a[@class="l"]').each do |link|
47
+ puts link.content
48
+ end
49
+
50
+
51
+ == REQUIREMENTS:
52
+
53
+ * ruby 1.8 or 1.9
54
+ * libxml
55
+
56
+ == INSTALL:
57
+
58
+ * sudo gem install nokogiri
59
+
60
+ == LICENSE:
61
+
62
+ (The MIT License)
63
+
64
+ Copyright (c) 2008:
65
+
66
+ * {Aaron Patterson}[http://tenderlovemaking.com]
67
+ * {Mike Dalessio}[http://mike.daless.io]
68
+
69
+ Permission is hereby granted, free of charge, to any person obtaining
70
+ a copy of this software and associated documentation files (the
71
+ 'Software'), to deal in the Software without restriction, including
72
+ without limitation the rights to use, copy, modify, merge, publish,
73
+ distribute, sublicense, and/or sell copies of the Software, and to
74
+ permit persons to whom the Software is furnished to do so, subject to
75
+ the following conditions:
76
+
77
+ The above copyright notice and this permission notice shall be
78
+ included in all copies or substantial portions of the Software.
79
+
80
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
81
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
82
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
83
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
84
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
85
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
86
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ = Nokogiri
2
+
3
+ * http://nokogiri.rubyforge.org/
4
+ * http://github.com/tenderlove/nokogiri/wikis
5
+ * http://github.com/tenderlove/nokogiri/tree/master
6
+
7
+ == DESCRIPTION:
8
+
9
+ Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser.
10
+
11
+ == FEATURES:
12
+
13
+ * XPath support for document searching
14
+ * CSS3 selector support for document searching
15
+ * XML/HTML builder
16
+ * Drop in replacement for Hpricot
17
+
18
+ Nokogiri parses and searches XML/HTML faster than Hpricot, and also has
19
+ correctly implemented CSS3 selector support as well as XPath support.
20
+
21
+ * http://gist.github.com/18533
22
+
23
+ Nokogiri also features an Hpricot compatibility layer to help ease the change
24
+ to using correct CSS and XPath.
25
+
26
+ == SYNOPSIS:
27
+
28
+ require 'nokogiri'
29
+ require 'open-uri'
30
+
31
+ doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
32
+
33
+ ####
34
+ # Search for nodes by css
35
+ doc.css('h3.r a.l').each do |link|
36
+ puts link.content
37
+ end
38
+
39
+ ####
40
+ # Search for nodes by xpath
41
+ doc.xpath('//h3/a[@class="l"]').each do |link|
42
+ puts link.content
43
+ end
44
+
45
+ ####
46
+ # Or mix and match.
47
+ doc.search('h3.r a.l', '//h3/a[@class="l"]').each do |link|
48
+ puts link.content
49
+ end
50
+
51
+
52
+ == REQUIREMENTS:
53
+
54
+ * ruby 1.8 or 1.9
55
+ * libxml
56
+
57
+ == INSTALL:
58
+
59
+ * sudo gem install nokogiri
60
+
61
+ == LICENSE:
62
+
63
+ (The MIT License)
64
+
65
+ Copyright (c) 2008:
66
+
67
+ * {Aaron Patterson}[http://tenderlovemaking.com]
68
+ * {Mike Dalessio}[http://mike.daless.io]
69
+
70
+ Permission is hereby granted, free of charge, to any person obtaining
71
+ a copy of this software and associated documentation files (the
72
+ 'Software'), to deal in the Software without restriction, including
73
+ without limitation the rights to use, copy, modify, merge, publish,
74
+ distribute, sublicense, and/or sell copies of the Software, and to
75
+ permit persons to whom the Software is furnished to do so, subject to
76
+ the following conditions:
77
+
78
+ The above copyright notice and this permission notice shall be
79
+ included in all copies or substantial portions of the Software.
80
+
81
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
82
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
83
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
84
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
85
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
86
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
87
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,264 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ kind = Config::CONFIG['DLEXT']
7
+ windows = RUBY_PLATFORM =~ /mswin/i ? true : false
8
+
9
+ LIB_DIR = File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
10
+ $LOAD_PATH << LIB_DIR
11
+
12
+ GENERATED_PARSER = "lib/nokogiri/css/generated_parser.rb"
13
+ GENERATED_TOKENIZER = "lib/nokogiri/css/generated_tokenizer.rb"
14
+
15
+ EXT = "ext/nokogiri/native.#{kind}"
16
+
17
+ require 'nokogiri/version'
18
+
19
+ HOE = Hoe.new('nokogiri', Nokogiri::VERSION) do |p|
20
+ p.developer('Aaron Patterson', 'aaronp@rubyforge.org')
21
+ p.clean_globs = [
22
+ 'ext/nokogiri/Makefile',
23
+ 'ext/nokogiri/*.{o,so,bundle,a,log,dll}',
24
+ 'ext/nokogiri/conftest.dSYM',
25
+ GENERATED_PARSER,
26
+ GENERATED_TOKENIZER,
27
+ 'cross',
28
+ ]
29
+ p.spec_extras = { :extensions => ["Rakefile"] }
30
+ end
31
+
32
+ namespace :gem do
33
+ namespace :dev do
34
+ task :spec do
35
+ File.open("#{HOE.name}.gemspec", 'w') do |f|
36
+ HOE.spec.version = "#{HOE.version}.#{Time.now.strftime("%Y%m%d%H%M%S")}"
37
+ f.write(HOE.spec.to_ruby)
38
+ end
39
+ end
40
+ end
41
+
42
+ namespace :win32 do
43
+ task :spec do
44
+ File.open("#{HOE.name}.gemspec", 'w') do |f|
45
+ HOE.spec.files += Dir['ext/nokogiri/**.{dll,so}']
46
+ if windows
47
+ HOE.spec.platform = Gem::Platform::CURRENT
48
+ else
49
+ HOE.spec.platform = 'x86-mswin32-60'
50
+ end
51
+ HOE.spec.extensions = []
52
+ f.write(HOE.spec.to_ruby)
53
+ end
54
+ end
55
+ end
56
+
57
+ namespace :unix do
58
+ task :spec do
59
+ File.open("#{HOE.name}.gemspec", 'w') do |f|
60
+ f.write(HOE.spec.to_ruby)
61
+ end
62
+ end
63
+ end
64
+
65
+ task :spec => ['gem:dev:spec']
66
+ end
67
+
68
+ desc "Run code-coverage analysis"
69
+ task :coverage do
70
+ rm_rf "coverage"
71
+ sh "rcov -x Library -I lib:test #{Dir[*HOE.test_globs].join(' ')}"
72
+ end
73
+
74
+ file GENERATED_PARSER => "lib/nokogiri/css/parser.y" do |t|
75
+ sh "racc -o #{t.name} #{t.prerequisites.first}"
76
+ end
77
+
78
+ file GENERATED_TOKENIZER => "lib/nokogiri/css/tokenizer.rex" do |t|
79
+ sh "frex -i --independent -o #{t.name} #{t.prerequisites.first}"
80
+ end
81
+
82
+ task 'ext/nokogiri/Makefile' do
83
+ Dir.chdir('ext/nokogiri') do
84
+ ruby "extconf.rb"
85
+ end
86
+ end
87
+
88
+ task EXT => 'ext/nokogiri/Makefile' do
89
+ Dir.chdir('ext/nokogiri') do
90
+ sh 'make'
91
+ end
92
+ end
93
+
94
+ task :build => [EXT, GENERATED_PARSER, GENERATED_TOKENIZER]
95
+
96
+ namespace :build do
97
+ namespace :win32 do
98
+ file 'cross/bin/ruby.exe' => ['cross/ruby-1.8.6-p287'] do
99
+ Dir.chdir('cross/ruby-1.8.6-p287') do
100
+ str = ''
101
+ File.open('Makefile.in', 'rb') do |f|
102
+ f.each_line do |line|
103
+ if line =~ /^\s*ALT_SEPARATOR =/
104
+ str += "\t\t " + 'ALT_SEPARATOR = "\\\\\"; \\'
105
+ str += "\n"
106
+ else
107
+ str += line
108
+ end
109
+ end
110
+ end
111
+ File.open('Makefile.in', 'wb') { |f| f.write str }
112
+ buildopts = if File.exists?('/usr/bin/i586-mingw32msvc-gcc')
113
+ "--host=i586-mingw32msvc --target=i386-mingw32 --build=i686-linux"
114
+ else
115
+ "--host=i386-mingw32 --target=i386-mingw32"
116
+ end
117
+ sh(<<-eocommand)
118
+ env ac_cv_func_getpgrp_void=no \
119
+ ac_cv_func_setpgrp_void=yes \
120
+ rb_cv_negative_time_t=no \
121
+ ac_cv_func_memcmp_working=yes \
122
+ rb_cv_binary_elf=no \
123
+ ./configure \
124
+ #{buildopts} \
125
+ --prefix=#{File.expand_path(File.join(Dir.pwd, '..'))}
126
+ eocommand
127
+ sh 'make'
128
+ sh 'make install'
129
+ end
130
+ end
131
+
132
+ desc 'build cross compiled ruby'
133
+ task :ruby => 'cross/bin/ruby.exe'
134
+ end
135
+
136
+ desc 'build nokogiri for win32'
137
+ task :win32 => [GENERATED_PARSER, GENERATED_TOKENIZER, 'build:externals', 'build:win32:ruby'] do
138
+ dash_i = File.expand_path(
139
+ File.join(File.dirname(__FILE__), 'cross/lib/ruby/1.8/i386-mingw32/')
140
+ )
141
+ Dir.chdir('ext/nokogiri') do
142
+ ruby " -I #{dash_i} extconf.rb"
143
+ sh 'make'
144
+ end
145
+ dlls = Dir[File.join(File.dirname(__FILE__), 'cross', '**/*.dll')]
146
+ dlls.each do |dll|
147
+ next if dll =~ /ruby/
148
+ cp dll, 'ext/nokogiri'
149
+ end
150
+ end
151
+
152
+ libs = %w{
153
+ iconv-1.9.2.win32
154
+ zlib-1.2.3.win32
155
+ libxml2-2.7.2.win32
156
+ libxslt-1.1.24.win32
157
+ }
158
+
159
+ libs.each do |lib|
160
+ file "stash/#{lib}.zip" do |t|
161
+ puts "downloading #{lib}"
162
+ FileUtils.mkdir_p('stash')
163
+ Dir.chdir('stash') do
164
+ url = "http://www.zlatkovic.com/pub/libxml/#{lib}.zip"
165
+ system("wget #{url} || curl -O #{url}")
166
+ end
167
+ end
168
+ file "cross/#{lib}" => ["stash/#{lib}.zip"] do |t|
169
+ puts "unzipping #{lib}.zip"
170
+ FileUtils.mkdir_p('cross')
171
+ Dir.chdir('cross') do
172
+ sh "unzip ../stash/#{lib}.zip"
173
+ sh "touch #{lib}"
174
+ end
175
+ end
176
+ end
177
+
178
+ file "stash/ruby-1.8.6-p287.tar.gz" do |t|
179
+ puts "downloading ruby"
180
+ FileUtils.mkdir_p('stash')
181
+ Dir.chdir('stash') do
182
+ url = ("ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p287.tar.gz")
183
+ system("wget #{url} || curl -O #{url}")
184
+ end
185
+ end
186
+ file 'cross/ruby-1.8.6-p287' => ["stash/ruby-1.8.6-p287.tar.gz"] do |t|
187
+ puts "unzipping ruby"
188
+ FileUtils.mkdir_p('cross')
189
+ Dir.chdir('cross') do
190
+ sh "tar zxvf ../stash/ruby-1.8.6-p287.tar.gz"
191
+ end
192
+ end
193
+
194
+ task :externals => libs.map { |x| "cross/#{x}" } + ['cross/ruby-1.8.6-p287']
195
+ end
196
+
197
+ desc "set environment variables to build and/or test with debug options"
198
+ task :debug do
199
+ ENV['NOKOGIRI_DEBUG'] = "true"
200
+ ENV['CFLAGS'] ||= ""
201
+ ENV['CFLAGS'] += " -DDEBUG"
202
+ end
203
+
204
+ def test_suite_cmdline
205
+ require 'find'
206
+ files = []
207
+ Find.find("test") do |f|
208
+ files << f if File.basename(f) =~ /.*test.*\.rb$/
209
+ end
210
+ cmdline = "ruby -w -I.:lib:ext:test -rtest/unit -e '%w[#{files.join(' ')}].each {|f| require f}'"
211
+ end
212
+
213
+ namespace :test do
214
+ # partial-loads-ok and undef-value-errors necessary to ignore
215
+ # spurious (and eminently ignorable) warnings from the ruby
216
+ # interpreter
217
+ VALGRIND_BASIC_OPTS = "--num-callers=50 --error-limit=no --partial-loads-ok=yes --undef-value-errors=no"
218
+
219
+ desc "run test suite under valgrind with basic ruby options"
220
+ task :valgrind => :build do
221
+ cmdline = "valgrind #{VALGRIND_BASIC_OPTS} #{test_suite_cmdline}"
222
+ puts cmdline
223
+ system cmdline
224
+ end
225
+
226
+ desc "run test suite under valgrind with memory-fill ruby options"
227
+ task :valgrind_mem => :build do
228
+ # fill malloced memory with "m" and freed memory with "f"
229
+ cmdline = "valgrind #{VALGRIND_BASIC_OPTS} --freelist-vol=100000000 --malloc-fill=6D --free-fill=66 #{test_suite_cmdline}"
230
+ puts cmdline
231
+ system cmdline
232
+ end
233
+
234
+ desc "run test suite under valgrind with memory-zero ruby options"
235
+ task :valgrind_mem0 => :build do
236
+ # fill malloced and freed memory with 0
237
+ cmdline = "valgrind #{VALGRIND_BASIC_OPTS} --freelist-vol=100000000 --malloc-fill=00 --free-fill=00 #{test_suite_cmdline}"
238
+ puts cmdline
239
+ system cmdline
240
+ end
241
+
242
+ desc "run test suite under gdb"
243
+ task :gdb => :build do
244
+ cmdline = "gdb --args #{test_suite_cmdline}"
245
+ puts cmdline
246
+ system cmdline
247
+ end
248
+
249
+ desc "run test suite with aggressive GC"
250
+ task :gc => :build do
251
+ ENV['NOKOGIRI_GC'] = "true"
252
+ Rake::Task["test"].invoke
253
+ end
254
+ end
255
+
256
+
257
+ # Only do this on unix, since we can't build on windows
258
+ unless windows
259
+ Rake::Task[:test].prerequisites << :build
260
+ Rake::Task[:check_manifest].prerequisites << GENERATED_PARSER
261
+ Rake::Task[:check_manifest].prerequisites << GENERATED_TOKENIZER
262
+ end
263
+
264
+ # vim: syntax=Ruby