compass/lib/compass/installers/manifest.rb
Chris Eppstein 92464c5f6a More flexible manifests that can see the installation options and might
not even have any stylesheets or require a project configuration file.
2009-08-29 15:14:52 -07:00

79 lines
1.6 KiB
Ruby

module Compass
module Installers
class Manifest
include Enumerable
# A Manifest entry
class Entry < Struct.new(:type, :from, :options)
def to
options[:to] || from
end
end
attr_reader :options
def initialize(manifest_file = nil, options = {})
@entries = []
@options = options
@generate_config = true
@compile_after_generation = true
parse(manifest_file) if manifest_file
end
def self.type(t)
eval <<-END
def #{t}(from, options = {})
@entries << Entry.new(:#{t}, from, options)
end
def has_#{t}?
@entries.detect {|e| e.type == :#{t}}
end
def each_#{t}
@entries.select {|e| e.type == :#{t}}.each {|e| yield e}
end
END
end
type :stylesheet
type :image
type :javascript
type :file
type :html
# Enumerates over the manifest files
def each
@entries.each {|e| yield e}
end
def generate_config?
@generate_config
end
def compile?
@compile_after_generation
end
protected
def no_configuration_file!
@generate_config = false
end
def skip_compilation!
@compile_after_generation = false
end
# parses a manifest file which is a ruby script
# evaluated in a Manifest instance context
def parse(manifest_file)
open(manifest_file) do |f|
eval(f.read, instance_binding, manifest_file)
end
end
def instance_binding
binding
end
end
end
end