beautiful_scaffold 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "beautiful_scaffold"
6
- s.version = "0.1.9"
6
+ s.version = "0.2.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.summary = "Beautiful Scaffold generate fully customizable scaffold"
9
9
  s.email = "claudel.sylvain@gmail.com"
@@ -0,0 +1,128 @@
1
+ # encoding : utf-8
2
+ class BeautifulDevisecancanGenerator < Rails::Generators::Base
3
+ require 'beautiful_scaffold_common_methods'
4
+ include BeautifulScaffoldCommonMethods
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ argument :model, :type => :string, :desc => "Name of model (downcase singular)"
9
+
10
+ def install_devise
11
+ view_path = "app/views/"
12
+
13
+ gem("devise", "2.1.0")
14
+
15
+ inside Rails.root do
16
+ run "bundle install"
17
+ end
18
+
19
+ generate("devise:install")
20
+
21
+ for current_env in ['production', 'development', 'test']
22
+ inject_into_file("config/environments/#{current_env}.rb", " config.action_mailer.default_url_options = { :host => 'localhost:3000' }", :after => "::Application.configure do\n" )
23
+ end
24
+
25
+ # Install devise in the model
26
+ generate("devise", model)
27
+
28
+ # Add :token_authenticatable and :lockable
29
+ # In model
30
+ inject_into_file( "app/models/#{model}.rb",
31
+ ":token_authenticatable, :lockable,",
32
+ :after => "devise ")
33
+ # In migration
34
+ filename = Dir.glob("db/migrate/*_add_devise_to_#{model.pluralize}.rb")[0]
35
+ gsub_file filename, /#\s*(t\.integer\s+:failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts)/, '\1'
36
+ gsub_file filename, /#\s*(t\.string\s+:unlock_token # Only if unlock strategy is :email or :both)/, '\1'
37
+ gsub_file filename, /#\s*(t\.datetime\s+:locked_at)/, '\1'
38
+ gsub_file filename, /#\s*(t\.string\s+:authentication_token)/, '\1'
39
+
40
+
41
+ # Limited access (Must be commented if use cancan)
42
+ inject_into_file("app/controllers/beautiful_controller.rb","before_filter :authenticate_#{model}!, :except => [:dashboard]", :after => 'layout "beautiful_layout"' + "\n")
43
+
44
+ # Custom redirect
45
+ inject_into_file("app/controllers/application_controller.rb","
46
+ def after_sign_out_path_for(resource_or_scope)
47
+ root_path
48
+ end
49
+ def after_sign_in_path_for(resource)
50
+ root_path
51
+ end
52
+ def after_sign_up_path_for(resource)
53
+ root_path
54
+ end
55
+ ", :after => "protect_from_forgery\n")
56
+ copy_file("lib/custom_failure.rb")
57
+ copy_file("app/controllers/registrations_controller.rb")
58
+ inject_into_file("config/initializers/devise.rb","
59
+ config.warden do |manager|
60
+ manager.failure_app = CustomFailure
61
+ end
62
+ ", :after => "Devise.setup do |config|\n")
63
+ inject_into_file("config/application.rb",' #{config.root}/lib', :after => '#{config.root}/app/modules')
64
+
65
+ # Use my register controller
66
+ inject_into_file("config/routes.rb",
67
+ ', :controllers => {:registrations => "registrations"}',
68
+ :after => "devise_for :#{model.pluralize}")
69
+
70
+
71
+ # Install partials dans layout (forget password, sign_in)
72
+ template("#{view_path}partials/_forget_password.html.erb", "#{view_path}layouts/_forget_password.html.erb")
73
+ template("#{view_path}partials/_sign_in_sign_out.html.erb", "#{view_path}layouts/_sign_in_sign_out.html.erb")
74
+ template("#{view_path}partials/_sign_in_form.html.erb", "#{view_path}layouts/_sign_in_form.html.erb")
75
+ template("#{view_path}partials/_register_form.html.erb", "#{view_path}layouts/_register_form.html.erb")
76
+
77
+ # Sign in sign out
78
+ inject_into_file("#{view_path}layouts/beautiful_layout.html.erb",
79
+ "<%= render :partial => 'layouts/sign_in_sign_out' %>",
80
+ :after => "<!-- Beautiful_scaffold - Signin - Do not remove -->\n")
81
+
82
+ # Modal (forget password)
83
+ inject_into_file("#{view_path}layouts/beautiful_layout.html.erb",
84
+ " <%= render :partial => 'layouts/forget_password' %>",
85
+ :after => "<!-- Beautiful_scaffold - Modal - Do not remove -->\n")
86
+ inject_into_file("#{view_path}layouts/beautiful_layout.html.erb",
87
+ " <%= render :partial => 'layouts/register_form' %>",
88
+ :after => "<!-- Beautiful_scaffold - Modal - Do not remove -->\n")
89
+
90
+ end
91
+
92
+ def install_cancan
93
+ gem("cancan")
94
+
95
+ inside Rails.root do
96
+ run "bundle install"
97
+ end
98
+
99
+ generate("cancan:ability")
100
+
101
+ inject_into_file("app/models/ability.rb", "
102
+ if not user.nil? then
103
+ if user.id == 1 then
104
+ can :manage, :all
105
+ end
106
+ end\n", :after => "def initialize(user)\n")
107
+
108
+ # current_user method need for CanCan
109
+ current_user_method = ""
110
+ if model != "user" then
111
+ current_user_method = "
112
+ def current_user
113
+ current_#{model}
114
+ end"
115
+ end
116
+
117
+ # Exception for AccessDenied
118
+ inject_into_file("app/controllers/application_controller.rb", "
119
+ rescue_from CanCan::AccessDenied do |exception|
120
+ redirect_to root_url, :alert => exception.message
121
+ end
122
+ #{current_user_method}
123
+ ", :after => "class ApplicationController < ActionController::Base\n")
124
+
125
+ # Access controlled by CanCan (in beautiful_scaffold)
126
+ inject_into_file("app/controllers/application_controller.rb", "#", :before => "before_filter :authenticate_#{model}!, :except => [:dashboard]")
127
+ end
128
+ end
@@ -1,9 +1,11 @@
1
1
  # encoding : utf-8
2
2
  class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < BeautifulController
3
- # Official Rails version : master/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
4
3
 
5
4
  before_filter :load_<%= model %>, :only => [:show, :edit, :update, :destroy]
6
5
 
6
+ # Uncomment for check abilities with CanCan
7
+ #authorize_resource
8
+
7
9
  def index
8
10
  session[:fields] ||= {}
9
11
  session[:fields][:<%= model %>] ||= (<%= model_camelize %>.columns.map(&:name) - ["id"])[0..4]
@@ -36,7 +36,7 @@ class BeautifulController < ApplicationController
36
36
  session[:search][model_sym] = nil if not params[:nosearch].blank?
37
37
  params[:page] = 1 if not params[:q].nil?
38
38
  params[:q] ||= session[:search][model_sym]
39
- session[:search][model_sym] = params[:q] if not params[:skip_save_search].blank?
39
+ session[:search][model_sym] = params[:q] if params[:skip_save_search].blank?
40
40
 
41
41
  # Scope
42
42
  session[:scope] ||= {}
@@ -0,0 +1,11 @@
1
+ # encoding : utf-8
2
+ class RegistrationsController < Devise::RegistrationsController
3
+ def create
4
+ super
5
+ if resource.id.nil? then
6
+ self.instance_variable_set(:@_response_body, nil)
7
+ @opened_modal = "#modal-register-form"
8
+ render "beautiful/dashboard", :layout => "beautiful_layout", :location => root_path
9
+ end
10
+ end
11
+ end
@@ -214,4 +214,9 @@ module BeautifulHelper
214
214
  </li>'
215
215
  return out.html_safe
216
216
  end
217
+
218
+ def clean_params
219
+ params.delete :q
220
+ params.delete :fields
221
+ end
217
222
  end
@@ -33,3 +33,15 @@ en:
33
33
  smaller_than: "Smaller than"
34
34
  select_columns: "Select Columns"
35
35
  treeview: "Treeview"
36
+ profile: "Profile"
37
+ sign_out: "Sign Out"
38
+ sign_in: "Sign in"
39
+ sign_up: "Sign up"
40
+ login: "Login"
41
+ remember_me: "Remember me"
42
+ email: "Email"
43
+ password: "Password"
44
+ password_confirmation: "Password (Confirmation)"
45
+ forgot_your_password: "Forgot your password?"
46
+ send_me_reset_password_instructions: "Send me reset password instructions"
47
+ register: "Register"
@@ -32,4 +32,16 @@ fr:
32
32
  greater_than: "Plus grand que"
33
33
  smaller_than: "Plus petit que"
34
34
  select_columns: "Selection des colonnes"
35
- treeview: "Arborescence"
35
+ treeview: "Arborescence"
36
+ profile: "Profil"
37
+ sign_out: "Déconnexion"
38
+ sign_in: "Authentification"
39
+ sign_up: "Inscription"
40
+ login: "Login"
41
+ remember_me: "Ce souvenir de moi"
42
+ email: "Email"
43
+ password: "Mot de passe"
44
+ password_confirmation: "Mot de passe (Confirmation)"
45
+ forgot_your_password: "Mot de passe oublié ?"
46
+ send_me_reset_password_instructions: "Me ré-envoyer les instructions de réinitialisation du mot de passe"
47
+ register: "Inscription"
@@ -90,7 +90,7 @@
90
90
 
91
91
  <div class="btn-toolbar">
92
92
  <div class="btn-group">
93
-
93
+ <%% clean_params %>
94
94
  <%%= will_paginate @<%= plural_table_name %>,
95
95
  :inner_window => 0,
96
96
  :outer_window => 0,
@@ -35,20 +35,12 @@
35
35
  </a>
36
36
  <ul class="nav">
37
37
  <li class="active">
38
- <a href="beautiful/dashboard">Home</a>
38
+ <a href="/">Home</a>
39
39
  </li>
40
40
  </ul>
41
41
  <ul class="nav pull-right">
42
42
  <li>
43
- <a class="dropdown-toggle" data-toggle="dropdown" href="#">
44
- <i class="icon-user"></i> Username
45
- <span class="caret"></span>
46
- </a>
47
- <ul class="dropdown-menu">
48
- <li><a href="#">Profile</a></li>
49
- <li class="divider"></li>
50
- <li><a href="#">Sign Out</a></li>
51
- </ul>
43
+ <!-- Beautiful_scaffold - Signin - Do not remove -->
52
44
  </li>
53
45
  </ul>
54
46
  </div>
@@ -93,7 +85,15 @@
93
85
  <div class="circle1"></div>
94
86
  </div>
95
87
 
96
- <%%= javascript_include_tag "bootstrap.min", "bootstrap-alert", "bootstrap-datepicker" ,"bootstrap-timepicker", "bootstrap-dropdown", "bootstrap-modal", "bootstrap-tooltip", "bootstrap-colorpicker", "wysihtml5-0.3.0.min", "bootstrap-wysihtml5" %>
88
+ <!-- Beautiful_scaffold - Modal - Do not remove -->
89
+
90
+ <script type="text/javascript">
91
+ <%% if not @opened_modal.blank? then %>
92
+ $('<%%= @opened_modal %>').modal('show');
93
+ <%% end %>
94
+ </script>
95
+
96
+ <%%= javascript_include_tag "bootstrap.min", "bootstrap-alert", "bootstrap-datepicker" ,"bootstrap-timepicker", "bootstrap-dropdown", "bootstrap-modal", "bootstrap-tooltip", "bootstrap-colorpicker", "a-wysihtml5-0.3.0.min", "bootstrap-wysihtml5" %>
97
97
  <script type="text/javascript">
98
98
  ;(function($){
99
99
  $.fn.datepicker.dates['<%= I18n.locale.to_s %>'] = {
@@ -0,0 +1,21 @@
1
+ <div class="modal hide" id="modal-forget-password">
2
+ <div class="modal-header">
3
+ <button type="button" class="close" data-dismiss="modal">×</button>
4
+ <h3><%%= t(:forgot_password, :default => "Forgot password") %></h3>
5
+ </div>
6
+ <div class="modal-body">
7
+ <%%= form_for('<%= model %>', :as => '<%= model %>', :url => password_path('<%= model %>'), :html => { :method => :post, :class => "form-horizontal" }) do |f| %>
8
+ <div class="control-group">
9
+ <%%= f.label :email, t(:email, :default => "Email"), :class => "control-label" %>
10
+ <div class="controls">
11
+ <%%= f.email_field :email %>
12
+ </div>
13
+ </div>
14
+ <div class="control-group">
15
+ <div class="controls">
16
+ <%%= f.submit t(:send_me_reset_password_instructions, :default => "Send me reset password instructions"), :class => 'btn' %>
17
+ </div>
18
+ </div>
19
+ <%% end %>
20
+ </div>
21
+ </div>
@@ -0,0 +1,40 @@
1
+
2
+ <div class="modal hide" id="modal-register-form">
3
+ <div class="modal-header">
4
+ <button type="button" class="close" data-dismiss="modal">×</button>
5
+ <h3><%%= t(:register, :default => "Register") %></h3>
6
+ </div>
7
+ <div class="modal-body">
8
+ <%% resource ||= <%= model.classify %>.new %>
9
+ <%%= form_for(resource, :as => '<%= model %>', :url => registration_path('<%= model %>'), :html => { :class => "form-horizontal" }) do |f| %>
10
+ <%% begin %>
11
+ <%%= devise_error_messages! %>
12
+ <%% rescue %>
13
+ <%% end %>
14
+ <div class="control-group">
15
+ <%%= f.label :email, t(:email, :default => "Email"), :class => "control-label" %>
16
+ <div class="controls">
17
+ <%%= f.email_field :email %>
18
+ </div>
19
+ </div>
20
+ <div class="control-group">
21
+ <%%= f.label :password, t(:password, :default => "Password"), :class => "control-label" %>
22
+ <div class="controls">
23
+ <%%= f.password_field :password %>
24
+ </div>
25
+ </div>
26
+ <div class="control-group">
27
+ <%%= f.label :password_confirmation, t(:password_confirmation, :default => "Password confirmation"), :class => "control-label" %>
28
+ <div class="controls">
29
+ <%%= f.password_field :password_confirmation %>
30
+ </div>
31
+ </div>
32
+
33
+ <div class="control-group">
34
+ <div class="controls">
35
+ <%%= f.submit t(:sign_up, :default => "Sign up"), :class => 'btn' %>
36
+ </div>
37
+ </div>
38
+ <%% end %>
39
+ </div>
40
+ </div>
@@ -0,0 +1,23 @@
1
+ <div style="padding:10px;">
2
+ <%%= form_for("<%= model %>", :url => <%= model %>_session_path, :html => { :class => "form-horizontal" }) do |f| %>
3
+ <div class="control-group">
4
+ <%%= f.text_field :email, :placeholder => t(:email, :default => "Email") %>
5
+ </div>
6
+ <div class="control-group">
7
+ <%%= f.password_field :password, :placeholder => t(:password, :default => "Password") %>
8
+ </div>
9
+ <div class="control-group">
10
+ <label for="<%= model %>_remember_me">
11
+ <%%= f.check_box :remember_me %> <%%= t(:remember_me, :default => "Remember me") %>
12
+ </label>
13
+ </div>
14
+ <%%= f.submit t(:sign_in, :default => "Sign in"), :class => "btn" %>
15
+ <%% end %>
16
+ <a data-toggle="modal" href="#modal-forget-password" class="nopjax"><%%= t(:forgot_your_password, :default => "Forgot your password?") %></a>
17
+ <a data-toggle="modal" href="#modal-register-form" class="nopjax"><%%= t(:register, :default => "Register") %></a>
18
+ <script type="text/javascript">
19
+ $('.dropdown-menu').find('form').click(function (e) {
20
+ e.stopPropagation();
21
+ });
22
+ </script>
23
+ </div>
@@ -0,0 +1,19 @@
1
+ <%% if <%= model %>_signed_in? then %>
2
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">
3
+ <i class="icon-user"></i> <%%= current_<%= model %>.caption %>
4
+ <span class="caret"></span>
5
+ </a>
6
+ <ul class="dropdown-menu">
7
+ <li><a href="#"><%%= t(:profile, :default => "Profile") %></a></li>
8
+ <li class="divider"></li>
9
+ <li><%%= link_to t(:sign_out, :default => "Sign Out"), destroy_<%= model %>_session_path, :method => :delete %></li>
10
+ </ul>
11
+ <%% else %>
12
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">
13
+ <i class="icon-user"></i> <%%= t(:login, :default => "Login") %>
14
+ <span class="caret"></span>
15
+ </a>
16
+ <ul class="dropdown-menu">
17
+ <li><%%= render :partial => "layouts/sign_in_form" %></li>
18
+ </ul>
19
+ <%% end %>
@@ -0,0 +1,15 @@
1
+ class CustomFailure < Devise::FailureApp
2
+ def redirect_url
3
+ #return super unless [:worker, :employer, :user].include?(scope) #make it specific to a scope
4
+ root_path
5
+ end
6
+
7
+ # You need to override respond to eliminate recall
8
+ def respond
9
+ if http_auth?
10
+ http_auth
11
+ else
12
+ redirect
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beautiful_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-21 00:00:00.000000000Z
12
+ date: 2012-08-24 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Beautiful Scaffold generate a complete scaffold (sort, export, paginate
15
15
  and filter data) http://www.beautiful-scaffold.com
@@ -23,6 +23,7 @@ files:
23
23
  - README.rdoc
24
24
  - beautiful_scaffold.gemspec
25
25
  - lib/generators/USAGE
26
+ - lib/generators/beautiful_devisecancan_generator.rb
26
27
  - lib/generators/beautiful_jointable_generator.rb
27
28
  - lib/generators/beautiful_locale_generator.rb
28
29
  - lib/generators/beautiful_migration_generator.rb
@@ -70,6 +71,7 @@ files:
70
71
  - lib/generators/templates/app/assets/stylesheets/timepicker.css
71
72
  - lib/generators/templates/app/controllers/base.rb
72
73
  - lib/generators/templates/app/controllers/master_base.rb
74
+ - lib/generators/templates/app/controllers/registrations_controller.rb
73
75
  - lib/generators/templates/app/helpers/beautiful_helper.rb
74
76
  - lib/generators/templates/app/helpers/model_helper.rb
75
77
  - lib/generators/templates/app/initializers/link_renderer.rb
@@ -87,14 +89,19 @@ files:
87
89
  - lib/generators/templates/app/views/index.html.erb
88
90
  - lib/generators/templates/app/views/layout.html.erb
89
91
  - lib/generators/templates/app/views/new.html.erb
92
+ - lib/generators/templates/app/views/partials/_forget_password.html.erb
90
93
  - lib/generators/templates/app/views/partials/_form_field.html.erb
91
94
  - lib/generators/templates/app/views/partials/_index_batch.html.erb
92
95
  - lib/generators/templates/app/views/partials/_index_column.html.erb
93
96
  - lib/generators/templates/app/views/partials/_index_header.html.erb
94
97
  - lib/generators/templates/app/views/partials/_index_search.html.erb
98
+ - lib/generators/templates/app/views/partials/_register_form.html.erb
95
99
  - lib/generators/templates/app/views/partials/_show_field.html.erb
100
+ - lib/generators/templates/app/views/partials/_sign_in_form.html.erb
101
+ - lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb
96
102
  - lib/generators/templates/app/views/show.html.erb
97
103
  - lib/generators/templates/app/views/treeview.html.erb
104
+ - lib/generators/templates/lib/custom_failure.rb
98
105
  - lib/generators/templates/markitup/jquery.markitup.js
99
106
  - lib/generators/templates/markitup/sets/bbcode/images/bold.png
100
107
  - lib/generators/templates/markitup/sets/bbcode/images/clean.png