admin-panel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +117 -0
  5. data/LICENSE +21 -0
  6. data/README.md +55 -0
  7. data/Rakefile +10 -0
  8. data/admin-panel.gemspec +29 -0
  9. data/lib/admin-panel/version.rb +3 -0
  10. data/lib/generators/admin_panel/install/install_generator.rb +69 -0
  11. data/lib/generators/admin_panel/install/templates/README +10 -0
  12. data/lib/generators/admin_panel/install/templates/assets/javascripts/admin.js +1 -0
  13. data/lib/generators/admin_panel/install/templates/assets/stylesheets/admin.css.scss +1 -0
  14. data/lib/generators/admin_panel/install/templates/controllers/admin/dashboard_controller.rb +3 -0
  15. data/lib/generators/admin_panel/install/templates/controllers/admin/passwords_controller.rb +4 -0
  16. data/lib/generators/admin_panel/install/templates/controllers/admin/sessions_controller.rb +4 -0
  17. data/lib/generators/admin_panel/install/templates/controllers/concerns/administrable.rb +9 -0
  18. data/lib/generators/admin_panel/install/templates/helpers/admin_helper.rb +19 -0
  19. data/lib/generators/admin_panel/install/templates/layouts/admin/_messages.html.erb +8 -0
  20. data/lib/generators/admin_panel/install/templates/layouts/admin/_navigation.html.erb +20 -0
  21. data/lib/generators/admin_panel/install/templates/layouts/admin/application.html.erb +22 -0
  22. data/lib/generators/admin_panel/install/templates/views/admin/dashboard/index.html.erb +1 -0
  23. data/lib/generators/admin_panel/install/templates/views/admin/passwords/edit.html.erb +17 -0
  24. data/lib/generators/admin_panel/install/templates/views/admin/passwords/new.html.erb +15 -0
  25. data/lib/generators/admin_panel/install/templates/views/admin/sessions/new.html.erb +17 -0
  26. data/lib/generators/admin_panel/scaffold/scaffold_generator.rb +168 -0
  27. data/lib/generators/admin_panel/scaffold/templates/controllers/controller.rb.erb +69 -0
  28. data/lib/generators/admin_panel/scaffold/templates/tests/test_unit/functional_test.rb.erb +51 -0
  29. data/lib/generators/admin_panel/scaffold/templates/views/erb/_form.html.erb.erb +13 -0
  30. data/lib/generators/admin_panel/scaffold/templates/views/erb/edit.html.erb.erb +12 -0
  31. data/lib/generators/admin_panel/scaffold/templates/views/erb/index.html.erb.erb +37 -0
  32. data/lib/generators/admin_panel/scaffold/templates/views/erb/new.html.erb.erb +14 -0
  33. data/lib/generators/admin_panel/scaffold/templates/views/erb/show.html.erb.erb +22 -0
  34. data/spec/dummy/Rakefile +7 -0
  35. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  36. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  37. data/spec/dummy/bin/rails +11 -0
  38. data/spec/dummy/config.ru +4 -0
  39. data/spec/dummy/config/application.rb +68 -0
  40. data/spec/dummy/config/boot.rb +6 -0
  41. data/spec/dummy/config/environment.rb +5 -0
  42. data/spec/dummy/config/environments/test.rb +39 -0
  43. data/spec/dummy/config/routes.rb +3 -0
  44. data/spec/dummy/db/seeds.rb +0 -0
  45. data/spec/generators/admin_panel/install/install_generator_spec.rb +79 -0
  46. data/spec/generators/admin_panel/scaffold/scaffold_generator_spec.rb +31 -0
  47. data/spec/spec_helper.rb +17 -0
  48. metadata +232 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66df4e9a3092fddf326c23404ad72b5bab8dedb0
