Class: Trestle::Admin
- Inherits:
-
Object
show all
- Defined in:
- lib/trestle/admin.rb,
lib/trestle/admin/builder.rb
Defined Under Namespace
Classes: Builder
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context = nil) ⇒ Admin
Returns a new instance of Admin.
7
8
9
|
# File 'lib/trestle/admin.rb', line 7
def initialize(context=nil)
@context = context
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Delegate all missing methods to corresponding class method if available
12
13
14
15
16
17
18
|
# File 'lib/trestle/admin.rb', line 12
def method_missing(name, *args, &block)
if self.class.respond_to?(name)
self.class.send(name, *args, &block)
else
super
end
end
|
Class Attribute Details
.breadcrumb ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/trestle/admin.rb', line 58
def breadcrumb
if @breadcrumb
Breadcrumb.cast(@breadcrumb.call)
else
default_breadcrumb
end
end
|
Returns the value of attribute form.
27
28
29
|
# File 'lib/trestle/admin.rb', line 27
def form
@form
end
|
Returns the value of attribute menu.
25
26
27
|
# File 'lib/trestle/admin.rb', line 25
def
@menu
end
|
.options ⇒ Object
32
33
34
|
# File 'lib/trestle/admin.rb', line 32
def options
@options ||= {}
end
|
.view_path ⇒ Object
107
108
109
|
# File 'lib/trestle/admin.rb', line 107
def view_path
@view_path || default_view_path
end
|
Class Method Details
.actions ⇒ Object
131
132
133
|
# File 'lib/trestle/admin.rb', line 131
def actions
[:index]
end
|
.additional_routes ⇒ Object
139
140
141
|
# File 'lib/trestle/admin.rb', line 139
def additional_routes
@additional_routes ||= []
end
|
.admin_name ⇒ Object
73
74
75
|
# File 'lib/trestle/admin.rb', line 73
def admin_name
name.underscore.sub(/_admin$/, '')
end
|
.build(&block) ⇒ Object
161
162
163
|
# File 'lib/trestle/admin.rb', line 161
def build(&block)
Admin::Builder.build(self, &block)
end
|
.controller_namespace ⇒ Object
119
120
121
|
# File 'lib/trestle/admin.rb', line 119
def controller_namespace
"#{name.underscore}/admin"
end
|
.default_breadcrumb ⇒ Object
66
67
68
69
70
71
|
# File 'lib/trestle/admin.rb', line 66
def default_breadcrumb
deprecated = I18n.t(:"admin.breadcrumbs.#{i18n_key}", default: human_admin_name)
label = translate("breadcrumbs.index", default: deprecated)
Breadcrumb.new(label, path)
end
|
.default_human_admin_name ⇒ Object
85
86
87
|
# File 'lib/trestle/admin.rb', line 85
def default_human_admin_name
name.demodulize.underscore.sub(/_admin$/, '').titleize
end
|
.default_view_path ⇒ Object
111
112
113
|
# File 'lib/trestle/admin.rb', line 111
def default_view_path
"admin/#{name.underscore.sub(/_admin$/, '')}"
end
|
.hooks ⇒ Object
40
41
42
|
# File 'lib/trestle/admin.rb', line 40
def hooks
@hooks ||= Hook::Set.new
end
|
.human_admin_name ⇒ Object
81
82
83
|
# File 'lib/trestle/admin.rb', line 81
def human_admin_name
translate("name", default: default_human_admin_name)
end
|
.i18n_key ⇒ Object
77
78
79
|
# File 'lib/trestle/admin.rb', line 77
def i18n_key
admin_name
end
|
.parameter_name ⇒ Object
97
98
99
|
# File 'lib/trestle/admin.rb', line 97
def parameter_name
unscope_path(admin_name.singularize)
end
|
.path(action = root_action, options = {}) ⇒ Object
123
124
125
|
# File 'lib/trestle/admin.rb', line 123
def path(action=root_action, options={})
Engine.routes.url_for(options.merge(controller: controller_namespace, action: action, only_path: true))
end
|
.railtie_routes_url_helpers(include_path_helpers = true) ⇒ Object
157
158
159
|
# File 'lib/trestle/admin.rb', line 157
def railtie_routes_url_helpers(include_path_helpers=true)
Trestle.railtie_routes_url_helpers(include_path_helpers)
end
|
.root_action ⇒ Object
135
136
137
|
# File 'lib/trestle/admin.rb', line 135
def root_action
:index
end
|
.route_name ⇒ Object
101
102
103
|
# File 'lib/trestle/admin.rb', line 101
def route_name
"#{admin_name.tr('/', '_')}_admin"
end
|
.routes ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/trestle/admin.rb', line 143
def routes
admin = self
Proc.new do
scope controller: admin.controller_namespace, path: admin.options[:path] || admin.admin_name do
get "", action: "index", as: admin.route_name
admin.additional_routes.each do |block|
instance_exec(&block)
end
end
end
end
|
.table ⇒ Object
Deprecated: Use ‘tables` instead
45
46
47
|
# File 'lib/trestle/admin.rb', line 45
def table
tables[:index]
end
|
.table=(table) ⇒ Object
Deprecated: Use ‘tables=` instead
50
51
52
|
# File 'lib/trestle/admin.rb', line 50
def table=(table)
tables[:index] = table
end
|
.tables ⇒ Object
36
37
38
|
# File 'lib/trestle/admin.rb', line 36
def tables
@tables ||= {}
end
|
.to_param ⇒ Object
127
128
129
|
# File 'lib/trestle/admin.rb', line 127
def to_param(*)
raise NoMethodError, "#to_param called on non-resourceful admin. You may need to explicitly specify the admin."
end
|
.translate(key, options = {}) ⇒ Object
Also known as:
t
89
90
91
92
93
94
|
# File 'lib/trestle/admin.rb', line 89
def translate(key, options={})
defaults = [:"admin.#{i18n_key}.#{key}", :"admin.#{key}"]
defaults << options[:default] if options[:default]
I18n.t(defaults.shift, **options.merge(default: defaults))
end
|
.validate! ⇒ Object
165
166
167
|
# File 'lib/trestle/admin.rb', line 165
def validate!
end
|
.view_path_prefixes ⇒ Object
115
116
117
|
# File 'lib/trestle/admin.rb', line 115
def view_path_prefixes
[view_path]
end
|
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
20
21
22
|
# File 'lib/trestle/admin.rb', line 20
def respond_to_missing?(name, include_private=false)
self.class.respond_to?(name, include_private) || super
end
|