padrino-admin 0.12.0.rc1 → 0.12.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59d3555e8e56082baba626251a152c8663016484
4
- data.tar.gz: 6cd5f67e229164a70c9d34dc0a335da06e904824
3
+ metadata.gz: e983af1fb92a4c0ad9457128ec169c15ca4a9ccf
4
+ data.tar.gz: 22517aab5237143525fb7721e24a4246bc50415d
5
5
  SHA512:
6
- metadata.gz: ec01231b86c0a2ebedd62a5bcfc7ceb82bacd0766ec933fa20e8ee8c95c908032252b4d8fccb50fcfff8fa655e05875262a4d082f63e51bed94437fd98ad326f
7
- data.tar.gz: ed059febbc883daddac9d2d9c790a520e5cdbd14b1665d80d4abd69d54b4d417f90f1327f3fa539f6e44fe6fa39fbe9669195868a98d190c6d09442d22473c7f
6
+ metadata.gz: 382fdbf12184bf8873fd3556e04f8bc855189af9ed1c5f4a0ab2c51f418d6e3cfd35402b2a2d1c13eadb37a84450d9d22ce70bce9c055433c5d9fe319a18569d
7
+ data.tar.gz: 9cd98159c6583825ca5b179641c84fe78e80543547628f8ef95aa8b41fba292d0415979c5948d32cb5cdfebd750e0953de7310a0edfe9248f31bd986b81743bf
@@ -41,16 +41,16 @@ module Padrino
41
41
  # Add access_control permission in our app.rb.
42
42
  #
43
43
  def add_project_module(controller)
44
- permission = " role.project_module :#{controller}, '/#{controller}'\n"
45
- inject_into_file destination_root('/admin/app.rb'), permission, :after => "access_control.roles_for :admin do |role|\n"
44
+ permission = " role.project_module :#{controller}, '/#{controller}'\n"
45
+ inject_into_file destination_root(@admin_path+'/app.rb'), permission, :after => "access_control.roles_for :admin do |role|\n"
46
46
  end
47
47
 
48
48
  ##
49
49
  # Remove from access_control permissions.
50
50
  #
51
51
  def remove_project_module(controller)
52
- path = destination_root('/admin/app.rb')
53
- say_status :replace, 'admin/app.rb', :red
52
+ path = destination_root(@admin_path+'/app.rb')
53
+ say_status :replace, @admin_path+'/app.rb', :red
54
54
  content = File.binread(path)
