Created
March 21, 2012 15:21
-
-
Save dperrymorrow/2148347 to your computer and use it in GitHub Desktop.
Generate a bookmarklet from a javascript file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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