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_mongoid', '1.0.1'
|
||||
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
|
||||
|
||||
|
10
Gemfile.lock
10
Gemfile.lock
@ -128,10 +128,6 @@ GEM
|
||||
jammit (0.5.4)
|
||||
closure-compiler (>= 0.1.0)
|
||||
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_pure (1.4.6)
|
||||
kgio (2.1.1)
|
||||
@ -143,6 +139,10 @@ GEM
|
||||
ruby_core_source (>= 0.1.4)
|
||||
locomotive_carrierwave (0.5.0.1.beta2)
|
||||
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_mongoid_acts_as_tree (0.1.5.1)
|
||||
bson (>= 0.20.1)
|
||||
@ -274,9 +274,9 @@ DEPENDENCIES
|
||||
heroku
|
||||
httparty (>= 0.6.1)
|
||||
inherited_resources (>= 1.1.2)
|
||||
jammit-s3
|
||||
launchy
|
||||
locomotive_carrierwave (= 0.5.0.1.beta2)
|
||||
locomotive_jammit-s3
|
||||
locomotive_liquid (= 2.2.2)
|
||||
locomotive_mongoid_acts_as_tree (= 0.1.5.1)
|
||||
mimetype-fu
|
||||
|
@ -18,4 +18,15 @@ class ThemeAssetUploader < AssetUploader
|
||||
%w(jpg jpeg gif png css js swf flv eot svg ttf woff otf ico)
|
||||
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
|
||||
|
@ -9,11 +9,7 @@ module Locomotive
|
||||
return '' if input.nil?
|
||||
|
||||
unless input =~ /^(\/|http:)/
|
||||
segments = "stylesheets/#{input}".split('/')
|
||||
|
||||
filename, folder = segments.pop, segments.join('/')
|
||||
|
||||
input = asset_url(folder, filename)
|
||||
input = asset_url("stylesheets/#{input}")
|
||||
end
|
||||
|
||||
input = "#{input}.css" unless input.ends_with?('.css')
|
||||
@ -27,14 +23,7 @@ module Locomotive
|
||||
return '' if input.nil?
|
||||
|
||||
unless input =~ /^(\/|http:)/
|
||||
segments = "javascripts/#{input}".split('/')
|
||||
|
||||
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)
|
||||
input = asset_url("javascripts/#{input}")
|
||||
end
|
||||
|
||||
input = "#{input}.js" unless input.ends_with?('.js')
|
||||
@ -47,11 +36,7 @@ module Locomotive
|
||||
|
||||
input = "images/#{input}" unless input.starts_with?('/')
|
||||
|
||||
segments = input.split('/')
|
||||
|
||||
filename, folder = segments.pop, segments.join('/')
|
||||
|
||||
asset_url(folder, filename)
|
||||
asset_url(input)
|
||||
end
|
||||
|
||||
# Write an image tag
|
||||
@ -143,12 +128,10 @@ module Locomotive
|
||||
input.respond_to?(:url) ? input.url : input
|
||||
end
|
||||
|
||||
def asset_url(folder, filename)
|
||||
asset = ThemeAsset.new(:site => @context.registers[:site], :folder => folder)
|
||||
uploader = ThemeAssetUploader.new(asset)
|
||||
uploader.retrieve_from_store!(filename)
|
||||
uploader.url
|
||||
def asset_url(path)
|
||||
ThemeAssetUploader.url_for(@context.registers[:site], path)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
::Liquid::Template.register_filter(Html)
|
||||
|
@ -1,15 +1,11 @@
|
||||
require 'rack/utils'
|
||||
|
||||
module Locomotive
|
||||
module Middlewares
|
||||
class Fonts
|
||||
include Rack::Utils
|
||||
|
||||
def initialize(app, opts = {})
|
||||
@app = app
|
||||
@path_regexp = opts[:path] || %r{^/fonts/}
|
||||
@file_server = ::Rack::File.new(opts[:root] || "#{Rails.root}/public")
|
||||
@expires_in = opts[:expires_in] || 24.hour
|
||||
@expires_in = opts[:expires_in] || 24.hour # varnish
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@ -19,13 +15,9 @@ module Locomotive
|
||||
if site.nil?
|
||||
@app.call(env)
|
||||
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)
|
||||
|
||||
response[1]['Cache-Control'] = "public; max-age=#{@expires_in}" # varnish
|
||||
|
||||
response
|
||||
[200, { 'Cache-Control' => "public; max-age=#{@expires_in}" }, [body]]
|
||||
end
|
||||
else
|
||||
@app.call(env)
|
||||
|
Loading…
Reference in New Issue
Block a user