Skip to content

Instantly share code, notes, and snippets.

@dperrymorrow
Created March 21, 2012 15:21
Show Gist options
  • Save dperrymorrow/2148347 to your computer and use it in GitHub Desktop.
Save dperrymorrow/2148347 to your computer and use it in GitHub Desktop.
Generate a bookmarklet from a javascript file
require 'uglifier'
module BookmarkletHelper
def get_bookmarklet(file, hash)
js = File.open( "#{Rails.root}/app/assets/javascripts/#{file}", 'r' ).read
js = Uglifier.compile(js, :mangle => false, :comments => :none)
js_vars.each_pair do |k, v|
js.gsub!("{{#{k.to_s}}}", v)
end
"javascript:(function(){#{js}}());"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment