-
-
Save th3hunt/49700193492b3bd87c68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// helper to create proper asset paths if an asset host is configured | |
App.assets = { | |
assets : { | |
<% AssetsUtil.images.each do |img| %> | |
"<%= img %>" : "<%= asset_path(img) %>", | |
<% end %> | |
}, | |
url : function(path) { | |
return window.ASSETS_URL ? window.ASSETS_URL + path : path; | |
}, | |
asset_path : function(source) { | |
return this.url("/assets/"+source); | |
}, | |
imageUrl : function(imageName) { | |
if(this.assets && this.assets[imageName]) return this.assets[imageName]; | |
return this.asset_path(imageName); | |
}, | |
} |
This file contains hidden or 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
module AssetsUtil | |
def self.assets_url | |
self.config["environments"][Rails.env]["assets"] | |
end | |
def self.server_host | |
self.config["environments"][Rails.env]["host"] | |
end | |
def self.config | |
@@config ||= YAML.load_file(File.join(Rails.root, 'config', 'assets.yml')) | |
@@config | |
end | |
def self.images | |
Dir.glob(Rails.root.join("app/assets/images/**/*.*")).map do |path| | |
path.gsub(Rails.root.join("app/assets/images/").to_s, "") | |
end | |
end | |
end |
This file contains hidden or 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
<div class="example"> | |
<img src="<%= App.assets.imageUrl('bookmarklet/add.png') %>"> | |
<div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment