Class: Frontyard::Actions

Inherits:
ApplicationComponent show all
Defined in:
app/components/frontyard/actions.rb

Constant Summary collapse

ButtonConfig =
Config.init(
  buttons: {
    submit: {
      type: "submit",
      text: "Submit"
    },
    cancel: {
      type: "cancel",
      text: "Cancel"
    }
  }
)

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#before_template, config, default_config, generate_css_class, #html_options, initialize_with, #namespace, #params, #render_model, #render_table

Constructor Details

#initialize(**kwargs, &block) ⇒ Actions

Returns a new instance of Actions.



18
19
20
21
22
# File 'app/components/frontyard/actions.rb', line 18

def initialize(**kwargs, &block)
  filtered_kwargs = filter_kwargs_for(self.class.superclass, kwargs)
  super(&block)
  @button_config = ButtonConfig.merge(kwargs.except(*filtered_kwargs.keys))
end

Instance Method Details

#view_template(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'app/components/frontyard/actions.rb', line 24

def view_template(&block)
  div(**self.class.config) do
    if block_given?
      yield
    else
      @button_config[:buttons].each do |_key, data|
        button(type: data[:type]) { data[:text] }
      end
    end
  end
end