class SymbolToFontawesome::Builder

Public Class Methods

call(*args, &block) click to toggle source
# File lib/symbol_to_fontawesome.rb, line 12
def call(*args, &block)
  new(*args, &block)
end
new(*args, &block) click to toggle source
# File lib/symbol_to_fontawesome.rb, line 17
def initialize(*args, &block)
  if block_given?
    args.shift
    @classes = ['fa-stack'] + args.map(&method(:analyze))
    @stacker = []
    instance_eval(&block)
  else
    @stacked = true if !!args.delete(:stacking)
    @classes = ['fa-' + args.shift] + args.map(&method(:analyze))
  end
end

Public Instance Methods

analyze(param) click to toggle source
# File lib/symbol_to_fontawesome.rb, line 29
def analyze(param)
  raise 'not number' if (i = param.to_i) == 0
  case param.to_i
    when 1, 2, 3, 4, 5
      if !!@stacked
        "fa-stack-#{i}x"
      else
        "fa-#{i}x"
      end
    when 90, 180, 270
      "fa-rotate-#{i}"
    else
      nil
  end
rescue
  case param
    when :fixed_width
      'fa-fw'
    when :left, :right
      "fa-pull-#{param}"
    when :horizontal, :vertical
      "fa-flip-#{param}"
    else
      if param.is_a?(Symbol)
        "fa-#{param}"
      else
        param
      end
  end
end
build!() click to toggle source
# File lib/symbol_to_fontawesome.rb, line 60
def build!
  tag = if !!@stacker
          %{<span class="#{@classes.join(' ')}">#{@stacker.join}</span>}
        else
          %{<i class="fa #{@classes.join(' ')}"></i>}
        end

  if tag.respond_to?(:html_safe)
    tag.html_safe
  else
    tag
  end
end
stack(*args) click to toggle source
# File lib/symbol_to_fontawesome.rb, line 74
def stack(*args)
  @stacker.push(args.shift.fa(*args + [:stacking]))
end