Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default options #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rake-pipeline/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class Middleware
# @param [#call] app a Rack application
# @param [String|Rake::Pipeline] pipeline either a path to an
# Assetfile to use to build a pipeline, or an existing pipeline.
def initialize(app, pipeline)
def initialize(app, pipeline, &defaults)
@app = app
@project = Rake::Pipeline::Project.new(pipeline)
@project = Rake::Pipeline::Project.new(pipeline, &defaults)
end

# Automatically compiles your assets if required and
Expand Down
18 changes: 13 additions & 5 deletions lib/rake-pipeline/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Project
# write their outputs by default
attr_reader :default_output_root

attr_reader :defaults

# @return [Array] a list of filters to be applied before
# the specified filters in every pipeline
attr_writer :before_filters
Expand Down Expand Up @@ -86,14 +88,17 @@ def add_to_digest(str)
# @param [String|Pipeline] assetfile_or_pipeline
# if this a String, create a Pipeline from the Assetfile at
# that path. If it's a Pipeline, just wrap that pipeline.
def initialize(assetfile_or_pipeline=nil)
def initialize(assetfile_or_pipeline=nil, &defaults)
reset!

if assetfile_or_pipeline.kind_of?(String)
@assetfile_path = File.expand_path(assetfile_or_pipeline)
rebuild_from_assetfile(@assetfile_path)
@defaults = defaults
rebuild_from_assetfile(@assetfile_path, &defaults)
elsif assetfile_or_pipeline
@pipelines << assetfile_or_pipeline
end

end

# Evaluate a block using the Rake::Pipeline::DSL::ProjectDSL
Expand All @@ -113,7 +118,7 @@ def invoke
if assetfile_path
source = File.read(assetfile_path)
if digest(source) != assetfile_digest
rebuild_from_assetfile(assetfile_path, source)
rebuild_from_assetfile(assetfile_path, source, &defaults)
end
end

Expand Down Expand Up @@ -241,12 +246,15 @@ def reset!
# evaluated instead of reading the file at assetfile_path.
#
# @return [void]
def rebuild_from_assetfile(path, source=nil)
def rebuild_from_assetfile(path, source=nil, &default_config)
reset!
source ||= File.read(path)
@assetfile_digest = digest(source)
@assetfile_path = path
build { instance_eval(source, path, 1) }
build do
instance_eval &default_config if block_given?
instance_eval(source, path, 1)
end
end

# Setup the pipeline so its output files will be up to date.
Expand Down