ucb_rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/README.md +34 -4
  2. data/app/controllers/ucb_rails/admin/base_controller.rb +4 -0
  3. data/app/controllers/ucb_rails/admin/users_controller.rb +70 -0
  4. data/app/controllers/ucb_rails/bootstrap_controller.rb +34 -0
  5. data/app/controllers/ucb_rails/controller_methods.rb +67 -6
  6. data/app/controllers/ucb_rails/home_controller.rb +5 -0
  7. data/app/controllers/ucb_rails/ldap_person_search_controller.rb +15 -0
  8. data/app/controllers/ucb_rails/sessions_controller.rb +33 -8
  9. data/app/helpers/ucb_rails/admin/users_helper.rb +14 -0
  10. data/app/helpers/ucb_rails/extractable_helper.rb +17 -0
  11. data/app/helpers/ucb_rails/icons_helper.rb +7 -0
  12. data/app/helpers/ucb_rails/ldap_person_search_helper.rb +21 -0
  13. data/app/helpers/ucb_rails/lps_typeahead_helper.rb +50 -0
  14. data/app/helpers/ucb_rails/renderer/base.rb +52 -0
  15. data/app/helpers/ucb_rails/renderer/ldap_person_search_result_link.rb +81 -0
  16. data/app/models/ucb_rails/ldap_person/entry.rb +54 -0
  17. data/app/models/ucb_rails/ldap_person/finder.rb +67 -0
  18. data/app/models/ucb_rails/ldap_person/test_finder.rb +50 -0
  19. data/app/models/ucb_rails/user.rb +28 -0
  20. data/app/models/ucb_rails/user_ldap_service.rb +50 -0
  21. data/app/models/ucb_rails/user_session_manager/active_in_user_table.rb +37 -0
  22. data/app/models/ucb_rails/user_session_manager/admin_in_user_table.rb +13 -0
  23. data/app/models/ucb_rails/user_session_manager/base.rb +44 -0
  24. data/app/models/ucb_rails/user_session_manager/in_people_ou.rb +27 -0
  25. data/app/models/ucb_rails/user_session_manager/in_people_ou_add_to_users_table.rb +19 -0
  26. data/app/models/ucb_rails/user_session_manager/ldap_person_user_wrapper.rb +29 -0
  27. data/app/models/ucb_rails/user_table_active.rb +3 -0
  28. data/app/views/ucb_rails/admin/users/_form.html.haml +16 -0
  29. data/app/views/ucb_rails/admin/users/_user.html.haml +12 -0
  30. data/app/views/ucb_rails/admin/users/edit.html.haml +3 -0
  31. data/app/views/ucb_rails/admin/users/index.html.haml +40 -0
  32. data/app/views/ucb_rails/lps/_form.html.haml +16 -0
  33. data/app/views/ucb_rails/lps/_modal.html.haml +6 -0
  34. data/app/views/ucb_rails/lps/_results.html.haml +21 -0
  35. data/app/views/ucb_rails/lps/search.js.haml +2 -0
  36. data/config/routes.rb +18 -1
  37. data/lib/generators/ucb_rails/install_generator.rb +27 -23
  38. data/lib/generators/ucb_rails/templates/README +13 -0
  39. data/lib/generators/ucb_rails/templates/app/assets/javascripts/application.js +19 -0
  40. data/lib/generators/ucb_rails/templates/app/assets/javascripts/lps.js +71 -0
  41. data/lib/generators/ucb_rails/templates/app/assets/javascripts/lps_typeahead.js +56 -0
  42. data/lib/generators/ucb_rails/templates/app/assets/javascripts/typeahead.js +8 -0
  43. data/lib/generators/ucb_rails/templates/app/assets/stylesheets/application.css +14 -0
  44. data/lib/generators/ucb_rails/templates/app/assets/stylesheets/bootstrap_and_overrides.css.scss +3 -0
  45. data/lib/generators/ucb_rails/templates/app/assets/stylesheets/ucb_rails.css.scss +51 -0
  46. data/lib/generators/ucb_rails/templates/app/helpers/ucb_rails/application_helper.rb +12 -0
  47. data/lib/generators/ucb_rails/templates/app/views/layouts/_developer.html.haml +13 -0
  48. data/lib/generators/ucb_rails/templates/app/views/layouts/_footer.html.haml +5 -0
  49. data/lib/generators/ucb_rails/templates/app/views/layouts/_navigation.html.haml +25 -0
  50. data/lib/generators/ucb_rails/templates/app/views/layouts/application.html.haml +22 -0
  51. data/lib/generators/ucb_rails/templates/config/initializers/local/active_record/dom_and_haml.rb +61 -0
  52. data/lib/generators/ucb_rails/templates/config/initializers/local/haml_buffer.rb +20 -0
  53. data/lib/generators/ucb_rails/templates/config/initializers/local/simple_form.rb +142 -0
  54. data/lib/generators/ucb_rails/templates/config/initializers/local/simple_form_bootstrap.rb +45 -0
  55. data/lib/generators/ucb_rails/templates/config/initializers/local/ucb_rails.rb +45 -0
  56. data/lib/generators/ucb_rails/templates/config/locales/simple_form.en.yml +26 -0
  57. data/lib/generators/ucb_rails/templates/db/migrate/create_users.rb +23 -0
  58. data/lib/generators/ucb_rails/templates/lib/templates/haml/scaffold/_form.html.haml +10 -0
  59. data/lib/ucb_rails/engine.rb +22 -1
  60. data/lib/ucb_rails/log_tagger.rb +20 -0
  61. data/lib/ucb_rails/version.rb +1 -1
  62. data/lib/ucb_rails.rb +16 -0
  63. metadata +312 -10
  64. data/lib/generators/ucb_rails/templates/initializer.rb +0 -4