55
55
  content.gsub!(/^\s+role\.project_module :#{controller}, '\/#{controller}'\n/, '')
56
56
  File.open(path, 'wb') { |f| f.write content }
@@ -21,7 +21,7 @@ module Padrino
21
21
 
22
22
  # Look for custom template files in a generators folder under the project root.
23
23
  def source_paths
24
- if File.exists? destination_root('generators', 'templates')
24
+ if File.exist? destination_root('generators', 'templates')
25
25
  ["#{destination_root('generators')}", File.expand_path(File.dirname(__FILE__))]
26
26
  else
27
27
  [File.expand_path(File.dirname(__FILE__))]
@@ -31,14 +31,12 @@ module Padrino
31
31
  desc "Description:\n\n\tpadrino-gen admin generates a new Padrino Admin application"
32
32
 
33
33
  class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
34
- # TODO FIXME Review these and implement accordingly.
35
- # See https://github.com/padrino/padrino-framework/issues/854#issuecomment-14749356
36
- # class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
37
34
  # class_option :models_path, :desc => 'The models destination path', :default => '.', :type => :string
38
35
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
39
36
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
40
37
  class_option :renderer, :aliases => '-e', :desc => "Rendering engine (erb, haml)", :type => :string
41
38
  class_option :admin_model, :aliases => '-m', :desc => "The name of model for access controlling", :default => 'Account', :type => :string
39
+ class_option :admin_name, :aliases => '-a', :desc => 'The admin application name and path', :default => 'admin', :type => :string
42
40
 
43
41
  # Copies over the Padrino base admin application.
44
42
  def create_admin
@@ -58,23 +56,27 @@ module Padrino
58
56
  # Get the app's namespace.
59
57
  @app_name = fetch_app_name
60
58
 
59
+ # setup admin app name
60
+ @admin_name = options[:admin_name].classify
61
+ @admin_path = options[:admin_name].underscore
62
+
61
63
  store_component_choice(:admin_renderer, tmp_ext)
62
64
 
63
65
  self.behavior = :revoke if options[:destroy]
64
66
 
65
- empty_directory destination_root("admin")
67
+ empty_directory destination_root(@admin_path)
66
68
 
67
69
  # Setup Admin Model
68
70
  @model_name = options[:admin_model].classify
69
71
  @model_singular = @model_name.underscore
70
72
  @model_plural = @model_singular.pluralize
71
73
 
72
- directory "templates/app", destination_root("admin")
73
- directory "templates/assets", destination_root("public", "admin")
74
- template "templates/app.rb.tt", destination_root("admin/app.rb")
75
- inject_into_file destination_root('config/apps.rb'), "\nPadrino.mount(\"#{@app_name}::Admin\", :app_file => File.expand_path('../../admin/app.rb', __FILE__)).to(\"/admin\")\n", :before => /^Padrino.mount.*\.to\('\/'\)$/
74
+ directory "templates/app", destination_root(@admin_path)
75
+ directory "templates/assets", destination_root("public", @admin_path)
76
+ template "templates/app.rb.tt", destination_root(@admin_path + "/app.rb")
77
+ inject_into_file destination_root('config/apps.rb'), "\nPadrino.mount(\"#{@app_name}::#{@admin_name}\", :app_file => Padrino.root('#{@admin_path}/app.rb')).to(\"/#{@admin_path}\")\n", :before => /^Padrino.mount.*\.to\('\/'\)$/
76
78
  unless options[:destroy]
77
- insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement', 'admin' if [:minirecord, :activerecord].include?(orm)
79
+ insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement', @admin_path if [:minirecord, :activerecord].include?(orm)
78
80
  end
79
81
 
80
82
  params = [
@@ -98,7 +100,7 @@ module Padrino
98
100
  ]
99
101
 
100
102
  unless options[:destroy]
101
- admin_app = Padrino::Generators::AdminPage.new([@model_singular], :root => options[:root], :destroy => options[:destroy], :admin_model => @model_singular)
103
+ admin_app = Padrino::Generators::AdminPage.new([@model_singular], :root => options[:root], :destroy => options[:destroy], :admin_model => @model_singular, :admin_name => @admin_name)
102
104
  admin_app.default_orm = Padrino::Admin::Generators::Orm.new(@model_singular, orm, columns, column_fields)
103
105
  admin_app.invoke_all
104
106
  end
@@ -111,21 +113,21 @@ module Padrino
111
113
  end
112
114
  template "templates/account/seeds.rb.tt", destination_root("db/seeds.rb")
113
115
 
114
- empty_directory destination_root("admin/controllers")
115
- empty_directory destination_root("admin/views")
116
- empty_directory destination_root("admin/views/base")
117
- empty_directory destination_root("admin/views/layouts")
118
- empty_directory destination_root("admin/views/sessions")
119
- empty_directory destination_root("admin/views/errors")
120
-
121
- template "templates/#{ext}/app/base/index.#{ext}.tt", destination_root("admin/views/base/index.#{ext}")
122
- template "templates/#{ext}/app/layouts/application.#{ext}.tt", destination_root("admin/views/layouts/application.#{ext}")
123
- template "templates/#{ext}/app/layouts/error.#{ext}.tt", destination_root("admin/views/layouts/error.#{ext}")
124
- template "templates/#{ext}/app/sessions/new.#{ext}.tt", destination_root("admin/views/sessions/new.#{ext}")
116
+ empty_directory destination_root(@admin_path+"/controllers")
117
+ empty_directory destination_root(@admin_path+"/views")
118
+ empty_directory destination_root(@admin_path+"/views/base")
119
+ empty_directory destination_root(@admin_path+"/views/layouts")
120
+ empty_directory destination_root(@admin_path+"/views/sessions")
121
+ empty_directory destination_root(@admin_path+"/views/errors")
122
+
123
+ template "templates/#{ext}/app/base/index.#{ext}.tt", destination_root(@admin_path+"/views/base/index.#{ext}")
124
+ template "templates/#{ext}/app/layouts/application.#{ext}.tt", destination_root(@admin_path+"/views/layouts/application.#{ext}")
125
+ template "templates/#{ext}/app/layouts/error.#{ext}.tt", destination_root(@admin_path+"/views/layouts/error.#{ext}")
126
+ template "templates/#{ext}/app/sessions/new.#{ext}.tt", destination_root(@admin_path+"/views/sessions/new.#{ext}")
125
127
  # Custom error.
126
- template "templates/#{ext}/app/errors/403.#{ext}.tt", destination_root("admin/views/errors/403.#{ext}")
127
- template "templates/#{ext}/app/errors/404.#{ext}.tt", destination_root("admin/views/errors/404.#{ext}")
128
- template "templates/#{ext}/app/errors/500.#{ext}.tt", destination_root("admin/views/errors/500.#{ext}")
128
+ template "templates/#{ext}/app/errors/403.#{ext}.tt", destination_root(@admin_path+"/views/errors/403.#{ext}")
129
+ template "templates/#{ext}/app/errors/404.#{ext}.tt", destination_root(@admin_path+"/views/errors/404.#{ext}")
130
+ template "templates/#{ext}/app/errors/500.#{ext}.tt", destination_root(@admin_path+"/views/errors/500.#{ext}")
129
131
 
130
132
  unless options[:destroy]
131
133
  add_project_module @model_plural
@@ -137,7 +139,7 @@ module Padrino
137
139
  # gsub_file destination_root("admin/views/#{@model_plural}/_form.#{ext}"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
138
140
 
139
141
  # Destroy account only if not logged in.
140
- gsub_file destination_root("admin/controllers/#{@model_plural}.rb"), "if #{@model_singular}.destroy", "if #{@model_singular} != current_account && #{@model_singular}.destroy"
142
+ gsub_file destination_root(@admin_path+"/controllers/#{@model_plural}.rb"), "if #{@model_singular}.destroy", "if #{@model_singular} != current_account && #{@model_singular}.destroy"
141
143
  return if self.behavior == :revoke
142
144
 
143
145
  instructions = []
@@ -145,7 +147,7 @@ module Padrino
145
147
  instructions << "Run 'bundle exec rake db:migrate'" if (orm == :activerecord || orm == :datamapper || orm == :sequel)
146
148
  instructions << "Now repeat after me... 'ohm mani padme hum', 'ohm mani padme hum'... :)" if orm == :ohm
147
149
  instructions << "Run 'bundle exec rake db:seed'"
148
- instructions << "Visit the admin panel in the browser at '/admin'"
150
+ instructions << "Visit the admin panel in the browser at '/#{@admin_path}'"
149
151
  instructions.map! { |i| " #{instructions.index(i)+1}) #{i}" }
150
152
 
151
153
  say
@@ -22,7 +22,7 @@ module Padrino
22
22
 
23
23
  # Look for custom template files in a generators folder under the project root.
24
24
  def source_paths
25
- if File.exists? destination_root('generators')
25
+ if File.exist? destination_root('generators')
26
26
  ["#{destination_root('generators')}", File.expand_path(File.dirname(__FILE__))]
27
27
  else
28
28
  [File.expand_path(File.dirname(__FILE__))]
@@ -32,32 +32,30 @@ module Padrino
32
32
  desc "Description:\n\n\tpadrino-gen admin_page model(s)"
33
33
  argument :models, :desc => "The name(s) of your model(s)", :type => :array
34
34
  class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
35
- # TODO FIXME Review these and implement accordingly.
36
- # See https://github.com/padrino/padrino-framework/issues/854#issuecomment-14749356
37
- # class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
38
35
  class_option :root, :desc => "The root destination", :aliases => '-r', :type => :string
39
36
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
37
+ class_option :admin_name, :aliases => '-a', :desc => 'The admin application name and path', :default => 'admin', :type => :string
40
38
  # Show help if no argv given.
41
39
  require_arguments!
42
40
 
43
41
  # Create controller for admin.
44
42
  def create_controller
45
43
  self.destination_root = options[:root]
46
- # TODO FIXME ??? Review
47
- # self.source_paths.unshift Padrino.root("vendor/padrino-admin/generators")
48
44
  if in_app_root?
49
45
  @app_name = fetch_app_name
46
+ @admin_name = options[:admin_name].classify
47
+ @admin_path = options[:admin_name].underscore
50
48
  @admin_model = options[:admin_model]
51
49
  models.each do |model|
52
50
  @orm = default_orm || Padrino::Admin::Generators::Orm.new(model, adapter)
53
51
  self.behavior = :revoke if options[:destroy]
54
- empty_directory destination_root("/admin/views/#{@orm.name_plural}")
52
+ empty_directory destination_root(@admin_path+"/views/#{@orm.name_plural}")
55
53
 
56
- template "templates/page/controller.rb.tt", destination_root("/admin/controllers/#{@orm.name_plural}.rb")
57
- template "templates/#{ext}/page/_form.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/_form.#{ext}")
58
- template "templates/#{ext}/page/edit.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/edit.#{ext}")
59
- template "templates/#{ext}/page/index.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/index.#{ext}")
60
- template "templates/#{ext}/page/new.#{ext}.tt", destination_root("/admin/views/#{@orm.name_plural}/new.#{ext}")
54
+ template "templates/page/controller.rb.tt", destination_root(@admin_path+"/controllers/#{@orm.name_plural}.rb")
55
+ template "templates/#{ext}/page/_form.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/_form.#{ext}")
56
+ template "templates/#{ext}/page/edit.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/edit.#{ext}")
57
+ template "templates/#{ext}/page/index.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/index.#{ext}")
58
+ template "templates/#{ext}/page/new.#{ext}.tt", destination_root(@admin_path+"/views/#{@orm.name_plural}/new.#{ext}")
61
59
 
