class Bootstrap4Helper::Component

This super class is meant to contain commonly used methods that all sub classes can leverage.

@note Every component that inherits from this class, needs to call the parent

initialization method! In order to properly render erb blocks within the
proper context, we need the template. The only way to get this, is to pass
in the template.

@note the `context` mentioned above, refers to the context of `@template` and

not to be confused with `@context` that can be found in the sub classes.
`@context` refers to the Bootstrap class context of the component.

Public Class Methods

new(template) click to toggle source

Used to ensure that the helpers always have the propert context for rendering and bindings.

@param [Class] template

# File lib/bootstrap4_helper/component.rb, line 20
def initialize(template)
  @template = template
end

Public Instance Methods

capture(*args) click to toggle source

Used to pass all context of the capture tag to then template. This ensures proper template binding of variables and methods!

@param [Mixed] args @return [String]

# File lib/bootstrap4_helper/component.rb, line 55
def capture(*args)
  @template.capture(*args)
end
concat(text) click to toggle source

Used to pass all concat references to the template. This ensures proper binding. Concat adds a String to the template Output buffer. Useful when trying to add a String with no block.

@param [String] text @return [String]

# File lib/bootstrap4_helper/component.rb, line 66
def concat(text)
  @template.concat(text)
end
config(setting, fallback) click to toggle source

Used to get config settings inside of components quicker.

@param [Symbol] setting @return [Mixed]

# File lib/bootstrap4_helper/component.rb, line 102
def config(setting, fallback)
  Bootstrap4Helper.config.send(setting) || fallback
end
content_tag( name, content_or_options_with_block = nil, options = nil, escape = true, &block ) click to toggle source

Used to pass all context of content_tag to the template. This ensures proper template binding of variables and methods!

@param [String] name @param [Hash|NilClass] content_or_options_with_block @param [Hash|NilClass] options @param [Boolean] escape @return [String]

# File lib/bootstrap4_helper/component.rb, line 33
def content_tag(
  name,
  content_or_options_with_block = nil,
  options = nil,
  escape = true,
  &block
)
  @template.content_tag(
    name,
    content_or_options_with_block,
    options,
    escape,
    &block
  )
end
parse_arguments(*args) click to toggle source

Used to parse method arguments. If the first argument is a Hash, then it is assumed that the user left off the bootstrap contectual class. So we will assign it to `secondary` and return the Hash to be used as options.

@param [Hash|NilClass|String|Symbol] args @return [Array]

# File lib/bootstrap4_helper/component.rb, line 78
def parse_arguments(*args)
  first, second = *args
  case first
  when Hash, NilClass
    ['secondary', first || second]
  when Symbol, String
    [first, second]
  end
end
uuid() click to toggle source

Used to generate a (hopefully) unique ID for DOM elements. Used as a fallback if the user doesn't specify one.

@return [String]

# File lib/bootstrap4_helper/component.rb, line 93
def uuid
  (0...10).map { rand(65..90).chr }.join
end