Permalink
Browse files

updated to padrino 0.11.4

  • Loading branch information...
williamn committed Dec 5, 2013
1 parent 8d0c33a commit 4038cefd2ab09e968f8102cfddd31e0ae00fa642
Showing with 5,075 additions and 435 deletions.
  1. +7 −3 .components
  2. +3 −1 .gitignore
  3. +27 −11 Gemfile
  4. +98 −0 Gemfile.lock
  5. +6 −0 Rakefile
  6. +42 −29 admin/app.rb
  7. +56 −13 admin/controllers/accounts.rb
  8. +2 −4 admin/controllers/base.rb
  9. +55 −14 admin/controllers/posts.rb
  10. +9 −5 admin/controllers/sessions.rb
  11. +42 −39 admin/views/accounts/_form.haml
  12. +7 −14 admin/views/accounts/edit.haml
  13. +53 −30 admin/views/accounts/index.haml
  14. +6 −13 admin/views/accounts/new.haml
  15. +11 −24 admin/views/base/index.haml
  16. +3 −0 admin/views/errors/403.haml
  17. +3 −0 admin/views/errors/404.haml
  18. +3 −0 admin/views/errors/500.haml
  19. +47 −29 admin/views/layouts/application.haml
  20. +18 −0 admin/views/layouts/error.haml
  21. +18 −15 admin/views/posts/_form.haml
  22. +7 −14 admin/views/posts/edit.haml
  23. +55 −28 admin/views/posts/index.haml
  24. +6 −13 admin/views/posts/new.haml
  25. +35 −23 admin/views/sessions/new.haml
  26. +14 −23 app/app.rb
  27. +1 −1 app/controllers/posts.rb
  28. +1 −1 app/helpers/posts_helper.rb
  29. +2 −2 app/views/posts/index.haml
  30. +9 −2 config.ru
  31. +35 −18 config/apps.rb
  32. +40 −13 config/boot.rb
  33. +21 −11 config/database.rb
  34. BIN db/development.db
  35. +8 −6 db/schema.rb
  36. +28 −0 db/seeds.old
  37. +5 −5 db/seeds.rb
  38. +11 −0 lib/sass_initializer.rb
  39. +38 −0 models/account.rb
  40. BIN public/admin/images/favicon.ico
  41. BIN public/admin/images/font/FontAwesome.otf
  42. BIN public/admin/images/font/fontawesome-webfont.eot
  43. +399 −0 public/admin/images/font/fontawesome-webfont.svg
  44. BIN public/admin/images/font/fontawesome-webfont.ttf
  45. BIN public/admin/images/font/fontawesome-webfont.woff
  46. BIN public/admin/images/logo.png
  47. +117 −0 public/admin/javascripts/application.js
  48. +126 −0 public/admin/javascripts/bootstrap/affix.js
  49. +98 −0 public/admin/javascripts/bootstrap/alert.js
  50. +6 −0 public/admin/javascripts/bootstrap/bootstrap.min.js
  51. +109 −0 public/admin/javascripts/bootstrap/button.js
  52. +217 −0 public/admin/javascripts/bootstrap/carousel.js
  53. +179 −0 public/admin/javascripts/bootstrap/collapse.js
  54. +154 −0 public/admin/javascripts/bootstrap/dropdown.js
  55. +246 −0 public/admin/javascripts/bootstrap/modal.js
  56. +117 −0 public/admin/javascripts/bootstrap/popover.js
  57. +158 −0 public/admin/javascripts/bootstrap/scrollspy.js
  58. +135 −0 public/admin/javascripts/bootstrap/tab.js
  59. +386 −0 public/admin/javascripts/bootstrap/tooltip.js
  60. +56 −0 public/admin/javascripts/bootstrap/transition.js
  61. +4 −0 public/admin/javascripts/jquery-1.9.0.min.js
  62. +347 −0 public/admin/stylesheets/application.css
  63. +1,238 −0 public/admin/stylesheets/bootstrap.css
  64. BIN public/favicon.ico
  65. +109 −0 public/javascripts/jquery-ujs.js
  66. +4 −19 public/javascripts/jquery.js
  67. +13 −0 test/app/controllers/posts_controller_test.rb
  68. +10 −3 test/test.rake
  69. +15 −9 test/test_config.rb
