Module: Rails2AssetPipeline

Defined in:
lib/rails2_asset_pipeline.rb,
lib/rails2_asset_pipeline/version.rb,
lib/rails2_asset_pipeline/view_helpers.rb,
lib/rails2_asset_pipeline/jammit_converter.rb

Defined Under Namespace

Modules: JammitConverter, ViewHelpers

Constant Summary collapse

STATIC_ENVIRONMENTS =
["production", "staging"]
VERSION =
'0.3.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dynamic_assets_availableObject

Returns the value of attribute dynamic_assets_available.



8
9
10
# File 'lib/rails2_asset_pipeline.rb', line 8

def dynamic_assets_available
  @dynamic_assets_available
end

.manifestObject

Returns the value of attribute manifest.



8
9
10
# File 'lib/rails2_asset_pipeline.rb', line 8

def manifest
  @manifest
end

.prefixObject

Returns the value of attribute prefix.



8
9
10
# File 'lib/rails2_asset_pipeline.rb', line 8

def prefix
  @prefix
end

Class Method Details

.config_ru(rack) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rails2_asset_pipeline.rb', line 25

def self.config_ru(rack)
  unless STATIC_ENVIRONMENTS.include?(Rails.env)
    prefix = Rails2AssetPipeline.prefix

    Rails2AssetPipeline.dynamic_assets_available = true

    rack.instance_eval do
      map "/#{prefix}" do
        run Rails2AssetPipeline.env
      end
    end
  end
end

.envObject



11
12
13
# File 'lib/rails2_asset_pipeline.rb', line 11

def self.env
  @env || setup
end

.setup {|@env| ... } ⇒ Object

Yields:



15
16
17
18
19
20
21
22
23
# File 'lib/rails2_asset_pipeline.rb', line 15

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

.static?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/rails2_asset_pipeline.rb', line 39

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

.warn_user_about_misconfiguration!Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rails2_asset_pipeline.rb', line 59

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

.with_dynamic_assets_available(value) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rails2_asset_pipeline.rb', line 43

def self.with_dynamic_assets_available(value)
  old = dynamic_assets_available
  self.dynamic_assets_available = value
  yield
ensure
  self.dynamic_assets_available = old
end