Module: Cumuliform::DSL::Helpers

Included in:
Template
Defined in:
lib/cumuliform/dsl/helpers.rb

Overview

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.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object (private)



61
62
63
64
65
66
67
# 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

Instance Method Details

#helpers(mod, ...) ⇒ Object #helpers(&block) ⇒ Object

Add helper methods to the template.

Overloads:

  • #helpers(mod, ...) ⇒ Object

    Include one or more helper modules

    Parameters:

    • mod (Module)

      Module containing helper methods to include

  • #helpers(&block) ⇒ Object

    Parameters:

    • block (lambda)

      Block containing helper method definitins to include



20
21
22
23
24
25
26
27
28
29
# 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