@@ -0,0 +1,67 @@
1
+ module UcbRails::LdapPerson
2
+ class Finder
3
+ BlankSearchTermsError = Class.new(StandardError)
4
+ PersonNotFound = Class.new(StandardError)
5
+
6
+ def benchmark(message = "Benchmarking")
7
+ result = nil
8
+ ms = Benchmark.ms { result = yield }
9
+ Rails.logger.debug "#{message} #{ms}"
10
+ result
11
+ end
12
+
13
+ def find_by_uid(uid)
14
+ benchmark("find_by_uid(#{uid})") do
15
+ find_by_attributes(:uid => uid.to_s).first
16
+ end
17
+ end
18
+
19
+ def find_by_uid!(uid)
20
+ find_by_uid(uid) or raise(PersonNotFound, "uid=#{uid.inspect}")
21
+ end
22
+
23
+ def find_by_first_last(first_name, last_name, options={})
24
+ raise BlankSearchTermsError unless first_name.present? || last_name.present?
25
+
26
+ find_by_attributes(:givenname => first_name, :sn => last_name).tap do |entries|
27
+ if options[:sort]
28
+ sort_symbol = options[:sort]
29
+ entries.sort_by!(&options[:sort])
30
+ end
31
+ end
32
+ end
33
+
34
+ def find_by_attributes(attributes)
35
+ attributes.each { |k, v| attributes.delete(k) if v.blank? }
36
+ UCB::LDAP::Person.
37
+ search(:filter => build_filter(attributes)).
38
+ map { |ldap_entry| Entry.new_from_ldap_entry(ldap_entry) }
39
+ end
40
+
41
+ def build_filter(attrs)
42
+ filter_parts = attrs.map { |k, v| build_filter_part(k, v) }
43
+ filter = filter_parts.inject { |accum, filter| accum.send(:&, filter) }
44
+ filter
45
+ end
46
+
47
+ def build_filter_part(key, value)
48
+ value = key.to_s == 'uid' ? value : "#{value}*"
49
+ Net::LDAP::Filter.eq(key.to_s, value)
50
+ end
51
+
52
+ class << self
53
+ def klass
54
+ if RailsEnvironment.test? || UcbRails[:omniauth_provider] == :developer
55
+ UcbRails::LdapPerson::TestFinder
56
+ else
57
+ UcbRails::LdapPerson::Finder
58
+ end
59
+ end
60
+
61
+ def method_missing(method, *args)
62
+ klass.new.send(method, *args)
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,50 @@
1
+ module UcbRails::LdapPerson
2
+ class TestFinder
3
+ PersonNotFound = Class.new(StandardError)
4
+
5
+ def find_by_uid(uid)
6
+ uid.presence and find_by_attributes(:uid => uid.to_s).first
7
+ end
8
+
9
+ def find_by_uid!(uid)
10
+ find_by_uid(uid) || raise(PersonNotFound, "uid=#{uid.inspect}")
11
+ end
12
+
13
+ def find_by_first_last(first_name, last_name, options={})
14
+ find_by_attributes(:first_name => first_name, :last_name => last_name)
15
+ end
16
+
17
+ def find_by_attributes(attributes)
18
+ self.class.entries.select { |entry| entry_matches_attributes(entry, attributes) }
19
+ end
20
+
21
+ def entry_matches_attributes(entry, attributes)
22
+ attributes.keys.all? do |key|
23
+ value = attributes[key].to_s.downcase
24
+ value.blank? || entry.send(key).downcase.include?(value)
25
+ end
26
+ end
27
+
28
+ def self.entries
29
+ [
30
+ new_entry("1", 'art', "Art", "Andrews", "art@example.com", "999-999-0001", "Dept 1"),
31
+ new_entry("2", 'beth', "Beth", "Brown", "beth@example.com", "999-999-0002", "Dept 2"),
32
+ new_entry("61065", 'runner', "Steven", "Hansen", "runner@berkeley.edu", "999-999-9998", "EAS"),
33
+ new_entry("191501", 'stevedowney', "Steve", "Downey", "sldowney@berkeley.edu", "999-999-9999", "EAS"),
34
+ ]
35
+ end
36
+
37
+ def self.new_entry(uid, calnet_id, fn, ln, email, phone, depts)
38
+ ::UcbRails::LdapPerson::Entry.new(
39
+ :uid => uid,
40
+ :calnet_id => calnet_id,
41
+ :first_name => fn,
42
+ :last_name => ln,
43
+ :email => email,
44
+ :phone => phone,
45
+ :departments => depts
46
+ )
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,28 @@
1
+ class UcbRails::User < ActiveRecord::Base
2
+ self.table_name = 'users'
3
+
4
+ attr_accessible :uid, :first_name, :last_name, :inactive
5
+
6
+ before_validation :set_first_last_name
7
+
8
+ def admin!
9
+ update_attribute(:admin, true)
10
+ end
11
+
12
+ def self.active
13
+ where(inactive: false)
14
+ end
15
+
16
+ def self.admin
17
+ where(admin: true)
18
+ end
19
+
20
+ private
21
+
22
+ def set_first_last_name
23
+ self.first_last_name = [first_name, last_name]
24
+ .select { |n| n.present? }
25
+ .join(' ')
26
+ .presence
27
+ end
28
+ end
@@ -0,0 +1,50 @@
1
+ class UcbRails::UserLdapService
2
+
3
+ class << self
4
+
5
+ def create_user_from_uid(uid)
6
+ ldap_entry = UcbRails::LdapPerson::Finder.find_by_uid!(uid)
7
+ create_user_from_ldap_entry(ldap_entry)
8
+ end
9
+
10
+ def create_user_from_ldap_entry(ldap_entry)
11
+
12
+ UcbRails::User.create! do |u|
13
+ u.uid = ldap_entry.uid
14
+ u.first_name = ldap_entry.first_name
15
+ u.last_name = ldap_entry.last_name
16
+ u.email = ldap_entry.email
17
+ u.phone = ldap_entry.phone
18
+
19
+ end
20
+
21
+ end
22
+
23
+ def update_user_from_ldap_entry(ldap_entry)
24
+ # ldap_entry = UcbRails::LdapPerson::Finder.find_by_uid!(uid)
25
+ UcbRails::User.find_by_uid!(ldap_entry.uid).tap do |user|
26
+ user.first_name = ldap_entry.first_name
27
+ user.last_name = ldap_entry.last_name
28
+ user.email = ldap_entry.email
29
+ user.phone = ldap_entry.phone
30
+ user.save(validate: false)
31
+ end
32
+ end
33
+
34
+ def create_or_update_user(uid)
35
+ if user = UcbRails::User.find_by_uid(uid)
36
+ update_user(uid)
37
+ else
38
+ create_user(uid)
39
+ end
40
+ end
41
+
42
+ def create_or_update_user_from_entry(entry)
43
+ if user = UcbRails::User.find_by_uid(entry.uid)
44
+ update_user_from_ldap_entry(entry)
45
+ else
46
+ create_user_from_ldap_entry(entry)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,37 @@
1
+ module UcbRails
2
+ module UserSessionManager
3
+ class ActiveInUserTable < Base
4
+
5
+ def login(uid)
6
+ self.uid = uid
7
+
8
+ if user_table_entry && people_ou_entry
9
+ UcbRails::UserLdapService.update_user_from_ldap_entry(people_ou_entry).tap do |user|
10
+ user.touch(:last_login_at)
11
+ end
12
+ else
13
+ false
14
+ end
15
+ end
16
+
17
+ def current_user(uid)
18
+ UcbRails::User.find_by_uid(uid)
19
+ end
20
+
21
+ def log_request(user)
22
+ user.present? and user.touch(:last_request_at)
23
+ end
24
+
25
+ def logout(user)
26
+ user.present? and user.touch(:last_logout_at)
27
+ end
28
+
29
+ private
30
+
31
+ def user_table_entry
32
+ active_user
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ module UcbRails
2
+ module UserSessionManager
3
+ class AdminInUserTable < ActiveInUserTable
4
+
5
+ private
6
+
7
+ def user_table_entry
8
+ active_admin_user
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ class UcbRails::UserSessionManager::Base
2
+ attr_accessor :uid
3
+
4
+ def login(uid)
5
+ raise NotImplementedError
6
+ end
7
+
8
+ def current_user(uid)
9
+ raise NotImplementedError
10
+ end
11
+
12
+ def log_request(user)
13
+ end
14
+
15
+ def logout(user)
16
+ end
17
+
18
+ def people_ou_entry(uid_in=nil)
19
+ self.uid = uid_in if uid_in.present?
20
+
21
+ @people_ou_entry ||= begin
22
+ if @people_ou_entry = UcbRails::LdapPerson::Finder.find_by_uid(uid)
23
+ @people_ou_entry
24
+ else
25
+ UcbRails.logger.debug "#{self.class} people_ou_entry not found for uid: #{uid.inspect}"
26
+ nil
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def active_user
34
+ @active_user ||= UcbRails::User.active.find_by_uid(uid)
35
+ end
36
+
37
+ def active_admin_user
38
+ @active_user ||= UcbRails::User.active.admin.find_by_uid(uid)
39
+ end
40
+
41
+ def ldap_person_user_wrapper(ldap_person_entry)
42
+ UcbRails::UserSessionManager::LdapPersonUserWrapper.new(ldap_person_entry)
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ module UcbRails
2
+ module UserSessionManager
3
+ class InPeopleOu < Base
4
+
5
+ def login(uid)
6
+ self.uid = uid
7
+
8
+ if people_ou_entry.present?
9
+ current_user(uid)
10
+ else
11
+ false
12
+ end
13
+ end
14
+
15
+ def current_user(uid)
16
+ self.uid = uid
17
+
18
+ if people_ou_entry.present?
19
+ ldap_person_user_wrapper(people_ou_entry)
20
+ else
21
+ nil
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ module UcbRails
2
+ module UserSessionManager
3
+
4
+ class InPeopleOuAddToUsersTable < ActiveInUserTable
5
+
6
+ def login(uid)
7
+ self.uid = uid
8
+
9
+ if people_ou_entry.present?
10
+ UcbRails::UserLdapService.create_or_update_user_from_entry(people_ou_entry)
11
+ else
12
+ nil
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module UcbRails
2
+ module UserSessionManager
3
+
4
+ class LdapPersonUserWrapper
5
+ attr_accessor :ldap_person_entry
6
+
7
+ def initialize(ldap_person_entry)
8
+ self.ldap_person_entry = ldap_person_entry
9
+ end
10
+
11
+ def id
12
+ uid
13
+ end
14
+
15
+ def admin?
16
+ false
17
+ end
18
+
19
+ def method_missing(method, *args, &block)
20
+ if ldap_person_entry.respond_to?(method)
21
+ ldap_person_entry.send(method, *args, &block)
22
+ else
23
+ super
24
+ end
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ class UcbRails::ActiveInUserTable
2
+
3
+ end
@@ -0,0 +1,16 @@
1
+ = simple_form_for(@user, url: url, method: method, :html => {:class => 'form-horizontal'}) do |f|
2
+ = f.input :uid, :input_html => {disabled: 'disabled'}
3
+ = f.input :first_name, :input_html => {disabled: 'disabled'}
4
+ = f.input :last_name, :input_html => {disabled: 'disabled'}
5
+ = f.input :email, :input_html => {disabled: 'disabled'}
6
+ = f.input :phone, :input_html => {disabled: 'disabled'}
7
+ = f.input :last_login_at, as: :string, :input_html => {disabled: 'disabled', value: datetime_to_s(@user.last_login_at, :long)}
8
+ = f.input :last_request_at, as: :string, :input_html => {disabled: 'disabled', value: datetime_to_s(@user.last_request_at, :long)}
9
+ = f.input :last_logout_at, as: :string, :input_html => {disabled: 'disabled', value: datetime_to_s(@user.last_logout_at, :long)}
10
+ = f.input :admin, :label => false, :as => :boolean, :inline_label => "Admin?"
11
+ = f.input :inactive, :label => false, :as => :boolean, :inline_label => "Inactive User?"
12
+
13
+ = form_actions do
14
+ = submit_button_tag("Update User")
15
+ = cancel_button_tag(url: ucb_rails_admin_users_path)
16
+
@@ -0,0 +1,12 @@
1
+ %tr[user]
2
+ = td_bln(user.admin)
3
+ = td_bln(user.inactive)
4
+ %td= user.first_name
5
+ %td= user.last_name
6
+ %td= mail_to(user.email)
7
+ %td.phone= user.phone
8
+ %td.dt= datetime_to_s(user.last_request_at, :long)
9
+ %td.min= user.uid
10
+ %td= link_to('edit', edit_ucb_rails_admin_user_path(user), :class => 'btn btn-mini', :id => dom_id(user, 'edit'))
11
+ %td= link_to('delete', ucb_rails_admin_user_path(user), :data => {confirm: 'Are you sure?'}, :method => :delete, :class => 'btn btn-mini btn-danger')
12
+
@@ -0,0 +1,3 @@
1
+ %h1 Edit User
2
+
3
+ = render partial: 'form', locals: { url: ucb_rails_admin_user_path(@user), method: :put }
@@ -0,0 +1,40 @@
1
+ %h1 Users
2
+
3
+ %p= link_to_new_user
4
+
5
+ = ucbr_table_tag UcbRails::User do
6
+ %thead
7
+ %tr
8
+ %th.min Admin?
9
+ %th.min Inactive?
10
+ %th First Name
11
+ %th Last Name
12
+ %th Email
13
+ %th Phone
14
+ %th.dt Last Request At
15
+ %th UID
16
+ %th.min Edit
17
+ %th.min Delete
18
+ %tbody.highlight
19
+ = render partial: 'ucb_rails/admin/users/user', collection: @users
20
+
21
+ = render :partial => 'ucb_rails/lps/modal'
22
+
23
+ :javascript
24
+ $('#ucb_rails_users').dataTable({
25
+ "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
26
+ "sPaginationType": "bootstrap",
27
+ "bStateSave": true,
28
+ "iDisplayLength": 20,
29
+ "aLengthMenu": [[10, 20, 50, -1], [10, 20, 50, 'All']],
30
+ "aaSorting": [[ 5, "desc" ]],
31
+ "aoColumnDefs": [
32
+ { "aDataSort": [ 0, 2, 3 ], "aTargets": [ 0 ] }, // admin
33
+ { "aDataSort": [ 1, 2, 3 ], "aTargets": [ 0 ] }, // active
34
+ { "aDataSort": [ 1, 2 ], "aTargets": [ 2 ] }, // first name
35
+ { "aDataSort": [ 2, 1], "aTargets": [ 3 ] }, // last name
36
+ { "bSortable": false, "aTargets": [ 8 ] }, // edit
37
+ { "bSortable": false, "aTargets": [ 9 ] }, // delete
38
+ ]
39
+ });
40
+
@@ -0,0 +1,16 @@
1
+ = form_tag('/ucb_rails/ldap_person_search', :class => "well form-inline", :id => 'lps-form', :method => :get, :remote => true) do
2
+
3
+ = hidden_field_tag('search-field-name')
4
+ = hidden_field_tag('result-link-http-method')
5
+ = hidden_field_tag('result-link-text')
6
+ = hidden_field_tag('result-link-class')
7
+ = hidden_field_tag('result-link-url')
8
+
9
+ = label_tag 'first_name', 'First Name'
10
+ = text_field_tag("first_name")
11
+ = label_tag 'last_name', 'Last Name'
12
+ = text_field_tag("last_name")
13
+
14
+ = submit_button_tag('Search', id: 'lps-search')
15
+ = button("Clear", url: "#", :id => 'lps-clear')
16
+
@@ -0,0 +1,6 @@
1
+ = modal(id: 'lps-modal') do
2
+ = modal_header('Search For Person')
3
+ = modal_body do
4
+ = render partial: 'ucb_rails/lps/form'
5
+ #lps-results
6
+ = modal_footer
@@ -0,0 +1,21 @@
1
+ - if @lps_entries.empty?
2
+ %p No records were found.
3
+ - else
4
+ = ucbr_table_tag(class: 'table-condensed') do
5
+ %thead
6
+ %tr
7
+ %th{style: 'width="1%"'}
8
+ %th First Name
9
+ %th Last Name
10
+ %th Email
11
+ %th Department
12
+ %tbody
13
+ - @lps_entries.each do |entry|
14
+ - entry_id = "ldap_uid_#{entry.uid}"
15
+ %tr{id: entry_id, class: ldap_entry_class(entry)}
16
+ %td= link_to_ldap_person_entry(entry)
17
+ %td= entry.first_name
18
+ %td= entry.last_name
19
+ %td= entry.email
20
+ %td= entry.departments
21
+
@@ -0,0 +1,2 @@
1
+ - results = render :partial => 'ucb_rails/lps/results'
2
+ $('#lps-results').html('#{j results}');
data/config/routes.rb CHANGED
@@ -5,7 +5,24 @@ Rails.application.routes.draw do
5
5
 
