Module: Webmate::Sprockets

Defined in:
lib/webmate/sprockets.rb,
lib/webmate/sprockets/helpers.rb,
lib/webmate/sprockets/version.rb,
lib/webmate/sprockets/asset_paths.rb,
lib/webmate/sprockets/configuration.rb,
lib/webmate/sprockets/static_compiler.rb

Defined Under Namespace

Modules: Helpers Classes: AssetPaths, Configuration, StaticCompiler

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.configObject



54
55
56
# File 'lib/webmate/sprockets.rb', line 54

def self.config
  @config ||= Configuration.new
end

.configure(&block) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/webmate/sprockets.rb', line 9

def self.configure(&block)
  block.call(config)
  raise ArgumentError, "Cannot initialize Sprockets Environment without an app reference" if config.app.nil?

  @environment = ::Sprockets::Environment.new(config.app.root)

  config.paths.each do |path|
    environment.append_path(File.join(config.app.root, path))
  end

  # require assets from other gems
  Gem::Specification.to_a.each do |gem_spec|
    ['stylesheets', 'javascripts', 'images'].each do |dir|
      assets_path = File.join(gem_spec.full_gem_path, 'vendor', 'assets', dir)
      if Dir.exists?(assets_path)
        environment.append_path(assets_path)
      end
    end
  end

  if config.compress_assets?
    environment.js_compressor = Closure::Compiler.new
    environment.css_compressor = YUI::CssCompressor.new
  else
    environment.js_compressor = false
    environment.css_compressor = false
  end

  if config.manifest_path
    path = File.join(config.app.root, config.manifest_path, "manifest.yml")
  else
    path = File.join(config.app.settings.public_path, 'assets', "manifest.yml")
  end

  if File.exist?(path)
    YAML.load_file(path).each do |path, value|
      config.digests[path] = value
    end
  end

  environment.context_class.instance_eval do
    include Helpers
  end
end

.environmentObject



58
59
60
# File 'lib/webmate/sprockets.rb', line 58

def self.environment
  @environment
end