Module: WrapIt::Switches

Extended by:
DerivedAttributes, ClassMethods
Included in:
Base
Defined in:
lib/wrap_it/switches.rb

Overview

Adds switches functionality

Author:

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.switch(name, options = {}) {|state| ... } ⇒ void Originally defined in module ClassMethods

This method returns an undefined value.

Adds switch. Switch is a boolean flag. When element created, creation arguments will be scanned for Symbol, that equals to name. If it founded, switch turned on. Also creation options inspected. If its contains name: true key-value pair, this pair removed from options and switch also turned on.

This method also adds getter and setter for this switch in form name? and name= respectively.

When html_class option specified and switch changes its state, HTML class for element will be computed as follows. if html_class options is true, html class produced from html_class_prefix and name of switch. If html_class is a String, Symbol or Array of this types, html class produced as array of html_class_prefix and each html_class concatinations. This classes added to element if switch is on or removed in other case.

Parameters:

  • name (String, Symbol)

    Switch name. Converted to Symbol.

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

    Switch options

Options Hash (options):

  • :html_class (true, String, Symbol, Array<String, Symbol>)

    HTML classes list that will automatically added to element if switch is on or removed from element if switch id off.

  • :aliases (Symbol, Array<Symbol>)

    list of aliases. Warning! Values are not converted - pass only Symbols here.

Yields:

  • (state)

    Runs block when switch state changed, gives it to block.

Yield Parameters:

  • state (Boolean)

    Whether switch is on or off.

Yield Returns:

  • (Object, FalseClass)

    if you return false, value will ommited.