Skip to content

Instantly share code, notes, and snippets.

@datapimp
Created October 24, 2012 03:08
Show Gist options
  • Select an option

  • Save datapimp/3943455 to your computer and use it in GitHub Desktop.

Select an option

Save datapimp/3943455 to your computer and use it in GitHub Desktop.
Hack for local development of asset pipeline gems
# Add this in a config/initializer within your Rails Project.
# This makes it easy to package your shared javascript and css assets as Rails::Engine
# for use with the asset pipeline, similarly to how jquery-rails works.
#
# In development, it allows you to edit those gems in their normal project folder and get immediate feedback on the asset pipeline changes.
# Without requiring you to ship the assets to whatever you use to host your gem.
# You will need to set ENV['GEM_PROJECT_ROOT'] to something like /Users/datapimp/Projects
if (Rails.env.test? or Rails.env.development?) and gem_projects_root = ENV['GEM_PROJECTS_ROOT']
# List the gems you develop locally.
# we will prepend their asset pipeline
# paths to sprockets so your local copy
# takes precedence.
gem_projects = %w{benchprep-assets}
existing = gem_projects.map do |project_name|
path = File.join(gem_projects_root, project_name)
if File.exists?( path )
path
end
end
# assumes the projects are rails engines which have their payloads
# in app/assets/javascripts
existing.compact.each do |project_folder|
asset_folders = %w{fonts images javascripts stylesheets}.each do |folder|
%w{app vendor lib}.each do |mount_point|
full_path = File.join( project_folder, mount_point, 'assets', folder)
if File.exists?(full_path)
Rails.application.assets.prepend_path( full_path )
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment