Module: Eldr::Assets::Helpers
- Defined in:
- lib/eldr/assets/helpers.rb
Constant Summary collapse
- APPEND_ASSET_EXTENSIONS =
%w(js css)
- ABSOLUTE_URL_PATTERN =
%r{^(https?://)}
Instance Method Summary collapse
- #asset_path(kind, source = nil) ⇒ Object
- #css(*sources) ⇒ Object
- #js(*sources) ⇒ Object
- #uri_root_path(*paths) ⇒ Object
Instance Method Details
#asset_path(kind, source = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/eldr/assets/helpers.rb', line 30 def asset_path(kind, source = nil) kind, source = source, kind if source.nil? source = asset_normalize_extension(kind, URI.escape(source.to_s)) return source if source =~ ABSOLUTE_URL_PATTERN || source =~ /^\// source = File.join(asset_folder_name(kind).to_s, source) = (source) result_path = uri_root_path(source) "#{result_path}#{}" end |
#css(*sources) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/eldr/assets/helpers.rb', line 11 def css(*sources) = { rel: 'stylesheet', type: 'text/css' }.update(sources..symbolize_keys) sources.flatten.inject(ActiveSupport::SafeBuffer.new) do |all,source| all << tag(:link, { href: asset_path(:css, source) }.update()) end end |
#js(*sources) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/eldr/assets/helpers.rb', line 21 def js(*sources) = { type: 'text/javascript' }.update(sources..symbolize_keys) sources.flatten.inject(ActiveSupport::SafeBuffer.new) do |all,source| all << content_tag(:script, nil, { src: asset_path(:js, source) }.update()) end end |
#uri_root_path(*paths) ⇒ Object
43 44 45 46 47 |
# File 'lib/eldr/assets/helpers.rb', line 43 def uri_root_path(*paths) root_uri = self.configuration.uri_root root_uri ||= ENV['ROOT_URI'] if ENV.include? 'ROOT_URI' File.join(ENV['RACK_BASE_URI'].to_s, root_uri || '/', *paths) end |