From: Eloy D. <elo...@gm...> - 2008-02-06 15:04:58
|
Hi Avram, I don't think it's likely that libtidy was already loaded. However, I think that the way you described by using NSXMLDocument is actually even nicer... I mean, if a complete drop in replacement for the ruby Tidy lib is as simple as the following 5 lines: class OSX::NSXMLDocument def self.tidy(html) alloc.initWithData_options_error(OSX::NSData.dataWithRubyString(html), OSX::NSXMLDocumentTidyHTML, nil).XMLData.rubyString end end # cleaned_html = OSX::NSXMLDocument.tidy(dirty_html) Then that's pretty neat in my book... :) Thanks for the update! Cheers, Eloy On 2/6/08, Avram Lyon <aj...@gm...> wrote: > Update: > > I haven't been able to track down why I can't dynamically load > libraries when using RubyCocoa, but I did find a fix for my specific > needs. > > The Tidy gem works just like the NSXMLDocument contructor when used > with the NSXMLDocumentTidyHTML option, so I was able to just replicate > the gem's functionality using equivalent Obj-C calls. Code follows. > > Since the Tidy library (but not gem) is installed by default on Macs, > this makes me wonder if the error I listed in my original post > (.../dl/import.rb:126:in `symbol': can't find the symbol `tidyCreate' > (RuntimeError)), was in fact because libtidy.dylib was already loaded. > Is that a possibility? > > Hope this workaround helps anyone else who finds herself in my situation. > > Avram > > (workaround code) > # Here we need to act like we use Tidy, without using it > def tidy_up_html(html) > data = OSX::NSData.dataWithRubyString(html) > document = > OSX::NSXMLDocument.alloc.initWithData_options_error(data, > OSX::NSXMLDocumentTidyHTML, nil) > ns_data = document.XMLData > cleaned = ns_data.rubyString > cleaned > end > > > On Feb 3, 2008 5:31 PM, Avram Lyon <aj...@gm...> wrote: > > I'm working on a RubyCocoa front-end for a Ruby library I wrote to > > access a certain web forum. The library uses the Tidy gem to normalize > > the messy HTML it gets from the web server before using REXML to parse > > out the needed content. This works fine for me when I'm using plain > > old Ruby, but when I call: > > > > Tidy.path=LOCAL_TIDY_LIB_PATH > > > > from my RubyCocoa app, I get a RuntimeError (trace below). As the > > trace shows, the error is thrown when dl/import.rb tries to load the > > local HTMLTidy library (/usr/lib/libtidy.dylib). > > > > My gut instinct here is that this a limitation of RubyCocoa -- I can't > > use dynamic loading. Is that the case? If so, is there a way to work > > around it? I've looked at the Tidy gem project documentation and the > > RubyCocoa documentation, and I don't see anything related to this. > > > > Thanks in advance for any and all advice, > > > > Avram Lyon > > > > Trace from XCode Debugger console follows: > > ==snip== > > /Development/Mac_Plans/build/Release/Mac_Plans.app/Contents/Resources/rb_main.rb:23 > > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/dl/import.rb:126:in > > `symbol': can't find the symbol `tidyCreate' (RuntimeError) > > from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/dl/import.rb:145:in > > `import' > > from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/dl/import.rb:61:in > > `extern' > > from /Library/Ruby/Gems/1.8/gems/tidy-1.1.2/lib/tidy/tidylib.rb:17:in `load' > > from /Library/Ruby/Gems/1.8/gems/tidy-1.1.2/lib/tidy.rb:46:in `path=' > > from /Development/Mac_Plans/build/Release/Mac_Plans.app/Contents/Resources/plans_client.rb:195:in > > `tidy_up_html' > > from /Development/Mac_Plans/build/Release/Mac_Plans.app/Contents/Resources/plans_client.rb:123:in > > `parse_v2' > > from /Development/Mac_Plans/build/Release/Mac_Plans.app/Contents/Resources/plans_client.rb:114:in > > `parse' > > from /Development/Mac_Plans/build/Release/Mac_Plans.app/Contents/Resources/plans_client.rb:72:in > > `login' > > from /Development/Mac_Plans/build/Release/Mac_Plans.app/Contents/Resources/plans_window_controller.rb:25:in > > `loginClient' > > from /Development/Mac_Plans/build/Release/Mac_Plans.app/Contents/Resources/rb_main.rb:23:in > > `NSApplicationMain' > > from /Development/Mac_Plans/build/Release/Mac_Plans.app/Contents/Resources/rb_main.rb:23 > > > > The Debugger has exited with status 1.The Debugger has exited with status 1. > > ==end of trace== > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > |