mcms_authentication 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +40 -0
- data/app/assets/images/background/page_bg.png +0 -0
- data/app/assets/images/background/text_field_background.png +0 -0
- data/app/assets/images/icons/accept.png +0 -0
- data/app/assets/images/icons/add.png +0 -0
- data/app/assets/images/icons/application_edit.png +0 -0
- data/app/assets/images/icons/cancel.png +0 -0
- data/app/assets/images/icons/delete.png +0 -0
- data/app/assets/images/icons/email_go.png +0 -0
- data/app/assets/images/rails.png +0 -0
- data/app/assets/javascripts/application.js +42 -0
- data/app/assets/javascripts/authentication_global.js +17 -0
- data/app/assets/stylesheets/application.css +33 -0
- data/app/assets/stylesheets/authentication_global.css +424 -0
- data/app/controllers/application_controller.rb +36 -0
- data/app/controllers/home_controller.rb +44 -0
- data/app/controllers/roles_controller.rb +375 -0
- data/app/controllers/users_controller.rb +202 -0
- data/app/models/ability.rb +82 -0
- data/app/models/existing_model.rb +24 -0
- data/app/models/plugin.rb +30 -0
- data/app/models/role.rb +70 -0
- data/app/models/roles_user.rb +33 -0
- data/app/models/user.rb +90 -0
- data/app/views/home/index.html.erb +18 -0
- data/app/views/layouts/users/_javascript.html.erb +3 -0
- data/app/views/layouts/users/_stylesheet.html.erb +3 -0
- data/app/views/layouts/users/devise.html.erb +40 -0
- data/app/views/layouts/users/home.html.erb +99 -0
- data/app/views/roles/_form.html.erb +240 -0
- data/app/views/roles/_form.js.erb +113 -0
- data/app/views/roles/edit.html.erb +26 -0
- data/app/views/roles/index.html.erb +73 -0
- data/app/views/roles/new.html.erb +25 -0
- data/app/views/users/_role.js.erb +47 -0
- data/app/views/users/confirmations/new.html.erb +29 -0
- data/app/views/users/edit.html.erb +131 -0
- data/app/views/users/index.html.erb +81 -0
- data/app/views/users/mailer/confirmation_instructions.html.erb +22 -0
- data/app/views/users/mailer/reset_password_instructions.html.erb +26 -0
- data/app/views/users/mailer/unlock_instructions.html.erb +24 -0
- data/app/views/users/new.html.erb +113 -0
- data/app/views/users/passwords/edit.html.erb +38 -0
- data/app/views/users/passwords/new.html.erb +32 -0
- data/app/views/users/sessions/new.html.erb +84 -0
- data/app/views/users/shared/_links.erb +39 -0
- data/app/views/users/unlocks/new.html.erb +25 -0
- data/config/initializers/constants.rb +30 -0
- data/config/initializers/devise.rb +217 -0
- data/config/locales/devise.en.yml +57 -0
- data/config/locales/en.yml +10 -0
- data/config/routes.rb +24 -0
- data/db/migrate/20120605112804_devise_create_users.rb +68 -0
- data/db/migrate/20120608104637_create_roles.rb +30 -0
- data/db/migrate/20120608140424_create_roles_users.rb +25 -0
- data/db/migrate/20120612050932_create_plugins.rb +14 -0
- data/db/migrate/20120625114340_create_existing_models.rb +9 -0
- data/db/migrate/20120711064709_add_username_to_users.rb +9 -0
- data/db/seeds.rb +29 -0
- data/lib/generators/mcms_authentication/USAGE +8 -0
- data/lib/generators/mcms_authentication/mcms_authentication_generator.rb +110 -0
- data/lib/generators/mcms_authentication/templates/asset_manager.rb +117 -0
- data/lib/generators/mcms_authentication/templates/models.rb +189 -0
- data/lib/mcms_authentication.rb +4 -0
- data/lib/mcms_authentication/engine.rb +20 -0
- data/lib/mcms_authentication/seeds.rb +14 -0
- data/lib/mcms_authentication/version.rb +3 -0
- data/lib/tasks/mcms_authentication_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/fixtures/existing_models.yml +11 -0
- data/test/functional/home_controller_test.rb +7 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/mcms_authentication_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/existing_model_test.rb +7 -0
- data/test/unit/helpers/home_helper_test.rb +4 -0
- metadata +234 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
|
2
|
+
|
3
|
+
en:
|
4
|
+
errors:
|
5
|
+
messages:
|
6
|
+
expired: "has expired, please request a new one"
|
7
|
+
not_found: "not found"
|
8
|
+
already_confirmed: "was already confirmed, please try signing in"
|
9
|
+
not_locked: "was not locked"
|
10
|
+
not_saved:
|
11
|
+
one: "1 error prohibited this %{resource} from being saved:"
|
12
|
+
other: "%{count} errors prohibited this %{resource} from being saved:"
|
13
|
+
|
14
|
+
devise:
|
15
|
+
failure:
|
16
|
+
already_authenticated: 'You are already signed in.'
|
17
|
+
unauthenticated: 'You need to sign in or sign up before continuing.'
|
18
|
+
unconfirmed: 'You have to confirm your account before continuing.'
|
19
|
+
locked: 'Your account is locked.'
|
20
|
+
invalid: 'Invalid email or password.'
|
21
|
+
invalid_token: 'Invalid authentication token.'
|
22
|
+
timeout: 'Your session expired, please sign in again to continue.'
|
23
|
+
inactive: 'Your account was not activated yet.'
|
24
|
+
sessions:
|
25
|
+
signed_in: 'Signed in successfully.'
|
26
|
+
signed_out: 'Signed out successfully.'
|
27
|
+
passwords:
|
28
|
+
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
29
|
+
updated: 'Your password was changed successfully. You are now signed in.'
|
30
|
+
updated_not_active: 'Your password was changed successfully.'
|
31
|
+
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
|
32
|
+
confirmations:
|
33
|
+
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
|
34
|
+
send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
|
35
|
+
confirmed: 'Your account was successfully confirmed. You are now signed in.'
|
36
|
+
registrations:
|
37
|
+
signed_up: 'Welcome! You have signed up successfully.'
|
38
|
+
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
|
39
|
+
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
|
40
|
+
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
|
41
|
+
updated: 'You updated your account successfully.'
|
42
|
+
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
|
43
|
+
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
44
|
+
unlocks:
|
45
|
+
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
|
46
|
+
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
|
47
|
+
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
|
48
|
+
omniauth_callbacks:
|
49
|
+
success: 'Successfully authenticated from %{kind} account.'
|
50
|
+
failure: 'Could not authenticate you from %{kind} because "%{reason}".'
|
51
|
+
mailer:
|
52
|
+
confirmation_instructions:
|
53
|
+
subject: 'Confirmation instructions'
|
54
|
+
reset_password_instructions:
|
55
|
+
subject: 'Reset password instructions'
|
56
|
+
unlock_instructions:
|
57
|
+
subject: 'Unlock Instructions'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Sample localization file for English. Add more files in this directory for other locales.
|
2
|
+
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
+
|
4
|
+
en:
|
5
|
+
hello: "Hello world"
|
6
|
+
sign_in: "Hi,Please Sign in"
|
7
|
+
default_uname: "The default email and password are both"
|
8
|
+
user_update_success: "%{user_email} updated successfully."
|
9
|
+
user_destroy_success: "%{user_email} successfully deleted."
|
10
|
+
user_create_success: "%{user_email} successfully created."
|
data/config/routes.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
devise_for :users , :controllers => {:registrations => "users"} do
|
3
|
+
|
4
|
+
# giving mcms namespace /prefix
|
5
|
+
|
6
|
+
get "mcms/users/login",:to => "devise/sessions#new"
|
7
|
+
get "mcms/users/logout",:to => "devise/sessions#destroy"
|
8
|
+
get "mcms/users",:to => "users#index"
|
9
|
+
get "mcms/users/new",:to => "users#new"
|
10
|
+
post "mcms/users", :to => "users#create"
|
11
|
+
get "mcms/users/edit/:id",:to => "users#edit"
|
12
|
+
put "mcms/update_user",:to => "users#update"
|
13
|
+
delete "mcms/destroy_user",:to => "users#destroy_user"
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
resources :users, :controller => "users"
|
18
|
+
|
19
|
+
resources :roles ,:path => 'mcms/role' # with proper namespace/prefix
|
20
|
+
|
21
|
+
match "mcms/roles",:to => "roles#index" # namespacing roles
|
22
|
+
|
23
|
+
root :to => "home#index" # home page
|
24
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
@File Name :timestamp_devise_create_user.rb
|
4
|
+
|
5
|
+
@Company Name :Mindfire Solutions Pvt. Ltd.
|
6
|
+
|
7
|
+
@Creator Name :Indranil Mukherjee
|
8
|
+
|
9
|
+
@Date Created :2012-06-04
|
10
|
+
|
11
|
+
@Date Modified :2012-06-25
|
12
|
+
|
13
|
+
@Last Modification Details :Making it as mcms project standard
|
14
|
+
|
15
|
+
@Purpose :Migrations to create users
|
16
|
+
|
17
|
+
=end
|
18
|
+
|
19
|
+
class DeviseCreateUsers < ActiveRecord::Migration
|
20
|
+
|
21
|
+
def change
|
22
|
+
|
23
|
+
create_table(:mcms_users) do |t|
|
24
|
+
## Database authenticatable
|
25
|
+
t.string :email, :null => false, :default => ""
|
26
|
+
t.string :encrypted_password, :null => false, :default => ""
|
27
|
+
|
28
|
+
## Recoverable
|
29
|
+
t.string :reset_password_token
|
30
|
+
t.datetime :reset_password_sent_at
|
31
|
+
|
32
|
+
## Rememberable
|
33
|
+
t.datetime :remember_created_at
|
34
|
+
|
35
|
+
## Trackable
|
36
|
+
t.integer :sign_in_count, :default => 0
|
37
|
+
t.datetime :current_sign_in_at
|
38
|
+
t.datetime :last_sign_in_at
|
39
|
+
t.string :current_sign_in_ip
|
40
|
+
t.string :last_sign_in_ip
|
41
|
+
|
42
|
+
## Confirmable
|
43
|
+
t.string :confirmation_token
|
44
|
+
t.datetime :confirmed_at
|
45
|
+
t.datetime :confirmation_sent_at
|
46
|
+
t.string :unconfirmed_email # Only if using reconfirmable
|
47
|
+
|
48
|
+
## Lockable
|
49
|
+
t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
|
50
|
+
t.string :unlock_token # Only if unlock strategy is :email or :both
|
51
|
+
t.datetime :locked_at
|
52
|
+
|
53
|
+
## Token authenticatable
|
54
|
+
t.string :authentication_token
|
55
|
+
|
56
|
+
|
57
|
+
t.timestamps
|
58
|
+
end
|
59
|
+
|
60
|
+
add_index :mcms_users, :email, :unique => true
|
61
|
+
add_index :mcms_users, :reset_password_token, :unique => true
|
62
|
+
add_index :mcms_users, :confirmation_token, :unique => true
|
63
|
+
add_index :mcms_users, :unlock_token, :unique => true
|
64
|
+
add_index :mcms_users, :authentication_token, :unique => true
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
=begin
|
2
|
+
******************************************************************************************************************
|
3
|
+
|
4
|
+
FileName: 20120608104637_devise_create_users.rb
|
5
|
+
|
6
|
+
Company Name and Copyright information: Mindfire Solutions Pvt. Ltd.
|
7
|
+
|
8
|
+
Creator name and date: Indranil Mukherjee 08/06/2012
|
9
|
+
|
10
|
+
Description of the file contents: This is the migration file for creating role table for users
|
11
|
+
In our case mcms_roles
|
12
|
+
|
13
|
+
******************************************************************************************************************
|
14
|
+
=end
|
15
|
+
|
16
|
+
class CreateRoles < ActiveRecord::Migration
|
17
|
+
|
18
|
+
def change
|
19
|
+
|
20
|
+
create_table :mcms_roles do |t|
|
21
|
+
|
22
|
+
t.string :title # only title column
|
23
|
+
|
24
|
+
t.timestamps
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
=begin
|
2
|
+
******************************************************************************************************************
|
3
|
+
|
4
|
+
FileName: 20120608140424_devise_create_users.rb
|
5
|
+
|
6
|
+
Company Name and Copyright information: Mindfire Solutions Pvt. Ltd.
|
7
|
+
|
8
|
+
Creator name and date: Indranil Mukherjee 08/06/2012
|
9
|
+
|
10
|
+
Description of the file contents: This is the migration file for creating roles_users table
|
11
|
+
which is a join table for users and roles
|
12
|
+
In our case mcms_roles_users
|
13
|
+
|
14
|
+
******************************************************************************************************************
|
15
|
+
=end
|
16
|
+
|
17
|
+
class CreateRolesUsers < ActiveRecord::Migration
|
18
|
+
def change
|
19
|
+
create_table :mcms_roles_users do |t|
|
20
|
+
t.belongs_to :user
|
21
|
+
t.belongs_to :role
|
22
|
+
t.timestamps
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreatePlugins < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :mcms_plugins do |t|
|
4
|
+
t.string :role_module
|
5
|
+
t.boolean :role_read
|
6
|
+
t.boolean :role_create
|
7
|
+
t.boolean :role_update
|
8
|
+
t.boolean :role_destroy
|
9
|
+
t.boolean :role_manage
|
10
|
+
t.belongs_to :role
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
7
|
+
# Mayor.create(name: 'Emanuel', city: cities.first)
|
8
|
+
#writting seeds
|
9
|
+
#puts "Enter admin user"
|
10
|
+
#a = gets.chomp
|
11
|
+
|
12
|
+
#puts "Enter password"
|
13
|
+
|
14
|
+
#b = gets.chomp
|
15
|
+
|
16
|
+
User.create!(:email => 'admin@mcms.com' ,:password => 'admin123' )
|
17
|
+
|
18
|
+
Role.create!(:title => 'superuser')
|
19
|
+
|
20
|
+
|
21
|
+
u = User.find_by_email('admin@mcms.com')
|
22
|
+
|
23
|
+
|
24
|
+
r = Role.find_by_title('superuser')
|
25
|
+
|
26
|
+
|
27
|
+
RolesUser.create!(:user_id => u.id , :role_id => r.id)
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
@File Name :mcms_authentication_generator.rb
|
4
|
+
|
5
|
+
@Company Name :Mindfire Solutions Pvt. Ltd.
|
6
|
+
|
7
|
+
@Creator Name :Indranil Mukherjee
|
8
|
+
|
9
|
+
@Date Created :2012-06-14
|
10
|
+
|
11
|
+
@Date Modified :2012-06-25
|
12
|
+
|
13
|
+
@Last Modification Details :Making it as mcms project standard
|
14
|
+
|
15
|
+
@Purpose :This file is responsible to install mcms_authentication module in other application/module
|
16
|
+
|
17
|
+
=end
|
18
|
+
|
19
|
+
class McmsAuthenticationGenerator < Rails::Generators::NamedBase
|
20
|
+
|
21
|
+
source_root File.expand_path('../templates', __FILE__)
|
22
|
+
|
23
|
+
desc "Installing MCMS_AUTHENTICATION"
|
24
|
+
|
25
|
+
# @Params : No parameter
|
26
|
+
# @Returns : Nothing is returned
|
27
|
+
# @Purpose : Copies all the migrations
|
28
|
+
|
29
|
+
def add_migrations
|
30
|
+
|
31
|
+
say "Copying migrations........."
|
32
|
+
|
33
|
+
rake("mcms_authentication_engine:install:migrations")
|
34
|
+
|
35
|
+
# create file deb/seeds.rb to parent app if not exists
|
36
|
+
create_file "db/seeds.rb" unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
|
37
|
+
|
38
|
+
# append data to app's seeds.rb
|
39
|
+
append_file 'db/seeds.rb', :verbose => true do
|
40
|
+
|
41
|
+
<<-EOH
|
42
|
+
|
43
|
+
McmsAuthentication::Engine.load_seed
|
44
|
+
|
45
|
+
EOH
|
46
|
+
|
47
|
+
end # end block
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
# @Params : No parameter
|
52
|
+
# @Returns : Nothing is returned
|
53
|
+
# @Purpose : Copies all the libraries required
|
54
|
+
|
55
|
+
def copy_core_libraries
|
56
|
+
|
57
|
+
copy_file "models.rb", "lib/mcms_authentication/models.rb" # module logic
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
# @Params : No parameter
|
62
|
+
# @Returns : Nothing is returned
|
63
|
+
# @Purpose : Configurations are done here
|
64
|
+
|
65
|
+
def configure
|
66
|
+
|
67
|
+
insert_into_file File.join('app/controllers', 'application_controller.rb'), :after => "ActionController::Base\n" do
|
68
|
+
|
69
|
+
|
70
|
+
'
|
71
|
+
include ApplicationHelper #including application_helper for the availability of filters
|
72
|
+
# The following snippet is responsible for rescuing from exception generated by CanCan gem
|
73
|
+
# for denying a particular module access with a notice to user and redirecting to root_url
|
74
|
+
rescue_from CanCan::AccessDenied do |exception|
|
75
|
+
|
76
|
+
flash[:error] = t(:access_denied,:default => "You are not authorized for doing this operation")
|
77
|
+
redirect_to root_url
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
#end of configuration
|
82
|
+
|
83
|
+
'
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
# @Params : No parameter
|
89
|
+
# @Returns : Nothing is returned
|
90
|
+
# @Purpose : Final instructions for developers who will use the gem
|
91
|
+
|
92
|
+
def prompt_user
|
93
|
+
|
94
|
+
say "\ndon't forget to run the following \n
|
95
|
+
|
96
|
+
rake db:migrate\n
|
97
|
+
rake db:seed\n
|
98
|
+
|
99
|
+
in the controllers where you want to apply auth\n
|
100
|
+
|
101
|
+
prepend_before_filter :authenticate_user! \n
|
102
|
+
|
103
|
+
load_and_authorize_resource \n
|
104
|
+
|
105
|
+
Enjoy!\n\n"
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
@File Name :asset_manager.rb
|
4
|
+
|
5
|
+
@Company Name :Mindfire Solutions Pvt. Ltd.
|
6
|
+
|
7
|
+
@Creator Name :Indranil Mukherjee
|
8
|
+
|
9
|
+
@Date Created :2012-06-04
|
10
|
+
|
11
|
+
@Date Modified :2012-06-15
|
12
|
+
|
13
|
+
@Last Modification Details :Making it as mcms project standard
|
14
|
+
|
15
|
+
@Purpose :Dynamically include assets
|
16
|
+
|
17
|
+
=end
|
18
|
+
|
19
|
+
class AssetManager
|
20
|
+
|
21
|
+
#Class methods start here
|
22
|
+
|
23
|
+
#include_css
|
24
|
+
#checking the file type if array then loop to include neither simple includes
|
25
|
+
def self.include_css file
|
26
|
+
if file.class == Array
|
27
|
+
file.each do |f|
|
28
|
+
include_css_file_individual f
|
29
|
+
end
|
30
|
+
else
|
31
|
+
include_css_file_individual file
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#include_contrib_library
|
36
|
+
#includes the javascripts in contrib folder those are the mandatory libraries
|
37
|
+
def self.include_contrib_library library
|
38
|
+
include_js_library library, :contrib
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
#include_local_library method
|
43
|
+
#includes the javascripts those are localy added
|
44
|
+
def self.include_local_library library
|
45
|
+
include_js_library library, :local
|
46
|
+
end
|
47
|
+
|
48
|
+
#include_js_library method
|
49
|
+
#includes the javascripts those are localy added
|
50
|
+
def self.include_js_library library, type = :local
|
51
|
+
Rails.logger.debug library.inspect
|
52
|
+
if library.class == Array
|
53
|
+
library.each do |l|
|
54
|
+
include_js_library_individual l, type
|
55
|
+
end
|
56
|
+
else
|
57
|
+
include_js_library_individual library, type
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
#get_libraries method
|
63
|
+
#return all javscripts included array
|
64
|
+
def self.get_libraries
|
65
|
+
return @@js_includes
|
66
|
+
end
|
67
|
+
|
68
|
+
#get_css method
|
69
|
+
#return css_includes array
|
70
|
+
#gloabal varibale
|
71
|
+
def self.get_css
|
72
|
+
return @@css_includes
|
73
|
+
end
|
74
|
+
|
75
|
+
#Private methods started here
|
76
|
+
private
|
77
|
+
@@js_includes = []
|
78
|
+
@@css_includes = []
|
79
|
+
|
80
|
+
#Pushing javascript libraries in the gloabal @@js_includes variable
|
81
|
+
def self.include_js_library_individual library, type
|
82
|
+
|
83
|
+
file = ""
|
84
|
+
|
85
|
+
case type
|
86
|
+
when :local
|
87
|
+
if library.class == Symbol
|
88
|
+
file = library.to_s + ".js"
|
89
|
+
else
|
90
|
+
file = library
|
91
|
+
end
|
92
|
+
when :contrib
|
93
|
+
file = "contrib/" + @@libraries[library]
|
94
|
+
end
|
95
|
+
|
96
|
+
@@js_includes << file unless file.blank? or @@js_includes.include? file
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
#pushing individual css files
|
101
|
+
def self.include_css_file_individual file
|
102
|
+
|
103
|
+
if file.class == Symbol
|
104
|
+
file = file.to_s + '.css'
|
105
|
+
end
|
106
|
+
|
107
|
+
@@css_includes << file unless file.blank? or @@css_includes.include? file
|
108
|
+
end
|
109
|
+
|
110
|
+
#Registering javascript libraries
|
111
|
+
@@libraries = {
|
112
|
+
:core_ui => "ui.core.js",
|
113
|
+
:jquery_widget => "ui.widget.js",
|
114
|
+
:jquery_tab => "ui.tabs.js"
|
115
|
+
}
|
116
|
+
|
117
|
+
end
|