module Hauler::Helpers::HaulerHelper

Public Instance Methods

asset_path(source, options = {}) click to toggle source
# File lib/hauler/helpers/hauler_helper.rb, line 55
def asset_path(source, options = {})
  hauler_asset_path(source, options) || orig_asset_path(source, options)
end
hauler_asset_path(path, options = {}) click to toggle source
# File lib/hauler/helpers/hauler_helper.rb, line 49
def hauler_asset_path(path, options = {})
  return nil unless options[:type].to_s == 'javascript'
  return nil unless hauler_dev_server? && hauler_entry?(path)
  [hauler_public_path, hauler_format_entry_path(path)].join('/')
end
hauler_dev_server?() click to toggle source
# File lib/hauler/helpers/hauler_helper.rb, line 13
def hauler_dev_server?
  Rails.application.config.hauler.dev_server
end
hauler_entries_names() click to toggle source
# File lib/hauler/helpers/hauler_helper.rb, line 22
def hauler_entries_names
  @hauler_entries_names ||= begin
    entries = hauler_webpack_config.try(:[], 'compilerConfig').try(:[], 'entry')
    entries.try(:keys) || []
  end
end
hauler_entry?(path) click to toggle source
# File lib/hauler/helpers/hauler_helper.rb, line 29
def hauler_entry?(path)
  entry = path.gsub(/\.(css|js)$/, '')
  hauler_entries_names.include?(entry)
end
hauler_format_entry_path(entry) click to toggle source
# File lib/hauler/helpers/hauler_helper.rb, line 41
def hauler_format_entry_path(entry)
  output = entry
  output += '.js' unless entry.end_with?('.js')
  output.gsub(%r{^/}, '')
end
hauler_public_path() click to toggle source
# File lib/hauler/helpers/hauler_helper.rb, line 34
def hauler_public_path
  @hauler_public_path ||= begin
    public_path = hauler_webpack_config.try(:[], 'devServerConfig').try(:[], 'publicPath')
    public_path.gsub(%r{/$}, '')
  end
end
hauler_webpack_config() click to toggle source
# File lib/hauler/helpers/hauler_helper.rb, line 17
def hauler_webpack_config
  return nil if !hauler_dev_server?
  @hauler_webpack_config ||= JSON.parse(`hauler-read-config #{Rails.root}`)
end
path_to_asset(*args) click to toggle source
# File lib/hauler/helpers/hauler_helper.rb, line 59
def path_to_asset(*args)
  asset_path(*args)
end