6
6
  match '/login', :to => 'ucb_rails/sessions#new', :as => 'login'
7
7
  match '/logout', :to => 'ucb_rails/sessions#destroy', :as => 'logout'
8
- match '/auth/:provider/callback' => 'ucb_rails/sessions#create'
8
+ match '/auth/:omniauth_provider/callback' => 'ucb_rails/sessions#create'
9
9
  match '/auth/failure' => "ucb_rails/sessions#failure"
10
+ match '/not_authorized', :to => 'ucb_rails/sessions#not_authorized', as: 'not_authorized'
11
+
12
+ match '/ucb_rails/bootstrap(/:uid)' => 'ucb_rails/bootstrap#index'
13
+
14
+ resources :hidden_announcements, path: '/announcements', only: [:index, :create, :destroy]
15
+
16
+ namespace :ucb_rails do
17
+ get '/ldap_person_search' => 'ldap_person_search#search', :as => :ldap_person_search
18
+
19
+ namespace :admin do
20
+ resources :announcements
21
+ resources :users do
22
+ get 'ldap_search', on: :collection
23
+ get 'typeahead_search', on: :collection
24
+ end
25
+ end
26
+ end
10
27
 
11
28
  end
@@ -1,39 +1,43 @@
1
1
  require 'rails/generators/active_record/migration'
