administrate 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of administrate might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/administrate/application.js +3 -0
- data/app/assets/javascripts/administrate/components/table.js +17 -0
- data/app/assets/stylesheets/administrate/_show.sass +16 -0
- data/app/assets/stylesheets/administrate/_sidebar.scss +48 -0
- data/app/assets/stylesheets/administrate/application.scss +14 -0
- data/app/assets/stylesheets/administrate/base/_base.scss +24 -0
- data/app/assets/stylesheets/administrate/base/_buttons.scss +11 -0
- data/app/assets/stylesheets/administrate/base/_forms.scss +78 -0
- data/app/assets/stylesheets/administrate/base/_grid-settings.scss +15 -0
- data/app/assets/stylesheets/administrate/base/_lists.scss +31 -0
- data/app/assets/stylesheets/administrate/base/_tables.scss +74 -0
- data/app/assets/stylesheets/administrate/base/_typography.scss +93 -0
- data/app/assets/stylesheets/administrate/base/_variables.scss +93 -0
- data/app/assets/stylesheets/administrate/base/extends/_button.scss +23 -0
- data/app/assets/stylesheets/administrate/base/extends/_clearfix.scss +3 -0
- data/app/assets/stylesheets/administrate/base/extends/_errors.scss +11 -0
- data/app/assets/stylesheets/administrate/base/extends/_flashes.scss +38 -0
- data/app/assets/stylesheets/administrate/base/extends/_hide-text.scss +3 -0
- data/app/assets/stylesheets/administrate/components/_components.scss +3 -0
- data/app/assets/stylesheets/administrate/components/_form.scss +31 -0
- data/app/assets/stylesheets/administrate/components/_header.scss +10 -0
- data/app/assets/stylesheets/administrate/components/_table.scss +11 -0
- data/app/assets/stylesheets/administrate/layout.scss +28 -0
- data/app/assets/stylesheets/administrate/mixins/_mixins.scss +1 -0
- data/app/assets/stylesheets/administrate/mixins/_shadow.scss +35 -0
- data/app/controllers/administrate/application_controller.rb +127 -0
- data/app/helpers/administrate/application_helper.rb +7 -0
- data/app/views/administrate/application/_flashes.html.erb +7 -0
- data/app/views/administrate/application/_form.html.erb +28 -0
- data/app/views/administrate/application/_javascript.html.erb +10 -0
- data/app/views/administrate/application/_sidebar.html.erb +16 -0
- data/app/views/administrate/application/_table.html.erb +44 -0
- data/app/views/administrate/application/edit.html.erb +6 -0
- data/app/views/administrate/application/index.html.erb +10 -0
- data/app/views/administrate/application/new.html.erb +6 -0
- data/app/views/administrate/application/show.html.erb +11 -0
- data/app/views/fields/form/_belongs_to.html.erb +7 -0
- data/app/views/fields/form/_email.html.erb +2 -0
- data/app/views/fields/form/_has_many.html.erb +11 -0
- data/app/views/fields/form/_image.html.erb +2 -0
- data/app/views/fields/form/_string.html.erb +2 -0
- data/app/views/fields/index/_belongs_to.html.erb +3 -0
- data/app/views/fields/index/_email.html.erb +1 -0
- data/app/views/fields/index/_has_many.html.erb +1 -0
- data/app/views/fields/index/_image.html.erb +1 -0
- data/app/views/fields/index/_string.html.erb +1 -0
- data/app/views/fields/show/_belongs_to.html.erb +3 -0
- data/app/views/fields/show/_email.html.erb +1 -0
- data/app/views/fields/show/_has_many.html.erb +5 -0
- data/app/views/fields/show/_image.html.erb +1 -0
- data/app/views/fields/show/_string.html.erb +1 -0
- data/app/views/layouts/administrate/application.html.erb +28 -0
- data/config/locales/administrate.en.yml +7 -0
- data/config/routes.rb +2 -0
- data/lib/administrate.rb +4 -0
- data/lib/administrate/base_dashboard.rb +36 -0
- data/lib/administrate/engine.rb +8 -0
- data/lib/administrate/fields/base.rb +31 -0
- data/lib/administrate/fields/belongs_to.rb +19 -0
- data/lib/administrate/fields/email.rb +8 -0
- data/lib/administrate/fields/has_many.rb +38 -0
- data/lib/administrate/fields/image.rb +8 -0
- data/lib/administrate/fields/string.rb +8 -0
- data/lib/administrate/namespace.rb +3 -0
- data/lib/administrate/pages/base.rb +28 -0
- data/lib/administrate/pages/form.rb +28 -0
- data/lib/administrate/pages/show.rb +24 -0
- data/lib/administrate/pages/table.rb +21 -0
- data/lib/administrate/version.rb +3 -0
- data/lib/generators/administrate/dashboard/USAGE +9 -0
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +44 -0
- data/lib/generators/administrate/dashboard/templates/controller.rb.erb +12 -0
- data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +50 -0
- data/lib/generators/administrate/install/install_generator.rb +52 -0
- data/lib/generators/administrate/install/templates/application_controller.rb +13 -0
- data/lib/generators/administrate/install/templates/dashboard_manifest.rb.erb +29 -0
- data/lib/generators/administrate/install/templates/routes.rb +7 -0
- data/lib/tasks/administrate_tasks.rake +4 -0
- metadata +179 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
<%= form_for([Administrate::NAMESPACE, @page.resource], class: "form") do |f| %>
|
2
|
+
<% if @page.resource.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2>
|
5
|
+
<%= pluralize(@page.resource.errors.count, "error") %>
|
6
|
+
prohibited this <%= @page.resource_name %> from being saved:
|
7
|
+
</h2>
|
8
|
+
|
9
|
+
<ul>
|
10
|
+
<% @page.resource.errors.full_messages.each do |message| %>
|
11
|
+
<li><%= message %></li>
|
12
|
+
<% end %>
|
13
|
+
</ul>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<div class="form-inputs">
|
18
|
+
<% @page.attributes.each do |attribute| -%>
|
19
|
+
<div class="form-field">
|
20
|
+
<%= render_field attribute, f: f %>
|
21
|
+
</div>
|
22
|
+
<% end -%>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div class="form-actions">
|
26
|
+
<%= f.submit %>
|
27
|
+
</div>
|
28
|
+
<% end %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<ul class="sidebar-list">
|
2
|
+
<div class="sidebar-logo">
|
3
|
+
<%= image_tag "logo.svg" %>
|
4
|
+
<h1 class="sidebar-logo-heading">Administrate</h1>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<% DashboardManifest.new.dashboards.each do |resource| %>
|
8
|
+
<li>
|
9
|
+
<%= link_to(
|
10
|
+
resource.to_s.titleize,
|
11
|
+
[Administrate::NAMESPACE, resource],
|
12
|
+
class: link_class(resource)
|
13
|
+
) %>
|
14
|
+
</li>
|
15
|
+
<% end %>
|
16
|
+
</ul>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<table>
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<% table_presenter.attribute_names.each do |attr_name| %>
|
5
|
+
<th><%= attr_name.to_s.titleize %></th>
|
6
|
+
<% end %>
|
7
|
+
<th colspan="3"></th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
|
11
|
+
<tbody>
|
12
|
+
<% resources.each do |resource| %>
|
13
|
+
<tr class="table-row"
|
14
|
+
role="link"
|
15
|
+
tabindex="0"
|
16
|
+
data-url="<%= polymorphic_path([Administrate::NAMESPACE, resource]) -%>"
|
17
|
+
>
|
18
|
+
<% table_presenter.attributes_for(resource).each do |attribute| %>
|
19
|
+
<td><%= render_field attribute %></td>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<td><%= link_to(
|
23
|
+
t("administrate.actions.show"),
|
24
|
+
[Administrate::NAMESPACE, resource],
|
25
|
+
class: "action-show",
|
26
|
+
) %></td>
|
27
|
+
|
28
|
+
<td><%= link_to(
|
29
|
+
t("administrate.actions.edit"),
|
30
|
+
[:edit, Administrate::NAMESPACE, resource],
|
31
|
+
class: "action-edit",
|
32
|
+
) %></td>
|
33
|
+
|
34
|
+
<td><%= link_to(
|
35
|
+
t("administrate.actions.destroy"),
|
36
|
+
[Administrate::NAMESPACE, resource],
|
37
|
+
class: "action-destroy",
|
38
|
+
method: :delete,
|
39
|
+
data: { confirm: t("administrate.actions.confirm") }
|
40
|
+
) %></td>
|
41
|
+
</tr>
|
42
|
+
<% end %>
|
43
|
+
</tbody>
|
44
|
+
</table>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<header class="header">
|
2
|
+
<h1 class="header-heading"><%= @page.resource_name.pluralize.titleize %></h1>
|
3
|
+
<%= link_to(
|
4
|
+
"New #{@page.resource_name.titleize.downcase}",
|
5
|
+
[:new, Administrate::NAMESPACE, @page.resource_name],
|
6
|
+
class: "button",
|
7
|
+
) %>
|
8
|
+
</header>
|
9
|
+
|
10
|
+
<%= render "table", table_presenter: @page, resources: @resources %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<header class="header">
|
2
|
+
<h1 class="header-heading"><%= @page.page_title %></h1>
|
3
|
+
<%= link_to 'Edit', [:edit, Administrate::NAMESPACE, @page.resource], class: "button" %>
|
4
|
+
</header>
|
5
|
+
|
6
|
+
<dl>
|
7
|
+
<% @page.attributes.each do |attribute| %>
|
8
|
+
<dt><%= attribute.name.titleize %></dt>
|
9
|
+
<dd><%= render_field attribute %></dd>
|
10
|
+
<% end %>
|
11
|
+
</dl>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= mail_to email.data %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= pluralize(has_many.data.count, has_many.attribute.to_s.humanize.downcase) %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= image_tag image.data %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= string.data %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= mail_to email.data %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= image_tag image.data %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= string.data %>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<meta name="ROBOTS" content="NOODP" />
|
6
|
+
<meta name="viewport" content="initial-scale=1" />
|
7
|
+
<title>Administrate</title>
|
8
|
+
<%= stylesheet_link_tag "//fonts.googleapis.com/css?family=Lato:300,400,900", media: "all" %>
|
9
|
+
<%= stylesheet_link_tag "administrate/application", media: "all" %>
|
10
|
+
<%= csrf_meta_tags %>
|
11
|
+
</head>
|
12
|
+
|
13
|
+
<body class="administrate">
|
14
|
+
<main class="main">
|
15
|
+
<div class="sidebar">
|
16
|
+
<%= render "sidebar" -%>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="content">
|
20
|
+
<%= render "flashes" -%>
|
21
|
+
|
22
|
+
<%= yield %>
|
23
|
+
|
24
|
+
<%= render "javascript" %>
|
25
|
+
</div>
|
26
|
+
</main>
|
27
|
+
</body>
|
28
|
+
</html>
|
data/config/routes.rb
ADDED
data/lib/administrate.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "administrate/fields/belongs_to"
|
2
|
+
require "administrate/fields/email"
|
3
|
+
require "administrate/fields/has_many"
|
4
|
+
require "administrate/fields/image"
|
5
|
+
require "administrate/fields/string"
|
6
|
+
|
7
|
+
module Administrate
|
8
|
+
class BaseDashboard
|
9
|
+
def permitted_attributes
|
10
|
+
form_attributes.map do |attr|
|
11
|
+
field_class(attr).permitted_attribute(attr)
|
12
|
+
end.uniq
|
13
|
+
end
|
14
|
+
|
15
|
+
def field_class(attr)
|
16
|
+
field_registry.fetch(attribute_types[attr])
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def field_registry
|
22
|
+
{
|
23
|
+
belongs_to: Administrate::Field::BelongsTo,
|
24
|
+
boolean: Administrate::Field::String,
|
25
|
+
datetime: Administrate::Field::String,
|
26
|
+
email: Administrate::Field::Email,
|
27
|
+
float: Administrate::Field::String,
|
28
|
+
has_many: Administrate::Field::HasMany,
|
29
|
+
image: Administrate::Field::Image,
|
30
|
+
integer: Administrate::Field::String,
|
31
|
+
string: Administrate::Field::String,
|
32
|
+
text: Administrate::Field::String,
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Administrate
|
2
|
+
module Field
|
3
|
+
class Base
|
4
|
+
def initialize(attribute, data, page)
|
5
|
+
@attribute = attribute
|
6
|
+
@data = data
|
7
|
+
@page = page
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.permitted_attribute(attr)
|
11
|
+
attr
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
attribute.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_partial_path
|
19
|
+
"/fields/#{page}/#{field_name}"
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :attribute, :data, :page
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def field_name
|
27
|
+
self.class.to_s.split("::").last.underscore
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Administrate
|
4
|
+
module Field
|
5
|
+
class BelongsTo < Field::Base
|
6
|
+
def self.permitted_attribute(attr)
|
7
|
+
:"#{attr}_id"
|
8
|
+
end
|
9
|
+
|
10
|
+
def permitted_attribute
|
11
|
+
self.class.permitted_attribute(attribute)
|
12
|
+
end
|
13
|
+
|
14
|
+
def candidate_records
|
15
|
+
Object.const_get(attribute.to_s.camelcase).all
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
require "administrate/pages/table"
|
3
|
+
|
4
|
+
module Administrate
|
5
|
+
module Field
|
6
|
+
class HasMany < Field::Base
|
7
|
+
def associated_table
|
8
|
+
Administrate::Page::Table.new(associated_dashboard)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.permitted_attribute(attribute)
|
12
|
+
{ "#{attribute.to_s.singularize}_ids".to_sym => [] }
|
13
|
+
end
|
14
|
+
|
15
|
+
def permitted_attribute
|
16
|
+
self.class.permitted_attribute(attribute)
|
17
|
+
end
|
18
|
+
|
19
|
+
def attribute_key
|
20
|
+
permitted_attribute.keys.first
|
21
|
+
end
|
22
|
+
|
23
|
+
def candidate_records
|
24
|
+
Object.const_get(resource_class_name).all
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def associated_dashboard
|
30
|
+
Object.const_get("#{resource_class_name}Dashboard").new
|
31
|
+
end
|
32
|
+
|
33
|
+
def resource_class_name
|
34
|
+
attribute.to_s.singularize.camelcase
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|