Changeset 156
- Timestamp:
- 11/12/2007 10:16:46 (13 months ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
Rakefile (modified) (5 diffs)
-
lib/hpricot/builder.rb (modified) (3 diffs)
-
lib/hpricot/traverse.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Rakefile
r152 r156 13 13 BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp}" 14 14 ARCHLIB = "lib/#{::Config::CONFIG['arch']}" 15 CLEAN.include ["ext/hpricot_scan/#{BIN}", "lib/**/#{BIN}", 'ext/hpricot_scan/Makefile', 15 CLEAN.include ["ext/hpricot_scan/#{BIN}", "ext/fast_xs/#{BIN}", "lib/**/#{BIN}", 16 'ext/fast_xs/Makefile', 'ext/hpricot_scan/Makefile', 16 17 '**/.*.sw?', '*.gem', '.config'] 17 18 RDOC_OPTS = ['--quiet', '--title', 'The Hpricot Reference', '--main', 'README', '--inline-source'] … … 67 68 end 68 69 69 extension = "hpricot_scan" 70 ext = "ext/hpricot_scan" 71 ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}" 72 ext_files = FileList[ 73 "#{ext}/*.c", 74 "#{ext}/*.h", 75 "#{ext}/*.rl", 76 "#{ext}/extconf.rb", 77 "#{ext}/Makefile", 78 "lib" 79 ] 70 ['hpricot_scan', 'fast_xs'].each do |extension| 71 ext = "ext/#{extension}" 72 ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}" 73 ext_files = FileList[ 74 "#{ext}/*.c", 75 "#{ext}/*.h", 76 "#{ext}/*.rl", 77 "#{ext}/extconf.rb", 78 "#{ext}/Makefile", 79 "lib" 80 ] 81 82 desc "Builds just the #{extension} extension" 83 task extension.to_sym => ["#{ext}/Makefile", ext_so ] 84 85 file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do 86 Dir.chdir(ext) do ruby "extconf.rb" end 87 end 88 89 file ext_so => ext_files do 90 Dir.chdir(ext) do 91 sh(PLATFORM =~ /win32/ ? 'nmake' : 'make') 92 end 93 mkdir_p ARCHLIB 94 cp ext_so, ARCHLIB 95 end 96 end 80 97 81 98 task "lib" do … … 84 101 85 102 desc "Compiles the Ruby extension" 86 task :compile => [:hpricot_scan ] do103 task :compile => [:hpricot_scan, :fast_xs] do 87 104 if Dir.glob(File.join(ARCHLIB,"hpricot_scan.*")).length == 0 88 105 STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" … … 95 112 task :hpricot_scan => [:ragel] 96 113 97 desc "Builds just the #{extension} extension"98 task extension.to_sym => ["#{ext}/Makefile", ext_so ]99 100 file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do101 Dir.chdir(ext) do ruby "extconf.rb" end102 end103 104 file ext_so => ext_files do105 Dir.chdir(ext) do106 sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')107 end108 mkdir_p ARCHLIB109 cp ext_so, ARCHLIB110 end111 112 114 desc "returns the ragel version" 113 115 task :ragel_version do … … 129 131 Win32Spec = SPEC.dup 130 132 Win32Spec.platform = Gem::Platform::WIN32 131 Win32Spec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.so" ]133 Win32Spec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.so", "#{ARCHLIB}/fast_xs.so"] 132 134 Win32Spec.extensions = [] 133 135 -
trunk/lib/hpricot/builder.rb
r145 r156 1 1 require 'hpricot/tags' 2 require ' hpricot/xchar'2 require 'fast_xs' 3 3 require 'hpricot/blankslate' 4 4 5 5 module Hpricot 6 PREDEFINED = { 7 34 => '"', # quotation mark 8 38 => '&', # ampersand 9 60 => '<', # left angle bracket 10 62 => '>' # right angle bracket 11 } 12 PREDEFINED_U = PREDEFINED.inject({}) { |hsh, (k, v)| hsh[v] = k; hsh } 13 14 # XML unescape 15 def self.uxs(str) 16 str.to_s. 17 gsub(/\&\w+;/) { |x| (PREDEFINED_U[x] || ??).chr }. 18 gsub(/\&\#(\d+);/) { [$1.to_i].pack("U*") } 19 end 20 6 21 def self.build(ele = Doc.new, assigns = {}, &blk) 7 22 ele.extend Builder … … 33 48 # Write a +string+ to the HTML stream, making sure to escape it. 34 49 def text!(string) 35 @children << Text.new( Hpricot.xs(string))50 @children << Text.new(string.fast_xs) 36 51 end 37 52 … … 80 95 Hpricot.make(x.to_html) 81 96 elsif x 82 Text.new( Hpricot.xs(x))97 Text.new(x.fast_xs) 83 98 end 84 99 end.flatten) 85 100 attrs = attrs.inject({}) do |hsh, ath| 86 101 ath.each do |k, v| 87 hsh[k] = Hpricot.xs(v.to_s)if v102 hsh[k] = v.to_s.fast_xs if v 88 103 end 89 104 hsh -
trunk/lib/hpricot/traverse.rb
r155 r156 817 817 altered! 818 818 self.raw_attributes ||= {} 819 self.raw_attributes[name.to_s] = Hpricot.xs(val)819 self.raw_attributes[name.to_s] = val.fast_xs 820 820 end 821 821 alias_method :[]=, :set_attribute
