nyc_devshop 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +50 -0
  3. data/Rakefile +32 -0
  4. data/lib/generators/devshop_admin_generator.rb +56 -0
  5. data/lib/generators/devshop_gems_generator.rb +32 -0
  6. data/lib/generators/devshop_generator.rb +138 -0
  7. data/lib/generators/templates/_form.html.haml +7 -0
  8. data/lib/generators/templates/admin.html.haml +29 -0
  9. data/lib/generators/templates/admin_application.css.sass +2 -0
  10. data/lib/generators/templates/admin_application.js +4 -0
  11. data/lib/generators/templates/admin_application_controller.rb +17 -0
  12. data/lib/generators/templates/application.css.sass +2 -0
  13. data/lib/generators/templates/application.html.haml +13 -0
  14. data/lib/generators/templates/application.js +2 -0
  15. data/lib/generators/templates/application_controller.rb +18 -0
  16. data/lib/generators/templates/application_helper.rb +36 -0
  17. data/lib/generators/templates/base.css.sass +20 -0
  18. data/lib/generators/templates/bootstrap.css +5909 -0
  19. data/lib/generators/templates/bootstrap.js +1992 -0
  20. data/lib/generators/templates/controller.rb +50 -0
  21. data/lib/generators/templates/database.yml +25 -0
  22. data/lib/generators/templates/edit.html.haml +2 -0
  23. data/lib/generators/templates/index.html.haml +25 -0
  24. data/lib/generators/templates/layout.html.haml +5 -0
  25. data/lib/generators/templates/new.html.haml +2 -0
  26. data/lib/generators/templates/normalize.css +406 -0
  27. data/lib/generators/templates/public_controller.rb +6 -0
  28. data/lib/generators/templates/seeds.rb +1 -0
  29. data/lib/generators/templates/sessions/new.html.haml +14 -0
  30. data/lib/generators/templates/sessions_controller.rb +22 -0
  31. data/lib/generators/templates/show.html.haml +8 -0
  32. data/lib/nyc_devshop.rb +2 -0
  33. data/lib/nyc_devshop/version.rb +3 -0
  34. data/lib/tasks/nyc_devshop_tasks.rake +4 -0
  35. data/test/dummy/README.rdoc +28 -0
  36. data/test/dummy/Rakefile +6 -0
  37. data/test/dummy/app/assets/javascripts/application.js +13 -0
  38. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  39. data/test/dummy/app/controllers/application_controller.rb +5 -0
  40. data/test/dummy/app/helpers/application_helper.rb +2 -0
  41. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  42. data/test/dummy/bin/bundle +3 -0
  43. data/test/dummy/bin/rails +4 -0
  44. data/test/dummy/bin/rake +4 -0
  45. data/test/dummy/config.ru +4 -0
  46. data/test/dummy/config/application.rb +23 -0
  47. data/test/dummy/config/boot.rb +5 -0
  48. data/test/dummy/config/database.yml +25 -0
  49. data/test/dummy/config/environment.rb +5 -0
  50. data/test/dummy/config/environments/development.rb +29 -0
  51. data/test/dummy/config/environments/production.rb +80 -0
  52. data/test/dummy/config/environments/test.rb +36 -0
  53. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  55. data/test/dummy/config/initializers/inflections.rb +16 -0
  56. data/test/dummy/config/initializers/mime_types.rb +5 -0
  57. data/test/dummy/config/initializers/secret_token.rb +12 -0
  58. data/test/dummy/config/initializers/session_store.rb +3 -0
  59. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  60. data/test/dummy/config/locales/en.yml +23 -0
  61. data/test/dummy/config/routes.rb +56 -0
  62. data/test/dummy/public/404.html +58 -0
  63. data/test/dummy/public/422.html +58 -0
  64. data/test/dummy/public/500.html +57 -0
  65. data/test/dummy/public/favicon.ico +0 -0
  66. data/test/nyc_devshop_test.rb +7 -0
  67. data/test/test_helper.rb +15 -0
  68. metadata +181 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = NycDevshop
