Class: Ferro::Element::List

Inherits:
BaseElement show all
Defined in:
opal/opal-ferro/elements/ferro_inline.js.rb

Overview

Creates an inline element. In the DOM creates a: <ol> or <ul> depending on option :type. Set to ‘1’, ‘A’, ‘a’, ‘I’ or ‘i’ to create <ol> elements. Leave option blank to create <ul> elements.

Constant Summary

Constants included from Ferro::Elementary

Ferro::Elementary::RESERVED_NAMES

Instance Attribute Summary collapse

Attributes inherited from BaseElement

#children, #domtype, #element, #parent, #sym

Instance Method Summary collapse

Methods inherited from BaseElement

#add_state, #add_states, #classify_state, #component, #dom_id, #factory, #get_text, #html, #initialize, #option_replace, #remove_attribute, #root, #router, #set_attribute, #set_text, #state_active?, #toggle_state, #update_state, #value, #value=

Methods included from Ferro::Elementary

#_after_create, #_stylize, #add_child, #after_create, #before_create, #cascade, #create, #creation, #destroy, #each_child, #forget_children, #method_missing, #remove_child, #style, #symbolize

Constructor Details

This class inherits a constructor from Ferro::BaseElement

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ferro::Elementary

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



29
30
31
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 29

def items
  @items
end

Instance Method Details

#_before_createObject

Internal method.



32
33
34
35
36
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 32

def _before_create
  @domtype = @options.has_key?(:type) ? :ol : :ul
  @items   = []
  @id      = Sequence.new 'list_'
end

#add_item(element_class, options = {}) ⇒ Object

Add an item to the (un)ordered list.

Parameters:

  • element_class (String)

    Ruby classname for the new element

  • options (Hash) (defaults to: {})

    Any options for the new element



42
43
44
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 42

def add_item(element_class, options = {})
  @items << add_child(@id.next, element_class, options).sym
end

#first_itemelement

The first item in the list.

Returns:

  • (element)

    Returns first element in the list



56
57
58
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 56

def first_item
  @children[@items.first]
end

#item_countInteger

The number of items in the list.

Returns:

  • (Integer)

    Returns the number of items in the list



49
50
51
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 49

def item_count
  @items.length
end

#last_itemelement

The last item in the list.

Returns:

  • (element)

    Returns last element in the list



63
64
65
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 63

def last_item
  @children[@items.last]
end

#unlist_item(sym) ⇒ Object

Remove an item from the (un)ordered list.

Parameters:

  • sym (Symbol)

    The symbol of the item to be removed



70
71
72
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 70

def unlist_item(sym)
  @items.delete_if { |item| item == sym }
end