Module: Jammit::Helper
- Defined in:
- lib/jammit/helper.rb
Overview
The Jammit::Helper module, which is made available to every view, provides helpers for writing out HTML tags for asset packages. In development you get the ordered list of source files — in any other environment, a link to the cached packages.
Constant Summary
- DATA_URI_START =
"<!--[if (!IE)|(gte IE 8)]><!-->"
- DATA_URI_END =
"<!--<![endif]-->"
- MHTML_START =
"<!--[if lte IE 7]>"
- MHTML_END =
"<![endif]-->"
Instance Method Summary (collapse)
-
- (Object) embedded_image_stylesheets(packages, options)
private
HTML tags for the ‘datauri’, and ‘mhtml’ versions of the packaged stylesheets, using conditional comments to load the correct variant.
- - (Object) html_safe(string) private
-
- (Object) include_javascripts(*packages)
Writes out the URL to the bundled and compressed javascript package, except in development, where it references the individual scripts.
-
- (Object) include_stylesheets(*packages)
If embed_assets is turned on, writes out links to the Data-URI and MHTML versions of the stylesheet package, otherwise the package is regular compressed CSS, and in development the stylesheet URLs are passed verbatim.
-
- (Object) include_templates(*packages)
Writes out the URL to the concatenated and compiled JST file — we always have to pre-process it, even in development.
-
- (Object) individual_stylesheets(packages, options)
private
HTML tags, in order, for all of the individual stylesheets.
-
- (Object) packaged_stylesheets(packages, options)
private
HTML tags for the stylesheet packages.
- - (Boolean) should_package? private
-
- (Object) tags_with_options(packages, options)
private
Generate the stylesheet tags for a batch of packages, with options, by yielding each package to a block.
Instance Method Details
- (Object) embedded_image_stylesheets(packages, options) (private)
HTML tags for the ‘datauri’, and ‘mhtml’ versions of the packaged stylesheets, using conditional comments to load the correct variant.
66 67 68 69 70 71 72 |
# File 'lib/jammit/helper.rb', line 66 def (packages, ) = (packages, ) {|p| Jammit.asset_url(p, :css, :datauri) } = Jammit.mhtml_enabled ? (packages, ) {|p| Jammit.asset_url(p, :css, :mhtml) } : packaged_stylesheets(packages, ) [DATA_URI_START, , DATA_URI_END, MHTML_START, , MHTML_END].join("\n") end |
- (Object) html_safe(string) (private)
50 51 52 |
# File 'lib/jammit/helper.rb', line 50 def html_safe(string) string.respond_to?(:html_safe) ? string.html_safe : string end |
- (Object) include_javascripts(*packages)
Writes out the URL to the bundled and compressed javascript package, except in development, where it references the individual scripts.
27 28 29 30 31 32 33 34 35 |
# File 'lib/jammit/helper.rb', line 27 def include_javascripts(*packages) = packages. .merge!(:extname=>false) html_safe packages.map {|pack| should_package? ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) }.flatten.map {|pack| "<script src=\"#{pack}\"></script>" }.join("\n") end |
- (Object) include_stylesheets(*packages)
If embed_assets is turned on, writes out links to the Data-URI and MHTML versions of the stylesheet package, otherwise the package is regular compressed CSS, and in development the stylesheet URLs are passed verbatim.
17 18 19 20 21 22 23 |
# File 'lib/jammit/helper.rb', line 17 def include_stylesheets(*packages) = packages. return html_safe(individual_stylesheets(packages, )) unless should_package? disabled = (.delete(:embed_assets) == false) || (.delete(:embed_images) == false) return html_safe(packaged_stylesheets(packages, )) if disabled || !Jammit. return html_safe((packages, )) end |
- (Object) include_templates(*packages)
Writes out the URL to the concatenated and compiled JST file — we always have to pre-process it, even in development.
39 40 41 |
# File 'lib/jammit/helper.rb', line 39 def include_templates(*packages) raise DeprecationError, "Jammit 0.5+ no longer supports separate packages for templates.\nYou can include your JST alongside your JS, and use include_javascripts." end |
- (Object) individual_stylesheets(packages, options) (private)
HTML tags, in order, for all of the individual stylesheets.
55 56 57 |
# File 'lib/jammit/helper.rb', line 55 def individual_stylesheets(packages, ) (packages, ) {|p| Jammit.packager.individual_urls(p.to_sym, :css) } end |
- (Object) packaged_stylesheets(packages, options) (private)
HTML tags for the stylesheet packages.
60 61 62 |
# File 'lib/jammit/helper.rb', line 60 def packaged_stylesheets(packages, ) (packages, ) {|p| Jammit.asset_url(p, :css) } end |
- (Boolean) should_package? (private)
46 47 48 |
# File 'lib/jammit/helper.rb', line 46 def should_package? Jammit.package_assets && !(Jammit.allow_debugging && params[:debug_assets]) end |
- (Object) tags_with_options(packages, options) (private)
Generate the stylesheet tags for a batch of packages, with options, by yielding each package to a block.
76 77 78 79 80 81 82 |
# File 'lib/jammit/helper.rb', line 76 def (packages, ) packages.dup.map {|package| yield package }.flatten.map {|package| stylesheet_link_tag package, }.join("\n") end |