Sha256: a6183ea5cef211342cf6cc34f1175c614cdd448f64cd47b9ed9684dc15369877

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module GlyphExtension
  # Render glyph and content html
  def glyph_and_content_html(content_html = nil)
    [glyph_with_space, ct_html(content_html)].compact.join(' ').html_safe
  end

  def ct_html(content_html)
    content_html || content if options[:text].nil? || options[:text] == true
  end

  # Render glyph with space html
  def glyph_with_space
    out = [glyph]
    out << ' ' if options[:text] != false
    out << content_tag(:span, ' ', class: 'empty-space') if options[:text] == false
    out.join unless glyph.nil?
  end

  # Render glyph html
  def glyph
    options[:content] = content if options[:text] == false

    glyph_options = case options[:glyph]
                    when Hash
                      options[:glyph]
                    when String
                      { name: options[:glyph] }
                    else
                      {}
                    end

    glyph_options[:text]       = options[:text] unless options[:text].nil?
    glyph_options[:content]    = options[:content] unless options[:content].nil?
    glyph_options[:shortcut]   = options[:shortcut] unless options[:shortcut].nil?
    glyph_options[:html_options] = options[:html_options]  unless options[:html_options].nil?

    UiBibz::Utils::GlyphChanger.new(glyph_options[:name], glyph_options).render unless glyph_options[:name].nil?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ui_bibz-3.0.0.alpha5 lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb
ui_bibz-3.0.0.alpha3 lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb
ui_bibz-3.0.0.alpha2 lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb