Class: Brandish::Configure::DSL::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/brandish/configure/dsl/form.rb

Overview

Constructs a form for use with the configure instance. A form is basically a format and name pair; different forms can have different entries, formats, and processors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, name = nil) ⇒ Form

Initialize the form DSL. This sets up the initial format and name, and intializes the instance variables.

Parameters:

  • format (::Symbol)

    The format.

  • name (::String, nil) (defaults to: nil)

    The name of the form.



28
29
30
31
32
33
# File 'lib/brandish/configure/dsl/form.rb', line 28

def initialize(format, name = nil)
  @name = name || _generate_form_name
  @format = format
  @entry = "index.br"
  @processors = []
end

Instance Attribute Details

#entry=(value) ⇒ ::String (writeonly)

The entry for the form. This is the file that begins the parsing for the form.

Returns:

  • (::String)


21
22
23
# File 'lib/brandish/configure/dsl/form.rb', line 21

def entry=(value)
  @entry = value
end

#name=(value) ⇒ ::String (writeonly)

The name of the form. This defaults to a random value. Do not rely on the name unless it is set.

Returns:

  • (::String)


15
16
17
# File 'lib/brandish/configure/dsl/form.rb', line 15

def name=(value)
  @name = value
end

Instance Method Details

#data(::String, ::Symbol, ::String, <(::String, ::String, ::Hash)>]

The data from this form. This is used to create the actual form that is used in the configuration.

Returns:

  • ((::String, ::Symbol, ::String, <(::String, ::String, ::Hash)>])

    (::String, ::Symbol, ::String, <(::String, ::String, ::Hash)>]



90
91
92
# File 'lib/brandish/configure/dsl/form.rb', line 90

def data
  [@name, @format, @entry, @processors]
end

#use(name, options = {}) ⇒ void #use(options = {}) { ... } ⇒ void Also known as: process, processor, define

This method returns an undefined value.

Adds a processor for use for the form. The order that this is called is important.

Examples:

config.form :html do |form|
  form.use :literal # Can expand to either "html:literal" or "all:literal"
                    # in that order.
  form.use "all:literal" # Only expands to "all:literal"
  form.use Brandish::Processors::All::Literal # allowed too
  form.use do
    # also allowed
  end
end

Overloads:

  • #use(name, options = {}) ⇒ void

    Parameters:

    • name (::String, ::Symbol, <::Symbol>, ::Class)

      The name of the processor. If the processor is a symbol, it is assumed to be the name of the processor; the format is guessed to be either the format of the form, or :all. If the processor is a string, and it contains a colon, it is assumed to be the name of the processor in the form <format>:<name>; if it doesn't contain the colon, it is treated as a symbol. If it is an array, it is assumed to be a pair containing the name of the process. If it is a class, it is assumed to be a processor, and is used directly.

    • options ({::Object => ::Object}) (defaults to: {})

      The options for the processor. The allowed values for the options are dependant on the processor.

  • #use(options = {}) { ... } ⇒ void

    Parameters:

    • options ({::Object => ::Object}) (defaults to: {})

      The options for the processor. The allowed values for the options are dependant on the processor.

    Yields:

    • into a new class; this allows a processor to be defined without having a named class.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/brandish/configure/dsl/form.rb', line 68

def use(*arguments)
  processor = options = nil

  if block_given?
    options = arguments[0]
    processor = Class.new(Brandish::Processor::Base, &::Proc.new)
  else
    name = arguments[0]
    options = arguments[1]
    processor = _guess_processor_name(name)
  end

  @processors << [processor, options || {}]
end