Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize Cache-Control with ThemesForRails.config #67

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/themes_for_rails/assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def handle_asset(prefix)
asset, theme = params[:asset], params[:theme]
find_themed_asset(asset, theme, prefix) do |path, mime_type|
response.headers['ETag'] = %("#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(File.mtime(path).to_s + path))}")
response.headers['Cache-Control'] = "public, max-age=2592000"
response.headers['Cache-Control'] = ThemesForRails.config.assets_cache_control
send_file path, :type => mime_type, :disposition => "inline"
end
end
Expand Down
15 changes: 10 additions & 5 deletions lib/themes_for_rails/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module ThemesForRails
class Config

attr_writer :base_dir, :themes_dir, :assets_dir, :views_dir, :themes_routes_dir
attr_writer :base_dir, :themes_dir, :assets_dir, :views_dir, :themes_routes_dir, :assets_cache_control
attr_accessor :use_sass, :default_theme

include Interpolation
Expand Down Expand Up @@ -39,6 +39,10 @@ def themes_dir
@themes_dir ||= ":root/themes"
end

def assets_cache_control
@assets_cache_control ||= "public, max-age=#{1.hours}"
end

# Full path to themes
def themes_path
interpolate(themes_dir)
Expand All @@ -57,10 +61,11 @@ def themes_routes_dir
end

def clear
@base_dir = nil
@themes_dir = nil
@assets_dir = nil
@views_dir = nil
@base_dir = nil
@themes_dir = nil
@assets_dir = nil
@views_dir = nil
@assets_cache_control = nil
end

def use_sass?
Expand Down
4 changes: 2 additions & 2 deletions themes_for_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = ThemesForRails::VERSION

gem.add_dependency('rails', [">= 3.0.0"])
gem.add_runtime_dependency 'rails', "~> 3.2.11", ">= 3.2.0"

gem.add_development_dependency "sqlite3"
gem.add_development_dependency "test-unit"
gem.add_development_dependency "contest"
gem.add_development_dependency "mocha"
gem.add_development_dependency('rails', ["= 3.0.11"])
end