Module: Webpacked::Helper

Defined in:
lib/webpacked/helper.rb

Overview

Add new view helpers

Instance Method Summary collapse

Instance Method Details

#asset_tag(entry, kind) ⇒ Object

Return include tags for entry point by given asset kind. No extra common file included even if it exists



30
31
32
33
34
35
36
37
38
# File 'lib/webpacked/helper.rb', line 30

def asset_tag(entry, kind)
  path = webpacked_asset_path(entry, kind)
  if path
    case kind
    when :js  then javascript_include_tag path
    when :css then stylesheet_link_tag    path
    end
  end
end

#webpacked_asset_path(entry, kind = nil) ⇒ Object

Alias for Webpacked::Manifest.asset_paths



41
42
43
# File 'lib/webpacked/helper.rb', line 41

def webpacked_asset_path(entry, kind = nil)
  Webpacked::Manifest.asset_paths(entry, kind)
end

#webpacked_css_tags(entries) ⇒ Object

Return stylesheet_link_tag for entry points. Also common CSS file could be included



12
13
14
# File 'lib/webpacked/helper.rb', line 12

def webpacked_css_tags(entries)
  webpacked_tags entries, :css
end

#webpacked_js_tags(entries) ⇒ Object

Return javascript_include_tag for entry points. Also common Javascript file could be included



6
7
8
# File 'lib/webpacked/helper.rb', line 6

def webpacked_js_tags(entries)
  webpacked_tags entries, :js
end

#webpacked_tags(entries, kind) ⇒ Object

Return include tags for entry points by given asset kind. Also common file could be included



18
19
20
21
22
23
24
25
26
# File 'lib/webpacked/helper.rb', line 18

def webpacked_tags(entries, kind)
  common_entry = ::Rails.configuration.webpacked.common_entry_name
  common_bundle = asset_tag(common_entry, kind)
  page_bundle = Array(entries).reduce('') do |memo, entry|
    tag = asset_tag(entry, kind)
    memo << tag if tag
  end
  common_bundle ? common_bundle + page_bundle : page_bundle
end