Class: Mime::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/mime-components/components/components.rb

Overview

A component is a class with a ‘render’ function. This function’s output will replace the final XML in the rendered document.

Direct Known Subclasses

ERBComponent

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &proc) ⇒ Component

Create a new component.

Parameters:

  • name (String)

    component name

  • proc (Proc)

    block to call on invocation



21
22
23
24
# File 'lib/mime-components/components/components.rb', line 21

def initialize(name, &proc)
   @name = name
   @proc = proc
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/mime-components/components/components.rb', line 34

def name
  @name
end

Class Method Details

.attr_true?(value) ⇒ True|False

Check if an attribute’s value is truthy.

Parameters:

  • value (String|Symbol)

    attribute to check

Returns:

  • (True|False)

    whether or not the value is truthy



14
15
16
# File 'lib/mime-components/components/components.rb', line 14

def self.attr_true?(value)
   [1, 'true', 'yes'].include?(value.to_s.strip.downcase)
end

Instance Method Details

#render(attributes, vars) ⇒ String

Call this component’s rendering function.

Parameters:

  • attributes (Hash)

    rendering parameters

  • vars (Hash)

    template variables

Returns:

  • (String)

    rendered component



30
31
32
# File 'lib/mime-components/components/components.rb', line 30

def render(attributes, vars)
   @proc.call(attributes, vars)
end