padrino-admin 0.9.29 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,7 @@ module Padrino
19
19
  desc "Description:\n\n\tpadrino-gen admin generates a new Padrino Admin application"
20
20
 
21
21
  class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
22
+ class_option :app, :aliases => "-a", :desc => "The model destination path", :default => '.', :type => :string
22
23
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
23
24
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
24
25
  class_option :theme, :desc => "Your admin theme: (#{self.themes.join(", ")})", :default => "default", :type => :string
@@ -52,9 +53,11 @@ module Padrino
52
53
  directory "templates/app", destination_root("admin")
53
54
  directory "templates/assets", destination_root("public", "admin")
54
55
  template "templates/app.rb.tt", destination_root("admin/app.rb")
56
+ append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"Admin\").to(\"/admin\")"
55
57
 
56
58
  account_params = [
57
59
  "account", "name:string", "surname:string", "email:string", "crypted_password:string", "role:string",
60
+ "-a=#{options[:app]}",
58
61
  "-r=#{options[:root]}"
59
62
  ]
60
63
 
@@ -77,7 +80,7 @@ module Padrino
77
80
  admin_app.default_orm = Padrino::Admin::Generators::Orm.new(:account, orm, columns, column_fields)
78
81
  admin_app.invoke_all
79
82
 
80
- template "templates/account/#{orm}.rb.tt", destination_root("app", "models", "account.rb"), :force => true
83
+ template "templates/account/#{orm}.rb.tt", destination_root(options[:app], "models", "account.rb"), :force => true
81
84
 
82
85
  if File.exist?(destination_root("db/seeds.rb"))
83
86
  append_file(destination_root("db/seeds.rb")) { "\n\n" + File.read(self.class.source_root+"/templates/account/seeds.rb.tt") }
@@ -98,14 +101,13 @@ module Padrino
98
101
 
99
102
  add_project_module :accounts
100
103
  require_dependencies('bcrypt-ruby', :require => 'bcrypt')
