Skip to content

Commit

Permalink
Add support for Roadie 3.1 external_asset_providers option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mange committed Sep 14, 2015
1 parent 48a524f commit 6bd5b75
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[full changelog](https://github.com/Mange/roadie-rails/compare/v1.1.0.rc1...master)

* Add support for `roadie`'s `external_asset_providers` option.

### 1.1.0.rc1

[full changelog](https://github.com/Mange/roadie-rails/compare/v1.0.6...v1.1.0.rc1)
Expand Down
30 changes: 23 additions & 7 deletions lib/roadie/rails/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Options
:after_transformation,
:asset_providers,
:before_transformation,
:external_asset_providers,
:keep_uninlinable_css,
:url_options,
]
Expand All @@ -13,11 +14,12 @@ class Options

def initialize(options = {})
complain_about_unknown_keys options.keys
self.after_transformation = options[:after_transformation]
self.asset_providers = options[:asset_providers]
self.before_transformation = options[:before_transformation]
self.keep_uninlinable_css = options[:keep_uninlinable_css]
self.url_options = options[:url_options]
self.after_transformation = options[:after_transformation]
self.asset_providers = options[:asset_providers]
self.before_transformation = options[:before_transformation]
self.external_asset_providers = options[:external_asset_providers]
self.keep_uninlinable_css = options[:keep_uninlinable_css]
self.url_options = options[:url_options]
end

def url_options=(options)
Expand Down Expand Up @@ -45,13 +47,23 @@ def asset_providers=(providers)
end
end

def external_asset_providers=(providers)
if providers
@external_asset_providers = ProviderList.wrap providers
# TODO: Raise an error when setting to nil in order to make this not a silent error.
# else
# raise ArgumentError, "Cannot set asset_providers to nil. Set to Roadie::NullProvider if you want no external assets inlined."
end
end

def apply_to(document)
document.url_options = url_options
document.before_transformation = before_transformation
document.after_transformation = after_transformation
# #asset_providers default to nil in this class and it's the one option
# that is not allowed to be nil on Document.

document.asset_providers = asset_providers if asset_providers
document.external_asset_providers = external_asset_providers if external_asset_providers

document.keep_uninlinable_css = keep_uninlinable_css unless keep_uninlinable_css.nil?
end

Expand Down Expand Up @@ -83,6 +95,10 @@ def combine!(options)
before_transformation, options[:before_transformation]
)

self.external_asset_providers = combine_providers(
external_asset_providers, options[:external_asset_providers]
)

self.keep_uninlinable_css =
options[:keep_uninlinable_css] if options.has_key?(:keep_uninlinable_css)

Expand Down
13 changes: 13 additions & 0 deletions spec/lib/roadie/rails/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ def expect_combinated_value(value)
end
end

it_behaves_like "attribute", :external_asset_providers do
let(:provider1) { double "Asset provider 1" }
let(:provider2) { double "Asset provider 2" }

let(:valid_value) { ProviderList.new([provider1]) }
let(:other_valid_value) { ProviderList.new([provider2]) }

def expect_combinated_value(value)
expect(value).to be_instance_of(ProviderList)
expect(value.to_a).to eq([provider1, provider2])
end
end

describe "asset_providers" do
it "automatically wraps values in a ProviderList" do
provider = double "Asset provider"
Expand Down

0 comments on commit 6bd5b75

Please sign in to comment.