62
60
  options[:destroy] ? remove_project_module(@orm.name_plural) : add_project_module(@orm.name_plural)
63
61
  end
@@ -1,5 +1,5 @@
1
1
  module <%= @app_name %>
2
- class Admin < Padrino::Application
2
+ class <%= @admin_name %> < Padrino::Application
3
3
  register Padrino::Rendering
4
4
  register Padrino::Mailer
5
5
  register Padrino::Helpers
@@ -22,7 +22,7 @@ module <%= @app_name %>
22
22
  #
23
23
 
24
24
  set :admin_model, '<%= @model_name %>'
25
- set :login_page, '/admin/sessions/new'
25
+ set :login_page, '/sessions/new'
26
26
 
27
27
  enable :sessions
28
28
  disable :store_location
@@ -1,4 +1,4 @@
1
- <%= @app_name %>::Admin.controllers :base do
1
+ <%= @app_name %>::<%= @admin_name %>.controllers :base do
2
2
  get :index, :map => "/" do
3
3
  render "base/index"
4
4
  end
@@ -1,4 +1,4 @@
1
- <%= @app_name %>::Admin.controllers :sessions do
1
+ <%= @app_name %>::<%= @admin_name %>.controllers :sessions do
2
2
  get :new do
3
3
  render "/sessions/new", nil, :layout => false
