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,93 @@
1
+ // Typography
2
+ $sans-serif: "Lato", $helvetica;
3
+ $serif: $georgia;
4
+ $base-font-family: $sans-serif;
5
+ $header-font-family: $base-font-family;
6
+
7
+ // Font Sizes
8
+ $base-font-size: 1em;
9
+ $small-font-size: 0.875em;
10
+ $h1-font-size: $base-font-size * 2.25;
11
+ $h2-font-size: $base-font-size * 2;
12
+ $h3-font-size: $base-font-size * 1.75;
13
+ $h4-font-size: $base-font-size * 1.5;
14
+ $h5-font-size: $base-font-size * 1.25;
15
+ $h6-font-size: $base-font-size;
16
+
17
+ // Font Weights
18
+ $light-font-weight: 300;
19
+ $normal-font-weight: 400;
20
+ $bold-font-weight: 900;
21
+
22
+ // Line height
23
+ $base-line-height: 1.5;
24
+ $header-line-height: 1.25;
25
+
26
+ // Other Sizes
27
+ $base-border-radius: 3px;
28
+ $base-spacing: $base-line-height * 1em;
29
+ $base-z-index: 0;
30
+
31
+ // Transitions
32
+ $base-easing: cubic-bezier(0.215, 0.610, 0.355, 1);
33
+ $base-timing: 0.25s;
34
+ $base-transition: all $base-timing $base-easing;
35
+
36
+ // Colors
37
+ $dark-blue: #293f53;
38
+ $blue: #2a94d6;
39
+ $light-blue: #4eb1cb;
40
+ $light-red: #cf5c60;
41
+ $light-yellow: #f3ae4e;
42
+ $light-green: #4ab471;
43
+
44
+ $form-field-background-color: #fff;
45
+ $white: #fff;
46
+ $grey-0: #f6f7f7;
47
+ $grey-1: #dfe0e1;
48
+ $grey-2: #cfd8dc;
49
+ $grey-3: #90acad;
50
+ $grey-4: #7b808c;
51
+ $grey-5: #4e6a68;
52
+ $grey-6: #344346;
53
+ $grey-7: #293f54;
54
+
55
+ // Background Color
56
+ $base-background-color: $dark-blue;
57
+
58
+ // Font Colors
59
+ $base-font-color: $grey-7;
60
+ $base-accent-color: $blue;
61
+
62
+ // Link Colors
63
+ $base-link-color: $blue;
64
+ $hover-link-color: shade($blue, 10);
65
+ $base-button-color: $base-link-color;
66
+ $hover-button-color: $hover-link-color;
67
+
68
+ // Sidebar Colors
69
+ $sidebar-active-color: $base-link-color;
70
+ $sidebar-hover-color: $hover-link-color;
71
+
72
+ // Flash Colors
73
+ $alert-color: $light-yellow;
74
+ $error-color: $light-red;
75
+ $notice-color: lighten($base-accent-color, 40);
76
+ $success-color: $light-green;
77
+
78
+ // Border color
79
+ $base-border-color: $grey-1;
80
+ $base-border-size: 1px;
81
+ $base-border: $base-border-size solid $base-border-color;
82
+ $dark-border-color: $grey-2;
83
+ $dark-border: $base-border-size solid $dark-border-color;
84
+
85
+ // Forms
86
+ $form-border-color: $base-border-color;
87
+ $form-border-color-hover: darken($base-border-color, 10);
88
+ $form-border-color-focus: $base-accent-color;
89
+ $form-border-radius: $base-border-radius;
90
+ $form-box-shadow: inset 0 1px 3px rgba(black,0.06);
91
+ $form-box-shadow-focus: $form-box-shadow, 0 0 5px rgba(darken($form-border-color-focus, 5), 0.7);
92
+ $form-font-size: $base-font-size;
93
+ $form-font-family: $base-font-family;
@@ -0,0 +1,23 @@
1
+ %button {
2
+ -webkit-font-smoothing: antialiased;
3
+ background-color: $base-button-color;
4
+ border-radius: $base-border-radius;
5
+ color: white;
6
+ display: inline-block;
7
+ font-size: $base-font-size;
8
+ font-weight: bold;
9
+ line-height: 1;
10
+ padding: 0.75em 1em;
11
+ text-decoration: none;
12
+ transition: background-color $base-timing $base-easing;
13
+
14
+ &:hover {
15
+ background-color: $hover-button-color;
16
+ color: white;
17
+ }
18
+
19
+ &:disabled {
20
+ cursor: not-allowed;
21
+ opacity: 0.5;
22
+ }
23
+ }
@@ -0,0 +1,3 @@
1
+ %clearfix {
2
+ @include clearfix;
3
+ }
@@ -0,0 +1,11 @@
1
+ %error {
2
+ color: darken($error-color, 60);
3
+ }
4
+
5
+ %warning {
6
+ color: darken($alert-color, 60);
7
+ }
8
+
9
+ %notice {
10
+ color: darken($notice-color, 60);
11
+ }
@@ -0,0 +1,38 @@
1
+ @mixin flash($color) {
2
+ background: $color;
3
+ color: darken($color, 60);
4
+
5
+ a {
6
+ color: darken($color, 70);
7
+
8
+ &:hover {
9
+ color: darken($color, 90);
10
+ }
11
+ }
12
+ }
13
+
14
+ %flash-base {
15
+ font-weight: bold;
16
+ margin-bottom: $base-spacing / 2;
17
+ padding: $base-spacing / 2;
18
+ }
19
+
20
+ %flash-alert {
21
+ @extend %flash-base;
22
+ @include flash($alert-color);
23
+ }
24
+
25
+ %flash-error {
26
+ @extend %flash-base;
27
+ @include flash($error-color);
28
+ }
29
+
30
+ %flash-notice {
31
+ @extend %flash-base;
32
+ @include flash($notice-color);
33
+ }
34
+
35
+ %flash-success {
36
+ @extend %flash-base;
37
+ @include flash($success-color);
38
+ }
@@ -0,0 +1,3 @@
1
+ %hide-text {
2
+ @include hide-text;
3
+ }
@@ -0,0 +1,3 @@
1
+ @import "form";
2
+ @import "header";
3
+ @import "table";
@@ -0,0 +1,31 @@
1
+ .form {
2
+ &-actions {
3
+ margin-left: 12em;
4
+ }
5
+
6
+ &-heading {
7
+ font-size: 1.75em;
8
+ margin: 0;
9
+ padding-bottom: 0.5em;
10
+ }
11
+
12
+ &-field {
13
+ align-items: baseline;
14
+ display: flex;
15
+ justify-content: flex-start;
16
+ margin: 1.2em 0;
17
+ width: 100%;
18
+
19
+ label {
20
+ margin-right: 2em;
21
+ text-align: right;
22
+ width: 10em;
23
+ }
24
+
25
+ input,
26
+ select {
27
+ background-color: $form-field-background-color;
28
+ max-width: 30em;
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,10 @@
1
+ .header {
2
+ @include display(flex);
3
+ @include justify-content(space-between);
4
+ @include align-items(flex-end);
5
+ padding: $base-spacing 0;
6
+
7
+ &-heading {
8
+ margin-top: 0;
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ .table-row {
2
+ background-color: $white;
3
+ border-left: 2px solid transparent;
4
+ transition: $base-transition;
5
+
6
+ &:hover {
7
+ background-color: $grey-0;
8
+ border-left-color: $blue;
9
+ cursor: pointer;
10
+ }
11
+ }
@@ -0,0 +1,28 @@
1
+ html,
2
+ body,
3
+ .main {
4
+ height: 100%;
5
+ min-height: 100%;
6
+ }
7
+
8
+ body {
9
+ background: $base-background-color;
10
+ }
11
+
12
+ .main {
13
+ @include clearfix;
14
+ @include align-items(stretch);
15
+ @include display(flex);
16
+ margin: 0 auto;
17
+ max-width: 100em;
18
+ }
19
+
20
+ .content {
21
+ @include flex(1);
22
+ @include card(2);
23
+ background-color: $grey-0;
24
+ height: 100%;
25
+ min-height: 100%;
26
+ overflow-y: auto;
27
+ padding: 0 $gutter;
28
+ }
@@ -0,0 +1,35 @@
1
+ @mixin shadow {
2
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
3
+ }
4
+
5
+ /// Computes a top-shadow for a card effect.
6
+ /// @param {Number} $depth - depth level
7
+ /// @return {List}
8
+ @function top-shadow($depth) {
9
+ $primary-offset: nth(1.5 3 10 14 19, $depth) * 1px;
10
+ $blur: nth(1.5 3 10 14 19, $depth) * 4px;
11
+ $color: rgba($grey-7, nth(0.12 0.16 0.19 0.25 0.30, $depth));
12
+
13
+ @return 0 $primary-offset $blur $color;
14
+ }
15
+
16
+ /// Computes a bottom-shadow for a card effect.
17
+ /// @param {Number} $depth - depth level
18
+ /// @return {List}
19
+ @function bottom-shadow($depth) {
20
+ $primary-offset: nth(1.5 3 6 10 15, $depth) * 1px;
21
+ $blur: nth(1 3 3 5 6, $depth) * 4px;
22
+ $color: rgba($grey-7, nth(0.24 0.23 0.23 0.22 0.22, $depth));
23
+
24
+ @return 0 $primary-offset $blur $color;
25
+ }
26
+
27
+ @mixin card($depth) {
28
+ @if $depth < 1 {
29
+ box-shadow: none;
30
+ } @else if $depth > 5 {
31
+ @warn "Invalid $depth `#{$depth}` for mixin `card`.";
32
+ } @else {
33
+ box-shadow: bottom-shadow($depth), top-shadow($depth);
34
+ }
35
+ }
@@ -0,0 +1,127 @@
1
+ require "administrate/namespace"
2
+ require "administrate/pages/form"
3
+ require "administrate/pages/table"
4
+ require "administrate/pages/show"
5
+
6
+ module Administrate
7
+ class ApplicationController < ActionController::Base
8
+ def index
9
+ @resources = resource_class.all
10
+ @page = Administrate::Page::Table.new(dashboard)
11
+ end
12
+
13
+ def show
14
+ set_resource
15
+
16
+ @page = Administrate::Page::Show.new(dashboard, resource)
17
+ end
18
+
19
+ def new
20
+ @page = Administrate::Page::Form.new(dashboard, resource_class.new)
21
+ end
22
+
23
+ def edit
24
+ set_resource
25
+
26
+ @page = Administrate::Page::Form.new(dashboard, resource)
27
+ end
28
+
29
+ def create
30
+ set_resource(resource_class.new(resource_params))
31
+
32
+ if resource.save
33
+ redirect_to(
34
+ [Administrate::NAMESPACE, resource],
35
+ notice: notices[:created],
36
+ )
37
+ else
38
+ @page = Administrate::Page::Form.new(dashboard, resource)
39
+ render :new
40
+ end
41
+ end
42
+
43
+ def update
44
+ set_resource
45
+
46
+ if resource.update(resource_params)
47
+ redirect_to(
48
+ [Administrate::NAMESPACE, resource],
49
+ notice: notices[:updated],
50
+ )
51
+ else
52
+ @page = Administrate::Page::Form.new(dashboard, resource)
53
+ render :edit
54
+ end
55
+ end
56
+
57
+ def destroy
58
+ set_resource
59
+
60
+ resource.destroy
61
+ flash[:notice] = notices[:destroyed]
62
+ redirect_to action: :index
63
+ end
64
+
65
+ private
66
+
67
+ helper_method :link_class
68
+ def link_class(resource)
69
+ if resource_name.to_s.pluralize == resource.to_s
70
+ :active
71
+ end
72
+ end
73
+
74
+ def resource_class
75
+ Object.const_get(resource_class_name)
76
+ end
77
+
78
+ def dashboard
79
+ @dashboard ||= dashboard_class.new
80
+ end
81
+
82
+ def set_resource(resource = nil)
83
+ resource ||= resource_class.find(params[:id])
84
+ instance_variable_set(instance_variable, resource)
85
+ end
86
+
87
+ def resource
88
+ instance_variable_get(instance_variable)
89
+ end
90
+
91
+ def resource_params
92
+ params.require(:"#{resource_name}").permit(*permitted_attributes)
93
+ end
94
+
95
+ def permitted_attributes
96
+ dashboard.permitted_attributes
97
+ end
98
+
99
+ def dashboard_class
100
+ Object.const_get("#{resource_class_name}Dashboard")
101
+ end
102
+
103
+ def resource_class_name
104
+ resource_name.to_s.camelcase
105
+ end
106
+
107
+ def instance_variable
108
+ "@#{resource_name}"
109
+ end
110
+
111
+ def resource_title
112
+ resource_class_name.titleize
113
+ end
114
+
115
+ def notices
116
+ {
117
+ created: "#{resource_title} was successfully created.",
118
+ updated: "#{resource_title} was successfully updated.",
119
+ destroyed: "#{resource_title} was successfully destroyed.",
120
+ }
121
+ end
122
+
123
+ def resource_name
124
+ controller_name.singularize.to_sym
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,7 @@
1
+ module Administrate
2
+ module ApplicationHelper
3
+ def render_field(field, locals = {})
4
+ render locals: locals, object: field, partial: field.to_partial_path
5
+ end
6
+ end
7
+ end