oliverfriedmann / rails-bookmarklet

A bookmarklet gem for rails
MIT License
38 stars 6 forks source link

NameError (uninitialized constant RailsBookmarklet::HTML) #4

Open amalhotra opened 9 years ago

amalhotra commented 9 years ago

Using Rails 4.2.0.

NameError (uninitialized constant RailsBookmarklet::HTML): app/controllers/bookmarklet_controller.rb:10:inshow'`

app/controllers/bookmarklet_controller.rb

class BookmarkletController < ApplicationController
  include BookmarkletHelper
  include ActionView
  # Dont need a layout here
  layout false

  def show
    render_bookmarklet("mybookmarklet", "show")
  end
end

app/helpers/bookmarklet_helper.rb

module BookmarkletHelper
  include RailsBookmarklet
end

My guess is that HTML::Document in render_bookmarklet is not working anymore.

oliverfriedmann commented 9 years ago

Quite possibly. Happy to accept a pull request.

amalhotra commented 9 years ago

I haven't looked into it as such. What exactly is this code trying to do:

document = HTML::Document.new(raw_html)
      document.root.children.each do |child|
        if child.tag?
          innerHTML = "";
          child.children.each { |child_child| innerHTML << child_child.to_s }
          tags.push({
            :name => child.name,
            :attributes => child.attributes,
            :innerHTML => innerHTML
          });
        end

Are you trying to strip_tags? There is a helper for that now. Otherwise using Nokogiri might be the way to go.

oliverfriedmann commented 9 years ago

I think the original idea was to serialize the html code so that the injected javascript can add it to the host website.

amalhotra commented 9 years ago

When you say serialize, what exactly are we serializing it to?

oliverfriedmann commented 9 years ago

Looks like an array of tags. Tags are serialized as associative array with tag name, attributes in innerhtml. We then use JS to deserialize this. I think the reason for that was to not make the host website depend on jQuery (otherwise we could probably have just taken the whole thing as a string and be done with it).