Last active
December 2, 2015 09:55
-
-
Save pascalbetz/1c6481c8c8c8d11edf9e to your computer and use it in GitHub Desktop.
Revisions
-
pascalbetz revised this gist
Dec 2, 2015 . 1 changed file with 8 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,10 +16,7 @@ module AssetUriHelpers # Generates the application-specific relative paths for assets def asset_path(*args) assets_prefix = asset_config.prefix args.push('') if args.empty? path_elements = ['', ASSETS_ROOT_DIRECTORY] @@ -45,14 +42,20 @@ def asset_url(*args) private def assets_class_name "#{application_module_name}::Assets" end def application_class_name "#{application_module_name}::Application" end def application_module_name self.class.name.split('::').first # extract app-name from class-name end def asset_config @_asset_config ||= Kernel.const_get(assets_class_name).configuration end def application_config @_application_config ||= Kernel.const_get(application_class_name).configuration end -
pascalbetz created this gist
Dec 2, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ require 'uri' require 'pry' module Lotus module Helpers # Helper methods to generate asset-paths # # @since 0.6.0 # @api public module AssetUriHelpers # HTTP-path-separator according to https://tools.ietf.org/html/rfc1738 - 3.3 HTTP PATH_SEPARATOR = '/'.freeze ASSETS_ROOT_DIRECTORY = 'assets'.freeze # Generates the application-specific relative paths for assets def asset_path(*args) config = Config::Assets.new(application_config) binding.pry # TODO: schau mal config an assets_prefix = application_config.assets.prefix.to_s args.push('') if args.empty? path_elements = ['', ASSETS_ROOT_DIRECTORY] path_elements.concat(assets_prefix.split(PATH_SEPARATOR).compact) if !assets_prefix.empty? path_elements.concat(args) path_elements.join(PATH_SEPARATOR) end # Generates the application-specific absolute URL for assets def asset_url(*args) url_path = asset_path(args) url_scheme = application_config.scheme.to_s url_host = application_config.host.to_s # TODO: to_s should be done in application_config url_port = application_config.port.to_i # TODO: to_i should be done in application_config url_port = nil if url_port <= 0 # TODO: why could it <= 0 ? #binding.pry URI::Generic.build({scheme: url_scheme, host: url_host, port: url_port, path: url_path}).to_s end private def application_class_name "#{application_module_name}::Application" end def application_module_name self.class.name.split('::').first # extract app-name from class-name end def application_config @_application_config ||= Kernel.const_get(application_class_name).configuration end end end end