godmin 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +5 -0
- data/README.md +5 -11
- data/app/views/godmin/application/welcome.html.erb +4 -52
- data/app/views/godmin/resource/_filters.html.erb +1 -1
- data/app/views/godmin/resource/_table.html.erb +2 -2
- data/app/views/layouts/godmin/_layout.html.erb +2 -2
- data/app/views/layouts/godmin/application.html.erb +2 -2
- data/godmin.gemspec +4 -1
- data/lib/generators/godmin/install/install_generator.rb +0 -10
- data/lib/godmin.rb +3 -6
- data/lib/godmin/application_controller.rb +8 -4
- data/lib/godmin/authorization.rb +1 -1
- data/lib/godmin/authorization/policy_finder.rb +4 -3
- data/lib/godmin/engine_wrapper.rb +49 -0
- data/lib/godmin/helpers/tables.rb +6 -6
- data/lib/godmin/resolver.rb +32 -36
- data/lib/godmin/version.rb +1 -1
- data/test/dummy/admin/Rakefile +24 -0
- data/test/dummy/admin/admin.gemspec +15 -0
- data/test/dummy/admin/app/assets/javascripts/admin/application.js +14 -0
- data/test/dummy/admin/app/assets/stylesheets/admin/application.css +16 -0
- data/test/dummy/admin/app/controllers/admin/application_controller.rb +5 -0
- data/test/dummy/admin/app/controllers/admin/articles_controller.rb +7 -0
- data/test/dummy/admin/app/helpers/admin/application_helper.rb +4 -0
- data/test/dummy/admin/app/services/admin/article_service.rb +11 -0
- data/test/dummy/{app/assets/images → admin/app/views/admin/articles}/.keep +0 -0
- data/test/dummy/{app/mailers → admin/app/views/admin/articles/columns}/.keep +0 -0
- data/test/dummy/admin/app/views/admin/articles/filters/.keep +0 -0
- data/test/dummy/admin/app/views/admin/resource/.keep +0 -0
- data/test/dummy/admin/app/views/admin/resource/columns/.keep +0 -0
- data/test/dummy/admin/app/views/admin/resource/filters/.keep +0 -0
- data/test/dummy/admin/app/views/admin/shared/_navigation.html.erb +1 -0
- data/test/dummy/admin/bin/rails +12 -0
- data/test/dummy/admin/config/routes.rb +4 -0
- data/test/dummy/admin/lib/admin.rb +4 -0
- data/test/dummy/admin/lib/admin/engine.rb +5 -0
- data/test/dummy/admin/lib/admin/version.rb +3 -0
- data/test/dummy/app/assets/javascripts/application.js +1 -0
- data/test/dummy/app/assets/stylesheets/application.css +2 -1
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/controllers/articles_controller.rb +3 -0
- data/test/dummy/app/models/article.rb +2 -0
- data/test/dummy/app/services/article_service.rb +9 -0
- data/test/dummy/app/views/articles/.keep +0 -0
- data/test/dummy/app/views/articles/columns/.keep +0 -0
- data/test/dummy/app/views/articles/filters/.keep +0 -0
- data/test/dummy/app/views/resource/.keep +0 -0
- data/test/dummy/app/views/resource/columns/.keep +0 -0
- data/test/dummy/app/views/resource/filters/.keep +0 -0
- data/test/dummy/app/views/shared/_navigation.html.erb +1 -0
- data/test/dummy/config/database.yml +0 -6
- data/test/dummy/config/environments/test.rb +4 -0
- data/test/dummy/config/routes.rb +3 -2
- data/test/dummy/db/migrate/20150717121532_create_articles.rb +11 -0
- data/test/dummy/db/schema.rb +9 -1
- data/test/fakes/article.rb +4 -0
- data/test/fakes/article_service.rb +68 -0
- data/test/integration/column_ordering_test.rb +23 -0
- data/test/integration/column_overriding_test.rb +59 -0
- data/test/integration/filter_overriding_test.rb +51 -0
- data/test/integration/partial_overriding_test.rb +51 -0
- data/test/integration/template_overriding_test.rb +51 -0
- data/test/integration/welcome_test.rb +8 -0
- data/test/lib/godmin/engine_wrapper_test.rb +55 -0
- data/test/lib/godmin/policy_finder_test.rb +30 -34
- data/test/lib/godmin/resolver_test.rb +26 -36
- data/test/lib/godmin/resources/resource_service/batch_actions_test.rb +1 -1
- data/test/lib/godmin/resources/resource_service/filters_test.rb +1 -1
- data/test/lib/godmin/resources/resource_service/pagination_test.rb +1 -1
- data/test/lib/godmin/resources/resource_service/scopes_test.rb +7 -7
- data/test/lib/godmin/resources/resource_service_test.rb +2 -2
- data/test/test_helper.rb +23 -66
- metadata +127 -20
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config/environments/production.rb +0 -80
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/godmin_test.rb +0 -7
- data/test/integration/navigation_test.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b77a64dfd0387ecd63d1b0dc2259a977cefcb664
|
4
|
+
data.tar.gz: a97772f66980a9d1d9def89509f1d24868337bf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5baf4c943138e0fc2195ca47c710ac0d4a7d4892564ae6a9c3bfedaca6fa7a650a892b12a14e7ba021d4a34db73e4b458fca4c1f5612bf84d83c3a46a48c5e32
|
7
|
+
data.tar.gz: 924ead99ee3ff13a41c58d10f5dc5bf5b5c2857e8144c28643461e1ff271841e2f770d56fd4b2665d1b32ed5033c243bc4c86fed7a6811dc54a544deaaef66d4
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 0.12.1 - 2015-09-07
|
4
|
+
Bug fixes
|
5
|
+
- Fixes issue where column ordering on index table didn't work (https://github.com/varvet/godmin/issues/124)
|
6
|
+
|
7
|
+
Other
|
8
|
+
- Adds integration tests
|
9
|
+
- Removes the namespace config in `initializers/godmin.rb`
|
10
|
+
|
11
|
+
In order to upgrade:
|
12
|
+
- Remove the `initializers/godmin.rb` file
|
13
|
+
|
3
14
|
### 0.12.0 - 2015-06-30
|
4
15
|
Features
|
5
16
|
- Adds new navigation helpers for building a custom navbar (https://github.com/varvet/godmin/issues/54)
|
data/Gemfile
CHANGED
@@ -9,3 +9,8 @@ gemspec
|
|
9
9
|
# your gemspec. These might include edge Rails or gems from your path or
|
10
10
|
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
11
|
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# The dummy app loads whatever is specified in this gemfile, therefore
|
14
|
+
# we add the admin engine used by the dummy app here
|
15
|
+
gem "admin", path: "test/dummy/admin", group: [:test, :development]
|
16
|
+
gem "codeclimate-test-reporter", group: :test, require: nil
|
data/README.md
CHANGED
@@ -3,8 +3,11 @@
|
|
3
3
|
[![Gem Version](http://img.shields.io/gem/v/godmin.svg)](https://rubygems.org/gems/godmin)
|
4
4
|
[![Build Status](https://img.shields.io/travis/varvet/godmin/master.svg)](https://travis-ci.org/varvet/godmin)
|
5
5
|
[![Code Climate](https://img.shields.io/codeclimate/github/varvet/godmin.svg)](https://codeclimate.com/github/varvet/godmin)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/varvet/godmin/badges/coverage.svg)](https://codeclimate.com/github/varvet/godmin/coverage)
|
6
7
|
|
7
|
-
Godmin is an admin framework for Rails 4+.
|
8
|
+
Godmin is an admin framework for Rails 4+. Use it to build dedicated admin sections for your apps, or stand alone admin apps such as internal tools. It has support for common features such as scoping, filtering and performing batch actions on your models.
|
9
|
+
|
10
|
+
Godmin differs from tools like [ActiveAdmin](http://activeadmin.info/) and [RailsAdmin](https://github.com/sferik/rails_admin) in how admin sections are created. Rather than being DSL-based, Godmin is a set of opt-in modules and helpers that can be applied to regular Rails apps and engines. An admin section built with Godmin is just that, a regular Rails app or Rails engine, with regular routes, controllers and views. That means there is less to learn, because you already know most of it, and fewer constraints on what you can do. After all, administrators are users too, and what better way to provide them with a tailor made experience than building them a Rails app?
|
8
11
|
|
9
12
|
![Screenshot](https://raw.githubusercontent.com/varvet/godmin/master/screenshot.png)
|
10
13
|
|
@@ -23,7 +26,7 @@ Godmin is an admin framework for Rails 4+.
|
|
23
26
|
- [Exporting](#exporting)
|
24
27
|
- [Views](#views)
|
25
28
|
- [Forms](#forms)
|
26
|
-
|
29
|
+
- [Navigation](#navigation)
|
27
30
|
- [Authentication](#authentication)
|
28
31
|
- [Built in authentication](#built-in-authentication)
|
29
32
|
- [Shared authentication](#shared-authentication)
|
@@ -92,15 +95,6 @@ Godmin should be up and running at `localhost:3000/admin`
|
|
92
95
|
|
93
96
|
Installing Godmin does a number of things to the Rails application.
|
94
97
|
|
95
|
-
A `config/initializers/godmin.rb` is created:
|
96
|
-
```ruby
|
97
|
-
Godmin.configure do |config|
|
98
|
-
config.namespace = nil
|
99
|
-
end
|
100
|
-
```
|
101
|
-
|
102
|
-
If Godmin was installed inside an engine, as in the previous section, the namespace is the underscored name of the engine, e.g. `"admin"`.
|
103
|
-
|
104
98
|
The application controller is modified as such:
|
105
99
|
```ruby
|
106
100
|
class ApplicationController < ActionController::Base
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<div class="row">
|
2
|
-
<div class="col-md-
|
2
|
+
<div class="col-md-6 col-md-offset-3">
|
3
3
|
<div class="jumbotron">
|
4
|
-
<h1>Welcome
|
4
|
+
<h1>Welcome</h1>
|
5
5
|
<p>
|
6
|
-
You are
|
7
|
-
|
6
|
+
You are running Godmin <%= Godmin::VERSION %>.
|
7
|
+
Add your own root route to the routes file in order to remove this page.
|
8
8
|
</p>
|
9
9
|
<p>
|
10
10
|
<a href="https://github.com/varvet/godmin/" class="btn btn-primary btn-lg" role="button">
|
@@ -13,53 +13,5 @@
|
|
13
13
|
</a>
|
14
14
|
</p>
|
15
15
|
</div>
|
16
|
-
<div class="row">
|
17
|
-
<div class="col-md-6">
|
18
|
-
<div class="panel panel-default">
|
19
|
-
<div class="panel-heading">Scopes</div>
|
20
|
-
<div class="panel-body">
|
21
|
-
<p>Scopes are a way of sectioning resources, useful for quick navigation.</p>
|
22
|
-
<%= link_to "Read more about scopes", "#" %>
|
23
|
-
</div>
|
24
|
-
</div>
|
25
|
-
</div>
|
26
|
-
<div class="col-md-6">
|
27
|
-
<div class="panel panel-default">
|
28
|
-
<div class="panel-heading">Filters</div>
|
29
|
-
<div class="panel-body">
|
30
|
-
<p>Filters offer great flexibility when it comes to searching for resources.</p>
|
31
|
-
<%= link_to "Read more about filters", "#" %>
|
32
|
-
</div>
|
33
|
-
</div>
|
34
|
-
</div>
|
35
|
-
</div>
|
36
|
-
<div class="row">
|
37
|
-
<div class="col-md-6">
|
38
|
-
<div class="panel panel-default">
|
39
|
-
<div class="panel-heading">Batch actions</div>
|
40
|
-
<div class="panel-body">
|
41
|
-
<p>Batch actions are an easy way to perform the same action on multiple resources.</p>
|
42
|
-
<%= link_to "Read more about batch actions", "#" %>
|
43
|
-
</div>
|
44
|
-
</div>
|
45
|
-
</div>
|
46
|
-
<div class="col-md-6">
|
47
|
-
<div class="panel panel-default">
|
48
|
-
<div class="panel-heading">Resource fetching</div>
|
49
|
-
<div class="panel-body">
|
50
|
-
<p>Control which resources to fetch, and apply arbitrary conditions, such as sorting.</p>
|
51
|
-
<%= link_to "Read more about resource fetching", "#" %>
|
52
|
-
</div>
|
53
|
-
</div>
|
54
|
-
</div>
|
55
|
-
</div>
|
56
|
-
</div>
|
57
|
-
<div class="col-md-4">
|
58
|
-
<div class="panel panel-default">
|
59
|
-
<div class="panel-heading">Version</div>
|
60
|
-
<div class="panel-body">
|
61
|
-
You are running Godmin <%= Godmin::VERSION %>
|
62
|
-
</div>
|
63
|
-
</div>
|
64
16
|
</div>
|
65
17
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<%= f.hidden_field :order, value: params[:order] %>
|
7
7
|
|
8
8
|
<% @resource_service.filter_map.each do |name, options| %>
|
9
|
-
<%= partial_override "filters/#{name}", f: f, name: name, options: options do %>
|
9
|
+
<%= partial_override "#{controller_path}/filters/#{name}", f: f, name: name, options: options do %>
|
10
10
|
<%= f.filter_field(name, options) %>
|
11
11
|
<% end %>
|
12
12
|
<% end %>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<th></th>
|
7
7
|
<% end %>
|
8
8
|
<% @resource_service.attrs_for_index.each do |attr| %>
|
9
|
-
<th>
|
9
|
+
<th class="column-<%= attr %>">
|
10
10
|
<%= column_header attr %>
|
11
11
|
</th>
|
12
12
|
<% end %>
|
@@ -28,7 +28,7 @@
|
|
28
28
|
</td>
|
29
29
|
<% end %>
|
30
30
|
<td>
|
31
|
-
<%= render partial: "columns/actions", locals: { resource: resource } %>
|
31
|
+
<%= render partial: "#{controller_path}/columns/actions", locals: { resource: resource } %>
|
32
32
|
</td>
|
33
33
|
</tr>
|
34
34
|
<% end %>
|
@@ -2,8 +2,8 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title><%= t("godmin.title") %></title>
|
5
|
-
<%= stylesheet_link_tag
|
6
|
-
<%= javascript_include_tag
|
5
|
+
<%= stylesheet_link_tag File.join(engine_wrapper.namespaced_path, "application").gsub(/^\//, ""), media: "all" %>
|
6
|
+
<%= javascript_include_tag File.join(engine_wrapper.namespaced_path, "application").gsub(/^\//, "") %>
|
7
7
|
<%= csrf_meta_tags %>
|
8
8
|
<%= yield :head %>
|
9
9
|
</head>
|
@@ -6,10 +6,10 @@
|
|
6
6
|
</div>
|
7
7
|
<div class="collapse navbar-collapse">
|
8
8
|
<ul class="nav navbar-nav">
|
9
|
-
<%= render partial: "shared/navigation" %>
|
9
|
+
<%= render partial: File.join(engine_wrapper.namespaced_path, "shared/navigation") %>
|
10
10
|
</ul>
|
11
11
|
<ul class="nav navbar-nav navbar-right">
|
12
|
-
<%= render partial: "shared/navigation_aside" %>
|
12
|
+
<%= render partial: File.join(engine_wrapper.namespaced_path, "shared/navigation_aside") %>
|
13
13
|
</ul>
|
14
14
|
</div>
|
15
15
|
</div>
|
data/godmin.gemspec
CHANGED
@@ -24,13 +24,16 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_dependency "bootstrap_form", "~> 2.2.0"
|
25
25
|
gem.add_dependency "coffee-rails", [">= 4.0", "< 4.2"]
|
26
26
|
gem.add_dependency "csv_builder", "~> 2.1.1"
|
27
|
+
gem.add_dependency "jquery-rails", ">= 3.0"
|
27
28
|
gem.add_dependency "momentjs-rails", ">= 2.8.1"
|
28
29
|
gem.add_dependency "rails", "~> 4.0"
|
29
30
|
gem.add_dependency "sass-rails", ">= 4.0"
|
30
31
|
gem.add_dependency "selectize-rails", "~> 0.12.0"
|
31
32
|
|
32
|
-
gem.add_development_dependency "
|
33
|
+
gem.add_development_dependency "capybara"
|
34
|
+
gem.add_development_dependency "m"
|
33
35
|
gem.add_development_dependency "minitest"
|
34
36
|
gem.add_development_dependency "minitest-reporters"
|
35
37
|
gem.add_development_dependency "pry"
|
38
|
+
gem.add_development_dependency "sqlite3"
|
36
39
|
end
|
@@ -1,16 +1,6 @@
|
|
1
1
|
require "godmin/generators/base"
|
2
2
|
|
3
3
|
class Godmin::InstallGenerator < Godmin::Generators::Base
|
4
|
-
def create_initializer
|
5
|
-
create_file "config/initializers/godmin.rb" do
|
6
|
-
<<-END.strip_heredoc
|
7
|
-
Godmin.configure do |config|
|
8
|
-
config.namespace = #{namespace ? "\"#{namespaced_path.join("/")}\"" : "nil"}
|
9
|
-
end
|
10
|
-
END
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
4
|
def create_routes
|
15
5
|
inject_into_file "config/routes.rb", before: /^end/ do
|
16
6
|
<<-END.strip_heredoc.indent(2)
|
data/lib/godmin.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require "bootstrap-sass"
|
2
2
|
require "bootstrap_form"
|
3
3
|
require "csv_builder"
|
4
|
+
require "jquery-rails"
|
4
5
|
require "momentjs-rails"
|
6
|
+
require "sass-rails"
|
5
7
|
require "selectize-rails"
|
6
8
|
require "godmin/application_controller"
|
7
9
|
require "godmin/authentication"
|
8
10
|
require "godmin/authorization"
|
9
11
|
require "godmin/engine"
|
12
|
+
require "godmin/engine_wrapper"
|
10
13
|
require "godmin/paginator"
|
11
14
|
require "godmin/resolver"
|
12
15
|
require "godmin/resources/resource_controller"
|
@@ -14,10 +17,4 @@ require "godmin/resources/resource_service"
|
|
14
17
|
require "godmin/version"
|
15
18
|
|
16
19
|
module Godmin
|
17
|
-
mattr_accessor :namespace
|
18
|
-
self.namespace = nil
|
19
|
-
|
20
|
-
def self.configure
|
21
|
-
yield self
|
22
|
-
end
|
23
20
|
end
|
@@ -17,8 +17,9 @@ module Godmin
|
|
17
17
|
|
18
18
|
helper_method :authentication_enabled?
|
19
19
|
helper_method :authorization_enabled?
|
20
|
+
helper_method :engine_wrapper
|
20
21
|
|
21
|
-
before_action :
|
22
|
+
before_action :append_view_paths
|
22
23
|
|
23
24
|
layout "godmin/application"
|
24
25
|
end
|
@@ -27,9 +28,12 @@ module Godmin
|
|
27
28
|
|
28
29
|
private
|
29
30
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
31
|
+
def engine_wrapper
|
32
|
+
EngineWrapper.new(self.class)
|
33
|
+
end
|
34
|
+
|
35
|
+
def append_view_paths
|
36
|
+
append_view_path Godmin::Resolver.new(controller_path, engine_wrapper)
|
33
37
|
end
|
34
38
|
|
35
39
|
def authentication_enabled?
|
data/lib/godmin/authorization.rb
CHANGED
@@ -2,9 +2,10 @@ module Godmin
|
|
2
2
|
module Authorization
|
3
3
|
class PolicyFinder
|
4
4
|
class << self
|
5
|
-
def find(object)
|
5
|
+
def find(object, namespace = nil)
|
6
6
|
return object.policy_class if object.respond_to?(:policy_class)
|
7
7
|
return object.class.policy_class if object.class.respond_to?(:policy_class)
|
8
|
+
|
8
9
|
klass =
|
9
10
|
if object.respond_to?(:model_name)
|
10
11
|
object.model_name
|
@@ -18,8 +19,8 @@ module Godmin
|
|
18
19
|
object.class
|
19
20
|
end
|
20
21
|
|
21
|
-
if
|
22
|
-
"#{
|
22
|
+
if namespace
|
23
|
+
"#{namespace}::#{klass}Policy"
|
23
24
|
else
|
24
25
|
"#{klass}Policy"
|
25
26
|
end.constantize
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Godmin
|
2
|
+
class EngineWrapper
|
3
|
+
attr_reader :engine
|
4
|
+
|
5
|
+
def initialize(controller)
|
6
|
+
@engine = find_engine(controller)
|
7
|
+
end
|
8
|
+
|
9
|
+
def namespace
|
10
|
+
@namespace ||= engine.railtie_namespace
|
11
|
+
end
|
12
|
+
|
13
|
+
def namespaced?
|
14
|
+
@namespaced ||= namespace.present?
|
15
|
+
end
|
16
|
+
|
17
|
+
def namespaced_path
|
18
|
+
@namespaced_path ||= begin
|
19
|
+
if namespaced?
|
20
|
+
namespace.name.classify.split("::").map(&:underscore)
|
21
|
+
else
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def root
|
28
|
+
engine.root
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def find_engine(controller)
|
34
|
+
engine_module = find_engine_module(controller)
|
35
|
+
|
36
|
+
if engine_module
|
37
|
+
"#{engine_module}::Engine".constantize
|
38
|
+
else
|
39
|
+
Rails.application
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_engine_module(controller)
|
44
|
+
controller.parents.find do |parent|
|
45
|
+
parent.respond_to?(:use_relative_model_naming?) && parent.use_relative_model_naming?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -4,11 +4,11 @@ module Godmin
|
|
4
4
|
def column_header(attribute)
|
5
5
|
if @resource_class.column_names.include?(attribute.to_s)
|
6
6
|
direction =
|
7
|
-
if params[:order]
|
8
|
-
if params[:order].
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
if params[:order].present?
|
8
|
+
if params[:order].match(/\A#{attribute.to_s}_(asc|desc)\z/)
|
9
|
+
$1 == "desc" ? "asc" : "desc"
|
10
|
+
elsif params[:order].match(/\A\w+_(asc|desc)\z/)
|
11
|
+
$1
|
12
12
|
end
|
13
13
|
else
|
14
14
|
"desc"
|
@@ -20,7 +20,7 @@ module Godmin
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def column_value(resource, attribute)
|
23
|
-
partial_override "columns/#{attribute}", resource: resource do
|
23
|
+
partial_override "#{controller_path}/columns/#{attribute}", resource: resource do
|
24
24
|
column_value = resource.send(attribute)
|
25
25
|
|
26
26
|
if column_value.is_a?(Date) || column_value.is_a?(Time)
|
data/lib/godmin/resolver.rb
CHANGED
@@ -1,56 +1,52 @@
|
|
1
1
|
module Godmin
|
2
2
|
class Resolver < ::ActionView::FileSystemResolver
|
3
|
-
|
3
|
+
def initialize(controller_path, engine_wrapper)
|
4
|
+
super ""
|
5
|
+
@controller_path = controller_path
|
6
|
+
@engine_wrapper = engine_wrapper
|
7
|
+
end
|
4
8
|
|
5
9
|
def find_templates(name, prefix, partial, details)
|
6
|
-
|
7
|
-
|
8
|
-
template_paths(prefix
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
templates = []
|
11
|
+
|
12
|
+
template_paths(prefix).each do |path|
|
13
|
+
if templates.present?
|
14
|
+
break
|
15
|
+
else
|
16
|
+
templates = super(name, path, partial, details)
|
17
|
+
end
|
12
18
|
end
|
13
19
|
|
14
|
-
|
20
|
+
templates
|
15
21
|
end
|
16
22
|
|
17
|
-
|
18
|
-
|
23
|
+
# Matches templates such as:
|
24
|
+
#
|
25
|
+
# { name: index, prefix: articles } => [app/views/resource/index, godmin/app/views/godmin/resource/index]
|
26
|
+
# { name: form, prefix: articles } => [app/views/resource/_form, godmin/app/views/godmin/resource/_form]
|
27
|
+
# { name: title, prefix: columns } => [app/views/resource/columns/_title]
|
28
|
+
# { name: welcome, prefix: application } => [godmin/app/views/godmin/application/welcome]
|
29
|
+
# { name: navigation, prefix: shared } => [godmin/app/views/godmin/shared/navigation]
|
30
|
+
def template_paths(prefix)
|
19
31
|
[
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
[namespace, "resource"],
|
25
|
-
[namespace]
|
26
|
-
].map { |path| path.compact.join("/") }.compact
|
32
|
+
File.join(@engine_wrapper.root, "app/views", resource_path_for_engine(prefix)),
|
33
|
+
File.join(Godmin::Engine.root, "app/views/godmin", resource_path_for_godmin(prefix)),
|
34
|
+
File.join(Godmin::Engine.root, "app/views/godmin", default_path_for_godmin(prefix))
|
35
|
+
]
|
27
36
|
end
|
28
37
|
|
29
38
|
private
|
30
39
|
|
31
|
-
def
|
32
|
-
prefix.
|
40
|
+
def resource_path_for_engine(prefix)
|
41
|
+
prefix.sub(/\A#{@controller_path}/, File.join(@engine_wrapper.namespaced_path, "resource"))
|
33
42
|
end
|
34
|
-
end
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
super [Godmin.namespace, "app/views"].compact.join("/")
|
39
|
-
self.namespace = Godmin.namespace
|
40
|
-
self.controller_name = controller_name
|
44
|
+
def resource_path_for_godmin(prefix)
|
45
|
+
prefix.sub(/\A#{@controller_path}/, "resource")
|
41
46
|
end
|
42
47
|
|
43
|
-
def
|
44
|
-
|
45
|
-
super
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class GodminResolver < Resolver
|
50
|
-
def initialize(controller_name)
|
51
|
-
super [Godmin::Engine.root, "app/views"].compact.join("/")
|
52
|
-
self.namespace = "godmin"
|
53
|
-
self.controller_name = controller_name
|
48
|
+
def default_path_for_godmin(prefix)
|
49
|
+
prefix.sub(/\A#{File.join(@engine_wrapper.namespaced_path)}/, "")
|
54
50
|
end
|
55
51
|
end
|
56
52
|
end
|