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]-->"
Method Summary
- - (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_images 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) embedded_image_stylesheets(packages) private HTML tags for the ‘datauri’, and ‘mhtml’ versions of the packaged stylesheets, using conditional comments to load the correct variant.
- - (Object) individual_stylesheets(packages) private HTML tags, in order, for all of the individual stylesheets.
- - (Object) packaged_stylesheets(packages) private HTML tags for the stylesheet packages.
- - (Object) tags_with_options(packages) private Generate the stylesheet tags for a batch of packages, with options, by yielding each package to a block.
Method Details
- (Object) include_javascripts(*packages)
Writes out the URL to the bundled and compressed javascript package, except in development, where it references the individual scripts.
25 26 27 28 29 30 |
# File 'lib/jammit/helper.rb', line 25 def include_javascripts(*packages) = packages.map do |pack| Jammit.package_assets ? Jammit.asset_url(pack, :js) : Jammit.packager.individual_urls(pack.to_sym, :js) end javascript_include_tag(.flatten) end |
- (Object) include_stylesheets(*packages)
If embed_images 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 |
# File 'lib/jammit/helper.rb', line 17 def include_stylesheets(*packages) return individual_stylesheets(packages) unless Jammit.package_assets return (packages) if Jammit. return packaged_stylesheets(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.
34 35 36 |
# File 'lib/jammit/helper.rb', line 34 def include_templates(*packages) javascript_include_tag(packages.map {|pack| Jammit.asset_url(pack, :jst) }) end |
- (Object) embedded_image_stylesheets(packages) (private)
HTML tags for the ‘datauri’, and ‘mhtml’ versions of the packaged stylesheets, using conditional comments to load the correct variant.
53 54 55 56 57 58 59 |
# File 'lib/jammit/helper.rb', line 53 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) individual_stylesheets(packages) (private)
HTML tags, in order, for all of the individual stylesheets.
42 43 44 |
# File 'lib/jammit/helper.rb', line 42 def individual_stylesheets(packages) (packages) {|p| Jammit.packager.individual_urls(p.to_sym, :css) } end |
- (Object) packaged_stylesheets(packages) (private)
HTML tags for the stylesheet packages.
47 48 49 |
# File 'lib/jammit/helper.rb', line 47 def packaged_stylesheets(packages) (packages) {|p| Jammit.asset_url(p, :css) } end |
- (Object) tags_with_options(packages) (private)
Generate the stylesheet tags for a batch of packages, with options, by yielding each package to a block.
63 64 65 66 67 68 69 |
# File 'lib/jammit/helper.rb', line 63 def (packages) packages = packages.dup = packages. packages.map! {|package| yield package }.flatten! packages.push() unless .empty? stylesheet_link_tag(*packages) end |