2
+
3
+ Nyc devshop is an internal gem for the company NYC Devshop created by Yanik Jayaram which contains custom generators for the purpose of auto-generating commonly used assets, configs, gems, controllers, routes, models and views
4
+
5
+ = Usage
6
+ In its current state, this gem should be used once and only once upon creation of your application.
7
+
8
+ couple of things to note:
9
+ * the controllers will be set up assuming you are using rails4.
10
+ * the strong parameters will not be auto-filled in the controllers. You must do this yourself
11
+
12
+ 1. Add the following line to your gemfile:
13
+
14
+ gem 'nyc_devshop'
15
+
16
+ 2. Run the following command:
17
+
18
+ $ bundle install
19
+
20
+ 3. Run the following command:
21
+
22
+ $ rails g devshop_gems
23
+
24
+ 4. Run the following command, passing the app name (ex, 'MyApp') as an argument:
25
+
26
+ $ rails g devshop MyApp
27
+
28
+ 5. Create and migrate any models for which you want CRUD actions and views to be created in your admin panel (with the exception of an Administrator model, which is automatically created for you via the generators).
29
+
30
+ e.g.
31
+ $ rails g model User first_name last_name email
32
+ $ rake db:migrate
33
+
34
+ 6. Run the following command, passing the names of the migrated models for which you want CRUD actions and views to be be created in your admin panel (formatting must be singular, lowercase, and space separated (*NO COMMAS*)):
35
+
36
+ e.g.
37
+ $ rails g devshop_admin administrator user
38
+
39
+ 7. Results
40
+
41
+ * Start your rails server and you should see a dummy public index page
42
+ * Go to http://localhost:3000/admin to see an admin login page. Login credentials are
43
+ login: 'admin@admin.com'
44
+ password: '123'
45
+ You should see your resources with associated crud actions.
46
+
47
+
48
+
49
+
50
+
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'NycDevshop'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,56 @@
1
+ class DevshopAdminGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ #must be run AFTER creating models and migrating
5
+
6
+ #to accept multiple arguments to be used in file generation
7
+ argument :resources, type: :array
8
+
9
+ def create_admin_view_sub_folders
10
+ resources.each do |resource|
11
+ empty_directory "app/views/admin/#{resource.pluralize}"
12
+ template "_form.html.haml", "app/views/admin/#{resource.pluralize}/_form.html.haml", resource: resource
13
+ template "show.html.haml", "app/views/admin/#{resource.pluralize}/show.html.haml", resource: resource
14
+ template "edit.html.haml", "app/views/admin/#{resource.pluralize}/edit.html.haml", resource: resource
15
+ template "new.html.haml", "app/views/admin/#{resource.pluralize}/new.html.haml", resource: resource
16
+ template "index.html.haml", "app/views/admin/#{resource.pluralize}/index.html.haml", resource: resource
17
+ end
18
+ end
19
+
20
+
21
+ def create_name_spaced_routes
22
+ #remove example code which screws up the route insert
23
+ gsub_file "config/routes.rb", /# namespace :admin do/, ""
24
+
25
+ #add resources inside admin namespace
26
+ insert_into_file "config/routes.rb", after: "namespace :admin do\n" do
27
+
28
+ my_string = "\t\tresources "
29
+
30
+ resources.each do |resource|
31
+ my_string.concat ":#{resource.pluralize}"
32
+ my_string.concat ", " unless resources.last == resource
33
+ end
34
+
35
+ my_string.concat "\n"
36
+ end
37
+
38
+ end
39
+
40
+ def create_admin_layout
41
+ ##admin layout
42
+ template "admin.html.haml", "app/views/layouts/admin.html.haml"
43
+ end
44
+
45
+
46
+ def create_admin_resource_controllers
47
+ empty_directory "app/controllers/admin"
48
+ ##create admin application controller
49
+ template "admin_application_controller.rb", "app/controllers/admin/application_controller.rb"
50
+
51
+ #iterate over each resource, creating the controller template
52
+ resources.each do |resource|
53
+ template "controller.rb", "app/controllers/admin/#{resource.pluralize}_controller.rb", resource: resource
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ class DevshopGemsGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def gems_to_enable
5
+ #uncomment these gems
6
+ ["'debugger'", "'bcrypt-ruby'", "'capistrano'"].each do |lib|
7
+ gsub_file 'Gemfile', /# gem #{lib}/ do |match|
8
+ "gem #{lib}"
9
+ end
10
+ end
11
+
12
+ #replace sqlite3 with mysql2
13
+ gsub_file 'Gemfile', /gem 'sqlite3'/ do |match|
14
+ "gem 'mysql2'"
15
+ end
16
+
17
+ #add haml, simple form
18
+ gem 'haml-rails'
19
+ gem 'simple_form'
20
+
21
+
22
+ #add following gems to development
23
+ gem_group :development do
24
+ gem 'letter_opener'
25
+ gem 'quiet_assets'
26
+ gem 'thin'
27
+ end
28
+
29
+ run "bundle install"
30
+ end
31
+
32
+ end
@@ -0,0 +1,138 @@
1
+ class DevshopGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ #to accept arguments
5
+ argument :app_name, type: :string
6
+
7
+ #remove files not being used or that will be replaced by our templates
8
+ def remove_files
9
+ remove_file "app/public/index.html"
10
+ remove_file "app/views/layouts/application.html.erb"
11
+ remove_file "app/assets/stylesheets/application.css"
12
+ remove_file "app/assets/javascripts/application.js"
13
+ remove_file "config/database.yml"
14
+ remove_file "app/helpers/application_helper.rb"
15
+ remove_file "db/seeds.rb"
16
+ end
17
+
18
+ def public_views
19
+ empty_directory 'app/views/public'
20
+ create_file 'app/views/public/index.html.haml', "this is your public index page"
21
+ end
22
+
23
+ def gems_to_enable
24
+ #uncomment these gems
25
+ ["'debugger'", "'bcrypt-ruby'", "'capistrano'"].each do |lib|
26
+ gsub_file 'Gemfile', /# gem #{lib}/ do |match|
27
+ "gem #{lib}"
28
+ end
29
+ end
30
+
31
+ #replace sqlite3 with mysql2
32
+ gsub_file 'Gemfile', /gem 'sqlite3'/ do |match|
33
+ "gem 'mysql2'"
34
+ end
35
+
36
+ #add haml gem
37
+ gem 'haml-rails'
38
+
39
+
40
+ #add following gems to development
41
+ gem_group :development do
42
+ gem 'letter_opener'
43
+ gem 'quiet_assets'
44
+ gem 'thin'
45
+ end
46
+
47
+ run "bundle install"
48
+ end
49
+
50
+ def create_sql_db_yml_file
51
+ template "database.yml", "config/database.yml"
52
+ run "rake db:create"
53
+ end
54
+
55
+ def setup_administrator_model
56
+ run "rails g model Administrator email password_digest"
57
+ run "rake db:migrate"
58
+ inject_into_class "app/models/administrator.rb", Administrator do
59
+ "has_secure_password\n"
60
+ end
61
+ end
62
+
63
+
64
+ def create_seed_file
65
+ template "seeds.rb", "db/seeds.rb"
66
+ run "rake db:seed"
67
+ end
68
+
69
+ def create_application_helper
70
+ template "application_helper.rb", "app/helpers/application_helper.rb"
71
+ end
72
+
73
+ def create_root_route
74
+ insert_into_file "config/routes.rb", after: ".draw do" do
75
+ "\n\troot to: 'public#index'"
76
+ end
77
+ end
78
+
79
+ def create_public_controller
80
+ template "public_controller.rb", "app/controllers/public_controller.rb"
81
+ end
82
+
83
+ def create_sessions_view
84
+ template "sessions/new.html.haml", "app/views/admin/sessions/new.html.haml"
85
+ end
86
+
87
+ def create_name_spaced_assets
88
+ #create js assets
89
+ template "application.js", "app/assets/javascripts/application.js"
90
+
91
+ #create css assets
92
+ template "normalize.css", "app/assets/stylesheets/normalize.css"
93
+ template "base.css.sass", "app/assets/stylesheets/base.css.sass"
94
+ template "application.css.sass", "app/assets/stylesheets/application.css.sass"
95
+
96
+
97
+ #create admin js assets
98
+ empty_directory "app/assets/javascripts/admin"
99
+ template "bootstrap.js", "app/assets/javascripts/admin/bootstrap.js"
100
+ template "admin_application.js", "app/assets/javascripts/admin/application.js"
101
+
102
+ #create admin css assets
103
+ empty_directory "app/assets/stylesheets/admin"
104
+ template "bootstrap.css", "app/assets/stylesheets/admin/bootstrap.css"
105
+ template "admin_application.css.sass", "app/assets/stylesheets/admin/application.css.sass"
106
+
107
+ ##application layout
108
+ template "application.html.haml", "app/views/layouts/application.html.haml"
109
+
110
+ end
111
+
112
+ def create_admin_sessions
113
+ #copy sessions controller template
114
+ template "sessions_controller.rb", "app/controllers/admin/sessions_controller.rb"
115
+ end
116
+
117
+ def create_basic_admin_routes
118
+ #remove example code which screws up the route insert
119
+ gsub_file "config/routes.rb", /# namespace :admin do/, ""
120
+
121
+ #insert admin namespace
122
+ insert_into_file "config/routes.rb", after: ".draw do" do
123
+ "\n\s namespace :admin do \n\tend"
124
+ end
125
+
126
+
127
+ #insert login / logout / create session routes
128
+ insert_into_file "config/routes.rb", after: "namespace :admin do" do
129
+ "\n\t\tget 'login', to: 'sessions#new', as: :login\n\t\tget 'logout', to: 'sessions#destroy', as: :logout\n\t\tpost 'sessions', to: 'sessions#create', as: :sessions"
130
+ end
131
+
132
+ #insert root admin route
133
+ insert_into_file "config/routes.rb", after: "namespace :admin do" do
134
+ "\n\t\tget '/', to: 'administrators#index', as: :root"
135
+ end
136
+
137
+ end
138
+ end
@@ -0,0 +1,7 @@
1
+ = simple_form_for [:admin, @<%= config[:resource] %>] do |f|
2
+ <%- config[:resource].classify.constantize.columns.reject {|c| !!(c.name =~ /created_at/ || c.name =~ /updated_at/ || c.name == "id")}.map {|c| [c.name, c.type]}.each do |field| -%>
3
+ .form-group
4
+ = f.input :<%= field.first.to_sym%>
5
+ <%- end -%>
6
+ .form-group
7
+ = f.submit
@@ -0,0 +1,29 @@
1
+ !!! html5
2
+ %html
3
+ %head
4
+ %title
5
+ = stylesheet_link_tag "admin/application", media: "all"
6
+ = javascript_include_tag "admin/application"
7
+ = csrf_meta_tags
8
+
9
+ %body
10
+ %nav.navbar.navbar-default{role: "navigation"}
11
+ .navbar-inner
12
+ .container
13
+ .navbar-brand
14
+ =link_to 'Brand Name Here', admin_root_path
15
+ - if current_admin
16
+ %ul.nav.navbar-nav
17
+ <%- resources.each do |resource| -%>
18
+ %li= link_to <%= resource.classify %>, admin_<%= resource.downcase.pluralize %>_path
19
+ <%- end -%>
20
+ %ul.nav.navbar-nav.pull-right
21
+ %li= link_to 'Logout', admin_logout_path
22
+ .clear
23
+ .container
24
+ .main
25
+ = bootstrap_flash
26
+ = yield
27
+
28
+
29
+
@@ -0,0 +1,2 @@
1
+ @import 'admin/bootstrap'
2
+ @import 'normalize'
@@ -0,0 +1,4 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require admin/bootstrap
4
+
@@ -0,0 +1,17 @@
1
+ class Admin::ApplicationController < ApplicationController
2
+ layout 'admin'
3
+ before_filter :require_admin
4
+
5
+
6
+
7
+ def current_admin
8
+ @admin ||= Administrator.find_by_id(session[:admin_id])
9
+ end
10
+ helper_method :current_admin
11
+
12
+ private
13
+ def require_admin
14
+ redirect_to admin_login_path unless current_admin
15
+ end
16
+
17
+ end
@@ -0,0 +1,2 @@
1
+ @import 'normalize'
2
+ @import 'base'
@@ -0,0 +1,13 @@
1
+ !!! html5
2
+ %html
3
+ %head
4
+ %title
5
+ = stylesheet_link_tag "application", media: "all"
6
+ = javascript_include_tag "application"
7
+ = csrf_meta_tags
8
+
9
+ %body
10
+ = yield
11
+
12
+
13
+
@@ -0,0 +1,2 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
@@ -0,0 +1,18 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ #check to see that user is logged in and assign helper
5
+ # def current_user
6
+ # @current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
7
+ # end
8
+ # helper_method :current_user
9
+
10
+ private
11
+
12
+ #redirect user to homepage unless he's logged in
13
+ # def require_user
14
+ # redirect_to index_path, notice: 'You must first login' unless current_user
15
+ # end
16
+
17
+
18
+ end