Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow procs to the :css option

  • Loading branch information...
commit 4ba78d8524dbf3d281dddab0d21cba59813e3564 1 parent 1a455c7
@Mange authored
View
2  Changelog.md
@@ -2,7 +2,7 @@
[full changelog](https://github.com/Mange/roadie/compare/v2.3.2...master)
-* Nothing yet
+* Allow proc objects to the :css option
### 2.3.2
View
11 lib/roadie/action_mailer_extensions.rb
@@ -46,8 +46,15 @@ def inline_style_response(response)
end
def css_targets
- return [] unless @targets
- Array.wrap(@targets || []).map { |target| target.to_s }
+ Array.wrap(@targets || []).map { |target| resolve_target(target) }.compact.map(&:to_s)
+ end
+
+ def resolve_target(target)
+ if target.respond_to? :call
+ target.call
+ else
+ target
+ end
end
end
end
View
27 spec/lib/roadie/action_mailer_extensions_spec.rb
@@ -30,6 +30,22 @@ def expect_global_css(files)
Roadie.stub(:current_provider => provider)
end
+ it "uses the default CSS when :css is not specified" do
+ expect_global_css ['default']
+ mailer.default_css
+ end
+
+ it "uses the specified CSS instead of the default" do
+ expect_global_css ['some', 'other/files']
+ mailer.override_css([:some, 'other/files'])
+ end
+
+ it "allows procs defining the CSS files to use" do
+ expect_global_css ['from proc']
+ proc = lambda { 'from proc' }
+ mailer.override_css([proc])
+ end
+
it "uses no global CSS when :css is set to nil" do
expect_global_css []
mailer.override_css(nil)
@@ -40,14 +56,9 @@ def expect_global_css(files)
mailer.override_css(false)
end
- it "uses the default CSS when :css is not specified" do
- expect_global_css ['default']
- mailer.default_css
- end
-
- it "uses the specified CSS instead of the default" do
- expect_global_css ['some', 'other/files']
- mailer.override_css([:some, 'other/files'])
+ it "uses no global CSS when :css is set to a proc returning nil" do
+ expect_global_css []
+ mailer.override_css(lambda { nil })
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.