Module: Lotus::Assets::Helpers
- Includes:
- Helpers::HtmlHelper
- Defined in:
- lib/lotus/assets/helpers.rb
Overview
HTML assets helpers
Include this helper in a view
Constant Summary collapse
- NEW_LINE_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"\n".freeze
- WILDCARD_EXT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'.*'.freeze
- JAVASCRIPT_EXT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'.js'.freeze
- STYLESHEET_EXT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'.css'.freeze
- JAVASCRIPT_MIME_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'text/javascript'.freeze
- STYLESHEET_MIME_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'text/css'.freeze
- FAVICON_MIME_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'image/x-icon'.freeze
- STYLESHEET_REL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'stylesheet'.freeze
- FAVICON_REL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'shortcut icon'.freeze
- DEFAULT_FAVICON =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'favicon.ico'.freeze
Class Method Summary collapse
-
.included(base) ⇒ Object
private
Inject helpers into the given class.
Instance Method Summary collapse
-
#asset_path(source) ⇒ String
It generates the relative URL for the given source.
-
#asset_url(source) ⇒ String
It generates the absolute URL for the given source.
-
#audio(source = nil, options = {}, &blk) ⇒ Lotus::Utils::Helpers::HtmlBuilder
Generate
audiotag for given source. -
#favicon(source = DEFAULT_FAVICON, options = {}) ⇒ Lotus::Utils::Helpers::HtmlBuilder
Generate
linktag application favicon. -
#image(source, options = {}) ⇒ Lotus::Utils::Helpers::HtmlBuilder
Generate
imgtag for given source. -
#javascript(*sources) ⇒ Lotus::Utils::Escape::SafeString
Generate
scripttag for given source(s). -
#stylesheet(*sources) ⇒ Lotus::Utils::Escape::SafeString
Generate
linktag for given source(s). -
#video(source = nil, options = {}, &blk) ⇒ Lotus::Utils::Helpers::HtmlBuilder
Generate
videotag for given source.
Class Method Details
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Inject helpers into the given class
63 64 65 66 67 68 69 70 71 |
# File 'lib/lotus/assets/helpers.rb', line 63 def self.included(base) conf = ::Lotus::Assets::Configuration.for(base) base.class_eval do include Utils::ClassAttribute class_attribute :assets_configuration self.assets_configuration = conf end end |
Instance Method Details
#asset_path(source) ⇒ String
It generates the relative URL for the given source.
It can be the name of the asset, coming from the sources or third party gems.
Absolute URLs are returned as they are.
If Digest mode is on, it returns the digest path of the source
If CDN mode is on, it returns the absolute URL of the asset.
606 607 608 |
# File 'lib/lotus/assets/helpers.rb', line 606 def asset_path(source) _asset_url(source) { _relative_url(source) } end |
#asset_url(source) ⇒ String
It generates the absolute URL for the given source.
It can be the name of the asset, coming from the sources or third party gems.
Absolute URLs are returned as they are.
If Digest mode is on, it returns the digest URL of the source
If CDN mode is on, it returns the absolute URL of the asset.
653 654 655 |
# File 'lib/lotus/assets/helpers.rb', line 653 def asset_url(source) _asset_url(source) { _absolute_url(source) } end |
#audio(source = nil, options = {}, &blk) ⇒ Lotus::Utils::Helpers::HtmlBuilder
Generate audio tag for given source
It accepts one string representing the name of the asset, if it comes from the application or third party gems. It also accepts string representing absolute URLs in case of public CDN (eg. Bootstrap CDN).
Alternatively, it accepts a block that allows to specify one or more sources via the source tag.
If the “digest mode” is on, src is the digest version of the relative URL.
If the “CDN mode” is on, the src is an absolute URL of the application CDN.
558 559 560 561 |
# File 'lib/lotus/assets/helpers.rb', line 558 def audio(source = nil, = {}, &blk) = (source, , &blk) html.audio(blk, ) end |
#favicon(source = DEFAULT_FAVICON, options = {}) ⇒ Lotus::Utils::Helpers::HtmlBuilder
Generate link tag application favicon.
If no argument is given, it assumes favico.ico from the application.
It accepts one string representing the name of the asset.
If the “digest mode” is on, href is the digest version of the relative URL.
If the “CDN mode” is on, the href is an absolute URL of the application CDN.
319 320 321 322 323 324 325 |
# File 'lib/lotus/assets/helpers.rb', line 319 def favicon(source = DEFAULT_FAVICON, = {}) [:href] = asset_path(source) [:rel] ||= FAVICON_REL [:type] ||= FAVICON_MIME_TYPE html.link() end |
#image(source, options = {}) ⇒ Lotus::Utils::Helpers::HtmlBuilder
Generate img tag for given source
It accepts one string representing the name of the asset, if it comes from the application or third party gems. It also accepts string representing absolute URLs in case of public CDN (eg. Bootstrap CDN).
alt Attribute is auto generated from src. You can specify a different value, by passing the :src option.
If the “digest mode” is on, src is the digest version of the relative URL.
If the “CDN mode” is on, the src is an absolute URL of the application CDN.
258 259 260 261 262 263 |
# File 'lib/lotus/assets/helpers.rb', line 258 def image(source, = {}) [:src] = asset_path(source) [:alt] ||= Utils::String.new(::File.basename(source, WILDCARD_EXT)).titleize html.img() end |
#javascript(*sources) ⇒ Lotus::Utils::Escape::SafeString
Generate script tag for given source(s)
It accepts one or more strings representing the name of the asset, if it comes from the application or third party gems. It also accepts strings representing absolute URLs in case of public CDN (eg. jQuery CDN).
If the “digest mode” is on, src is the digest version of the relative URL.
If the “CDN mode” is on, the src is an absolute URL of the application CDN.
128 129 130 131 132 |
# File 'lib/lotus/assets/helpers.rb', line 128 def javascript(*sources) (*sources) do |source| html.script(src: _typed_asset_path(source, JAVASCRIPT_EXT), type: JAVASCRIPT_MIME_TYPE).to_s end end |
#stylesheet(*sources) ⇒ Lotus::Utils::Escape::SafeString
Generate link tag for given source(s)
It accepts one or more strings representing the name of the asset, if it comes from the application or third party gems. It also accepts strings representing absolute URLs in case of public CDN (eg. Bootstrap CDN).
If the “digest mode” is on, href is the digest version of the relative URL.
If the “CDN mode” is on, the href is an absolute URL of the application CDN.
189 190 191 192 193 |
# File 'lib/lotus/assets/helpers.rb', line 189 def stylesheet(*sources) (*sources) do |source| html.link(href: _typed_asset_path(source, STYLESHEET_EXT), type: STYLESHEET_MIME_TYPE, rel: STYLESHEET_REL).to_s end end |
#video(source = nil, options = {}, &blk) ⇒ Lotus::Utils::Helpers::HtmlBuilder
Generate video tag for given source
It accepts one string representing the name of the asset, if it comes from the application or third party gems. It also accepts string representing absolute URLs in case of public CDN (eg. Bootstrap CDN).
Alternatively, it accepts a block that allows to specify one or more sources via the source tag.
If the “digest mode” is on, src is the digest version of the relative URL.
If the “CDN mode” is on, the src is an absolute URL of the application CDN.
440 441 442 443 |
# File 'lib/lotus/assets/helpers.rb', line 440 def video(source = nil, = {}, &blk) = (source, , &blk) html.video(blk, ) end |