Sha256: ed47b95906b9993f8183ef7258e0020463c6aeba986b69d29dbee2b9df956ee0

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

module Netzke::Core
  # This class is responsible for configuring an action. It is passed as a block parameter to the +action+ DSL method:
  #
  #   class MyComponent < Netzke::Base
  #     action :do_something do |c|
  #       c.text = "Do it!"
  #       c.tooltip = "Do something"
  #       c.icon = :tick
  #     end
  #   end
  class ActionConfig < ActiveSupport::OrderedOptions
    def initialize(name, component)
      @component = component
      @name = name.to_s
      @text = @tooltip = @icon = ""

      build_localized_attributes

      self.name = @name
      self.text = @text.presence || @name.humanize
      self.tooltip = @tooltip.presence || @name.humanize
      self.icon = @icon.to_sym if @icon.present?
    end

    def icon=(path)
      self[:icon] = path.is_a?(Symbol) ? Netzke::Base.uri_to_icon(path) : path
    end

    # later
    def set_defaults!
    end

  private

    def build_localized_attributes
      @component.class.netzke_ancestors.each do |c|
        i18n_id = c.i18n_id
        @text = I18n.t("#{i18n_id}.actions.#{@name}.text", default: "").presence || @text
        @tooltip = I18n.t("#{i18n_id}.actions.#{@name}.tooltip", default: "").presence || @tooltip
        @icon = I18n.t("#{i18n_id}.actions.#{@name}.icon", default: "").presence || @icon
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
netzke-core-0.8.3 lib/netzke/core/action_config.rb
netzke-core-0.8.2 lib/netzke/core/action_config.rb