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.
5
6
7
|
# File 'lib/trestle/admin.rb', line 5
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
10
11
12
13
14
15
16
|
# File 'lib/trestle/admin.rb', line 10
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
57
58
59
60
61
62
63
|
# File 'lib/trestle/admin.rb', line 57
def breadcrumb
if @breadcrumb
Breadcrumb.cast(@breadcrumb.call)
elsif actions.include?(:index)
default_breadcrumb
end
end
|
Returns the value of attribute form.
26
27
28
|
# File 'lib/trestle/admin.rb', line 26
def form
@form
end
|
Returns the value of attribute menu.
24
25
26
|
# File 'lib/trestle/admin.rb', line 24
def
@menu
end
|
.options ⇒ Object
31
32
33
|
# File 'lib/trestle/admin.rb', line 31
def options
@options ||= {}
end
|
.view_path ⇒ Object
106
107
108
|
# File 'lib/trestle/admin.rb', line 106
def view_path
@view_path || default_view_path
end
|
Class Method Details
.actions ⇒ Object
140
141
142
|
# File 'lib/trestle/admin.rb', line 140
def actions
@actions ||= default_actions.dup
end
|
.additional_routes ⇒ Object
148
149
150
|
# File 'lib/trestle/admin.rb', line 148
def additional_routes
@additional_routes ||= []
end
|
.admin_name ⇒ Object
72
73
74
|
# File 'lib/trestle/admin.rb', line 72
def admin_name
name.underscore.sub(/_admin$/, '')
end
|
.build(&block) ⇒ Object
170
171
172
|
# File 'lib/trestle/admin.rb', line 170
def build(&block)
Admin::Builder.build(self, &block)
end
|
.controller_namespace ⇒ Object
118
119
120
|
# File 'lib/trestle/admin.rb', line 118
def controller_namespace
"#{name.underscore}/admin"
end
|
.default_actions ⇒ Object
136
137
138
|
# File 'lib/trestle/admin.rb', line 136
def default_actions
[:index]
end
|
.default_breadcrumb ⇒ Object
65
66
67
68
69
70
|
# File 'lib/trestle/admin.rb', line 65
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
84
85
86
|
# File 'lib/trestle/admin.rb', line 84
def default_human_admin_name
name.demodulize.underscore.sub(/_admin$/, '').titleize
end
|
.default_view_path ⇒ Object
110
111
112
|
# File 'lib/trestle/admin.rb', line 110
def default_view_path
"admin/#{name.underscore.sub(/_admin$/, '')}"
end
|
.hooks ⇒ Object
39
40
41
|
# File 'lib/trestle/admin.rb', line 39
def hooks
@hooks ||= Hook::Set.new
end
|
.human_admin_name ⇒ Object
80
81
82
|
# File 'lib/trestle/admin.rb', line 80
def human_admin_name
translate("name", default: default_human_admin_name)
end
|
.i18n_key ⇒ Object
76
77
78
|
# File 'lib/trestle/admin.rb', line 76
def i18n_key
admin_name
end
|
.parameter_name ⇒ Object
96
97
98
|
# File 'lib/trestle/admin.rb', line 96
def parameter_name
unscope_path(admin_name.singularize)
end
|
.path(action = nil, options = {}) ⇒ Object
122
123
124
125
126
127
128
129
130
|
# File 'lib/trestle/admin.rb', line 122
def path(action=nil, options={})
defaults = {
controller: controller_namespace,
action: action || root_action,
only_path: true
}
Engine.routes.url_for(defaults.merge(options))
end
|
.railtie_routes_url_helpers(include_path_helpers = true) ⇒ Object
166
167
168
|
# File 'lib/trestle/admin.rb', line 166
def railtie_routes_url_helpers(include_path_helpers=true)
Trestle.railtie_routes_url_helpers(include_path_helpers)
end
|
.root_action ⇒ Object
144
145
146
|
# File 'lib/trestle/admin.rb', line 144
def root_action
:index
end
|
.route_name ⇒ Object
100
101
102
|
# File 'lib/trestle/admin.rb', line 100
def route_name
"#{admin_name.tr('/', '_')}_admin"
end
|
.routes ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/trestle/admin.rb', line 152
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 if admin.actions.include?(:index)
admin.additional_routes.each do |block|
instance_exec(&block)
end
end
end
end
|
.table ⇒ Object
Deprecated: Use ‘tables` instead
44
45
46
|
# File 'lib/trestle/admin.rb', line 44
def table
tables[:index]
end
|
.table=(table) ⇒ Object
Deprecated: Use ‘tables=` instead
49
50
51
|
# File 'lib/trestle/admin.rb', line 49
def table=(table)
tables[:index] = table
end
|
.tables ⇒ Object
35
36
37
|
# File 'lib/trestle/admin.rb', line 35
def tables
@tables ||= {}
end
|
.to_param ⇒ Object
132
133
134
|
# File 'lib/trestle/admin.rb', line 132
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
88
89
90
91
92
93
|
# File 'lib/trestle/admin.rb', line 88
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
174
175
176
|
# File 'lib/trestle/admin.rb', line 174
def validate!
end
|
.view_path_prefixes ⇒ Object
114
115
116
|
# File 'lib/trestle/admin.rb', line 114
def view_path_prefixes
[view_path]
end
|
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
19
20
21
|
# File 'lib/trestle/admin.rb', line 19
def respond_to_missing?(name, include_private=false)
self.class.respond_to?(name, include_private) || super
end
|