Sha256: 6acb9883a859819855da101653bd0111505790b92230458eaaf11ff74aa69e16

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 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.join unless glyph.nil?
  end

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

    glyph_options = if options[:glyph].is_a?(Hash)
                      options[:glyph]
                    elsif options[:glyph].is_a?(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

6 entries across 6 versions & 1 rubygems

Version Path
ui_bibz-2.5.6 lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb
ui_bibz-2.5.5 lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb
ui_bibz-2.5.3 lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb
ui_bibz-2.5.2 lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb
ui_bibz-2.5.1 lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb
ui_bibz-2.5.0 lib/ui_bibz/ui/extensions/core/component/glyph_extension.rb