4
4
  end
@@ -31,7 +31,7 @@
31
31
  <%% else %>
32
32
  <li class=navbar-module>
33
33
  <%% end %>
34
- <%%= link_to project_module.human_name, project_module.path("/admin") %>
34
+ <%%= link_to project_module.human_name, url(project_module.path) %>
35
35
  </li>
36
36
  <%% end %>
37
37
  </ul>
@@ -26,7 +26,7 @@
26
26
  %ul.nav.navbar-nav.pull-left
27
27
  - project_modules.each do |project_module|
28
28
  %li{:class => "navbar-module #{('active' if request.path_info =~ /^#{project_module.path}/)}"}
29
- =link_to project_module.human_name, project_module.path('/admin')
29
+ =link_to project_module.human_name, url(project_module.path)
30
30
 
31
31
  .container.main
32
32
  .main-wrapper
@@ -1,4 +1,4 @@
1
- <%= @app_name %>::Admin.controllers :<%= @orm.name_plural %> do
1
+ <%= @app_name %>::<%= @admin_name %>.controllers :<%= @orm.name_plural %> do
2
2
  get :index do
3
3
  @title = "<%= @orm.name_plural.capitalize %>"
4
4
  @<%= @orm.name_plural %> = <%= @orm.all %>
@@ -26,7 +26,7 @@ html lang='en'
26
26
  ul class='nav navbar-nav pull-left'
