fonts did not work when stored in amazon s3
This commit is contained in:
parent
56a7a09903
commit
c828301f37
2
Gemfile
2
Gemfile
@ -30,7 +30,7 @@ gem 'RedCloth'
|
|||||||
gem 'delayed_job', '2.1.2'
|
gem 'delayed_job', '2.1.2'
|
||||||
gem 'delayed_job_mongoid', '1.0.1'
|
gem 'delayed_job_mongoid', '1.0.1'
|
||||||
gem 'rubyzip'
|
gem 'rubyzip'
|
||||||
gem 'jammit-s3'
|
gem 'locomotive_jammit-s3', :require => 'jammit-s3'
|
||||||
|
|
||||||
# The rest of the dependencies are for use when in the locomotive dev environment
|
# The rest of the dependencies are for use when in the locomotive dev environment
|
||||||
|
|
||||||
|
10
Gemfile.lock
10
Gemfile.lock
@ -128,10 +128,6 @@ GEM
|
|||||||
jammit (0.5.4)
|
jammit (0.5.4)
|
||||||
closure-compiler (>= 0.1.0)
|
closure-compiler (>= 0.1.0)
|
||||||
yui-compressor (>= 0.9.1)
|
yui-compressor (>= 0.9.1)
|
||||||
jammit-s3 (0.5.4.3)
|
|
||||||
jammit (>= 0.5.4)
|
|
||||||
mimemagic (>= 0.1.7)
|
|
||||||
s3 (>= 0.3.7)
|
|
||||||
json (1.4.6)
|
json (1.4.6)
|
||||||
json_pure (1.4.6)
|
json_pure (1.4.6)
|
||||||
kgio (2.1.1)
|
kgio (2.1.1)
|
||||||
@ -143,6 +139,10 @@ GEM
|
|||||||
ruby_core_source (>= 0.1.4)
|
ruby_core_source (>= 0.1.4)
|
||||||
locomotive_carrierwave (0.5.0.1.beta2)
|
locomotive_carrierwave (0.5.0.1.beta2)
|
||||||
activesupport (~> 3.0)
|
activesupport (~> 3.0)
|
||||||
|
locomotive_jammit-s3 (0.5.4.4)
|
||||||
|
jammit (>= 0.5.4)
|
||||||
|
mimemagic (>= 0.1.7)
|
||||||
|
s3 (>= 0.3.7)
|
||||||
locomotive_liquid (2.2.2)
|
locomotive_liquid (2.2.2)
|
||||||
locomotive_mongoid_acts_as_tree (0.1.5.1)
|
locomotive_mongoid_acts_as_tree (0.1.5.1)
|
||||||
bson (>= 0.20.1)
|
bson (>= 0.20.1)
|
||||||
@ -274,9 +274,9 @@ DEPENDENCIES
|
|||||||
heroku
|
heroku
|
||||||
httparty (>= 0.6.1)
|
httparty (>= 0.6.1)
|
||||||
inherited_resources (>= 1.1.2)
|
inherited_resources (>= 1.1.2)
|
||||||
jammit-s3
|
|
||||||
launchy
|
launchy
|
||||||
locomotive_carrierwave (= 0.5.0.1.beta2)
|
locomotive_carrierwave (= 0.5.0.1.beta2)
|
||||||
|
locomotive_jammit-s3
|
||||||
locomotive_liquid (= 2.2.2)
|
locomotive_liquid (= 2.2.2)
|
||||||
locomotive_mongoid_acts_as_tree (= 0.1.5.1)
|
locomotive_mongoid_acts_as_tree (= 0.1.5.1)
|
||||||
mimetype-fu
|
mimetype-fu
|
||||||
|
@ -18,4 +18,15 @@ class ThemeAssetUploader < AssetUploader
|
|||||||
%w(jpg jpeg gif png css js swf flv eot svg ttf woff otf ico)
|
%w(jpg jpeg gif png css js swf flv eot svg ttf woff otf ico)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.url_for(site, path)
|
||||||
|
build(site, path).url
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.build(site, path)
|
||||||
|
asset = ThemeAsset.new(:site => site, :folder => File.dirname(path))
|
||||||
|
uploader = ThemeAssetUploader.new(asset)
|
||||||
|
uploader.retrieve_from_store!(File.basename(path))
|
||||||
|
uploader
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -9,11 +9,7 @@ module Locomotive
|
|||||||
return '' if input.nil?
|
return '' if input.nil?
|
||||||
|
|
||||||
unless input =~ /^(\/|http:)/
|
unless input =~ /^(\/|http:)/
|
||||||
segments = "stylesheets/#{input}".split('/')
|
input = asset_url("stylesheets/#{input}")
|
||||||
|
|
||||||
filename, folder = segments.pop, segments.join('/')
|
|
||||||
|
|
||||||
input = asset_url(folder, filename)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
input = "#{input}.css" unless input.ends_with?('.css')
|
input = "#{input}.css" unless input.ends_with?('.css')
|
||||||
@ -27,14 +23,7 @@ module Locomotive
|
|||||||
return '' if input.nil?
|
return '' if input.nil?
|
||||||
|
|
||||||
unless input =~ /^(\/|http:)/
|
unless input =~ /^(\/|http:)/
|
||||||
segments = "javascripts/#{input}".split('/')
|
input = asset_url("javascripts/#{input}")
|
||||||
|
|
||||||
filename, folder = segments.pop, segments.join('/')
|
|
||||||
|
|
||||||
input = asset_url(folder, filename)
|
|
||||||
# javascript = ThemeAsset.new(:site => @context.registers[:site], :folder => folder)
|
|
||||||
#
|
|
||||||
# input = '/' + ThemeAssetUploader.new(javascript).store_path(filename)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
input = "#{input}.js" unless input.ends_with?('.js')
|
input = "#{input}.js" unless input.ends_with?('.js')
|
||||||
@ -47,11 +36,7 @@ module Locomotive
|
|||||||
|
|
||||||
input = "images/#{input}" unless input.starts_with?('/')
|
input = "images/#{input}" unless input.starts_with?('/')
|
||||||
|
|
||||||
segments = input.split('/')
|
asset_url(input)
|
||||||
|
|
||||||
filename, folder = segments.pop, segments.join('/')
|
|
||||||
|
|
||||||
asset_url(folder, filename)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write an image tag
|
# Write an image tag
|
||||||
@ -143,12 +128,10 @@ module Locomotive
|
|||||||
input.respond_to?(:url) ? input.url : input
|
input.respond_to?(:url) ? input.url : input
|
||||||
end
|
end
|
||||||
|
|
||||||
def asset_url(folder, filename)
|
def asset_url(path)
|
||||||
asset = ThemeAsset.new(:site => @context.registers[:site], :folder => folder)
|
ThemeAssetUploader.url_for(@context.registers[:site], path)
|
||||||
uploader = ThemeAssetUploader.new(asset)
|
|
||||||
uploader.retrieve_from_store!(filename)
|
|
||||||
uploader.url
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
::Liquid::Template.register_filter(Html)
|
::Liquid::Template.register_filter(Html)
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
require 'rack/utils'
|
|
||||||
|
|
||||||
module Locomotive
|
module Locomotive
|
||||||
module Middlewares
|
module Middlewares
|
||||||
class Fonts
|
class Fonts
|
||||||
include Rack::Utils
|
|
||||||
|
|
||||||
def initialize(app, opts = {})
|
def initialize(app, opts = {})
|
||||||
@app = app
|
@app = app
|
||||||
@path_regexp = opts[:path] || %r{^/fonts/}
|
@path_regexp = opts[:path] || %r{^/fonts/}
|
||||||
@file_server = ::Rack::File.new(opts[:root] || "#{Rails.root}/public")
|
@expires_in = opts[:expires_in] || 24.hour # varnish
|
||||||
@expires_in = opts[:expires_in] || 24.hour
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
@ -19,13 +15,9 @@ module Locomotive
|
|||||||
if site.nil?
|
if site.nil?
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
else
|
else
|
||||||
env["PATH_INFO"] = ::File.join('/', 'sites', site.id.to_s, 'theme', env["PATH_INFO"])
|
body = ThemeAssetUploader.build(site, env["PATH_INFO"]).read.to_s
|
||||||
|
|
||||||
response = @file_server.call(env)
|
[200, { 'Cache-Control' => "public; max-age=#{@expires_in}" }, [body]]
|
||||||
|
|
||||||
response[1]['Cache-Control'] = "public; max-age=#{@expires_in}" # varnish
|
|
||||||
|
|
||||||
response
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
Loading…
Reference in New Issue
Block a user