Module: Faalis::Dashboard::Sections::ResourceShow::ClassMethods

Defined in:
lib/faalis/dashboard/sections/resource_show.rb

Overview

The actual DSL for index ages

Instance Method Summary collapse

Instance Method Details

#in_show(&block) ⇒ Object

To specify any property and action for ‘show` section you must use `in_index` class method with block of properties. For example:

“‘ruby

class ExamplesController < Dashboard::Application
  in_show do
    attributes :name, :description
    action_button :close, label: 'Close', href: dashboard_example_close_path
  end
end

“‘



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/faalis/dashboard/sections/resource_show.rb', line 74

def in_show(&block)
  name  = controller_name
  path  = controller_path.gsub(name, '').gsub(/dashboard\//, '')
  model = "#{path}#{name}".classify.constantize
  show_props = Faalis::Dashboard::DSL::Show.new(model)

  unless block_given?
    fail ArgumentError, "You have to provide a block for 'in_show'"
  end

  show_props.instance_eval(&block) if block_given?

  define_method(:show_properties) do
    unless defined? @__show_props__
      instance_exec(show_props, &block)
      @__show_props__ = show_props
    end
    return @__show_props__
  end
end