Sha256: ad4dda1e17811baee4838292d9d3d093a457a7f25f62f8fda359024772e484a1

Contents?: true

Size: 1.23 KB

Versions: 14

Compression:

Stored size: 1.23 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 < DslConfigBase
    def initialize(name, component)
      super

      @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

14 entries across 14 versions & 1 rubygems

Version Path
netzke-core-0.12.3 lib/netzke/core/action_config.rb
netzke-core-0.12.2 lib/netzke/core/action_config.rb
netzke-core-0.12.1 lib/netzke/core/action_config.rb
netzke-core-0.12.0 lib/netzke/core/action_config.rb
netzke-core-0.12.0.rc1 lib/netzke/core/action_config.rb
netzke-core-0.12.0.beta lib/netzke/core/action_config.rb
netzke-core-0.11.0 lib/netzke/core/action_config.rb
netzke-core-0.10.1 lib/netzke/core/action_config.rb
netzke-core-0.10.0 lib/netzke/core/action_config.rb
netzke-core-0.9.0 lib/netzke/core/action_config.rb
netzke-core-0.10.0.rc2 lib/netzke/core/action_config.rb
netzke-core-0.10.0.rc1 lib/netzke/core/action_config.rb
netzke-core-0.9.0.rc1 lib/netzke/core/action_config.rb
netzke-core-0.8.4 lib/netzke/core/action_config.rb