Module: AppKit::Dsl::ResourceDsl

Included in:
Resource
Defined in:
lib/app_kit/dsl/resource_dsl.rb

Instance Method Summary collapse

Instance Method Details

#action(name, options = {}, &block) ⇒ Object

A DSL method for defining a new action.

Attributes

  • name - The controller action to bind to.

  • options - An optional hash of params.

  • &block - The code to execute. This block is yielded the model instance

Examples

action :update do |record|
    record.parent_record.update_information
end


16
17
18
# File 'lib/app_kit/dsl/resource_dsl.rb', line 16

def action(name, options={}, &block)
  member_actions[name] = AppKit::Action.new(name, self, options, &block)
end

#before(action, &block) ⇒ Object

DSL method for defining before_actions on resources.

Parameters:

  • action (Symbol)

    The action the before filter should execute for. Generally :new, :create, :update, or :destroy

  • block (Block)

    A block to execute. This block is given the record object.



50
51
52
# File 'lib/app_kit/dsl/resource_dsl.rb', line 50

def before(action, &block)
  before_actions[action] = block if block_given?
end

#field(name, options = {}, &block) ⇒ Object

A DSL method for defining fields and their options.

Examples:

Define a new field

field :name, editable: false, display_in_details: false

Parameters:

  • name (Symbol)

    the field name. This should relate to a method name on the model.

  • options (Hash) (defaults to: {})

    an optional hash to list field options. For a full list of field options see the AppKit::Field class.

  • block (Block)

    If a block is passed a DSL can be used to define the fields settings, instead of passing them in the options hash.



27
28
29
30
# File 'lib/app_kit/dsl/resource_dsl.rb', line 27

def field(name, options={}, &block)
  field = AppKit::Field.new(model, name, options, &block)
  fields << field
end

#icon(icon_name) ⇒ Object

DSL method for defining an icon to be used in the navigation menu for this resource. These icons use FontAwesome and should relate to the FontAwesome icon name.

Examples:

icon 'list'

Parameters:

  • icon (String)

    The FontAwesome icon name to use.



59
60
61
# File 'lib/app_kit/dsl/resource_dsl.rb', line 59

def icon(icon_name)
  self.navigation_icon = icon_name
end

#show_in_navigation(val = true, position = :left) ⇒ Object

DSL method for displaying resources in the main navigation bar.

Parameters:

  • position (:left, :right) (defaults to: :left)

    the position for the navigation item



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/app_kit/dsl/resource_dsl.rb', line 35

def show_in_navigation(val=true, position = :left)
  if val == true
    nav_item = AppKit::NavigationItem.new
    nav_item.resource = self
    nav_item.position = position
    nav_item.icon = self.navigation_icon
    AppKit.application.navigation_items << nav_item
  else
    AppKit.application.navigation_items.delete_if {|i| i.resource == self}
  end
end