Class: Sprockets::Standalone::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/sprockets/standalone.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) {|_self, environment| ... } ⇒ RakeTask

Returns a new instance of RakeTask.

Yields:

Yield Parameters:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sprockets/standalone.rb', line 45

def initialize(*args)
  @namespace   = args.shift || :assets
  @assets      = %w(application.js application.css *.png *.jpg *.gif)
  @sources     = []
  @output      = File.expand_path('dist', Dir.pwd)
  @digest      = false
  @compress    = false

  @environment = Sprockets::Environment.new(Dir.pwd) do |env|
    env.logger = Logger.new $stdout
    env.logger.level = Logger::INFO
  end

  yield self, environment if block_given?

  Array(sources).each { |source| environment.append_path source }

  manifest.compress_assets = !!@compress
  manifest.digest_assets   = !!@digest

  namespace @namespace do
    desc 'Compile assets'
    task :compile do
      manifest.compile *Array(assets)
    end

    desc 'Remove all assets'
    task :clobber do
      manifest.clobber
    end

    desc 'Clean old assets'
    task :clean do
      manifest.clean
    end
  end
end

Instance Attribute Details

#assetsObject

List of sprocket file targets that should be compiled.



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

def assets
  @assets
end

#compressObject

If assets should be compressed. Default is false.



32
33
34
# File 'lib/sprockets/standalone.rb', line 32

def compress
  @compress
end

#digestObject

If assets should include digest. Default is false.



29
30
31
# File 'lib/sprockets/standalone.rb', line 29

def digest
  @digest
end

#environmentObject

‘Environment` instance used for finding assets.



35
36
37
# File 'lib/sprockets/standalone.rb', line 35

def environment
  @environment
end

#outputObject

Set output directory. Defaults to ‘dist` in current working directory.



26
27
28
# File 'lib/sprockets/standalone.rb', line 26

def output
  @output
end

#sourcesObject

List of source directories. This is a convenience method as it will add all available sub-directories like ‘stylesheets`, `javascripts` to sprockets include path.

Example: If you have a typical sprockets directory layout like ‘src/assets/stylesheets`, `src/assets/javascripts` all you need to add to `source` is `src/assets`.



22
23
24
# File 'lib/sprockets/standalone.rb', line 22

def sources
  @sources
end

Instance Method Details

#indexObject



37
38
39
# File 'lib/sprockets/standalone.rb', line 37

def index
  @index ||= environment.index if environment
end

#manifestObject



41
42
43
# File 'lib/sprockets/standalone.rb', line 41

def manifest
  @manifest ||= Sprockets::Standalone::Manifest.new index, File.join(output, "manifest.json")
end