Module: PageMagic::Elements

Included in:
Element
Defined in:
lib/page_magic/elements.rb

Overview

module Elements - contains methods that add element definitions to the objects it is mixed in to

Defined Under Namespace

Modules: InheritanceHooks

Constant Summary collapse

INVALID_METHOD_NAME_MSG =
'a method already exists with this method name'.freeze
TYPES =
[:text_field, :button, :link, :checkbox, :select_list, :radios, :textarea].freeze

Instance Method Summary collapse

Instance Method Details

#element(name, selector, &block) ⇒ Object #element(element_class, &block) ⇒ Object #element(name, element_class, &block) ⇒ Object #element(name, element_class, selector, &block) ⇒ Object

Creates an element defintion. Element defintions contain specifications for locating them and other sub elements. if a block is specified then it will be executed against the element defintion. This method is aliased to each of the names specified in TYPES

Examples:

element :widget, id: 'widget' do
  link :next, text: 'next'
end

Overloads:

  • #element(name, selector, &block) ⇒ Object

    Parameters:

    • name (Symbol)

      the name of the element.

    • selector (Hash)

      a key value pair defining the method for locating this element

    Options Hash (selector):

    • :text (String)

      text contained within the element

    • :css (String)

      css selector

    • :id (String)

      the id of the element

    • :name (String)

      the value of the name attribute belonging to the element

    • :label (String)

      value of the label tied to the require field

  • #element(element_class, &block) ⇒ Object

    Parameters:

    • element_class (ElementClass)

      a custom class of element that inherits PageMagic::Element. the name of the element is derived from the class name. the Class name coverted to snakecase. The selector must be defined on the class itself.

  • #element(name, element_class, &block) ⇒ Object

    Parameters:

    • name (Symbol)

      the name of the element.

    • element_class (ElementClass)

      a custom class of element that inherits PageMagic::Element. The selector must be defined on the class itself.

  • #element(name, element_class, selector, &block) ⇒ Object

    Parameters:

    • name (Symbol)

      the name of the element.

    • element_class (ElementClass)

      a custom class of element that inherits PageMagic::Element.

    • selector (Hash)

      a key value pair defining the method for locating this element. See above for details



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/page_magic/elements.rb', line 53

def element(*args, &block)
  block ||= proc {}
  options = compute_options(args.dup)
  options[:type] = __callee__
  section_class = options.delete(:section_class)

  add_element_definition(options.delete(:name)) do |parent_element, *e_args|
    definition_class = Class.new(section_class) do
      parent_element(parent_element)
      class_exec(*e_args, &block)
    end
    ElementDefinitionBuilder.new(options.merge(definition_class: definition_class))
  end
end

#element_definitionsHash

Returns element definition names mapped to blocks that can be used to create unique instances of and PageMagic::Element definitions.

Returns:

  • (Hash)

    element definition names mapped to blocks that can be used to create unique instances of and PageMagic::Element definitions



72
73
74
# File 'lib/page_magic/elements.rb', line 72

def element_definitions
  @element_definitions ||= {}
end