Sha256: dd332b79ff9f4ad73303f02ef80eb257b01dc7fa0940037be9cf3c9674e9b68b

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

module ViewAssets
  module ActionViewHelpers
    require 'view_assets'
    require 'view_assets/finder/core'
    require 'yaml'

    def retrieve_assets(controller, action)
      assets = []
      if Rails.env.production?
        css_path     = "/assets/#{ViewAssets::CSS_PATH}"
        js_path      = "/assets/#{ViewAssets::JS_PATH}"
        css_manifest = YAML.load(File.open("#{Rails.public_path}#{css_path}/manifest.yml").read)
        js_manifest  = YAML.load(File.open("#{Rails.public_path}#{js_path}/manifest.yml").read)

        case
        when css_location = css_manifest["#{css_path}/#{controller}_#{action}.#{ViewAssets::CSS_EXT}"]
        when css_location = css_manifest["#{css_path}/#{controller}.#{ViewAssets::CSS_EXT}"]
        when css_location = css_manifest["#{css_path}/application.#{ViewAssets::CSS_EXT}"]
        end

        case
        when js_location = js_manifest["#{js_path}/#{controller}_#{action}.#{ViewAssets::JS_EXT}"]
        when js_location = js_manifest["#{js_path}/#{controller}.#{ViewAssets::JS_EXT}"]
        when js_location = js_manifest["#{js_path}/application.#{ViewAssets::JS_EXT}"]
        end

        assets.push ViewAssets.tag(:css, css_location)
        assets.push ViewAssets.tag(:js, js_location)
      else
        assets.concat ViewAssets::Finder::CssFinder.new.retrieve(controller, action, :tagged => true)
        assets.concat ViewAssets::Finder::JsFinder.new.retrieve(controller, action, :tagged => true)
      end

      assets.map { |asset| raw(asset) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
view_assets-1.0.0 lib/view_assets/action_view.rb