module Temple::Mixins::EngineDSL

def chain_element(args, block)

def chain_element(args, block)
  name = args.shift
  if Class === name
    filter = name
    name = filter.name.to_sym
  else
    raise(ArgumentError, 'Name argument must be Class or Symbol') unless Symbol === name
  end
  if block
    raise(ArgumentError, 'Class and block argument are not allowed at the same time') if filter
    filter = block
  end
  filter ||= args.shift
  case filter
  when Proc
    # Proc or block argument
    # The proc is converted to a method of the engine class.
    # The proc can then access the option hash of the engine.
    raise(ArgumentError, 'Too many arguments') unless args.empty?
    [name, chain_proc_constructor(name, filter)]
  when Class
    # Class argument (e.g Filter class)
    # The options are passed to the classes constructor.
    [name, chain_class_constructor(filter, args)]
  else
    # Other callable argument (e.g. Object of class which implements #call or Method)
    # The callable has no access to the option hash of the engine.
    raise(ArgumentError, 'Too many arguments') unless args.empty?
    [name, chain_callable_constructor(filter)]
  end
end