27
27
  - project_modules.each do |project_module|
28
28
  li class=("navbar-module #{'active' if request.path_info =~ /^#{project_module.path}/}")
29
- = link_to project_module.human_name, project_module.path('/admin')
29
+ = link_to project_module.human_name, url(project_module.path)
30
30
 
31
31
  div class='container main'
32
32
  div class='main-wrapper'
@@ -78,23 +78,19 @@ module Padrino
78
78
  private
79
79
 
80
80
  def access_denied
81
- # If we have a login_page we redirect the user
82
- if login_page
83
- redirect(login_page)
81
+ if login_page.present?
82
+ redirect url(login_page)
84
83
  else
85
84
  halt 401, "You don't have permission for this resource"
86
85
  end
87
86
  end
88
87
 
89
88
  def login_page
90
- login_page ||= settings.login_page rescue nil
91
- return unless login_page
92
- login_page = File.join(ENV['RACK_BASE_URI'].to_s, login_page) if ENV['RACK_BASE_URI']
93
- login_page
89
+ settings.respond_to?(:login_page) && settings.login_page
94
90
  end
95
91
 
96
92
  def store_location
97
- settings.store_location rescue nil
93
+ settings.respond_to?(:store_location) && settings.store_location
98
94
  end
99
95
 
100
96
  def login_from_session
@@ -104,7 +100,7 @@ module Padrino
104
100
  def admin_model_obj
105
101
  @_admin_model_obj ||= settings.admin_model.constantize
106
102
  rescue NameError
107
- raise Padrino::Admin::AccessControlError, "You must define an #{settings.admin_model} Model!"
103
+ raise Padrino::Admin::AccessControlError, "You must define an #{settings.admin_model} Model"
108
104
  end
109
105
  end
110
106
  end
@@ -47,12 +47,18 @@ describe "AdminAppGenerator" do
47
47
  assert_file_exists("#{@apptmp}/sample_project/models/account.rb")
48
48
  assert_file_exists("#{@apptmp}/sample_project/db/seeds.rb")
49
49
  assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_accounts.rb")
50
- assert_match_in_file 'Padrino.mount("SampleProject::Admin", :app_file => File.expand_path(\'../../admin/app.rb\', __FILE__)).to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
50
+ assert_match_in_file 'Padrino.mount("SampleProject::Admin", :app_file => Padrino.root(\'admin/app.rb\')).to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
51
51
  assert_match_in_file 'module SampleProject', "#{@apptmp}/sample_project/admin/app.rb"
52
52
  assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
53
53
  assert_match_in_file 'role.project_module :accounts, \'/accounts\'', "#{@apptmp}/sample_project/admin/app.rb"
54
54
  end
55
55
 
56
+ it "should generate the master app" do
57
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord') }
58
+ capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project", '--admin-name=master') }
59
+ assert_file_exists("#{@apptmp}/sample_project/master/app.rb")
60
+ end
61
+
56
62
  # users can override certain templates from a generators/templates folder in the destination_root
57
63
  it "should use custom generator templates from the project root, if they exist" do
58
64
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord') }
data/test/helper.rb CHANGED
@@ -67,7 +67,7 @@ class MiniTest::Spec
67
67
  end
68
68
 
69
69
  def assert_no_match_in_file(pattern, file)
70
- File.exists?(file) ? assert_no_match(pattern, File.read(file)) : assert_file_exists(file)
70
+ File.exist?(file) ? assert_no_match(pattern, File.read(file)) : assert_file_exists(file)
71
71
  end
72
72
 
73
73
  # Delegate other missing methods to response.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0.rc1
4
+ version: 0.12.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-12-31 00:00:00.000000000 Z
14
+ date: 2014-01-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-core
@@ -19,28 +19,28 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.12.0.rc1
22
+ version: 0.12.0.rc2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.12.0.rc1
29
+ version: 0.12.0.rc2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: padrino-helpers
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - '='
35
35
  - !ruby/object:Gem::Version
36
- version: 0.12.0.rc1
36
+ version: 0.12.0.rc2
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - '='
42
42
  - !ruby/object:Gem::Version
43
- version: 0.12.0.rc1
43
+ version: 0.12.0.rc2
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: therubyracer
46
46
  requirement: !ruby/object:Gem::Requirement