Sha256: 05b7b3911c44d249ae883edd9c98ba159a742470f9d37ad93acec8d3705b3cc9

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

require 'rails2_asset_pipeline/version'
require 'sprockets'

module Rails2AssetPipeline
  STATIC_ENVIRONMENTS = ["production", "staging"]

  class << self
    attr_accessor :dynamic_assets_available
  end

  def self.env
    @env || setup
  end

  def self.setup
    @env ||= Sprockets::Environment.new
    Dir[Rails.root.join("app", "assets", "*")].each do |folder|
      @env.append_path folder
    end
    # TODO vendor + lib
    yield @env if block_given?
    @env
  end

  def self.config_ru
    lambda do
      unless STATIC_ENVIRONMENTS.include?(Rails.env)
        Rails2AssetPipeline.dynamic_assets_available = true
        map '/assets' do
          run Rails2AssetPipeline.env
        end
      end
    end
  end

  def self.static?
    not Rails2AssetPipeline.dynamic_assets_available or Rails2AssetPipeline::STATIC_ENVIRONMENTS.include?(Rails.env)
  end

  def self.manifest
    "#{Rails.root}/public/assets/manifest.json"
  end

  def self.warn_user_about_misconfiguration!
    return unless Rails2AssetPipeline.static?
    return if @manifest_exists ||= File.exist?(manifest)

    config = "config.ru.example"
    if File.exist?(config) and File.read(config).include?("Rails2AssetPipeline.config_ru")
      raise "No dynamic assets available and no #{manifest} found, run `rake assets:precompile` for static assets or `cp #{config} config.ru` for dynamic assets"
    else
      raise "No dynamic assets available and no #{manifest} found, run `rake assets:precompile` for static assets or read https://github.com/grosser/rails2_asset_pipeline#dynamic-assets-for-development for instructions on dynamic assets"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails2_asset_pipeline-0.1.16 lib/rails2_asset_pipeline.rb
rails2_asset_pipeline-0.1.15 lib/rails2_asset_pipeline.rb