module WrapIt::HTML

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

@author Alexey Ovchinnikov <alexiss@cybernetlab.ru>

Public Class Methods

included(base) click to toggle source
# File lib/wrap_it/html.rb, line 21
def self.included(base)
  base == Base || fail(
    TypeError,
    "#{self.class.name} can be included only into WrapIt::Base"
  )
  base.class_eval do
    extend ClassMethods

    option(:class) { |_, v| self.html_class << v }

    # TODO: extend hashes for html_attr and html_data
    before_initialize do
      html_class
      @html_attr ||= {}
      @html_data ||= {}
    end
  end
end

Public Instance Methods

html_attr() click to toggle source

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

@return [Hash] attributes

# File lib/wrap_it/html.rb, line 64
def html_attr
  @html_attr ||= {}
end
html_attr=(hash) click to toggle source

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

@param hash [Hash] attributes

@return [Hash] resulting attributes

# 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_class() click to toggle source

Retrieves HTML class of element

See {HTMLClass} for details

@return [HTMLClass] HTML class of element

# File lib/wrap_it/html.rb, line 107
def html_class
  @html_class ||= HTMLClass.new
end
html_class=(value) click to toggle source

Sets HTML class(es) for element

@example

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

@param value [Symbol, String, Array<Symbol, String>] HTML class or list

of classes. All classes will be converted to Strings, duplicates are
removed. Refer to {HTMLClass} description for details.

@return [HTMLClass] resulting html class

# File lib/wrap_it/html.rb, line 97
def html_class=(value)
  @html_class = HTMLClass.new(value)
end
html_class_prefix() click to toggle source

HTML class prefix getter

This prefix used in enums to combine HTML classes.

@return [String] HTML class prefix.

# File lib/wrap_it/html.rb, line 82
def html_class_prefix
  @html_class_prefix ||= self.class.html_class_prefix
end
html_data() click to toggle source

Retrieves HTML data hash

@return [Hash] data

# File lib/wrap_it/html.rb, line 72
def html_data
  @html_data ||= {}
end

Protected Instance Methods

add_default_classes() click to toggle source
# File lib/wrap_it/html.rb, line 113
def add_default_classes
  html_class << self.class.collect_derived(
    :@html_class, HTMLClass.new, :<<
  )
end