Class: Extruder::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/extruder/dsl.rb

Overview

This class exists purely to provide a convenient DSL for configuring an extruder.

All instance methods of DSL are available in the context the block passed to build

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extruder) ⇒ void

Create a new Extruder::DSL to configure an extruder.

Parameters:

  • extruder (Extruder::Main)

    the extruder that the DSL should configure.



41
42
43
# File 'lib/extruder/dsl.rb', line 41

def initialize(extruder)
  @extruder = extruder
end

Instance Attribute Details

#extruderExtruder::Main (readonly)

Returns the extruder the DSL should configure.

Returns:



14
15
16
# File 'lib/extruder/dsl.rb', line 14

def extruder
  @extruder
end

Class Method Details

.evaluate(extruder, &block) ⇒ void

This method returns an undefined value.

Configure an extruder with a passed block.

Parameters:

  • extruder (extruder)

    the extruder that the DSL should configure.

  • block (Proc)

    the block describing the configuration. This block will be evaluated in the context of a new instance of Extruder::DSL



27
28
29
30
31
# File 'lib/extruder/dsl.rb', line 27

def self.evaluate(extruder, &block)
  # create instance of self with the pipline passed
  # and evalute the block within it
  new(extruder).instance_eval(&block)
end

Instance Method Details

#concat(*args, &block) ⇒ Object Also known as: copy

A helper method for adding a concat filter to the Extruder. If the first argument is an Array, it adds a new OrderingConcatFilter, otherwise it adds a new ConcatFilter.



145
146
147
148
149
150
151
# File 'lib/extruder/dsl.rb', line 145

def concat(*args, &block)
  if args.first.kind_of?(Array)
    filter(OrderingConcatFilter, *args, &block)
  else
    filter(ConcatFilter, *args, &block)
  end
end

#filter(filter_class, *ctor_args, &block) ⇒ void

This method returns an undefined value.

Add a filter to the pipeline, normally called from within a match block. If a filter is added without a match block, the Extruder will automatically create one that matches all input files.

In addition to a filter class, #filter takes a block that describes how the filter should map input files to output files.

By default, the block maps an input file into an output file with the same name.

Any additional arguments passed to #filter will be passed on to the filter class’s constructor.

Parameters:

  • filter_class (Class)

    the class of the filter.

  • ctor_args (Array)

    a list of arguments to pass to the filter’s constructor.

  • block (Proc)

    an output file name generator.

See Also:



118
119
120
121
# File 'lib/extruder/dsl.rb', line 118

def filter(filter_class, *ctor_args, &block)
  filter = filter_class.new(*ctor_args, &block)
  extruder.add_filter(filter)
end

#input(root, pattern = '**/*') ⇒ void

This method returns an undefined value.

Define the input location and files for the extruder.

Examples:

Extruder.build do
  input "app/assets", "**/*.js"
  # ...
end

Parameters:

  • root (String)

    the root path where the extruder should find its input files.

  • glob (String)

    a file pattern that represents the list of all files that the extruder should process within root. The default is */.



63
64
65
# File 'lib/extruder/dsl.rb', line 63

def input(root, pattern='**/*')
  extruder.add_input root, pattern
end

#match(pattern, &block) ⇒ void

This method returns an undefined value.

Add a match to the pipeline with a passed block containing filters that belong to it.

Examples:

Extruder.build do
  input "app/assets"

  match "*.js" do
    concat "app.js"
  end

end

Parameters:

  • root (String)

    the output directory.



86
87
88
89
# File 'lib/extruder/dsl.rb', line 86

def match(pattern, &block)
  extruder.add_match pattern
  block.call
end

#output(root) ⇒ void

This method returns an undefined value.

Specify the output directory for the pipeline.

Parameters:

  • root (String)

    the output directory.



130
131
132
# File 'lib/extruder/dsl.rb', line 130

def output(root)
  extruder.output_root = root
end