Class: FA::Build

Inherits:
Layer show all
Defined in:
lib/fa/build.rb

Overview

FontAwesome 5 (Pro) Helper for piecewise building layered icons and spans

Since:

  • 0.1.0

Constant Summary

Constants inherited from Base

FA::Base::MODES, FA::Base::STYLES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#safe

Constructor Details

#initialize(icons = {}, title: nil, grow: 0, css: '') {|_self| ... } ⇒ Build

Creates a new Layer instance

Add icons or spans to the stack from bottom to top

This is a variand of FA::Layer, to allow for DSL building stacks

Note: scaling counters does not work well with :grow, so should use the older “fa-3x” syntax in :css instead.

Parameters:

  • icons (Array) (defaults to: {})

    The complete hash configurations for each icon/span

  • title (String) (defaults to: nil)

    The tooltip text

  • grow (Integer) (defaults to: 0)

    An additional global scaling factor added in

  • css (String) (defaults to: '')

    Additional arbitrary CSS classes, space-delimited

Yields:

  • (_self)

Yield Parameters:

  • _self (FA::Build)

    the object that the method was called on

Since:

  • 0.1.0



19
20
21
22
23
# File 'lib/fa/build.rb', line 19

def initialize(icons = {}, title: nil, grow: 0, css: '')
  super
  @contents = ''
  yield(self) if block_given?
end

Class Method Details

.p(*args, &block) ⇒ Object

Shortcut for create and output safe

Since:

  • 0.1.0



43
44
45
# File 'lib/fa/build.rb', line 43

def self.p(*args, &block)
  new(*args).instance_eval(&block).safe
end

Instance Method Details

#icon(icon, **options) ⇒ Object

Adds an icon to the stack using the same argument format.

Since:

  • 0.1.0



31
32
33
34
# File 'lib/fa/build.rb', line 31

def icon(icon, **options)
  @contents += FA::Icon.p(icon, full_options(options))
  self
end

#rawObject

Outputs the formatted stack of icons and spans directly.

Since:

  • 0.1.0



26
27
28
# File 'lib/fa/build.rb', line 26

def raw
  build { @contents }
end

#span(type, text, **options) ⇒ Object

Adds a span to the stack using the same argument format.

Since:

  • 0.1.0



37
38
39
40
# File 'lib/fa/build.rb', line 37

def span(type, text, **options)
  @contents += FA::Span.p(type, text, full_options(options))
  self
end