Class: AmberComponent::Base Abstract

Inherits:
ActionView::Base
  • Object
show all
Extended by:
ActiveModel::Callbacks, Assets::ClassMethods, Helpers::ClassHelper, Props::ClassMethods, Rendering::ClassMethods, Views::ClassMethods, Memery
Includes:
Assets::InstanceMethods, Helpers::CssHelper, Props::InstanceMethods, Rendering::InstanceMethods, Views::InstanceMethods
Defined in:
lib/amber_component/base.rb

Overview

This class is abstract.

Create a subclass to define a new component.

Abstract class which serves as a base for all Amber Components.

There are a few life cycle callbacks that can be defined. The same way as in ‘ActiveRecord` models and `ActionController` controllers.

  • before_render

  • around_render

  • after_render

  • before_initialize

  • around_initialize

  • after_initialize

    class ButtonComponent < ::AmberComponent::Base
      # You can provide a Symbol of the method that should be called
      before_render :before_render_method
      # Or provide a block that will be executed
      after_initialize do
        # Your code here
      end
    
      def before_render_method
        # Your code here
      end
    end
    

Direct Known Subclasses

ApplicationComponent

Instance Attribute Summary

Attributes included from Views::ClassMethods

#method_view

Attributes included from Props::ClassMethods

#prop_definitions

Instance Method Summary collapse

Methods included from Helpers::ClassHelper

const_name, source_location

Methods included from Views::ClassMethods

view, view_file_name, view_path, view_type

Methods included from Assets::ClassMethods

all_asset_dir_paths, asset_dir_from_name, asset_dir_path, asset_file_names, asset_path

Methods included from Rendering::ClassMethods

render

Methods included from Props::ClassMethods

prop, prop_names, required_prop_names

Methods included from Rendering::InstanceMethods

#render, #render_in

Methods included from Helpers::CssHelper

#css_identifier

Constructor Details

#initialize(**kwargs) ⇒ Base

Returns a new instance of Base.

Parameters:

  • kwargs (Hash{Symbol => Object})

Raises:



125
126
127
128
129
130
131
# File 'lib/amber_component/base.rb', line 125

def initialize(**kwargs)
  run_callbacks :initialize do
    next if bind_props(kwargs)

    bind_instance_variables(kwargs)
  end
end