Skip to content

Commit

Permalink
Begin implementation of singular resources
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed May 17, 2018
1 parent 0cad70f commit e8b220c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/trestle/admin.rb
Expand Up @@ -65,14 +65,18 @@ def controller_namespace
"#{name.underscore}/admin"
end

def path(action=:index, options={})
def path(action=root_action, options={})
Engine.routes.url_for(options.merge(controller: controller_namespace, action: action, only_path: true))
end

def actions
[:index]
end

def root_action
:index
end

def routes
admin = self

Expand Down
19 changes: 18 additions & 1 deletion lib/trestle/resource.rb
Expand Up @@ -99,19 +99,36 @@ def actions
@actions ||= (readonly? ? READONLY_ACTIONS : RESOURCE_ACTIONS).dup
end

def root_action
singular? ? :show : :index
end

def readonly?
options[:readonly]
end

def singular?
options[:singular]
end

def default_breadcrumb
Breadcrumb.new(I18n.t("admin.breadcrumbs.#{admin_name}", default: model_name.plural.titleize), path)
end

def routes
admin = self

resource_method = singular? ? :resource : :resources
resource_name = admin_name
resource_options = {
controller: controller_namespace,
as: route_name,
path: options[:path],
except: (RESOURCE_ACTIONS - actions)
}

Proc.new do
resources admin.admin_name, controller: admin.controller_namespace, as: admin.route_name, path: admin.options[:path], except: (RESOURCE_ACTIONS - admin.actions) do
public_send(resource_method, resource_name, resource_options) do
instance_exec(&admin.additional_routes) if admin.additional_routes
end
end
Expand Down

0 comments on commit e8b220c

Please sign in to comment.