2
2
 
3
3
  module UcbRails
4
+ # @private
4
5
  module Generators
6
+ # @private
5
7
  class InstallGenerator < Rails::Generators::Base
6
8
  include Rails::Generators::Migration
7
9
  extend ActiveRecord::Generators::Migration
8
10
  source_root File.join(File.dirname(__FILE__), "templates")
9
11
 
10
- def self.initializer_path; 'config/initializers/local_vendor/ucb_rails.rb';end
11
-
12
- desc <<DESC
13
- Description:
14
- # Copies stylesheet to 'app/assets/stylesheets/user_announcements.css'
15
- Copies configuration
16
- # Copies db migration to 'db/migrate/<timestamp>/create_user_announcement_tables.rb'
17
-
18
- DESC
19
-
20
- def preamble
21
- puts "\n============================================================"
22
- puts "Installing UCB Rails Essentials\n"
23
- end
12
+ desc 'Copy ucb_rails files'
13
+ class_option :readme, aliases: '-r', type: :boolean, desc: 'Display README and exit'
24
14
 
25
15
  def install
26
- # copy_file "template.css", 'app/assets/stylesheets/user_announcements.css'
27
- copy_file "initializer.rb", 'config/initializers/local_vendor/ucb_rails.rb'
28
- # migration_template "migration.rb", "db/migrate/create_user_announcement_tables.rb"
16
+ return if options.readme?
17
+
18
+ directory 'app/assets'
19
+ directory 'app/helpers'
20
+ directory 'app/views'
21
+ directory 'config'
22
+ install_migrations
29
23
  end
