Skip to content

Commit

Permalink
[merb-assets] Moving :asset_timestamp to the Plugin config.
Browse files Browse the repository at this point in the history
It should be local to Merb::Plugin.config[:asset_helpers] not in the
global configuration.
  • Loading branch information
pk committed Mar 20, 2010
1 parent ab432d4 commit c2736e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions merb-assets/lib/merb-assets.rb
Expand Up @@ -12,6 +12,7 @@
:asset_domain => "assets%s",
:domain => "my-awesome-domain.com",
:use_ssl => false,
:asset_timestamp => false,

# Global prefix/suffix for css/js include tags, overridable in js_include_tag and css_include_tag
#
Expand Down
10 changes: 5 additions & 5 deletions merb-assets/lib/merb-assets/assets_mixin.rb
Expand Up @@ -35,10 +35,10 @@ def self.append_random_query_string?(intention, allow_default = true)
# Merb::AssetsMixin.append_timestamp_query_string?(options[:timestamp], !absolute)
#
# @param [Boolean] intention: true if a timestamp string shall be appended
# @param [Boolean] allow_default: true if it's ok to use Merb::Config[:asset_timestamps]
# @param [Boolean] allow_default: true if it's ok to use Merb::Plugins.config[:asset_helpers][:asset_timestamp]
# @return [Boolean] true if a timestamp query string shall be appended
def self.append_timestamp_query_string?(intention, allow_default = true)
intention.nil? && allow_default ? Merb::Config[:asset_timestamps] : intention
intention.nil? && allow_default ? Merb::Plugins.config[:asset_helpers][:asset_timestamp] : intention
end

# Automatically generates link for CSS and JS
Expand Down Expand Up @@ -148,7 +148,7 @@ def link_to(name, url='', opts={})
# Override the Merb::Config[:reload_templates] value. If true, a random query param will be appended
# to the image url
# @option opts [Boolean, String] :timestamp
# Override the Merb::Config[:asset_timestamp] value. If true, a timestamp query param will be appended
# Override the Merb::Plugins.config[:asset_helpers][:asset_timestamp] value. If true, a timestamp query param will be appended
# to the image url. The value will be File.mtime(Merb.dir_for(:public) / path).
# If String is passed than it will be used as the timestamp.
#
Expand Down Expand Up @@ -496,7 +496,7 @@ def include_required_css(options = {})
# Override the Merb::Config[:reload_templates] value. If true, a random query param will be appended
# to the js url
# @option opts [Boolean, String] :timestamp
# Override the Merb::Config[:asset_timestamp] value. If true, a timestamp query param will be appended
# Override the Merb::Plugins.config[:asset_helpers][:asset_timestamp] value. If true, a timestamp query param will be appended
# to the image url. The value will be File.mtime(Merb.dir_for(:public) / path).
# If String is passed than it will be used as the timestamp.
#
Expand Down Expand Up @@ -587,7 +587,7 @@ def js_include_tag(*scripts)
# Override the Merb::Config[:reload_templates] value. If true, a random query param will be appended
# to the css url
# @option opts [Boolean, String] :timestamp
# Override the Merb::Config[:asset_timestamp] value. If true, a timestamp query param will be appended
# Override the Merb::Plugins.config[:asset_helper][:asset_timestamp] value. If true, a timestamp query param will be appended
# to the image url. The value will be File.mtime(Merb.dir_for(:public) / path).
# If String is passed than it will be used as the timestamp.
#
Expand Down
16 changes: 8 additions & 8 deletions merb-assets/spec/merb-assets_spec.rb
Expand Up @@ -184,12 +184,12 @@
end
end

describe "With Merb::Config[:asset_timestamps] set," do
describe "With Merb::Plugins.config[:asset_helpers][:asset_timestamp] set," do
before(:all) do
Merb::Config[:asset_timestamps] = true
Merb::Plugins.config[:asset_helpers][:asset_timestamp] = true
end
after(:all) do
Merb::Config[:asset_timestamps] = false
Merb::Plugins.config[:asset_helpers][:asset_timestamp] = false
end

it "should create image tag with absolute url" do
Expand Down Expand Up @@ -358,19 +358,19 @@
end
end

describe "with Merb::Config[:asset_timestamps] set" do
describe "with Merb::Plugins.config[:asset_helpers][:asset_timestamp] set" do
it "should create a css include tag with a timestamp query string" do
Merb::Config[:asset_timestamps] = true
Merb::Plugins.config[:asset_helpers][:asset_timestamp] = true
result = css_include_tag('style.css')
result.should match(%r{/stylesheets/style.css\?\d+})
Merb::Config[:asset_timestamps] = false
Merb::Plugins.config[:asset_helpers][:asset_timestamp] = false
end

it "should create a js include tag with a timestamp query string" do
Merb::Config[:asset_timestamps] = true
Merb::Plugins.config[:asset_helpers][:asset_timestamp] = true
result = js_include_tag('jquery.js')
result.should match(%r{/javascripts/jquery.js\?\d+})
Merb::Config[:asset_timestamps] = false
Merb::Plugins.config[:asset_helpers][:asset_timestamp] = false
end
end

Expand Down

0 comments on commit c2736e6

Please sign in to comment.