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:
Helpers::CssHelper, Props::InstanceMethods, Rendering::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

Class Method Summary collapse

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_template_source, 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

compile, compile?, compiled?, render, template_handler

Methods included from Props::ClassMethods

prop, prop_names, required_prop_names

Methods included from Rendering::InstanceMethods

#nested_content, #render, #render_in, #safe_capture

Methods included from Helpers::CssHelper

#css_identifier

Constructor Details

#initialize(**kwargs) ⇒ Base

Returns a new instance of Base.

Parameters:

  • kwargs (Hash{Symbol => Object})

Raises:



145
146
147
148
149
150
151
# File 'lib/amber_component/base.rb', line 145

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

    bind_instance_variables(kwargs)
  end
end

Class Method Details

.compiled_method_containerClass

Returns:

  • (Class)


65
66
67
# File 'lib/amber_component/base.rb', line 65

def compiled_method_container
  self
end

.formatSymbol

Returns:

  • (Symbol)


75
76
77
# File 'lib/amber_component/base.rb', line 75

def format
  :html
end

.identifierString

Returns:

  • (String)


80
81
82
# File 'lib/amber_component/base.rb', line 80

def identifier
  source_location.first
end

.typeString

Returns:

  • (String)


70
71
72
# File 'lib/amber_component/base.rb', line 70

def type
  'text/html'
end

Instance Method Details

#compiled_method_containerClass

Returns:

  • (Class)


154
155
156
# File 'lib/amber_component/base.rb', line 154

def compiled_method_container
  self.class
end