30
24
 
31
- def postscript
32
- puts %(
33
- Installation complete:
34
- * review settings in the intializer
35
- )
36
- puts "============================================================\n\n"
25
+ def show_readme
26
+ if behavior == :invoke
27
+ readme "README"
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def install_migrations
34
+ template_dir = Pathname.new(self.class.source_root)
35
+ Dir["#{template_dir}/db/migrate/*.rb"].each do |migration_file|
36
+ # migration_template migration_file
37
+ # puts migration_file
38
+ relative_name = Pathname.new(migration_file).relative_path_from(Pathname.new(template_dir))
39
+ migration_template relative_name
40
+ end
37
41
  end
38
42
  end
39
43
  end
@@ -0,0 +1,13 @@
1
+ ****************************************************************************
2
+ * Check configuration settings in config/initializers/local/ucb_rails.rb
3
+
4
+ * run other generators, migrate db, remove superseded files
5
+
6
+ rails generate user_announcements:install
7
+ rails generate simple_form:install --bootstrap
8
+ rake db:migrate
9
+ rm public/index.html
10
+ rm app/views/layouts/application.html.erb
11
+
12
+
13
+ ****************************************************************************
@@ -0,0 +1,19 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require bootstrap
16
+ //= require dataTables/jquery.dataTables
17
+ //= require dataTables/jquery.dataTables.api.fnSetFilteringDelay
18
+ //= require dataTables/jquery.dataTables.bootstrap
19
+ //= require_tree .