Skip to content

Behaviors \ Components

gdotdesign edited this page Nov 2, 2014 · 2 revisions

The components behavior gives you the ability to compose components together with the component DSL:

class Button < Fron::Component
end

class MyComponent < Fron::Component
  # Creates a Button component
  component :button, Button
  # Creates a Fron::Component with 'small' tag
  component :info, 'small' do
    # This block is evaluated on the components instance
    component :icon, 'i.icon-message'
    component :text, 'span'
  end
end

Syntax

component("name", Component) { block }

  • It is available as a class and an instance method
    • If the class method is called then it adds the definition to the registry from which the components are created in order when component is instantiated.
    • If the instance method is called then it creates a child component with the given arguments and appends it to the component.
  • The first argument is the name of the child component
    • If there is no method then then the child component is available with this is as a public method

      myComp = MyComponent.new
      myComp.button # #<Button:007>
    • The child component is available whit this as an instance variable

      @button # #<Button:007> 
  • The second arguments is the Component to create
    • If a descendant of Fron::Component is given then it will instantiate it when the component is created
    • If a string or symbol is given then it will create a component with that tagname
  • If a block is passed it will be run on the child component instance scope right after initialization.
Clone this wiki locally