module Cumuliform::DSL::Helpers

Contains DSL methods for including modules containing simple helper methods

Helper methods are isolated from the template object, so they can't call other DSL methods. They're really intended for wrapping code that is used in several places but requires complex setup, for example a third-party API that issues tokens you need to include in your template in some way.

Public Instance Methods

helpers(*mods, &block) click to toggle source

Add helper methods to the template.

@overload helpers(mod, …)

Include one or more helper modules
@param mod [Module] Module containing helper methods to include

@overload helpers(&block)

@param block [lambda] Block containing helper method definitins to include
# File lib/cumuliform/dsl/helpers.rb, line 20
def helpers(*mods, &block)
  if block_given?
    mods << Module.new(&block)
  end
  mods.each do |mod|
    helpers_class.class_eval {
      include mod
    }
  end
end

Protected Instance Methods

has_helper?(meth) click to toggle source

@api private

# File lib/cumuliform/dsl/helpers.rb, line 34
def has_helper?(meth)
  helpers_instance.respond_to?(meth)
end
send_helper(meth, *args) click to toggle source

@api private

# File lib/cumuliform/dsl/helpers.rb, line 47
def send_helper(meth, *args)
  helpers_instance.send(meth, *args)
end
template_for_helper(meth) click to toggle source

@api private

# File lib/cumuliform/dsl/helpers.rb, line 39
def template_for_helper(meth)
  return self if has_helper?(meth)
  imports.reverse.find { |template|
    template.template_for_helper(meth)
  }
end

Private Instance Methods

helpers_class() click to toggle source
# File lib/cumuliform/dsl/helpers.rb, line 53
def helpers_class
  @helpers_class ||= Class.new
end
helpers_instance() click to toggle source
# File lib/cumuliform/dsl/helpers.rb, line 57
def helpers_instance
  @helpers_instance ||= helpers_class.new
end
method_missing(meth, *args) click to toggle source
Calls superclass method
# File lib/cumuliform/dsl/helpers.rb, line 61
def method_missing(meth, *args)
  if template = template_for_helper(meth)
    template.send_helper(meth, *args)
  else
    super
  end
end