lazy-head-gen 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/Gemfile +0 -2
  2. data/README.md +10 -2
  3. data/VERSION +1 -1
  4. data/lazy-head-gen.gemspec +43 -10
  5. data/lib/lazy-head-gen.rb +1 -1
  6. data/lib/lazy-head-gen/admin_controller_test.rb +2 -1
  7. data/lib/lazy-head-gen/bootstrapped_admin_app.rb +121 -0
  8. data/lib/lazy-head-gen/bootstrapped_admin_page.rb +58 -0
  9. data/lib/lazy-head-gen/scaffold.rb +8 -7
  10. data/lib/lazy-head-gen/templates/admin_app/account/activerecord.rb.tt +38 -0
  11. data/lib/lazy-head-gen/templates/admin_app/account/seeds.rb.tt +28 -0
  12. data/lib/lazy-head-gen/templates/admin_app/app.rb.tt +36 -0
  13. data/lib/lazy-head-gen/templates/admin_app/app/controllers/base.rb +6 -0
  14. data/lib/lazy-head-gen/templates/admin_app/app/controllers/sessions.rb.tt +26 -0
  15. data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.css +815 -0
  16. data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.min.css +9 -0
  17. data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.css +4983 -0
  18. data/lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.min.css +9 -0
  19. data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-114-precomposed.png +0 -0
  20. data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-144-precomposed.png +0 -0
  21. data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-57-precomposed.png +0 -0
  22. data/lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-72-precomposed.png +0 -0
  23. data/lib/lazy-head-gen/templates/admin_app/assets/ico/favicon.ico +0 -0
  24. data/lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings-white.png +0 -0
  25. data/lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings.png +0 -0
  26. data/lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.js +1825 -0
  27. data/lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.min.js +6 -0
  28. data/lib/lazy-head-gen/templates/admin_app/assets/js/jquery-min.js +4 -0
  29. data/lib/lazy-head-gen/templates/admin_app/assets/js/jquery-ujs.js +92 -0
  30. data/lib/lazy-head-gen/templates/admin_app/assets/js/jquery.js +9404 -0
  31. data/lib/lazy-head-gen/templates/admin_app/erb/app/base/index.erb.tt +14 -0
  32. data/lib/lazy-head-gen/templates/admin_app/erb/app/layouts/application.erb.tt +79 -0
  33. data/lib/lazy-head-gen/templates/admin_app/erb/app/sessions/new.erb.tt +98 -0
  34. data/lib/lazy-head-gen/templates/admin_app/erb/page/_form.erb.tt +16 -0
  35. data/lib/lazy-head-gen/templates/admin_app/erb/page/edit.erb.tt +26 -0
  36. data/lib/lazy-head-gen/templates/admin_app/erb/page/index.erb.tt +41 -0
  37. data/lib/lazy-head-gen/templates/admin_app/erb/page/new.erb.tt +23 -0
  38. data/lib/lazy-head-gen/templates/admin_app/page/controller.rb.tt +47 -0
  39. data/lib/lazy-head-gen/templates/{admin_controller_test.rb.tt → admin_controller_test/admin_controller_test.rb.tt} +0 -0
  40. data/lib/lazy-head-gen/templates/{blueprints.rb.tt → scaffold/blueprints.rb.tt} +0 -0
  41. data/lib/lazy-head-gen/templates/{controller.rb.tt → scaffold/controller.rb.tt} +0 -0
  42. data/lib/lazy-head-gen/templates/{controller_test.rb.tt → scaffold/controller_test.rb.tt} +0 -0
  43. data/lib/lazy-head-gen/templates/{helper.rb.tt → scaffold/helper.rb.tt} +0 -0
  44. data/lib/lazy-head-gen/templates/{model.rb.tt → scaffold/model.rb.tt} +0 -0
  45. data/lib/lazy-head-gen/templates/{model_test.rb.tt → scaffold/model_test.rb.tt} +0 -0
  46. data/lib/lazy-head-gen/templates/{view.erb.tt → scaffold/view.erb.tt} +0 -0
  47. data/test/helper.rb +1 -5
  48. data/test/lazy-head-gen/test_bootstrapped_admin_app_generator.rb +211 -0
  49. data/test/lazy-head-gen/test_bootstrapped_admin_page_generator.rb +94 -0
  50. metadata +45 -12
