Sha256: aa3f3282ccd8d465b03c6fb37f45610dd1c2aa1312f9efea25383e4efc68b0ac

Contents?: true

Size: 883 Bytes

Versions: 13

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true

module UiBibz
  module ViewObjects
    class GlyphComponentViewObject
      attr_accessor :options, :content

      def initialize(options, content = nil)
        @options = options
        @content = content
      end

      def render
        UiBibz::Ui::Core::Icons::Glyph.new(glyph_options[:name], mute_glyph_option).render if glyph_options[:name].present?
      end

      private

      def glyph_options
        if options[:glyph].is_a?(Hash)
          options[:glyph]
        elsif options[:glyph]
          { name: options[:glyph] }
        else
          {}
        end
      end

      def mute_glyph_option
        glyph_options.tap do |h|
          h[:text] = options[:text]
          h[:label] = options[:label] || content
          h[:shortcut] = options[:shortcut] unless options[:shortcut].nil?
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ui_bibz-4.0.0.beta18 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta17 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta16 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta15 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta14 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta13 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta10 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta9 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta8 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta7 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta6 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta4 lib/ui_bibz/view_objects/glyph_component_view_object.rb
ui_bibz-4.0.0.beta3 lib/ui_bibz/view_objects/glyph_component_view_object.rb