lib/i18n/assets/sprockets.rb in i18n-assets-0.0.4 vs lib/i18n/assets/sprockets.rb in i18n-assets-0.0.5

- old
+ new

@@ -3,10 +3,11 @@ module Sprockets LOCALIZABLE_ASSETS_EXT = %w( js css ) LOCALIZABLE_ASSETS_REGEX = Regexp.new("\\.(?:#{ LOCALIZABLE_ASSETS_EXT * '|' })") LOCALIZABLE_COMPILABLE_ASSETS_REGEX = Regexp.new("\\.(?:#{ LOCALIZABLE_ASSETS_EXT * '|' })\\..+$") + GLOBAL_ASSET_REGEX = /^(https?)?:\/\// module Helpers module RailsHelper alias_method :asset_path_without_locale, :asset_path @@ -115,17 +116,21 @@ module ActionView class AssetPaths alias_method :compute_public_path_without_locale, :compute_public_path def compute_public_path(source, dir, options = nil) - source = prepend_locale(source) if file_localizable?(source, options) && !file_already_localized?(source) + source = prepend_locale(source) if local_resource?(source) && file_localizable?(source, options) && !file_already_localized?(source) compute_public_path_without_locale(source, dir, options) end private def prepend_locale(source) "#{ I18n.locale }/#{ source }" + end + + def local_resource?(source) + source !~ Sprockets::GLOBAL_ASSET_REGEX end def file_localizable?(source, options) source =~ Sprockets::LOCALIZABLE_ASSETS_REGEX || Sprockets::LOCALIZABLE_ASSETS_EXT.include?(options.try(:[], :ext)) end