data/Gemfile CHANGED
@@ -11,8 +11,6 @@ group :development do
11
11
  gem "bundler"
12
12
  gem "jeweler", "~> 1.6.4"
13
13
  gem "yard", "~> 0.6.0"
14
- # gem 'ruby-debug'
15
- # gem "simplecov"
16
14
 
17
15
  # From Padrino Framework
18
16
  if ENV['SINATRA_EDGE']
data/README.md CHANGED
@@ -19,9 +19,9 @@ gem 'lazy-head-gen', :group => [:development, :test]
19
19
  Padrino gotcha: You'll need to put the `gem 'lazy-head-gen'` requirement *after* `gem 'padrino'` in your Gemfile.
20
20
  Lazy Head Gen needs Padrino loaded before it can work.
21
21
 
22
- ## Usage
22
+ Also you will need to add this gem for both :development and :test groups. This is because there are a couple of added test helper functions and assertions used by the output from the generators.
23
23
 
24
- There are currently 2 extra generators, scaffold and admin_controller_tests.
24
+ ## Usage
25
25
 
26
26
  ### Scaffold Generator
27
27
 
@@ -67,6 +67,14 @@ padrino g admin_controller_tests products
67
67
 
68
68
  This will generate a fully tested admin controller test for the 6 CRUD routes of a standard Padrino admin controller.
69
69
 
70
+ ### Bootstrapped Admin Generator
71
+
72
+ TODO: write about this
73
+
74
+ ### Bootstrapped Admin Page Generator
75
+
76
+ TODO: write about this
77
+
70
78
  ## Extras
71
79
 
72
80
  ### Built in assertions and test helpers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lazy-head-gen"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Stuart Chinery"]
12
- s.date = "2012-06-07"
12
+ s.date = "2012-07-04"
13
13
  s.description = "Lazy Head Gen is simply a couple of extra generators for the excellent Padrino framework."
14
14
  s.email = "stuart.chinery@headlondon.com"
