class Webpack::ViewHelpers::Context

Attributes

view_context[R]

Public Class Methods

new(view_context) click to toggle source
# File lib/webpack/view_helpers.rb, line 33
def initialize(view_context)
  @view_context = view_context
end

Public Instance Methods

entry_url(name, ext) click to toggle source
# File lib/webpack/view_helpers.rb, line 37
def entry_url(name, ext)
  if Webpack.config.use_server
    server_url("#{name}.#{ext}")
  else
    entry = Webpack.fetch_entry(name.to_s, ext.to_s)
    full_url(entry)
  end
end
static_file_url(path) click to toggle source
# File lib/webpack/view_helpers.rb, line 46
def static_file_url(path)
  if Webpack.config.use_server
    server_url(path)
  else
    static_file = Webpack.fetch_static_file("#{Webpack.config.static_path}/#{path}")
    full_url(static_file)
  end
end

Private Instance Methods

full_url(path) click to toggle source
# File lib/webpack/view_helpers.rb, line 57
def full_url(path)
  if Webpack.config.cdn_host.present?
    [protocol, Webpack.config.cdn_host, path].join
  else
    path
  end
end
protocol() click to toggle source
# File lib/webpack/view_helpers.rb, line 69
def protocol
  return "#{Webpack.config.protocol}://" if Webpack.config.protocol
  view_context.try(:request).try(:protocol) || '//'
end
server_host() click to toggle source
# File lib/webpack/view_helpers.rb, line 74
def server_host
  return Webpack.config.host if Webpack.config.host

  host = view_context.try(:request).try(:host) || 'localhost'

  "#{host}:#{Webpack.config.port}"
end
server_url(path) click to toggle source
# File lib/webpack/view_helpers.rb, line 65
def server_url(path)
  "#{protocol}#{server_host}#{Webpack.config.public_path}/#{path}"
end