forked from rstacruz/sinatra-assetpack
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image cache busting in CSS, and embeds.
- Loading branch information
Showing
28 changed files
with
134 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Sinatra | ||
module AssetPack | ||
module Css | ||
def self.preproc(str, assets) | ||
str.gsub(/url\(["']?(.*?)["']?\)/) { |url| | ||
file, options = $1.split('?') | ||
local = assets.local_file_for file | ||
|
||
url = if local | ||
if options.to_s.include?('embed') | ||
to_data_uri(local) | ||
else | ||
BusterHelpers.add_cache_buster(file, local) | ||
end | ||
else | ||
url | ||
end | ||
|
||
"url(#{url})" | ||
} | ||
end | ||
|
||
def self.to_data_uri(file) | ||
require 'base64' | ||
|
||
data = File.read(file) | ||
ext = File.extname(file) | ||
mime = Sinatra::Base.mime_type(ext) | ||
b64 = Base64.encode64(data).gsub("\n", '') | ||
|
||
"data:#{mime};base64,#{b64}" | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module Sinatra | ||
module AssetPack | ||
def self.version | ||
"0.0.1" | ||
"0.0.2" | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#background | ||
color: rgba(blue, 0.3) | ||
|
||
background: url(/images/email.png) | ||
background-repeat: no-repeat | ||
|
||
#sidebar | ||
background: url(/images/email.png?embed) |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
div { color: red; } | ||
body { background: url(/images/background.jpg); } |
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require File.expand_path('../test_helper', __FILE__) | ||
|
||
class PreprocTest < UnitTest | ||
test "preproc" do | ||
get '/css/screen.css' | ||
assert body =~ %r{email.[0-9]+.png} | ||
end | ||
|
||
test "preproc static files" do | ||
get '/css/style.css' | ||
assert body =~ %r{background.[0-9]+.jpg} | ||
end | ||
|
||
test "preproc on minify" do | ||
get '/css/application.css' | ||
assert body =~ %r{email.[0-9]+.png} | ||
end | ||
|
||
test "embed" do | ||
get '/css/screen.css' | ||
assert body =~ %r{data:image/png;base64,[A-Za-z0-9=/]{100,}} | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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