15
15
  s.extra_rdoc_files = [
@@ -27,17 +27,50 @@ Gem::Specification.new do |s|
27
27
  "lazy-head-gen.gemspec",
28
28
  "lib/lazy-head-gen.rb",
29
29
  "lib/lazy-head-gen/admin_controller_test.rb",
30
+ "lib/lazy-head-gen/bootstrapped_admin_app.rb",
31
+ "lib/lazy-head-gen/bootstrapped_admin_page.rb",
30
32
  "lib/lazy-head-gen/scaffold.rb",
31
- "lib/lazy-head-gen/templates/admin_controller_test.rb.tt",
32
- "lib/lazy-head-gen/templates/blueprints.rb.tt",
33
- "lib/lazy-head-gen/templates/controller.rb.tt",
34
- "lib/lazy-head-gen/templates/controller_test.rb.tt",
35
- "lib/lazy-head-gen/templates/helper.rb.tt",
36
- "lib/lazy-head-gen/templates/model.rb.tt",
37
- "lib/lazy-head-gen/templates/model_test.rb.tt",
38
- "lib/lazy-head-gen/templates/view.erb.tt",
33
+ "lib/lazy-head-gen/templates/admin_app/account/activerecord.rb.tt",
34
+ "lib/lazy-head-gen/templates/admin_app/account/seeds.rb.tt",
35
+ "lib/lazy-head-gen/templates/admin_app/app.rb.tt",
36
+ "lib/lazy-head-gen/templates/admin_app/app/controllers/base.rb",
37
+ "lib/lazy-head-gen/templates/admin_app/app/controllers/sessions.rb.tt",
38
+ "lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.css",
39
+ "lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap-responsive.min.css",
40
+ "lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.css",
41
+ "lib/lazy-head-gen/templates/admin_app/assets/css/bootstrap.min.css",
42
+ "lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-114-precomposed.png",
43
+ "lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-144-precomposed.png",
44
+ "lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-57-precomposed.png",
45
+ "lib/lazy-head-gen/templates/admin_app/assets/ico/apple-touch-icon-72-precomposed.png",
46
+ "lib/lazy-head-gen/templates/admin_app/assets/ico/favicon.ico",
47
+ "lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings-white.png",
48
+ "lib/lazy-head-gen/templates/admin_app/assets/img/glyphicons-halflings.png",
49
+ "lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.js",
50
+ "lib/lazy-head-gen/templates/admin_app/assets/js/bootstrap.min.js",
51
+ "lib/lazy-head-gen/templates/admin_app/assets/js/jquery-min.js",
52
+ "lib/lazy-head-gen/templates/admin_app/assets/js/jquery-ujs.js",
53
+ "lib/lazy-head-gen/templates/admin_app/assets/js/jquery.js",
54
+ "lib/lazy-head-gen/templates/admin_app/erb/app/base/index.erb.tt",
55
+ "lib/lazy-head-gen/templates/admin_app/erb/app/layouts/application.erb.tt",
56
+ "lib/lazy-head-gen/templates/admin_app/erb/app/sessions/new.erb.tt",
57
+ "lib/lazy-head-gen/templates/admin_app/erb/page/_form.erb.tt",
58
+ "lib/lazy-head-gen/templates/admin_app/erb/page/edit.erb.tt",
59
+ "lib/lazy-head-gen/templates/admin_app/erb/page/index.erb.tt",
60
+ "lib/lazy-head-gen/templates/admin_app/erb/page/new.erb.tt",
61
+ "lib/lazy-head-gen/templates/admin_app/page/controller.rb.tt",
62
+ "lib/lazy-head-gen/templates/admin_controller_test/admin_controller_test.rb.tt",
63
+ "lib/lazy-head-gen/templates/scaffold/blueprints.rb.tt",
64
+ "lib/lazy-head-gen/templates/scaffold/controller.rb.tt",
65
+ "lib/lazy-head-gen/templates/scaffold/controller_test.rb.tt",
66
+ "lib/lazy-head-gen/templates/scaffold/helper.rb.tt",
67
+ "lib/lazy-head-gen/templates/scaffold/model.rb.tt",
68
+ "lib/lazy-head-gen/templates/scaffold/model_test.rb.tt",
69
+ "lib/lazy-head-gen/templates/scaffold/view.erb.tt",
39
70
  "test/helper.rb",
40
71
  "test/lazy-head-gen/test_admin_controller_test.rb",
72
+ "test/lazy-head-gen/test_bootstrapped_admin_app_generator.rb",
73
+ "test/lazy-head-gen/test_bootstrapped_admin_page_generator.rb",
41
74
  "test/lazy-head-gen/test_scaffold.rb",
42
75
  "test/load_paths.rb",
43
76
  "test/test_lazy-head-gen.rb"
data/lib/lazy-head-gen.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  begin
2
2
  require 'padrino-gen'
3
- Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/lazy-head-gen/{admin_controller_test,scaffold}.rb']
3
+ Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/lazy-head-gen/{admin_controller_test,scaffold,actions,orm,bootstrapped_admin_app,bootstrapped_admin_page}.rb']
4
4
  rescue LoadError
5
5
  # Fail silently
6
6
  end
@@ -23,6 +23,7 @@ module Padrino
23
23
 
24
24
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
25
25
 
26
+ # Show help if no argv given
26
27
  require_arguments!
27
28
 
28
29
  def create_admin_controller_test
@@ -41,7 +42,7 @@ module Padrino
41
42
  controller_path = destination_root("admin", "controllers", "#{@pluralized}.rb")
42
43
 
43
44
  if File.exist?(controller_path)
44
- template "templates/admin_controller_test.rb.tt", destination_root("test", "admin", "controllers", "#{@pluralized}_controller_test.rb")
45
+ template "templates/admin_controller_test/admin_controller_test.rb.tt", destination_root("test", "admin", "controllers", "#{@pluralized}_controller_test.rb")
45
46
  else
46
47
  say "The controller '#{controller_path} does not exist, please run 'padrino g admin_page #{@model}' to create the initial admin controller", :red
47
48
  return
@@ -0,0 +1,121 @@
1
+ module Padrino
2
+ module Generators
3
+ ##
4
+ # Defines the generator for creating a new admin app.
5
+ #
6
+ class BootstrappedAdminApp < Thor::Group
7
+
8
+ # Add this generator to our padrino-gen
9
+ Padrino::Generators.add_generator(:bootstrapped_admin, self)
10
+
11
+ # Define the source template root and themes.
12
+ def self.source_root; File.expand_path(File.dirname(__FILE__)); end
13
+ # Defines the "banner" text for the CLI.
14
+ def self.banner; "padrino-gen bootstrapped_admin"; end
15
+ # Defines the theme names for admin based on available.
16
+ # def self.themes; Dir[File.dirname(__FILE__) + "/templates/admin_app/assets/stylesheets/themes/*"].map { |t| File.basename(t) }.sort; end
17
+
18
+ # Include related modules
19
+ include Thor::Actions
20
+ include Padrino::Generators::Actions
21
+ include Padrino::Generators::Admin::Actions
22
+
23
+ desc "Description:\n\n\tpadrino-gen bootstrapped_admin generates a new Padrino Admin application with Twitter Bootstrapped integrated"
24
+
25
+ class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
26
+
27
+ class_option :app, :aliases => "-a", :desc => "The model destination path", :default => '.', :type => :string
28
+
29
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
30
+
31
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
32
+
33
+ class_option :admin_model, :aliases => '-m', :desc => "The name of model for access controlling", :default => 'Account', :type => :string
34
+
35
+ # Copies over the Padrino base admin application
36
+ def create_admin
37
+ self.destination_root = options[:root]
38
+ if in_app_root?
39
+ store_component_choice(:admin_renderer, :erb)
40
+
41
+ self.behavior = :revoke if options[:destroy]
42
+
43
+ empty_directory destination_root("admin")
44
+ directory "templates/admin_app/app", destination_root("admin")
45
+ directory "templates/admin_app/assets", destination_root("public", "admin")
46
+ template "templates/admin_app/app.rb.tt", destination_root("admin/app.rb")
47
+ append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"Admin\").to(\"/admin\")"
48
+ insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement', 'admin'
49
+
50
+ account_params = [
51
+ options[:admin_model].underscore, "name:string", "surname:string", "email:string", "crypted_password:string", "role:string",
52
+ "-a=#{options[:app]}",
53
+ "-r=#{options[:root]}"
54
+ ]
55
+
56
+ account_params << "-s" if options[:skip_migration]
57
+ account_params << "-d" if options[:destroy]
58
+
59
+ Padrino::Generators::Model.start(account_params)
60
+ column = Struct.new(:name, :type)
61
+ columns = [:id, :name, :surname, :email].map { |col| column.new(col) }
62
+ column_fields = [
63
+ { :name => :name, :field_type => :text_field },
64
+ { :name => :surname, :field_type => :text_field },
65
+ { :name => :email, :field_type => :text_field },
66
+ { :name => :password, :field_type => :password_field },
67
+ { :name => :password_confirmation, :field_type => :password_field },
68
+ { :name => :role, :field_type => :text_field }
69
+ ]
70
+
71
+ admin_page = Padrino::Generators::BootstrappedAdminPage.new([options[:admin_model].underscore], :root => options[:root], :destroy => options[:destroy])
72
+ admin_page.default_orm = Padrino::Admin::Generators::Orm.new(options[:admin_model].underscore, orm, columns, column_fields)
73
+ admin_page.invoke_all
74
+
75
+ template "templates/admin_app/account/activerecord.rb.tt", destination_root(options[:app], "models", "#{options[:admin_model].underscore}.rb"), :force => true
76
+
77
+ if File.exist?(destination_root("db/seeds.rb"))
78
+ run "mv #{destination_root('db/seeds.rb')} #{destination_root('db/seeds.old')}"
79
+ end
80
+ template "templates/admin_app/account/seeds.rb.tt", destination_root("db/seeds.rb")
81
+
82
+ empty_directory destination_root("admin/controllers")
83
+ empty_directory destination_root("admin/views")
84
+ empty_directory destination_root("admin/views/base")
85
+ empty_directory destination_root("admin/views/layouts")
86
+ empty_directory destination_root("admin/views/sessions")
87
+
88
+ template "templates/admin_app/#{ext}/app/base/index.#{ext}.tt", destination_root("admin/views/base/index.#{ext}")
89
+ template "templates/admin_app/#{ext}/app/layouts/application.#{ext}.tt", destination_root("admin/views/layouts/application.#{ext}")
90
+ template "templates/admin_app/#{ext}/app/sessions/new.#{ext}.tt", destination_root("admin/views/sessions/new.#{ext}")
91
+
92
+ model_singular = options[:admin_model].underscore
93
+ model_plural = model_singular.pluralize
94
+
95
+ add_project_module model_plural
96
+ require_dependencies('bcrypt-ruby', :require => 'bcrypt')
97
+ gsub_file destination_root("admin/views/#{model_plural}/_form.#{ext}"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
98
+ gsub_file destination_root("admin/controllers/#{model_plural}.rb"), "if #{model_singular}.destroy", "if #{model_singular} != current_account && #{model_singular}.destroy"
99
+ return if self.behavior == :revoke
100
+
101
+ instructions = []
102
+ instructions << "Run 'bundle install'"
103
+ instructions << "Run 'padrino rake ar:migrate'"
104
+ instructions << "Run 'padrino rake seed'"
105
+ instructions << "Visit the admin panel in the browser at '/admin'"
106
+ instructions.map! { |i| " #{instructions.index(i)+1}) #{i}" }
107
+
108
+ say
109
+ say "="*65, :green
110
+ say "The admin panel has been mounted! Next, follow these steps:", :green
111
+ say "="*65, :green
112
+ say instructions.join("\n")
113
+ say "="*65, :green
114
+ say
115
+ else
116
+ say "You are not at the root of a Padrino application! (config/boot.rb not found)"
117
+ end
118
+ end
119
+ end # AdminApp
120
+ end # Generators
121
+ end # Padrino
@@ -0,0 +1,58 @@
1
+ module Padrino
2
+ module Generators
3
+ ##
4
+ # Defines the generator for creating a new admin page.
5
+ #
6
+ class BootstrappedAdminPage < Thor::Group
7
+ attr_accessor :default_orm
8
+
9
+ # Add this generator to our padrino-gen
10
+ Padrino::Generators.add_generator(:bootstrapped_admin_page, self)
11
+
12
+ # Define the source template root
13
+ def self.source_root; File.expand_path(File.dirname(__FILE__)); end
14
+ # Defines the "banner" text for the CLI.
15
+ def self.banner; "padrino-gen bootstrapped_admin_page [model]"; end
16
+
17
+ # Include related modules
18
+ include Thor::Actions
19
+ include Padrino::Generators::Actions
20
+ include Padrino::Generators::Admin::Actions
21
+
22
+ desc "Description:\n\n\tpadrino-gen bootstrapped_admin_page model(s) generates a new Padrino Admin page with Twitter Bootstrapped integrated"
23
+
24
+ argument :models, :desc => "The name(s) of your model(s)", :type => :array
25
+
26
+ class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
27
+
28
+ class_option :root, :desc => "The root destination", :aliases => '-r', :type => :string
29
+
30
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
31
+
32
+ # Show help if no argv given
33
+ require_arguments!
34
+
35
+ # Create controller for admin
36
+ def create_controller
37
+ self.destination_root = options[:root]
38
+ if in_app_root?
39
+ models.each do |model|
40
+ @orm = default_orm || Padrino::Admin::Generators::Orm.new(model, adapter)
41
+ self.behavior = :revoke if options[:destroy]
42
+ empty_directory destination_root("/admin/views/#{@orm.name_plural}")
43
+
44
+ template "templates/admin_app/page/controller.rb.tt", destination_root("/admin/controllers/#{@orm.name_plural}.rb")
45
+ template "templates/admin_app/erb/page/_form.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/_form.erb")
46
+ template "templates/admin_app/erb/page/edit.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/edit.erb")
47
+ template "templates/admin_app/erb/page/index.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/index.erb")
48
+ template "templates/admin_app/erb/page/new.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/new.erb")
49
+
50
+ options[:destroy] ? remove_project_module(@orm.name_plural) : add_project_module(@orm.name_plural)
51
+ end
52
+ else
53
+ say "You are not at the root of a Padrino application! (config/boot.rb not found)"
54
+ end
55
+ end
56
+ end # AdminPage
57
+ end # Generators
58
+ end # Padrino
@@ -38,6 +38,7 @@ module Padrino
38
38
  class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean,
