Module: WrapIt::HTML

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

Overview

Methods for manipulationg with HTML class. For internal usage. You should not include this class directly - subclass from WrapIt::Base instead.

Author:

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

#html_class([html_class, ...]) ⇒ void Originally defined in module ClassMethods

This method returns an undefined value.

Adds default html classes, thats are automatically added when element created.

Parameters:

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

    HTML class. Converted to String

.html_class_prefix(prefix = nil) ⇒ void Originally defined in module ClassMethods

This method returns an undefined value.

Sets HTML class prefix. It used in switchers and enums

Parameters:

  • prefix (String) (defaults to: nil)

    HTML class prefix

Instance Method Details

#html_attrHash

Retrieves HTML attributes hash (without HTML class and HTML data)

Returns:

  • (Hash)

    attributes



64
65
66
# File 'lib/wrap_it/html.rb', line 64

def html_attr
  @html_attr ||= {}
end

#html_attr=(hash) ⇒ Hash

TODO: actually we should have separate setter and merge (see Base)

Sets HTML attributes hash.

Actually it merges its with current attributes. To remove some attributes use html_attr.delete(:attr). extracts HTML class and data from provided hash and places its to appropriate holder

Parameters:

  • hash (Hash)

    attributes

Returns:

  • (Hash)

    resulting attributes



52
53
54
55
56
57
58
# File 'lib/wrap_it/html.rb', line 52

def html_attr=(hash)
  return unless hash.is_a?(Hash)
  hash.symbolize_keys!
  html_class << hash.delete(:class)
  html_data.merge(hash.delete(:data) || {})
  (@html_attr ||= {}).merge!(hash)
end

#html_classHTMLClass

Retrieves HTML class of element

See WrapIt::HTMLClass for details

Returns:



107
108
109
# File 'lib/wrap_it/html.rb', line 107

def html_class
  @html_class ||= HTMLClass.new
end

#html_class=(value) ⇒ HTMLClass

Sets HTML class(es) for element

Examples:

element.html_class = [:a, 'b', ['c', :d, 'a']]
element.html_class #=> ['a', 'b', 'c', 'd']

Parameters:

  • value (Symbol, String, Array<Symbol, String>)

    HTML class or list of classes. All classes will be converted to Strings, duplicates are removed. Refer to WrapIt::HTMLClass description for details.

Returns:



97
98
99
# File 'lib/wrap_it/html.rb', line 97

def html_class=(value)
  @html_class = HTMLClass.new(value)
end

#html_class_prefixString

HTML class prefix getter

This prefix used in enums to combine HTML classes.

Returns:

  • (String)

    HTML class prefix.



82
83
84
# File 'lib/wrap_it/html.rb', line 82

def html_class_prefix
  @html_class_prefix ||= self.class.html_class_prefix
end

#html_dataHash

Retrieves HTML data hash

Returns:

  • (Hash)

    data



72
73
74
# File 'lib/wrap_it/html.rb', line 72

def html_data
  @html_data ||= {}
end