View
@@ -1,6 +1,10 @@
----
-:test: shoulda
+---
:orm: activerecord
-:mock: mocha
+:test: shoulda
+:mock: none
:script: jquery
:renderer: haml
+:stylesheet: sass
+:namespace: SampleBlog
+:migration_format: number
+:admin_renderer: haml
View
@@ -4,4 +4,6 @@ tmp/**/*
bin/*
vendor/gems/*
!vendor/gems/cache/
-.sass-cache/*
+.sass-cache/*
+db/*.db
+.*.sw*
View
38 Gemfile
@@ -1,20 +1,36 @@
-source :rubygems
+source 'https://rubygems.org'
+
+# Distribute your app as a gem
+# gemspec
+
+# Server requirements
+# gem 'thin' # or mongrel
+# gem 'trinidad', :platform => 'jruby'
+
+# Optional JSON codec (faster performance)
+# gem 'oj'
# Project requirements
-gem 'bundler', '>= 0.9.26'
-gem 'sinatra-flash', :require => 'sinatra/flash'
-gem 'thin' # or mongrel
+gem 'rake'
# Component requirements
-gem 'haml'
+gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'sass'
-gem 'activerecord', :require => "active_record"
-gem 'sqlite3-ruby', :require => "sqlite3"
+gem 'haml'
+gem 'activerecord', '>= 3.1', :require => 'active_record'
+gem 'sqlite3'
# Test requirements
-gem 'mocha', :group => "test"
-gem 'shoulda', :group => "test"
+gem 'shoulda', :group => 'test'
gem 'rack-test', :require => 'rack/test', :group => 'test'
-# Padrino
-gem 'padrino'
+# Padrino Stable Gem
+gem 'padrino', '0.11.4'
+
+# Or Padrino Edge
+# gem 'padrino', :github => 'padrino/padrino-framework'
+
+# Or Individual Gems
+# %w(core gen helpers cache mailer admin).each do |g|
+# gem 'padrino-' + g, '0.11.4'
+# end
View
@@ -0,0 +1,98 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ activemodel (3.2.16)
+ activesupport (= 3.2.16)
+ builder (~> 3.0.0)
+ activerecord (3.2.16)
+ activemodel (= 3.2.16)
+ activesupport (= 3.2.16)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activesupport (3.2.16)
+ i18n (~> 0.6, >= 0.6.4)
+ multi_json (~> 1.0)
+ arel (3.0.3)
+ bcrypt-ruby (3.1.2)
+ builder (3.0.4)
+ haml (4.0.4)
+ tilt
+ http_router (0.11.0)
+ rack (>= 1.0.0)
+ url_mount (~> 0.2.1)
+ i18n (0.6.9)
+ mail (2.5.4)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.25.1)
+ multi_json (1.8.2)
+ padrino (0.11.4)
+ padrino-admin (= 0.11.4)
+ padrino-cache (= 0.11.4)
+ padrino-core (= 0.11.4)
+ padrino-gen (= 0.11.4)
+ padrino-helpers (= 0.11.4)
+ padrino-mailer (= 0.11.4)
+ padrino-admin (0.11.4)
+ padrino-core (= 0.11.4)
+ padrino-helpers (= 0.11.4)
+ padrino-cache (0.11.4)
+ padrino-core (= 0.11.4)
+ padrino-helpers (= 0.11.4)
+ padrino-core (0.11.4)
+ activesupport (>= 3.1, < 4.0)
+ http_router (~> 0.11.0)
+ rack-protection (>= 1.5.0)
+ sinatra (~> 1.4.2)
+ thor (~> 0.17.0)
+ tilt (~> 1.4.1)
+ padrino-gen (0.11.4)
+ bundler (~> 1.0)
+ padrino-core (= 0.11.4)
+ padrino-helpers (0.11.4)
+ i18n (~> 0.6)
+ padrino-core (= 0.11.4)
+ padrino-mailer (0.11.4)
+ mail (~> 2.5.3)
+ padrino-core (= 0.11.4)
+ polyglot (0.3.3)
+ rack (1.5.2)
+ rack-protection (1.5.1)
+ rack
+ rack-test (0.6.2)
+ rack (>= 1.0)
+ rake (10.1.0)
+ sass (3.2.12)
+ shoulda (3.5.0)
+ shoulda-context (~> 1.0, >= 1.0.1)
+ shoulda-matchers (>= 1.4.1, < 3.0)
+ shoulda-context (1.1.6)
+ shoulda-matchers (2.4.0)
+ activesupport (>= 3.0.0)
+ sinatra (1.4.4)
+ rack (~> 1.4)
+ rack-protection (~> 1.4)
+ tilt (~> 1.3, >= 1.3.4)
+ sqlite3 (1.3.8)
+ thor (0.17.0)
+ tilt (1.4.1)
+ treetop (1.4.15)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.38)
+ url_mount (0.2.1)
+ rack
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (>= 3.1)
+ bcrypt-ruby
+ haml
+ padrino (= 0.11.4)
+ rack-test
+ rake
+ sass
+ shoulda
+ sqlite3
View
@@ -0,0 +1,6 @@
+require 'bundler/setup'
+require 'padrino-core/cli/rake'
+
+PadrinoTasks.use(:database)
+PadrinoTasks.use(:activerecord)
+PadrinoTasks.init
View
@@ -1,33 +1,46 @@
-class Admin < Padrino::Application
- register Padrino::Helpers
- register Padrino::Mailer
- register Padrino::Admin::AccessControl
- register Padrino::Rendering
-
- ##
- # Application-specific configuration options
- #
- # set :raise_errors, true # Show exceptions (default for development)
- # set :public, "foo/bar" # Location for static assets (default root/public)
- # set :sessions, false # Enabled by default
- # set :reload, false # Reload application files (default in development)
- # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
- # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
- # disable :flash # Disables rack-flash (enabled by default)
- # enable :authentication # Enable padrino-admin authentication (disabled by default)
- # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
- #
- enable :authentication
- disable :store_location
- set :login_page, "/admin/sessions/new"
+module SampleBlog
+ class Admin < Padrino::Application
+ use ActiveRecord::ConnectionAdapters::ConnectionManagement
+ register Padrino::Rendering
+ register Padrino::Mailer
+ register Padrino::Helpers
+ register Padrino::Admin::AccessControl
- access_control.roles_for :any do |role|
- role.protect "/"
- role.allow "/sessions"
- end
+ ##
+ # Application configuration options
+ #
+ # set :raise_errors, true # Raise exceptions (will stop application) (default for test)
+ # set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development)
+ # set :show_exceptions, true # Shows a stack trace in browser (default for development)
+ # set :logging, true # Logging in STDOUT for development and file for production (default only for development)
+ # set :public_folder, "foo/bar" # Location for static assets (default root/public)
+ # set :reload, false # Reload application files (default in development)
+ # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
+ # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
+ # disable :sessions # Disabled sessions by default (enable if needed)
+ # disable :flash # Disables sinatra-flash (enabled by default if Sinatra::Flash is defined)
+ # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
+ #
+
+ set :admin_model, 'Account'
+ set :login_page, '/admin/sessions/new'
+
+ enable :sessions
+ disable :store_location
+
+ access_control.roles_for :any do |role|
+ role.protect '/'
+ role.allow '/sessions'
+ end
+
+ access_control.roles_for :admin do |role|
+ role.project_module :posts, '/posts'
+ role.project_module :accounts, '/accounts'
+ end
- access_control.roles_for :admin do |role, account|
- role.project_module :posts, "/posts"
- role.project_module :accounts, "/accounts"
+ # Custom error management
+ error(403) { @title = "Error 403"; render('errors/403', :layout => :error) }
+ error(404) { @title = "Error 404"; render('errors/404', :layout => :error) }
+ error(500) { @title = "Error 500"; render('errors/500', :layout => :error) }
end
end
@@ -1,47 +1,90 @@
-Admin.controllers :accounts do
-
+SampleBlog::Admin.controllers :accounts do
get :index do
+ @title = "Accounts"
@accounts = Account.all
render 'accounts/index'
end
get :new do
+ @title = pat(:new_title, :model => 'account')
@account = Account.new
render 'accounts/new'
end
post :create do
@account = Account.new(params[:account])
if @account.save
- flash[:notice] = 'Account was successfully created.'
- redirect url(:accounts, :edit, :id => @account.id)
+ @title = pat(:create_title, :model => "account #{@account.id}")
+ flash[:success] = pat(:create_success, :model => 'Account')
+ params[:save_and_continue] ? redirect(url(:accounts, :index)) : redirect(url(:accounts, :edit, :id => @account.id))
else
+ @title = pat(:create_title, :model => 'account')
+ flash.now[:error] = pat(:create_error, :model => 'account')
render 'accounts/new'
end
end
get :edit, :with => :id do
+ @title = pat(:edit_title, :model => "account #{params[:id]}")
@account = Account.find(params[:id])
- render 'accounts/edit'
+ if @account
+ render 'accounts/edit'
+ else
+ flash[:warning] = pat(:create_error, :model => 'account', :id => "#{params[:id]}")
+ halt 404
+ end
end
put :update, :with => :id do
+ @title = pat(:update_title, :model => "account #{params[:id]}")
@account = Account.find(params[:id])
- if @account.update_attributes(params[:account])
- flash[:notice] = 'Account was successfully updated.'
- redirect url(:accounts, :edit, :id => @account.id)
+ if @account
+ if @account.update_attributes(params[:account])
+ flash[:success] = pat(:update_success, :model => 'Account', :id => "#{params[:id]}")
+ params[:save_and_continue] ?
+ redirect(url(:accounts, :index)) :
+ redirect(url(:accounts, :edit, :id => @account.id))
+ else
+ flash.now[:error] = pat(:update_error, :model => 'account')
+ render 'accounts/edit'
+ end
else
- render 'accounts/edit'
+ flash[:warning] = pat(:update_warning, :model => 'account', :id => "#{params[:id]}")
+ halt 404
end
end
delete :destroy, :with => :id do
+ @title = "Accounts"
account = Account.find(params[:id])
- if account.destroy
- flash[:notice] = 'Account was successfully destroyed.'
+ if account
+ if account != current_account && account.destroy
+ flash[:success] = pat(:delete_success, :model => 'Account', :id => "#{params[:id]}")
+ else
+ flash[:error] = pat(:delete_error, :model => 'account')
+ end
+ redirect url(:accounts, :index)
else
- flash[:error] = 'Impossible destroy Account!'
+ flash[:warning] = pat(:delete_warning, :model => 'account', :id => "#{params[:id]}")
+ halt 404
+ end
+ end
+
+ delete :destroy_many do
+ @title = "Accounts"
+ unless params[:account_ids]
+ flash[:error] = pat(:destroy_many_error, :model => 'account')
+ redirect(url(:accounts, :index))
+ end
+ ids = params[:account_ids].split(',').map(&:strip)
+ accounts = Account.find(ids)
+
+ if accounts.include? current_account
+ flash[:error] = pat(:delete_error, :model => 'account')
+ elsif Account.destroy accounts
+
+ flash[:success] = pat(:destroy_many_success, :model => 'Accounts', :ids => "#{ids.to_sentence}")
end
redirect url(:accounts, :index)
end
-end
+end
@@ -1,7 +1,5 @@
-Admin.controllers :base do
-
+SampleBlog::Admin.controllers :base do
get :index, :map => "/" do
render "base/index"
end
-
-end
+end
Oops, something went wrong.

0 comments on commit 4038cef

Please sign in to comment.