39
39
  :desc => "Specify whether to skip generating a migration"
40
40
 
41
+ # Show help if no argv given
41
42
  require_arguments!
42
43
 
43
44
  def create_scaffold
@@ -74,13 +75,13 @@ module Padrino
74
75
  # model_path = options[:model_path]
75
76
  model_path = "."
76
77
 
77
- template "templates/model.rb.tt", destination_root(model_path, "models", "#{@singular}.rb")
78
- template "templates/model_test.rb.tt", destination_root("test", model_path, "models", "#{@singular}_test.rb")
78
+ template "templates/scaffold/model.rb.tt", destination_root(model_path, "models", "#{@singular}.rb")
79
+ template "templates/scaffold/model_test.rb.tt", destination_root("test", model_path, "models", "#{@singular}_test.rb")
79
80
 
80
81
  # Create controller
81
- template "templates/controller.rb.tt", destination_root(app, "controllers", "#{@pluralized}.rb")
82
- template "templates/controller_test.rb.tt", destination_root("test", app, "controllers", "#{@pluralized}_controller_test.rb")
83
- template "templates/helper.rb.tt", destination_root(app, "helpers", "#{@pluralized}_helper.rb")
82
+ template "templates/scaffold/controller.rb.tt", destination_root(app, "controllers", "#{@pluralized}.rb")
83
+ template "templates/scaffold/controller_test.rb.tt", destination_root("test", app, "controllers", "#{@pluralized}_controller_test.rb")
84
+ template "templates/scaffold/helper.rb.tt", destination_root(app, "helpers", "#{@pluralized}_helper.rb")
84
85
 