101
- append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"Admin\").to(\"/admin\")"
102
104
  gsub_file destination_root("admin/views/accounts/_form.#{ext}"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
103
105
  gsub_file destination_root("admin/controllers/accounts.rb"), "if account.destroy", "if account != current_account && account.destroy"
104
106
  return if self.behavior == :revoke
105
107
 
106
108
  instructions = []
107
109
  instructions << "Run 'padrino rake ar:migrate'" if orm == :activerecord
108
- instructions << "Run 'padrino rake dm:migrate'" if orm == :datamapper
110
+ instructions << "Run 'padrino rake dm:auto:upgrade'" if orm == :datamapper
109
111
  instructions << "Run 'padrino rake seed'"
110
112
  instructions << "Visit the admin panel in the browser at '/admin'"
111
113
  instructions.map! { |i| " #{instructions.index(i) + 1}) #{i}" }
@@ -125,4 +127,4 @@ module Padrino
125
127
  end
126
128
  end # AdminApp
127
129
  end # Generators
128
- end # Padrino
130
+ end # Padrino
@@ -34,7 +34,7 @@ module Padrino
34
34
  def columns
35
35
  @columns ||= case orm
36
36
  when :activerecord then @klass.columns
37
- when :datamapper then @klass.properties.map { |p| Column.new(p.name, p.primitive || p.type) }
37
+ when :datamapper then @klass.properties.map { |p| dm_column(p) }
38
38
  when :couchrest then @klass.properties
39
39
  when :mongoid then @klass.fields.values
40
40
  when :mongomapper then @klass.keys.values.reject { |key| key.name == "_id" } # On MongoMapper keys are an hash
@@ -42,6 +42,25 @@ module Padrino
42
42
  else raise OrmError, "Adapter #{orm} is not yet supported!"
43
43
  end
44
44
  end
45
+
46
+ def dm_column(p)
47
+ case p
48
+ when DataMapper::Property::Text
49
+ Column.new(p.name, :text)
50
+ when DataMapper::Property::Boolean
51
+ Column.new(p.name, :boolean)
52
+ when DataMapper::Property::Integer
53
+ Column.new(p.name, :integer)
54
+ when DataMapper::Property::Decimal
55
+ Column.new(p.name, :decimal)
56
+ when DataMapper::Property::Float
57
+ Column.new(p.name, :float)
58
+ when DataMapper::Property::String
59
+ Column.new(p.name, :string)
60
+ else #if all fails, lets assume its stringish
61
+ Column.new(p.name, :string)
62
+ end
63
+ end
45
64
 
46
65
  def column_fields
47
66
  excluded_columns = %w[id created_at updated_at]
@@ -1,4 +1,5 @@
1
1
  class Admin < Padrino::Application
2
+ register Padrino::Rendering
2
3
  register Padrino::Mailer
3
4
  register Padrino::Helpers
4
5
  register Padrino::Admin::AccessControl
@@ -0,0 +1,16 @@
1
+ hu:
2
+ padrino:
3
+ admin:
4
+ save: ment
5
+ cancel: elvet
6
+ list: lista
7
+ edit: szerkeszt
8
+ new: új
9
+ show: mutat
10
+ delete: töröl
11
+ confirm: Biztos vagy benne?
12
+ created_at: készült
13
+ all: mind
14
+ profile: adatlap
15
+ settings: beállítások
16
+ logout: kilépés
@@ -0,0 +1,26 @@
1
+ hu:
2
+ activemodel: &activemodel
3
+ errors:
4
+ messages:
5
+ inclusion: ": a lista nem tartalmazza"
6
+ exclusion: ": tilos"
7
+ invalid: ": érvénytelen"
8
+ confirmation: ": nem egyezik a megerősítéssel"
9
+ accepted: ": el kell fogadnod"
10
+ empty: ": nem lehet üres"
11
+ blank: ": nem lehet üres"
12
+ too_long: ": túl hosszú (a maximum %{count} karakter)"
13
+ too_short: ": túl rövid (a minimum %{count} karakter)"
14
+ wrong_length: ": nem megfelelő hosszúságú (%{count} karakternek kellene lennie)"
15
+ taken: ": már foglalt"
16
+ not_a_number: ": nem szám"
17
+ greater_than: ": nagyobbnak kell lennie, mint %{count}"
18
+ greater_than_or_equal_to: ": nem lehet kisebb, mint %{count}"
19
+ equal_to: ": egyenlőnek kell lennie %{count}"
20
+ less_than: ": kevesebbnek kell lennie, mint %{count}"
21
+ less_than_or_equal_to: ": nem lehet nagyobb, mint %{count}"
22
+ odd: ": páratlannak kell lennie"
23
+ even: ": párosnak kell lennie"
24
+ record_invalid: "Érvénytelen: %{errors}"
25
+ content_type: ": a fájl formátuma nem támogatott"
26
+ activerecord: *activemodel
@@ -1,4 +1,6 @@
1
- # -*- encoding: utf-8 -*-
1
+ #!/usr/bin/env gem build
2
+ # encoding: utf-8
3
+
2
4
  require File.expand_path("../../padrino-core/lib/padrino-core/version.rb", __FILE__)
3
5
 
4
6
  Gem::Specification.new do |s|
@@ -14,9 +14,9 @@ class TestAccountModelGenerator < Test::Unit::TestCase
14
14
  context 'account model using couchrest' do
15
15
  setup do
16
16
  silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=couchrest') }
17
- silence_logger { generate(:admin_app, "--root=#{@apptmp}/sample_project") }
17
+ silence_logger { generate(:admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") }
18
18
 
19
- @model = "#{@apptmp}/sample_project/app/models/account.rb"
19
+ @model = "#{@apptmp}/sample_project/admin/models/account.rb"
20
20
  end
21
21
 
22
22
  should 'be a couchrest model instance' do
@@ -35,4 +35,4 @@ class TestAccountModelGenerator < Test::Unit::TestCase
35
35
  assert_match_in_file(/errors\.add\(:email, "is not unique"\)/m, @model)
36
36
  end
37
37
  end
38
- end
38
+ end
@@ -52,7 +52,7 @@ class TestAdminAppGenerator < Test::Unit::TestCase
52
52
  assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.haml")
53
53
  assert_file_exists("#{@apptmp}/sample_project/public/admin")
54
54
  assert_file_exists("#{@apptmp}/sample_project/public/admin/stylesheets")
55
- assert_file_exists("#{@apptmp}/sample_project/app/models/account.rb")
55
+ assert_file_exists("#{@apptmp}/sample_project/models/account.rb")
56
56
  assert_file_exists("#{@apptmp}/sample_project/db/seeds.rb")
57
57
  assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_accounts.rb")
58
58
  assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
@@ -84,7 +84,7 @@ class TestAdminAppGenerator < Test::Unit::TestCase
84
84
  assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.erb")
85
85
  assert_file_exists("#{@apptmp}/sample_project/public/admin")
86
86
  assert_file_exists("#{@apptmp}/sample_project/public/admin/stylesheets")
87
- assert_file_exists("#{@apptmp}/sample_project/app/models/account.rb")
87
+ assert_file_exists("#{@apptmp}/sample_project/models/account.rb")
88
88
  assert_file_exists("#{@apptmp}/sample_project/db/seeds.rb")
89
89
  assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_accounts.rb")
90
90
  assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
@@ -116,7 +116,7 @@ class TestAdminAppGenerator < Test::Unit::TestCase
116
116
  assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.slim")
117
117
  assert_file_exists("#{@apptmp}/sample_project/public/admin")
118
118
  assert_file_exists("#{@apptmp}/sample_project/public/admin/stylesheets")
119
- assert_file_exists("#{@apptmp}/sample_project/app/models/account.rb")
119
+ assert_file_exists("#{@apptmp}/sample_project/models/account.rb")
120
120
  assert_file_exists("#{@apptmp}/sample_project/db/seeds.rb")
121
121
  assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_accounts.rb")
122
122
  assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
@@ -125,6 +125,39 @@ class TestAdminAppGenerator < Test::Unit::TestCase
125
125
  assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.slim"
126
126
  end
127
127
 
128
+ should 'correctly generate a new padrino admin application with model in non-default application path' do
129
+ assert_nothing_raised { silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=haml') } }
130
+ assert_nothing_raised { silence_logger { generate(:admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") } }
131
+ assert_file_exists("#{@apptmp}/sample_project")
132
+ assert_file_exists("#{@apptmp}/sample_project/admin")
133
+ assert_file_exists("#{@apptmp}/sample_project/admin/app.rb")
134
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers")
135
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/accounts.rb")
136
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/base.rb")
137
+ assert_file_exists("#{@apptmp}/sample_project/admin/controllers/sessions.rb")
138
+ assert_file_exists("#{@apptmp}/sample_project/admin/views")
139
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/_form.haml")
140
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/edit.haml")
141
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/index.haml")
142
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/accounts/new.haml")
143
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/base/index.haml")
144
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.haml")
145
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/base/_sidebar.haml")
146
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/base/index.haml")
147
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/layouts/application.haml")
148
+ assert_file_exists("#{@apptmp}/sample_project/admin/views/sessions/new.haml")
149
+ assert_file_exists("#{@apptmp}/sample_project/public/admin")
150
+ assert_file_exists("#{@apptmp}/sample_project/public/admin/stylesheets")
151
+ assert_file_exists("#{@apptmp}/sample_project/admin/models/account.rb")
152
+ assert_no_file_exists("#{@apptmp}/sample_project/models/account.rb")
153
+ assert_file_exists("#{@apptmp}/sample_project/db/seeds.rb")
154
+ assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_accounts.rb")
155
+ assert_match_in_file 'Padrino.mount("Admin").to("/admin")', "#{@apptmp}/sample_project/config/apps.rb"
156
+ assert_match_in_file 'class Admin < Padrino::Application', "#{@apptmp}/sample_project/admin/app.rb"
157
+ assert_match_in_file 'role.project_module :accounts, "/accounts"', "#{@apptmp}/sample_project/admin/app.rb"
158
+ assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.haml"
159
+ end
160
+
128
161
  should 'not conflict with existing seeds file' do
129
162
  assert_nothing_raised { silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=erb') } }
130
163
 
@@ -151,4 +184,4 @@ class TestAdminAppGenerator < Test::Unit::TestCase
151
184
  # cli(:rake, '-T', "-c=#{@apptmp}/sample_project")
152
185
  end
153
186
  end
154
- end
187
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: padrino-admin
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.29
5
+ version: 0.10.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Padrino Team
@@ -13,7 +13,8 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2011-05-23 00:00:00 Z
16
+ date: 2011-07-07 00:00:00 -07:00
17
+ default_executable:
17
18
  dependencies:
18
19
  - !ruby/object:Gem::Dependency
19
20
  name: padrino-core
@@ -23,7 +24,7 @@ dependencies:
23
24
  requirements:
24
25
  - - "="
25
26
  - !ruby/object:Gem::Version
26
- version: 0.9.29
27
+ version: 0.10.0
27
28
  type: :runtime
28
29
  version_requirements: *id001
29
30
  - !ruby/object:Gem::Dependency
@@ -34,7 +35,7 @@ dependencies:
34
35
  requirements:
35
36
  - - "="
36
37
  - !ruby/object:Gem::Version
37
- version: 0.9.29
38
+ version: 0.10.0
38
39
  type: :runtime
39
40
  version_requirements: *id002
40
41
  description: Admin View for Padrino applications
@@ -113,6 +114,7 @@ files:
113
114
  - lib/padrino-admin/locale/admin/en.yml
114
115
  - lib/padrino-admin/locale/admin/es.yml
115
116
  - lib/padrino-admin/locale/admin/fr.yml
117
+ - lib/padrino-admin/locale/admin/hu.yml
116
118
  - lib/padrino-admin/locale/admin/it.yml
117
119
  - lib/padrino-admin/locale/admin/ja.yml
118
120
  - lib/padrino-admin/locale/admin/nl.yml
@@ -130,6 +132,7 @@ files:
130
132
  - lib/padrino-admin/locale/orm/en.yml
131
133
  - lib/padrino-admin/locale/orm/es.yml
132
134
  - lib/padrino-admin/locale/orm/fr.yml
135
+ - lib/padrino-admin/locale/orm/hu.yml
133
136
  - lib/padrino-admin/locale/orm/it.yml
134
137
  - lib/padrino-admin/locale/orm/ja.yml
135
138
  - lib/padrino-admin/locale/orm/nl.yml
@@ -149,6 +152,7 @@ files:
149
152
  - test/generators/test_admin_page_generator.rb
150
153
  - test/helper.rb
151
154
  - test/test_admin_application.rb
155
+ has_rdoc: true
152
156
  homepage: http://www.padrinorb.com
153
157
  licenses: []
154
158
 
@@ -172,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
176
  requirements: []
173
177
 
174
178
  rubyforge_project: padrino-admin
175
- rubygems_version: 1.7.2
179
+ rubygems_version: 1.6.2
176
180
  signing_key:
177
181
  specification_version: 3
178
182
  summary: Admin Dashboard for Padrino