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
56
57
58
59
60
61
62
|
# File 'lib/trestle/admin.rb', line 56
def breadcrumb
if @breadcrumb
Breadcrumb.cast(@breadcrumb.call)
elsif actions.include?(:index)
default_breadcrumb
end
end
|
Returns the value of attribute form.
25
26
27
|
# File 'lib/trestle/admin.rb', line 25
def form
@form
end
|
Returns the value of attribute menu.
23
24
25
|
# File 'lib/trestle/admin.rb', line 23
def
@menu
end
|
.options ⇒ Object
30
31
32
|
# File 'lib/trestle/admin.rb', line 30
def options
@options ||= {}
end
|
.view_path ⇒ Object
105
106
107
|
# File 'lib/trestle/admin.rb', line 105
def view_path
@view_path || default_view_path
end
|
Class Method Details
.actions ⇒ Object
133
134
135
|
# File 'lib/trestle/admin.rb', line 133
def actions
@actions ||= default_actions.dup
end
|
.additional_routes ⇒ Object
141
142
143
|
# File 'lib/trestle/admin.rb', line 141
def additional_routes
@additional_routes ||= []
end
|
.admin_name ⇒ Object
71
72
73
|
# File 'lib/trestle/admin.rb', line 71
def admin_name
name.underscore.sub(/_admin$/, '')
end
|
.build(&block) ⇒ Object
163
164
165
|
# File 'lib/trestle/admin.rb', line 163
def build(&block)
Admin::Builder.build(self, &block)
end
|
.controller_namespace ⇒ Object
117
118
119
|
# File 'lib/trestle/admin.rb', line 117
def controller_namespace
"#{name.underscore}/admin"
end
|
.default_actions ⇒ Object
129
130
131
|
# File 'lib/trestle/admin.rb', line 129
def default_actions
[:index]
end
|
.default_breadcrumb ⇒ Object
64
65
66
67
68
69
|
# File 'lib/trestle/admin.rb', line 64
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
83
84
85
|
# File 'lib/trestle/admin.rb', line 83
def default_human_admin_name
name.demodulize.underscore.sub(/_admin$/, '').titleize
end
|
.default_view_path ⇒ Object
109
110
111
|
# File 'lib/trestle/admin.rb', line 109
def default_view_path
"admin/#{name.underscore.sub(/_admin$/, '')}"
end
|
.hooks ⇒ Object
38
39
40
|
# File 'lib/trestle/admin.rb', line 38
def hooks
@hooks ||= Hook::Set.new
end
|
.human_admin_name ⇒ Object
79
80
81
|
# File 'lib/trestle/admin.rb', line 79
def human_admin_name
translate("name", default: default_human_admin_name)
end
|
.i18n_key ⇒ Object
75
76
77
|
# File 'lib/trestle/admin.rb', line 75
def i18n_key
admin_name
end
|
.parameter_name ⇒ Object
95
96
97
|
# File 'lib/trestle/admin.rb', line 95
def parameter_name
unscope_path(admin_name.singularize)
end
|
.path(action = root_action, options = {}) ⇒ Object
121
122
123
|
# File 'lib/trestle/admin.rb', line 121
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
159
160
161
|
# File 'lib/trestle/admin.rb', line 159
def railtie_routes_url_helpers(include_path_helpers=true)
Trestle.railtie_routes_url_helpers(include_path_helpers)
end
|
.root_action ⇒ Object
137
138
139
|
# File 'lib/trestle/admin.rb', line 137
def root_action
:index
end
|
.route_name ⇒ Object
99
100
101
|
# File 'lib/trestle/admin.rb', line 99
def route_name
"#{admin_name.tr('/', '_')}_admin"
end
|
.routes ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/trestle/admin.rb', line 145
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
43
44
45
|
# File 'lib/trestle/admin.rb', line 43
def table
tables[:index]
end
|
.table=(table) ⇒ Object
Deprecated: Use ‘tables=` instead
48
49
50
|
# File 'lib/trestle/admin.rb', line 48
def table=(table)
tables[:index] = table
end
|
.tables ⇒ Object
34
35
36
|
# File 'lib/trestle/admin.rb', line 34
def tables
@tables ||= {}
end
|
.to_param ⇒ Object
125
126
127
|
# File 'lib/trestle/admin.rb', line 125
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
87
88
89
90
91
92
|
# File 'lib/trestle/admin.rb', line 87
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
167
168
169
|
# File 'lib/trestle/admin.rb', line 167
def validate!
end
|
.view_path_prefixes ⇒ Object
113
114
115
|
# File 'lib/trestle/admin.rb', line 113
def view_path_prefixes
[view_path]
end
|
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
18
19
20
|
# File 'lib/trestle/admin.rb', line 18
def respond_to_missing?(name, include_private=false)
self.class.respond_to?(name, include_private) || super
end
|