Class: Trestle::Admin::Builder
- Defined in:
- lib/trestle/admin/builder.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #admin(&block) ⇒ Object
- #breadcrumb(label = nil, path = nil, &block) ⇒ Object
- #controller(&block) ⇒ Object
- #form(options = {}, &block) ⇒ Object
- #hook(name, options = {}, &block) ⇒ Object
-
#initialize(admin) ⇒ Builder
constructor
A new instance of Builder.
- #menu(*args, &block) ⇒ Object
- #remove_action(*actions) ⇒ Object
- #routes(&block) ⇒ Object
- #table(name_or_options = {}, options = {}, &block) ⇒ Object
Methods inherited from Builder
Constructor Details
#initialize(admin) ⇒ Builder
Returns a new instance of Builder.
14 15 16 |
# File 'lib/trestle/admin/builder.rb', line 14 def initialize(admin) @admin, @controller = admin, admin.const_get(:AdminController) end |
Class Method Details
.create(name, options = {}, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/trestle/admin/builder.rb', line 18 def self.create(name, ={}, &block) # Create admin subclass admin = Class.new(admin_class) admin. = # Define a constant based on the admin name scope = [:scope] || Object scope.const_set("#{name.to_s.camelize}Admin", admin) # Define admin controller class # This is done using class_eval rather than Class.new so that the full # class name and parent chain is set when Rails' inherited hooks are called. admin.class_eval("class AdminController < #{controller.call.name}; end") # Set a reference on the controller class to the admin class controller = admin.const_get(:AdminController) controller.instance_variable_set("@admin", admin) admin.build(&block) admin.validate! admin end |
Instance Method Details
#admin(&block) ⇒ Object
67 68 69 70 |
# File 'lib/trestle/admin/builder.rb', line 67 def admin(&block) @admin.instance_eval(&block) if block_given? @admin end |
#breadcrumb(label = nil, path = nil, &block) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/trestle/admin/builder.rb', line 81 def (label=nil, path=nil, &block) if block_given? @admin. = block elsif label @admin. = -> { Breadcrumb.new(label, path) } else @admin. = -> { false } end end |
#controller(&block) ⇒ Object
72 73 74 75 |
# File 'lib/trestle/admin/builder.rb', line 72 def controller(&block) @controller.class_eval(&block) if block_given? @controller end |
#form(options = {}, &block) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/trestle/admin/builder.rb', line 55 def form(={}, &block) if block_given? admin.form = Form.new(, &block) else admin.form = Form::Automatic.new(admin, ) end end |
#hook(name, options = {}, &block) ⇒ Object
63 64 65 |
# File 'lib/trestle/admin/builder.rb', line 63 def hook(name, ={}, &block) admin.hooks.append(name, , &block) end |
#menu(*args, &block) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/trestle/admin/builder.rb', line 42 def (*args, &block) if block_given? admin. = Navigation::Block.new(admin, &block) else { item(*args) } end end |
#remove_action(*actions) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/trestle/admin/builder.rb', line 91 def remove_action(*actions) actions.each do |action| controller.remove_possible_method(action.to_sym) @admin.actions.delete(action.to_sym) end end |
#routes(&block) ⇒ Object
77 78 79 |
# File 'lib/trestle/admin/builder.rb', line 77 def routes(&block) @admin.additional_routes << block end |