Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/assets #350

Merged
merged 2 commits into from Apr 27, 2016
Merged

Feature/assets #350

merged 2 commits into from Apr 27, 2016

Conversation

loganfreeman
Copy link
Contributor

add support to override asset loading path.

just create a directory in Rails.root called themes. and put assets inside it. it will be the first to be loaded.

@wtholt
Copy link
Contributor

wtholt commented Apr 15, 2016

You can easily add assets through vendor/assets then include them in manifest files. Why do it this way?

@loganfreeman
Copy link
Contributor Author

The CUSTOM_ASSET_PATH is a mess by itself.

I did a search on CUSTOM_ASSET_PATH.

and found:

  = link_to image_tag("#{CUSTOM_ASSET_PATH}about.png", class: 'button-hover'), "javascript:void(0);", class: "about_sparc_request"


  = image_tag "/assets/#{CUSTOM_ASSET_PATH}department_name_460_by_60.gif",class: 'header_logo_2', :alt => "department_logo"

some of them use relative path, others use absolute path.

Do you have to include CUSTOM_ASSET_PATH in all the places where custom images are required?

it cluttered the code.

and about the search path:

the CUSTOM_ASSET_PATH directory hasn't been added to the search path.

So the above image tag image_tag("#{CUSTOM_ASSET_PATH}about.png" will result in 404 not found since CUSTOM_ASSET_PATH is not even in the search path for assets.

Search path

2.2.1 Search Paths
When a file is referenced from a manifest or a helper, Sprockets searches the three default asset locations for it.

The default locations are: the images, javascripts and stylesheets directories under the app/assets folder, but these subdirectories are not special - any path under assets/* will be searched.

@loganfreeman loganfreeman reopened this Apr 19, 2016
@loganfreeman
Copy link
Contributor Author

loganfreeman commented Apr 19, 2016

according to:
~/.rvm/gems/ruby-2.1.5/gems/sprockets-rails-2.3.3/lib/sprockets/railtie.rb

any directories under app/assets directory will be added to assets_path.

  class Engine < Railtie
    # Skip defining append_assets_path on Rails <= 4.2
    unless initializers.find { |init| init.name == :append_assets_path }
      initializer :append_assets_path, :group => :all do |app|
        if paths["app/assets"].respond_to?(:existent_directories)
          app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
          app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
          app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
        else
          app.config.assets.paths.unshift(*paths["vendor/assets"].paths.select { |d| File.directory?(d) })
          app.config.assets.paths.unshift(*paths["lib/assets"].paths.select { |d| File.directory?(d) })
          app.config.assets.paths.unshift(*paths["app/assets"].paths.select { |d| File.directory?(d) })
        end
      end
    end
  end
end

You don't even need custom_asset_path.

All you need do is add an image_override directory under app/assets. then it will find it.

@wtholt
Copy link
Contributor

wtholt commented Apr 20, 2016

Sounds good to me

@jwiel86 jwiel86 merged commit e6069cb into sparc-request:master Apr 27, 2016
@loganfreeman loganfreeman deleted the feature/assets branch June 22, 2016 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants