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.

Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/Rakefile +37 -0
  4. data/app/assets/javascripts/administrate/application.js +3 -0
  5. data/app/assets/javascripts/administrate/components/table.js +17 -0
  6. data/app/assets/stylesheets/administrate/_show.sass +16 -0
  7. data/app/assets/stylesheets/administrate/_sidebar.scss +48 -0
  8. data/app/assets/stylesheets/administrate/application.scss +14 -0
  9. data/app/assets/stylesheets/administrate/base/_base.scss +24 -0
  10. data/app/assets/stylesheets/administrate/base/_buttons.scss +11 -0
  11. data/app/assets/stylesheets/administrate/base/_forms.scss +78 -0
  12. data/app/assets/stylesheets/administrate/base/_grid-settings.scss +15 -0
  13. data/app/assets/stylesheets/administrate/base/_lists.scss +31 -0
  14. data/app/assets/stylesheets/administrate/base/_tables.scss +74 -0
  15. data/app/assets/stylesheets/administrate/base/_typography.scss +93 -0
  16. data/app/assets/stylesheets/administrate/base/_variables.scss +93 -0
  17. data/app/assets/stylesheets/administrate/base/extends/_button.scss +23 -0
  18. data/app/assets/stylesheets/administrate/base/extends/_clearfix.scss +3 -0
  19. data/app/assets/stylesheets/administrate/base/extends/_errors.scss +11 -0
  20. data/app/assets/stylesheets/administrate/base/extends/_flashes.scss +38 -0
  21. data/app/assets/stylesheets/administrate/base/extends/_hide-text.scss +3 -0
  22. data/app/assets/stylesheets/administrate/components/_components.scss +3 -0
  23. data/app/assets/stylesheets/administrate/components/_form.scss +31 -0
  24. data/app/assets/stylesheets/administrate/components/_header.scss +10 -0
  25. data/app/assets/stylesheets/administrate/components/_table.scss +11 -0
  26. data/app/assets/stylesheets/administrate/layout.scss +28 -0
  27. data/app/assets/stylesheets/administrate/mixins/_mixins.scss +1 -0
  28. data/app/assets/stylesheets/administrate/mixins/_shadow.scss +35 -0
  29. data/app/controllers/administrate/application_controller.rb +127 -0
  30. data/app/helpers/administrate/application_helper.rb +7 -0
  31. data/app/views/administrate/application/_flashes.html.erb +7 -0
  32. data/app/views/administrate/application/_form.html.erb +28 -0
  33. data/app/views/administrate/application/_javascript.html.erb +10 -0
  34. data/app/views/administrate/application/_sidebar.html.erb +16 -0
  35. data/app/views/administrate/application/_table.html.erb +44 -0
  36. data/app/views/administrate/application/edit.html.erb +6 -0
  37. data/app/views/administrate/application/index.html.erb +10 -0
  38. data/app/views/administrate/application/new.html.erb +6 -0
  39. data/app/views/administrate/application/show.html.erb +11 -0
  40. data/app/views/fields/form/_belongs_to.html.erb +7 -0
  41. data/app/views/fields/form/_email.html.erb +2 -0
  42. data/app/views/fields/form/_has_many.html.erb +11 -0
  43. data/app/views/fields/form/_image.html.erb +2 -0
  44. data/app/views/fields/form/_string.html.erb +2 -0
  45. data/app/views/fields/index/_belongs_to.html.erb +3 -0
  46. data/app/views/fields/index/_email.html.erb +1 -0
  47. data/app/views/fields/index/_has_many.html.erb +1 -0
  48. data/app/views/fields/index/_image.html.erb +1 -0
  49. data/app/views/fields/index/_string.html.erb +1 -0
  50. data/app/views/fields/show/_belongs_to.html.erb +3 -0
  51. data/app/views/fields/show/_email.html.erb +1 -0
  52. data/app/views/fields/show/_has_many.html.erb +5 -0
  53. data/app/views/fields/show/_image.html.erb +1 -0
  54. data/app/views/fields/show/_string.html.erb +1 -0
  55. data/app/views/layouts/administrate/application.html.erb +28 -0
  56. data/config/locales/administrate.en.yml +7 -0
  57. data/config/routes.rb +2 -0
  58. data/lib/administrate.rb +4 -0
  59. data/lib/administrate/base_dashboard.rb +36 -0
  60. data/lib/administrate/engine.rb +8 -0
  61. data/lib/administrate/fields/base.rb +31 -0
  62. data/lib/administrate/fields/belongs_to.rb +19 -0
  63. data/lib/administrate/fields/email.rb +8 -0
  64. data/lib/administrate/fields/has_many.rb +38 -0
  65. data/lib/administrate/fields/image.rb +8 -0
  66. data/lib/administrate/fields/string.rb +8 -0
  67. data/lib/administrate/namespace.rb +3 -0
  68. data/lib/administrate/pages/base.rb +28 -0
  69. data/lib/administrate/pages/form.rb +28 -0
  70. data/lib/administrate/pages/show.rb +24 -0
  71. data/lib/administrate/pages/table.rb +21 -0
  72. data/lib/administrate/version.rb +3 -0
  73. data/lib/generators/administrate/dashboard/USAGE +9 -0
  74. data/lib/generators/administrate/dashboard/dashboard_generator.rb +44 -0
  75. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +12 -0
  76. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +50 -0
  77. data/lib/generators/administrate/install/install_generator.rb +52 -0
  78. data/lib/generators/administrate/install/templates/application_controller.rb +13 -0
  79. data/lib/generators/administrate/install/templates/dashboard_manifest.rb.erb +29 -0
  80. data/lib/generators/administrate/install/templates/routes.rb +7 -0
  81. data/lib/tasks/administrate_tasks.rake +4 -0
  82. metadata +179 -0
@@ -0,0 +1,7 @@
1
+ <% if flash.any? %>
2
+ <div id="flash">
3
+ <% flash.each do |key, value| -%>
4
+ <div class="flash-<%= key %>"><%= value %></div>
5
+ <% end -%>
6
+ </div>
7
+ <% end %>
@@ -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,10 @@
1
+ <%= javascript_include_tag "administrate/application" %>
2
+
3
+ <%= yield :javascript %>
4
+
5
+ <% if Rails.env.test? %>
6
+ <%= javascript_tag do %>
7
+ $.fx.off = true;
8
+ $.ajaxSetup({ async: false });
9
+ <% end %>
10
+ <% 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,6 @@
1
+ <header class="header">
2
+ <h1 class="header-heading">Edit <%= @page.page_title %></h1>
3
+ <%= link_to "Show #{@page.resource}", [Administrate::NAMESPACE, @page.resource], class: "button" %>
4
+ </header>
5
+
6
+ <%= render "form" %>
@@ -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,6 @@
1
+ <header class="header">
2
+ <h1 class="header-heading">New <%= @page.resource_name.titleize %></h1>
3
+ <%= link_to 'Back', @page.resource_name.pluralize, class: "button" %>
4
+ </header>
5
+
6
+ <%= render 'form' %>
@@ -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,7 @@
1
+ <%= f.label belongs_to.permitted_attribute %>
2
+ <%= f.collection_select(
3
+ belongs_to.permitted_attribute,
4
+ belongs_to.candidate_records,
5
+ :id,
6
+ :to_s
7
+ ) %>
@@ -0,0 +1,2 @@
1
+ <%= f.label email.attribute %>
2
+ <%= f.email_field email.attribute %>
@@ -0,0 +1,11 @@
1
+ <%= f.label has_many.attribute_key %>
2
+
3
+ <%= f.collection_select(
4
+ has_many.attribute_key,
5
+ has_many.candidate_records,
6
+ :id,
7
+ :to_s,
8
+ {},
9
+ { multiple: true }
10
+ )
11
+ %>
@@ -0,0 +1,2 @@
1
+ <%= f.label image.attribute %>
2
+ <%= f.text_field image.attribute %>
@@ -0,0 +1,2 @@
1
+ <%= f.label string.attribute %>
2
+ <%= f.text_field string.attribute %>
@@ -0,0 +1,3 @@
1
+ <% if belongs_to.data %>
2
+ <%= link_to belongs_to.data, [Administrate::NAMESPACE, belongs_to.data] %>
3
+ <% end %>
@@ -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,3 @@
1
+ <% if belongs_to.data %>
2
+ <%= link_to belongs_to.data, [Administrate::NAMESPACE, belongs_to.data] %>
3
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= mail_to email.data %>
@@ -0,0 +1,5 @@
1
+ <%= render(
2
+ "table",
3
+ table_presenter: has_many.associated_table,
4
+ resources: has_many.data
5
+ ) %>
@@ -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>
@@ -0,0 +1,7 @@
1
+ en:
2
+ administrate:
3
+ actions:
4
+ show: Show
5
+ edit: Edit
6
+ destroy: Destroy
7
+ confirm: Are you sure?
@@ -0,0 +1,2 @@
1
+ Administrate::Engine.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ require "administrate/engine"
2
+
3
+ module Administrate
4
+ end
@@ -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,8 @@
1
+ require "neat"
2
+ require "normalize-rails"
3
+
4
+ module Administrate
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Administrate
7
+ end
8
+ 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,8 @@
1
+ require_relative "base"
2
+
3
+ module Administrate
4
+ module Field
5
+ class Email < Field::Base
6
+ end
7
+ end
8
+ 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
@@ -0,0 +1,8 @@
1
+ require_relative "base"
2
+
3
+ module Administrate
4
+ module Field
5
+ class Image < Field::Base
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "base"
2
+
3
+ module Administrate
4
+ module Field
5
+ class String < Field::Base
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Administrate
2
+ NAMESPACE = :admin
3
+ end