moocode / asset_id Goto Github PK
View Code? Open in Web Editor NEWRails 3 library that uploads all static assets to amazon s3 with a unique id encoded into the path
License: MIT License
Rails 3 library that uploads all static assets to amazon s3 with a unique id encoded into the path
License: MIT License
I'm preparing mime-types 2.0 for release, and it has some breaking API changes (not for most uses, but some esoteric features). The most important API change is that mime-types 2.0 no longer supports Ruby 1.8.
If this matters, the gemspec needs to be changed from >= 1.16 to ~> 1.16.
I use a sprite plugin that appends the timestamp to the url in css:
url(/images/logo.png?194819891)
So if you just add url = url.split("?")[0]
, to the following method, it works great!
def replace_css_images!(options={})
options[:prefix] ||= ''
# adapted from https://github.com/blakink/asset_id
data.gsub! /url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)/mi do |match|
begin
# $1 is the double quoted string, $2 is single quoted, $3 is no quotes
uri = ($1 || $2 || $3).to_s.strip
uri.gsub!(/^\.\.\//, '/')
# if the uri appears to begin with a protocol then the asset isn't on the local filesystem
if uri =~ /[a-z]+:\/\//i
"url(#{uri})"
else
url = url.split("?")[0]
asset = Asset.new(uri)
# TODO: Check the referenced asset is in the asset_paths
puts " - Changing CSS URI #{uri} to #{options[:prefix]}#{asset.fingerprint}" if @@debug
"url(#{options[:prefix]}#{asset.fingerprint})"
end
rescue Errno::ENOENT => e
puts " - Warning: #{uri} not found" if @@debug
"url(#{uri})"
end
end
end
It would be ideal if one could specify the location of the yml file holding the credentials for S3 to keep things DRY.
Hey, have you any good way to set a file path e.g. in CSS with url()...
I can hardcode url(http://static.host.com/images/pic.jpg) but then in development mode, maybe when I'm offline, I have the trouble.
And I think it's a stupid way to hardcode the full host address.
Maybe I will change the domain in the future and so on.
Daniel
Since asset_id inserts an md5 hash into the filename of each asset uploaded, wouldn't it be faster to check on s3 for the presence of the file before reuploading every resource every time?
Hi. first of all, thanks for putting asset_id together, it's very handy.
My project uses compass/sass, so I need to modify the output of the compass image-url method. compass has it's own asset_host specification system, it doesn't cleverly inherit from rails or anything.
Was just wondering if you've used asset_id with compass and how you achieved that. If not, I'll let you know what I put together.
We have two buckets for production and staging.
Once we uploaded to staging then we can't upload to production without deleting log file.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.