85
86
  # Create views
86
87
  views = ["index", "show"]
@@ -90,7 +91,7 @@ module Padrino
90
91
 
91
92
  views.each do |view|
92
93
  @view = view
93
- template "templates/view.erb.tt", destination_root(app, "views", "#{@pluralized}", "#{@view}.erb")
94
+ template "templates/scaffold/view.erb.tt", destination_root(app, "views", "#{@pluralized}", "#{@view}.erb")
94
95
  end
95
96
 
96
97
  # Create a migration unless skipped
@@ -98,7 +99,7 @@ module Padrino
98
99
 
99
100
  # Check if blueprints file exists and copy into place if not
100
101
  if !File.exist?(destination_root("test", "blueprints.rb"))
101
- template "templates/blueprints.rb.tt", destination_root("test", "blueprints.rb")
102
+ template "templates/scaffold/blueprints.rb.tt", destination_root("test", "blueprints.rb")
102
103
  end
103
104
 
104
105
  # Insert into text_config.rb require blueprints.rb
@@ -0,0 +1,38 @@
1
+ class <%= options[:admin_model].underscore.camelize %> < ActiveRecord::Base
2
+ attr_accessor :password, :password_confirmation
3
+
4
+ # Validations
5
+ validates_presence_of :email, :role
6
+ validates_presence_of :password, :if => :password_required
7
+ validates_presence_of :password_confirmation, :if => :password_required
8
+ validates_length_of :password, :within => 4..40, :if => :password_required
9
+ validates_confirmation_of :password, :if => :password_required
10
+ validates_length_of :email, :within => 3..100
11
+ validates_uniqueness_of :email, :case_sensitive => false
12
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
13
+ validates_format_of :role, :with => /[A-Za-z]/
14
+
15
+ # Callbacks
16
+ before_save :encrypt_password, :if => :password_required
17
+
18
+ ##
19
+ # This method is for authentication purpose
20
+ #
21
+ def self.authenticate(email, password)
22
+ account = first(:conditions => { :email => email }) if email.present?
23
+ account && account.has_password?(password) ? account : nil
24
+ end
25
+
26
+ def has_password?(password)
27
+ ::BCrypt::Password.new(crypted_password) == password
28
+ end
29
+
30
+ private
31
+ def encrypt_password
32
+ self.crypted_password = ::BCrypt::Password.create(password)
33
+ end
34
+
35
+ def password_required
36
+ crypted_password.blank? || password.present?
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ # Seed add you the ability to populate your db.
2
+ # We provide you a basic shell for interaction with the end user.
3
+ # So try some code like below:
4
+ #
5
+ # name = shell.ask("What's your name?")
6
+ # shell.say name
7
+ #
8
+ email = shell.ask "Which email do you want use for logging into admin?"
9
+ password = shell.ask "Tell me the password to use:"
10
+
11
+ shell.say ""
12
+
13
+ account = <%= options[:admin_model].underscore.camelize %>.create(:email => email, :name => "Foo", :surname => "Bar", :password => password, :password_confirmation => password, :role => "admin")
14
+
15
+ if account.valid?
16
+ shell.say "================================================================="
17
+ shell.say "<%= options[:admin_model].underscore.camelize %> has been successfully created, now you can login with:"
18
+ shell.say "================================================================="
19
+ shell.say " email: #{email}"
20
+ shell.say " password: #{password}"
21
+ shell.say "================================================================="
22
+ else
23
+ shell.say "Sorry but some thing went wrong!"
24
+ shell.say ""
25
+ account.errors.full_messages.each { |m| shell.say " - #{m}" }
26
+ end
27
+
28
+ shell.say ""
@@ -0,0 +1,36 @@
1
+ class Admin < Padrino::Application
2
+ register Padrino::Rendering
3
+ register Padrino::Mailer
4
+ register Padrino::Helpers
5
+ register Padrino::Admin::AccessControl
6
+
7
+ ##
8
+ # Application configuration options
9
+ #
10
+ # set :raise_errors, true # Raise exceptions (will stop application) (default for test)
11
+ # set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development)
12
+ # set :show_exceptions, true # Shows a stack trace in browser (default for development)
13
+ # set :logging, true # Logging in STDOUT for development and file for production (default only for development)
14
+ # set :public_folder, "foo/bar" # Location for static assets (default root/public)
15
+ # set :reload, false # Reload application files (default in development)
16
+ # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
17
+ # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
18
+ # disable :sessions # Disabled sessions by default (enable if needed)
19
+ # disable :flash # Disables sinatra-flash (enabled by default if Sinatra::Flash is defined)
20
+ # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
21
+ #
22
+
23
+ set :admin_model, '<%= options[:admin_model] %>'
24
+ set :login_page, "/admin/sessions/new"
25
+
26
+ enable :sessions
27
+ disable :store_location
28
+
29
+ access_control.roles_for :any do |role|
30
+ role.protect "/"
31
+ role.allow "/sessions"
32
+ end
33
+
34
+ access_control.roles_for :admin do |role|
35
+ end
36
+ end