diff --git a/shard.yml b/shard.yml index acb42084f..6e5ac866a 100644 --- a/shard.yml +++ b/shard.yml @@ -60,7 +60,7 @@ dependencies: development_dependencies: ameba: github: veelenga/ameba - version: ~> 0.9 + version: ~> 0.9.0 scripts: postinstall: script/precompile_tasks diff --git a/spec/lucky/asset_helpers_spec.cr b/spec/lucky/asset_helpers_spec.cr index 38e733eef..4ecef0352 100644 --- a/spec/lucky/asset_helpers_spec.cr +++ b/spec/lucky/asset_helpers_spec.cr @@ -50,6 +50,12 @@ describe Lucky::AssetHelpers do it "strips the prefixed '/assets/ in path" do TestPage.new.strips_prefixed_asset_path.should eq "/assets/images/inside-assets-folder.png" end + + it "prepends the asset_host configuration option" do + Lucky::Server.temp_config(asset_host: "https://production.com") do + TestPage.new.asset_path.should eq "https://production.com/images/logo-with-hash.png" + end + end end describe "dynamic asset helper" do @@ -66,5 +72,11 @@ describe Lucky::AssetHelpers do TestPage.new.missing_dynamic_asset_path end end + + it "prepends the asset_host configuration option" do + Lucky::Server.temp_config(asset_host: "https://production.com") do + TestPage.new.dynamic_asset_path.should eq "https://production.com/images/logo-with-hash.png" + end + end end end diff --git a/src/lucky/asset_helpers.cr b/src/lucky/asset_helpers.cr index 8eeddf97b..7c4e49d4e 100644 --- a/src/lucky/asset_helpers.cr +++ b/src/lucky/asset_helpers.cr @@ -14,7 +14,7 @@ module Lucky::AssetHelpers {% if path.is_a?(StringLiteral) %} {% if Lucky::AssetHelpers::ASSET_MANIFEST[path] %} - {{ Lucky::AssetHelpers::ASSET_MANIFEST[path] }} + Lucky::Server.settings.asset_host + {{ Lucky::AssetHelpers::ASSET_MANIFEST[path] }} {% else %} {% asset_paths = Lucky::AssetHelpers::ASSET_MANIFEST.keys.join(",") %} {{ run "../run_macros/missing_asset", path, asset_paths }} @@ -48,7 +48,7 @@ module Lucky::AssetHelpers def dynamic_asset(path) fingerprinted_path = Lucky::AssetHelpers::ASSET_MANIFEST[path]? if fingerprinted_path - fingerprinted_path + Lucky::Server.settings.asset_host + fingerprinted_path else raise "Missing asset: #{path}" end diff --git a/src/lucky/server.cr b/src/lucky/server.cr index 810265a53..18ab6d8e8 100644 --- a/src/lucky/server.cr +++ b/src/lucky/server.cr @@ -3,5 +3,6 @@ class Lucky::Server setting secret_key_base : String setting host : String setting port : Int32 + setting asset_host : String = "" end end