class BookmarkletRenderer class << self def cached_name @cached ||= File.join(Rails.application.config.paths["tmp"].first, "cache", "bookmarklet.cached") end def source_name @source ||= Rails.application.assets["bookmarklet.js"].pathname.to_s end def body if !File.exist?(cached_name) && Rails.env.production? raise "please run the Rake task to compile the bookmarklet: `bundle exec rake assets:uglify_bookmarklet`" end compile unless Rails.env.production? # don't make me re-run rake in development @body ||= File.read(cached_name) end def compile src = File.read(source_name) @body = Uglifier.compile(src) File.open(cached_name, "w") {|f| f.write(@body) } end end end