开发者

How can I use readability gem on Rails 3.0.x?

I'm going to use readability gem on my rails 3 app. I can't use it as advised on the github page http://github.com/sspinc/readability inside the app although it works fine on ruby console.

On the ruby console:

> require 'open-uri'
 => true 
> require 'readability'
 => true
> doc = Nokogiri::HTML(open('http://google.com'))
 => #<Nokogiri::HTML::Document:0x81345324 name="document"
> doc.to_readable
 => #<Nokogiri::XML::Element:0x813299a8 name="html" 
# (expected result without any error)

On the rails console:

> doc = Nokogiri::HTML(open('http://google.com'))
 => #<Nokogiri::HTML::Document:0x81c2baec name="document"
# (and so on.. expected result)
> readable = doc.to_readable
SyntaxError: /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/readability-0.1.5/lib/readability/js/readability.js:2: syntax error, unexpected '='
    if(typeof console !== 'undefined') {
                         ^
/Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/readability-0.1.5/lib/readability/js/readability.js:2: syntax error, unexpected '{', expecting kTHEN or ':' or '\n' or ';'
/Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/readability-0.1.5/lib/readability/js/readability.js:5: syntax error, unexpected '}', expecting $end
        from /Users/apra开发者_JAVA技巧ditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
        from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
        from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
        from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
        from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/harmony-0.5.6/lib/harmony/page.rb:76:in `load'

I verified that it is not a javascript syntax error. Judging by the active support error, it failed loading the dependencies, I suspect that Rails has failed to load the required gems that readability use (like harmony, johnson and envjs) to handle javascript and DOM in Ruby.

So my guess was may be somthing wrong in the Gemfile? Here's my current Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.0.3'
gem 'devise', '~> 1.1.5'
gem 'haml', '3.0.24'
gem 'simple_form'
gem 'cancan'
gem 'will_paginate', '~> 3.0.beta'
gem 'feedzirra', :require => [ 'feedzirra' ]
gem 'loofah', '1.0.0.beta.1'
gem 'compass', '~> 0.10.4'
gem 'meta_where', '~> 0.9'
gem 'populator'
gem 'simple-navigation'
gem 'readability'

I have tried adding :require option in readability to specify harmony, johnson and envjs; and reran 'bundle install' without any error, but I still have the same error.

I have also checked the config/application.rb to require all the gems in the Gemfile. with this line

Bundler.require(:default, Rails.env) if defined?(Bundler)

So, back to the question, how can I use readability on Rails 3.0.x? Did I miss something? I'm on MacOS 10.6.5 if that matters.

Thank you


On my Mac (Rails 3.x, Ruby 1.9.2 I had trouble with it loading the johnson gem which is a dependency . However, ruby-readability gem works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