4
+ data.tar.gz: f6fc832605453bb2cd6adfbae5589313dd9fa162
5
+ SHA512:
6
+ metadata.gz: ff55ce389b1186867a88e0ea5dcd7855f405c5313a1d69bd78d53a8a3d96db947ce5eae531af1e40982ebe88e4195f68677b9d0159b75ecc5b1fa437fb4f08be
7
+ data.tar.gz: 7144c2efae1b7517d346965735ca7e75d2794ced6d4f40b10bea177f30a1852fdace4244e2ea4abf2df4e2f32e3163110fce2e4b8894528e5dfab366904fb5fd
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .idea
2
+ tmp/
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,117 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ admin-panel (0.1.0)
5
+ bootstrap-sass (~> 3.1)
6
+ devise (~> 3.2)
7
+ railties (>= 4.0.0)
8
+ sass-rails (>= 4.0.0)
9
+ simple_form (>= 3.1.0.rc1)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ actionpack (4.1.1)
15
+ actionview (= 4.1.1)
16
+ activesupport (= 4.1.1)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ actionview (4.1.1)
20
+ activesupport (= 4.1.1)
21
+ builder (~> 3.1)
22
+ erubis (~> 2.7.0)
23
+ activemodel (4.1.1)
24
+ activesupport (= 4.1.1)
25
+ builder (~> 3.1)
26
+ activesupport (4.1.1)
27
+ i18n (~> 0.6, >= 0.6.9)
28
+ json (~> 1.7, >= 1.7.7)
29
+ minitest (~> 5.1)
30
+ thread_safe (~> 0.1)
31
+ tzinfo (~> 1.1)
32
+ ammeter (1.0.0)
33
+ activesupport (>= 3.0)
34
+ railties (>= 3.0)
35
+ rspec-rails (>= 2.2)
36
+ bcrypt (3.1.7)
37
+ bootstrap-sass (3.1.1.1)
38
+ sass (~> 3.2)
39
+ builder (3.2.2)
40
+ devise (3.2.4)
41
+ bcrypt (~> 3.0)
42
+ orm_adapter (~> 0.1)
43
+ railties (>= 3.2.6, < 5)
44
+ thread_safe (~> 0.1)
45
+ warden (~> 1.2.3)
46
+ diff-lcs (1.2.5)
47
+ erubis (2.7.0)
48
+ hike (1.2.3)
49
+ i18n (0.6.9)
50
+ json (1.8.1)
51
+ minitest (5.3.4)
52
+ multi_json (1.10.1)
53
+ orm_adapter (0.5.0)
54
+ rack (1.5.2)
55
+ rack-test (0.6.2)
56
+ rack (>= 1.0)
57
+ railties (4.1.1)
58
+ actionpack (= 4.1.1)
59
+ activesupport (= 4.1.1)
60
+ rake (>= 0.8.7)
61
+ thor (>= 0.18.1, < 2.0)
62
+ rake (10.3.2)
63
+ rspec (3.0.0)
64
+ rspec-core (~> 3.0.0)
65
+ rspec-expectations (~> 3.0.0)
66
+ rspec-mocks (~> 3.0.0)
67
+ rspec-core (3.0.1)
68
+ rspec-support (~> 3.0.0)
69
+ rspec-expectations (3.0.1)
70
+ diff-lcs (>= 1.2.0, < 2.0)
71
+ rspec-support (~> 3.0.0)
72
+ rspec-mocks (3.0.1)
73
+ rspec-support (~> 3.0.0)
74
+ rspec-rails (3.0.1)
75
+ actionpack (>= 3.0)
76
+ activesupport (>= 3.0)
77
+ railties (>= 3.0)
78
+ rspec-core (~> 3.0.0)
79
+ rspec-expectations (~> 3.0.0)
80
+ rspec-mocks (~> 3.0.0)
81
+ rspec-support (~> 3.0.0)
82
+ rspec-support (3.0.0)
83
+ sass (3.2.19)
84
+ sass-rails (4.0.3)
85
+ railties (>= 4.0.0, < 5.0)
86
+ sass (~> 3.2.0)
87
+ sprockets (~> 2.8, <= 2.11.0)
88
+ sprockets-rails (~> 2.0)
89
+ simple_form (3.1.0.rc1)
90
+ actionpack (~> 4.0)
91
+ activemodel (~> 4.0)
92
+ sprockets (2.11.0)
93
+ hike (~> 1.2)
94
+ multi_json (~> 1.0)
95
+ rack (~> 1.0)
96
+ tilt (~> 1.1, != 1.3.0)
97
+ sprockets-rails (2.1.3)
98
+ actionpack (>= 3.0)
99
+ activesupport (>= 3.0)
100
+ sprockets (~> 2.8)
101
+ thor (0.19.1)
102
+ thread_safe (0.3.4)
103
+ tilt (1.4.1)
104
+ tzinfo (1.2.1)
105
+ thread_safe (~> 0.1)
106
+ warden (1.2.3)
107
+ rack (>= 1.0)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ admin-panel!
114
+ ammeter (~> 1.0)
115
+ bundler (~> 1.5)
116
+ rake (~> 10.0)
117
+ rspec (~> 3.0)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Michał Matyas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ Admin Panel
2
+ ===========
3
+
4
+ This gem has been created as a recruitment task I was given. It's a set of generators to create administration panel for your website.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Start with adding these gems to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'admin-panel', '~> 0.1.0'
13
+ gem 'devise', '~> 3.2'
14
+ gem 'simple_form', '3.1.0.rc1'
15
+ gem 'bootstrap-sass', '~> 3.1'
16
+ ```
17
+
18
+ Then do @bundle install@ and run the installer:
19
+
20
+ ```bash
21
+ $ rails generate admin_panel:install
22
+ ```
23
+
24
+ Using the scaffolder
25
+ --------------------
26
+
27
+ The scaffolder has basically the same syntax as the Rails one, except there's currently no support for custom namespace.
28
+
29
+ ```bash
30
+ $ rails generate admin_panel:scaffold NAME [field:type field:type ...]
31
+ ```
32
+
33
+ Running tests
34
+ -------------
35
+
36
+ Tests can be run using @rake spec@. They are written using rspec and [ammeter](https://github.com/alexrothenberg/ammeter)
37
+
38
+ Thanks
39
+ ------
40
+
41
+ This gem was based mostly on two different pieces of software: [bootstrap-generators](https://github.com/decioferreira/bootstrap-generators) and [rails-admin-scaffold](https://github.com/dhampik/rails-admin-scaffold)
42
+
43
+ TODO
44
+ ----
45
+
46
+ Currently this gem is pretty much one-evening project, I'm not sure if I'll continue it's development past this point.
47
+
48
+ Things that'd be nice to have:
49
+
50
+ - support for anything more than Active Record
51
+ - support for anything more than Erb (haml, slim)
52
+ - namespace change support and more configuration options
53
+ - kaminari/will_paginate support
54
+ - I liked the idea of copying the files to your project during install at first but now it just seems silly; I should probably rewrite everything from scratch to work more similarly to Devise, including the ability to extend default controllers where necessary
55
+ - I was also supposed to add Carrierwave support too but ran out of time
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'admin-panel/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'admin-panel'
6
+ spec.version = AdminPanel::VERSION
7
+
8
+ spec.authors = ['Michał Matyas']
9
+ spec.email = ['michal@higher.lv']
10
+ spec.summary = 'Generates Twitter Bootstrap based admin panel with scaffolder'
11
+ spec.description = 'Generates Twitter Bootstrap based admin panel with scaffolder. Project is quite opinionated, requires Rails 4, SASS, SimpleForm and Devise.'
12
+ spec.homepage = 'https://github.com/d4rky-pl/admin-panel'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.5'
20
+ spec.add_development_dependency 'rake', '~> 10.0'
21
+ spec.add_development_dependency 'rspec', '~> 3.0'
22
+ spec.add_development_dependency 'ammeter', '~> 1.0'
23
+
24
+ spec.add_runtime_dependency 'railties', '>= 4.0.0'
25
+ spec.add_runtime_dependency 'sass-rails', '>= 4.0.0'
26
+ spec.add_runtime_dependency 'bootstrap-sass', '~> 3.1'
27
+ spec.add_runtime_dependency 'simple_form', '>= 3.1.0.rc1'
28
+ spec.add_runtime_dependency 'devise', '~> 3.2'
29
+ end
@@ -0,0 +1,3 @@
1
+ module AdminPanel
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,69 @@
1
+ require 'rails/generators'
2
+
3
+ module AdminPanel
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ desc 'Generate basic admin panel with authentication namespaced as Admin'
7
+ source_root ::File.expand_path('../templates', __FILE__)
8
+
9
+ class_option :template_engine
10
+
11
+ def install_devise
12
+ invoke 'devise:install'
13
+ end
14
+
15
+ def install_simple_form
16
+ invoke 'simple_form:install', [], ['--bootstrap']
17
+ end
18
+
19
+ attr_reader :app_name
20
+
21
+ def copy_layout
22
+ @app_name = ::Rails.application.class.to_s.split("::").first.humanize
23
+ extension = "html.#{options[:template_engine]}"
24
+
25
+ template "layouts/admin/application.#{extension}", "app/views/layouts/admin/application.#{extension}"
26
+ [ '_messages', '_navigation'].each do |file|
27
+ filename = "#{file}.#{extension}"
28
+ copy_file "layouts/admin/#{filename}", "app/views/layouts/admin/#{filename}"
29
+ end
30
+ end
31
+
32
+ def copy_assets
33
+ directory 'assets', 'app/assets'
34
+ end
35
+
36
+ def copy_helpers
37
+ directory 'helpers', 'app/helpers'
38
+ end
39
+
40
+ def copy_scaffold
41
+ directory 'controllers', 'app/controllers'
42
+ directory 'views', 'app/views'
43
+ end
44
+
45
+ def create_admin_model
46
+ invoke 'active_record:devise', ['admin'], ['--routes', false]
47
+ append_to_file 'db/seeds.rb', %Q(
48
+ Admin.create!({ email: 'admin@example.com', password: 'administrator' })
49
+ )
50
+ end
51
+
52
+ def create_routes
53
+ route %Q(
54
+ devise_for :admin,
55
+ :only => [:sessions, :passwords],
56
+ :controllers => { :sessions => 'admin/sessions', :passwords => 'admin/passwords' }
57
+
58
+ namespace :admin do
59
+ get '/', to: 'dashboard#index', as: :dashboard
60
+ end
61
+ )
62
+ end
63
+
64
+ def show_install_message
65
+ readme "README"
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,10 @@
1
+ ===============================================================================
2
+
3
+ Remember to invoke these commands after the installation process is done:
4
+
5
+ $ rake db:migrate
6
+ $ rake db:seed
7
+
8
+ Your default account is set to admin@example.com , password: administrator
9
+
10
+ ===============================================================================
@@ -0,0 +1 @@
1
+ //= require 'bootstrap'
@@ -0,0 +1,3 @@
1
+ class Admin::DashboardController < ApplicationController
2
+ include Administrable
3
+ end
@@ -0,0 +1,4 @@
1
+ class Admin::PasswordsController < Devise::PasswordsController
2
+ helper AdminHelper
3
+ layout 'admin/application'
4
+ end
@@ -0,0 +1,4 @@
1
+ class Admin::SessionsController < Devise::SessionsController
2
+ helper AdminHelper
3
+ layout 'admin/application'
4
+ end
@@ -0,0 +1,9 @@
1
+ module Administrable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_filter :authenticate_admin!
6
+ helper AdminHelper
7
+ layout 'admin/application'
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module AdminHelper
2
+ def admin_pages
3
+ # TODO: something more elegant
4
+ non_scaffold_pages = %w(dashboard sessions passwords)
5
+
6
+ Dir.glob(Rails.root.join('app', 'controllers', 'admin', '*.rb')).map do |path|
7
+ filename = File.basename(path)
8
+ resource_name = filename.sub(/_controller\.rb$/, '')
9
+
10
+ unless non_scaffold_pages.include? resource_name
11
+ {
12
+ name: resource_name.humanize,
13
+ controller: "#{resource_name}",
14
+ url: self.send("admin_#{resource_name}_path")
15
+ }
16
+ end
17
+ end.compact
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ <% flash.each do |name, msg| %>
2
+ <% if msg.is_a?(String) %>
3
+ <div class="alert alert-<%= name.to_s == 'notice' ? 'success' : 'danger' %>">
4
+ <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
5
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
6
+ </div>
7
+ <% end %>
8
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <nav class="navbar navbar-default" role="navigation">
2
+ <div class="container-fluid">
3
+ <div class="navbar-header">
4
+ <a class="navbar-brand" href="<%= admin_dashboard_path %>">App name</a>
5
+ </div>
6
+
7
+ <% if admin_signed_in? %>
8
+ <ul class="nav navbar-nav">
9
+ <% admin_pages.each do |page| %>
10
+ <li class="<%= controller_name == page[:controller] ? 'active' : '' %>">
11
+ <a href="<%= page[:url] %>"><%= page[:name] %></a>
12
+ </li>
13
+ <% end %>
14
+ </ul>
15
+ <ul class="nav navbar-nav navbar-right">
16
+ <li><%= link_to 'Sign out', destroy_admin_session_path, method: :delete %></li>
17
+ </ul>
18
+ <% end %>
19
+ </div>
20
+ </nav>
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
+ <title><%%= content_for?(:title) ? yield(:title) : "<%= app_name.underscore.titleize %>" %></title>
6
+ <meta name="description" content="<%%= content_for?(:description) ? yield(:description) : "<%= app_name.underscore.titleize %>" %>">
7
+ <%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
8
+ <%%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
9
+ <%%= csrf_meta_tags %>
10
+ </head>
11
+ <body>
12
+ <header>
13
+ <%%= render partial: 'layouts/admin/navigation' %>
14
+ </header>
15
+ <main role="main">
16
+ <div class="container">
17
+ <%%= render partial: 'layouts/admin/messages' %>
18
+ <%%= yield %>
19
+ </div>
20
+ </main>
21
+ </body>
22
+ </html>