Skip to content

Commit

Permalink
Add support for asset hosts containing %d
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed Jun 8, 2014
1 parent dc2a5a4 commit ffb61be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
13 changes: 11 additions & 2 deletions lib/tinymce/rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ def self.relative_url_root
end

def self.asset_host
unless Rails.application.config.action_controller.asset_host.respond_to?(:call)
Rails.application.config.action_controller.asset_host
host = Rails.application.config.action_controller.asset_host

if host.respond_to?(:call)
# Callable asset hosts cannot be supported during
# precompilation as there is no request object
nil
elsif host =~ /%d/
# Load all TinyMCE assets from the first asset host
host % 0
else
host
end
end
end
Expand Down
32 changes: 14 additions & 18 deletions spec/lib/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@ module TinyMCE::Rails
Rails.application.config.stub(:relative_url_root).and_return "/prefix"
TinyMCE::Rails::Engine.default_base.should eq "/prefix/assets/tinymce"
end

context "asset_host" do

context "Asset host as a string" do
it "includes the asset host if provided" do
Rails.application.config.action_controller.stub(:asset_host).and_return "http://assets.example.com"
TinyMCE::Rails::Engine.default_base.should eq "http://assets.example.com/assets/tinymce"
end
end

context "Asset host as a proc or object that respond to call" do
it "should not use the asset_host because precompile don't know about the request" do
Rails.application.config.action_controller.stub(:asset_host).and_return ->(request) { "http://assets.example.com" }
TinyMCE::Rails::Engine.default_base.should eq "/assets/tinymce"
end
end


it "includes the asset host if it is a string" do
Rails.application.config.action_controller.stub(:asset_host).and_return "http://assets.example.com"
TinyMCE::Rails::Engine.default_base.should eq "http://assets.example.com/assets/tinymce"
end

it "interpolates the asset host if it is a string containing %d" do
Rails.application.config.action_controller.stub(:asset_host).and_return "http://assets%d.example.com"
TinyMCE::Rails::Engine.default_base.should eq "http://assets0.example.com/assets/tinymce"
end

it "does not include the asset host if it is a callable" do
Rails.application.config.action_controller.stub(:asset_host).and_return ->(request) { "http://assets.example.com" }
TinyMCE::Rails::Engine.default_base.should eq "/assets/tinymce"
end

end
end
end

0 comments on commit ffb61be

Please sign in to comment.