Unverified Commit 61afb358 authored by Benjamin Neff's avatar Benjamin Neff

Merge pull request #7510 from SuperTux88/fix-bookmarklet-for-sprockets-3

Fix bookmarklet for sprockets 3
parents c42315f3 1007b3cd
......@@ -72,6 +72,7 @@ module Diaspora
jquery_ujs.js
main.js
jsxc.js
bookmarklet.js
mobile/bookmarklet.js
mobile/mobile.js
templates.js
......
......@@ -2,27 +2,35 @@
class BookmarkletRenderer
class << self
def cached_name
@cached ||= Rails.root.join("public", "assets", "bookmarklet.js")
@cached_name ||= if Rails.application.config.assets.compile
"bookmarklet.js"
else
Rails.application.assets_manifest.assets["bookmarklet.js"]
end
end
def source_name
def cached_path
@cached_path ||= Rails.root.join("public", "assets", cached_name)
end
def source
@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`"
unless File.exist?(cached_path) || Rails.application.config.assets.compile
raise "Please run the rake task to compile the bookmarklet: `bin/rake assets:precompile`"
end
compile unless Rails.env.production? # don't make me re-run rake in development
@body ||= File.read(cached_name)
compile if Rails.application.config.assets.compile
@body ||= File.read(cached_path)
end
def compile
src = File.read(source_name)
src = File.read(source)
@body = Uglifier.compile(src)
FileUtils.mkdir_p cached_name.dirname
File.open(cached_name, "w") {|f| f.write(@body) }
FileUtils.mkdir_p cached_path.dirname
File.open(cached_path, "w") {|f| f.write(@body) }
end
end
end
......@@ -5,24 +5,18 @@ namespace :assets do
renderer.render
end
desc "Uglify bookmarklet snippet"
task :uglify_bookmarklet => :environment do
BookmarkletRenderer.compile
end
desc "Create non digest assets"
task non_digest_assets: :environment do
logger = ::Logging::Logger["assets:non_digest_assets"]
non_digest_assets = Diaspora::Application.config.assets.non_digest_assets
manifest_path = Dir.glob(Rails.root.join("public", "assets", ".sprockets-manifest-*.json")).first
JSON.load(File.new(manifest_path))["assets"].each do |logical_path, digested_path|
Rails.application.assets_manifest.assets.each do |logical_path, digested_path|
logical_pathname = Pathname.new(logical_path)
next unless non_digest_assets.any? {|testpath| logical_pathname.fnmatch?(testpath, File::FNM_PATHNAME) }
full_digested_path = File.join(Rails.root, "public/assets", digested_path)
full_non_digested_path = File.join(Rails.root, "public/assets", logical_path)
full_digested_path = Rails.root.join("public", "assets", digested_path)
full_non_digested_path = Rails.root.join("public", "assets", logical_path)
next unless FileUtils.uptodate?(full_digested_path, [full_non_digested_path])
......@@ -35,7 +29,6 @@ namespace :assets do
# Augment precompile with error page generation
task :precompile do
Rake::Task["assets:generate_error_pages"].invoke
Rake::Task["assets:uglify_bookmarklet"].invoke
Rake::Task["assets:non_digest_assets"].invoke
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment