fetty-generators 1.7.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. data/Gemfile +2 -0
  2. data/README.rdoc +42 -36
  3. data/Rakefile +1 -3
  4. data/lib/generators/fetty.rb +160 -10
  5. data/lib/generators/fetty/authentication/USAGE +4 -0
  6. data/lib/generators/fetty/authentication/authentication_generator.rb +171 -0
  7. data/lib/generators/fetty/authentication/templates/controllers/reset_passwords_controller.rb +45 -0
  8. data/lib/generators/fetty/authentication/templates/controllers/sessions_controller.rb +30 -0
  9. data/lib/generators/fetty/authentication/templates/controllers/users_controller.rb +78 -0
  10. data/lib/generators/fetty/authentication/templates/helpers/reset_passwords_helper.rb +2 -0
  11. data/lib/generators/fetty/authentication/templates/helpers/sessions_helper.rb +2 -0
  12. data/lib/generators/fetty/authentication/templates/helpers/users_helper.rb +2 -0
  13. data/lib/generators/fetty/authentication/templates/lib/sessions_authentication.rb +53 -0
  14. data/lib/generators/fetty/authentication/templates/lib/users_authentication.rb +110 -0
  15. data/lib/generators/fetty/authentication/templates/mailers/setup_mail.rb +11 -0
  16. data/lib/generators/fetty/authentication/templates/mailers/user_mailer.rb +14 -0
  17. data/lib/generators/fetty/authentication/templates/models/active_record/create_users.rb +17 -0
  18. data/lib/generators/fetty/authentication/templates/models/active_record/user.rb +15 -0
  19. data/lib/generators/fetty/authentication/templates/models/mongoid/user.rb +23 -0
  20. data/lib/generators/fetty/authentication/templates/spec/controllers/reset_passwords_controller_spec.rb +93 -0
  21. data/lib/generators/fetty/authentication/templates/spec/controllers/sessions_controller_spec.rb +61 -0
  22. data/lib/generators/fetty/authentication/templates/spec/controllers/users_controller_spec.rb +158 -0
  23. data/lib/generators/fetty/authentication/templates/spec/models/user_spec.rb +108 -0
  24. data/lib/generators/fetty/authentication/templates/spec/routing/reset_passwords_routing_spec.rb +21 -0
  25. data/lib/generators/fetty/authentication/templates/spec/routing/sessions_routing_spec.rb +17 -0
  26. data/lib/generators/fetty/authentication/templates/spec/routing/users_routing_spec.rb +37 -0
  27. data/lib/generators/fetty/authentication/templates/spec/support/user_factories.rb +6 -0
  28. data/lib/generators/fetty/authentication/templates/views/layouts/application.html.erb +33 -0
  29. data/lib/generators/fetty/authentication/templates/views/reset_passwords/edit.html.erb +19 -0
  30. data/lib/generators/fetty/authentication/templates/views/reset_passwords/new.html.erb +14 -0
  31. data/lib/generators/fetty/authentication/templates/views/sessions/new.html.erb +22 -0
  32. data/lib/generators/fetty/authentication/templates/views/user_mailer/user_activation.text.erb +4 -0
  33. data/lib/generators/fetty/authentication/templates/views/user_mailer/user_forgot_password.text.erb +7 -0
  34. data/lib/generators/fetty/authentication/templates/views/users/_table.html.erb +23 -0
  35. data/lib/generators/fetty/authentication/templates/views/users/edit.html.erb +21 -0
  36. data/lib/generators/fetty/authentication/templates/views/users/index.html.erb +7 -0
  37. data/lib/generators/fetty/authentication/templates/views/users/index.js.erb +1 -0
  38. data/lib/generators/fetty/authentication/templates/views/users/new.html.erb +23 -0
  39. data/lib/generators/fetty/authentication/templates/views/users/show.html.erb +19 -0
  40. data/lib/generators/fetty/messages/USAGE +4 -0
  41. data/lib/generators/fetty/messages/messages_generator.rb +136 -0
  42. data/lib/generators/fetty/messages/templates/assets/javascripts/jquery.tokeninput.js +718 -0
  43. data/lib/generators/fetty/messages/templates/assets/javascripts/messages.js +19 -0
  44. data/lib/generators/fetty/messages/templates/assets/stylesheets/messages.css +87 -0
  45. data/lib/generators/fetty/messages/templates/assets/stylesheets/token-input-facebook.css +122 -0
  46. data/lib/generators/fetty/messages/templates/controllers/messages_controller.rb +109 -0
  47. data/lib/generators/fetty/messages/templates/helpers/messages_helper.rb +2 -0
  48. data/lib/generators/fetty/messages/templates/lib/users_messages.rb +67 -0
  49. data/lib/generators/fetty/messages/templates/models/active_record/create_messages.rb +24 -0
  50. data/lib/generators/fetty/messages/templates/models/active_record/message.rb +67 -0
  51. data/lib/generators/fetty/messages/templates/models/mongoid/message.rb +81 -0
  52. data/lib/generators/fetty/messages/templates/spec/controllers/messages_controller_spec.rb +78 -0
  53. data/lib/generators/fetty/messages/templates/spec/models/message_spec.rb +53 -0
  54. data/lib/generators/fetty/messages/templates/spec/routing/messages_routing_spec.rb +61 -0
  55. data/lib/generators/fetty/messages/templates/spec/support/message_factories.rb +8 -0
  56. data/lib/generators/fetty/messages/templates/views/_head.html.erb +20 -0
  57. data/lib/generators/fetty/messages/templates/views/_messages.html.erb +56 -0
  58. data/lib/generators/fetty/messages/templates/views/_tabs_panel.html.erb +11 -0
  59. data/lib/generators/fetty/messages/templates/views/index.html.erb +10 -0
  60. data/lib/generators/fetty/messages/templates/views/index.js.erb +1 -0
  61. data/lib/generators/fetty/messages/templates/views/new.html.erb +26 -0
  62. data/lib/generators/fetty/messages/templates/views/show.html.erb +35 -0
  63. data/lib/generators/fetty/scaffold/USAGE +2 -52
  64. data/lib/generators/fetty/scaffold/scaffold_generator.rb +96 -329
  65. data/lib/generators/fetty/scaffold/templates/controllers/active_record/controller.rb +60 -0
  66. data/lib/generators/fetty/scaffold/templates/controllers/mongoid/controller.rb +60 -0
  67. data/lib/generators/fetty/scaffold/templates/helpers/helper.rb +2 -0
  68. data/lib/generators/fetty/scaffold/templates/models/active_record/migration.rb +16 -0
  69. data/lib/generators/fetty/scaffold/templates/models/active_record/model.rb +10 -0
  70. data/lib/generators/fetty/scaffold/templates/models/mongoid/model.rb +16 -0
  71. data/lib/generators/fetty/scaffold/templates/test/rspec/controller.rb +98 -0
  72. data/lib/generators/fetty/scaffold/templates/test/rspec/factories.rb +26 -0
  73. data/lib/generators/fetty/scaffold/templates/test/rspec/helper.rb +15 -0
  74. data/lib/generators/fetty/scaffold/templates/test/rspec/model.rb +9 -0
  75. data/lib/generators/fetty/scaffold/templates/test/rspec/request.rb +11 -0
  76. data/lib/generators/fetty/scaffold/templates/test/rspec/routing.rb +41 -0
  77. data/lib/generators/fetty/scaffold/templates/test/test_unit/controller.rb +62 -0
  78. data/lib/generators/fetty/scaffold/templates/{fixtures.yml → test/test_unit/fixtures.yml} +2 -0
  79. data/lib/generators/fetty/scaffold/templates/test/test_unit/helper.rb +4 -0
  80. data/lib/generators/fetty/scaffold/templates/test/test_unit/model.rb +7 -0
  81. data/lib/generators/fetty/scaffold/templates/views/_form.html.erb +20 -0
  82. data/lib/generators/fetty/scaffold/templates/views/_table.html.erb +48 -0
  83. data/lib/generators/fetty/scaffold/templates/views/edit.html.erb +13 -0
  84. data/lib/generators/fetty/scaffold/templates/views/index.html.erb +15 -0
  85. data/lib/generators/fetty/scaffold/templates/views/{erb/index.js.erb → index.js.erb} +0 -0
  86. data/lib/generators/fetty/scaffold/templates/views/new.html.erb +9 -0
  87. data/lib/generators/fetty/scaffold/templates/views/show.html.erb +28 -0
  88. data/lib/generators/fetty/setup/USAGE +3 -20
  89. data/lib/generators/fetty/setup/setup_generator.rb +122 -61
  90. data/lib/generators/fetty/setup/templates/ability.rb +0 -0
  91. data/lib/generators/fetty/setup/templates/ckeditor.rb +54 -0
  92. data/lib/generators/fetty/setup/templates/ckeditor.tar.gz +0 -0
  93. data/lib/generators/fetty/setup/templates/escape_utils.rb +7 -0
  94. data/lib/generators/fetty/setup/templates/file_uploader.rb +15 -0
  95. data/lib/generators/fetty/setup/templates/image_uploader.rb +48 -0
  96. data/lib/generators/fetty/setup/templates/spec_helper.rb +44 -0
  97. data/lib/generators/fetty/views/USAGE +5 -0
  98. data/lib/generators/fetty/{layout/templates/stylesheet.css → views/templates/application.css} +184 -166
  99. data/lib/generators/fetty/views/templates/application.html.erb +23 -0
  100. data/lib/generators/fetty/{layout → views}/templates/application.js +0 -0
  101. data/lib/generators/fetty/views/templates/application_helper.rb +10 -0
  102. data/lib/generators/fetty/views/templates/down_arrow.gif +0 -0
  103. data/lib/generators/fetty/{layout → views}/templates/error_messages_helper.rb +0 -0
  104. data/lib/generators/fetty/{layout → views}/templates/layout_helper.rb +0 -0
  105. data/lib/generators/fetty/views/templates/up_arrow.gif +0 -0
  106. data/lib/generators/fetty/views/views_generator.rb +51 -0
  107. data/lib/generators/scaffold.rb +204 -0
  108. metadata +126 -111
  109. data/LICENSE +0 -20
  110. data/lib/generators/fetty/layout/USAGE +0 -26
  111. data/lib/generators/fetty/layout/layout_generator.rb +0 -44
  112. data/lib/generators/fetty/layout/templates/layout.html.erb +0 -32
  113. data/lib/generators/fetty/layout/templates/layout.html.haml +0 -34
  114. data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.erb +0 -23
  115. data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.haml +0 -23
  116. data/lib/generators/fetty/layout/templates/stylesheet.sass +0 -163
  117. data/lib/generators/fetty/scaffold/templates/actions/create.rb +0 -8
  118. data/lib/generators/fetty/scaffold/templates/actions/destroy.rb +0 -5
  119. data/lib/generators/fetty/scaffold/templates/actions/edit.rb +0 -3
  120. data/lib/generators/fetty/scaffold/templates/actions/index.rb +0 -10
  121. data/lib/generators/fetty/scaffold/templates/actions/new.rb +0 -3
  122. data/lib/generators/fetty/scaffold/templates/actions/show.rb +0 -3
  123. data/lib/generators/fetty/scaffold/templates/actions/update.rb +0 -8
  124. data/lib/generators/fetty/scaffold/templates/controller.rb +0 -7
  125. data/lib/generators/fetty/scaffold/templates/helper.rb +0 -2
  126. data/lib/generators/fetty/scaffold/templates/migration.rb +0 -16
  127. data/lib/generators/fetty/scaffold/templates/model.rb +0 -7
  128. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/create.rb +0 -11
  129. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/destroy.rb +0 -6
  130. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/edit.rb +0 -4
  131. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/index.rb +0 -4
  132. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/new.rb +0 -4
  133. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/show.rb +0 -4
  134. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/update.rb +0 -11
  135. data/lib/generators/fetty/scaffold/templates/tests/rspec/controller.rb +0 -8
  136. data/lib/generators/fetty/scaffold/templates/tests/rspec/model.rb +0 -7
  137. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/create.rb +0 -13
  138. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/destroy.rb +0 -8
  139. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/edit.rb +0 -6
  140. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/index.rb +0 -6
  141. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/new.rb +0 -6
  142. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/show.rb +0 -6
  143. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/update.rb +0 -13
  144. data/lib/generators/fetty/scaffold/templates/tests/shoulda/controller.rb +0 -5
  145. data/lib/generators/fetty/scaffold/templates/tests/shoulda/model.rb +0 -7
  146. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/create.rb +0 -11
  147. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/destroy.rb +0 -6
  148. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/edit.rb +0 -4
  149. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/index.rb +0 -4
  150. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/new.rb +0 -4
  151. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/show.rb +0 -4
  152. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/update.rb +0 -11
  153. data/lib/generators/fetty/scaffold/templates/tests/testunit/controller.rb +0 -5
  154. data/lib/generators/fetty/scaffold/templates/tests/testunit/model.rb +0 -7
  155. data/lib/generators/fetty/scaffold/templates/views/erb/_form.html.erb +0 -22
  156. data/lib/generators/fetty/scaffold/templates/views/erb/_table.html.erb +0 -50
  157. data/lib/generators/fetty/scaffold/templates/views/erb/edit.html.erb +0 -12
  158. data/lib/generators/fetty/scaffold/templates/views/erb/index.html.erb +0 -13
  159. data/lib/generators/fetty/scaffold/templates/views/erb/new.html.erb +0 -9
  160. data/lib/generators/fetty/scaffold/templates/views/erb/show.html.erb +0 -26
  161. data/lib/generators/fetty/scaffold/templates/views/haml/_form.html.haml +0 -8
  162. data/lib/generators/fetty/scaffold/templates/views/haml/_table.html.haml +0 -33
  163. data/lib/generators/fetty/scaffold/templates/views/haml/edit.html.haml +0 -14
  164. data/lib/generators/fetty/scaffold/templates/views/haml/index.html.haml +0 -12
  165. data/lib/generators/fetty/scaffold/templates/views/haml/index.js.haml +0 -1
  166. data/lib/generators/fetty/scaffold/templates/views/haml/new.html.haml +0 -8
  167. data/lib/generators/fetty/scaffold/templates/views/haml/show.html.haml +0 -23
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
1
  source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fetty-generators.gemspec
2
4
  gemspec
data/README.rdoc CHANGED
@@ -1,69 +1,75 @@
1
1
  = Fetty Generators
2
2
 
3
- If you are a fan of railscast.com by Ryan Bates, you could found so many useful plugins / gems that ryan covers to us how to use it,
4
- and if you familiar with nifty_scaffold by ryanb, or always working with it alongside Devise + CanCan for authetication and authorization,
5
- you may try to use this generators to build your basic Rails application quickly up-and-running.
6
- This generators are inherited from nifty-generators, but change a little-bit in the result of scaffolding.
3
+ Gem dependencies :
4
+ - CanCan
5
+ - simple_form
6
+ - ckeditor 3.5.4
7
+ - kaminari
8
+ - carrierwave
9
+ - etc. (it will automatically setup the gems)
7
10
 
8
- fetty (as i choose the name as a brother of nifty) have a little extra features like :
9
- - using simple_form as a default generated form.
10
- - add some extra AJAX features to search and sorting using meta_search, and pagination in your index page.
11
- - using Devise(josevalim) for authentication and CanCan(ryanb) for authorizations [optional].
12
- - giving the default checking abilities like ( can? :read ) in your views for authorizations.
13
- - closable flash message.
14
- - alow you pass custom field:type such as paperclip / tinymce in scaffolding.
15
-
16
- it also provides for ERB and HAML template. Ups sorry this generators only works for Rails 3
11
+ This generators only works with Rails 3
17
12
 
18
13
  == Setup
19
14
 
20
15
  === Rails 3
21
16
 
22
- require gems to be install first.
17
+ Add the gem into your Gemfile.
23
18
 
24
- gem install meta_where meta_search simple_form will_paginate jquery-rails devise cancan paperclip tinymce
19
+ gem 'fetty-generators', :group => :development
25
20
 
26
- And add the gem to your Gemfile.
21
+ run the setup first!
27
22
 
28
- gem "fetty-generators", :group => :development
23
+ rails g fetty:setup
29
24
 
30
- generate the setup first before you can generate layout / scaffolding
25
+ or if you like to using with MongoDB, this generator will works with mongoid
31
26
 
32
- rails generate fetty:setup
27
+ rails g fetty:setup --mongoid
33
28
 
34
- Then you can run layout generator to generate your application layout.
29
+ Then generate the layout
35
30
 
36
- rails generate fetty:layout
31
+ rails g fetty:views layout
37
32
 
38
- And then you just simply type the command "fetty:scaffold" for scaffolding
33
+ And then you just simply type the command `fetty:scaffold` for scaffolding
39
34
 
40
- rails g fetty:scaffold Post title:string content:text
35
+ rails g fetty:scaffold post title:string content:text published:boolean
41
36
 
42
- after that simply run the migration "rake db:migrate" and start your server "rails s"
37
+ Don't forget to run `rake db:migrate` if you are using ActiveRecord
43
38
 
44
39
  == Additional field type
45
40
 
46
- You could also passing custom field type in your arguments, 'for example you want to use paperclip for handle your attachment
47
- and you also want to use tinymce for editor in your textarea'
41
+ This version using carrierwave for handling an attachment and ckeditor for WYSIWYG editor,
42
+ by passing 'image', 'file' and 'editor' as an argument when generate a scaffolding.
43
+
44
+ rails g fetty:scaffold post title:string content:editor photo:image attachment:file
45
+
46
+ == Fetty:Authentication
48
47
 
49
- rails g fetty:scaffold Post title:string content:tinymce photo:paperclip
48
+ This generator will generate simple authentication for your rails app.
50
49
 
51
- this will generate the required column names for paperclip into your migration file and also configured the model, controller and views.
50
+ rails g fetty:authentication
52
51
 
53
- == Included Generators
52
+ after generate the authentication you may need to change root_url on 'config/routes.rb'
53
+ and setting your ActionMailer email address on 'config/initializers/setup_mail.rb'
54
54
 
55
- * fetty:layout: generates generic layout, stylesheet, and helper files.
56
- * fetty:scaffold: generates a controller and optional model/migration.
57
- * fetty:setup: configure your gems needed by fetty-generators.
55
+ == Fetty:Messages
58
56
 
59
- To view the README for each generator, run it with the +help+ option.
57
+ This generator will generate simple messaging system for your rails app
60
58
 
61
- rails g fetty:layout --help
59
+ rails g fetty:messages
62
60
 
61
+ Required you to have user model, please generate `fetty:authentication` first
62
+ at this moment `fetty:messages` only works with ActiveRecord.
63
+
64
+ == Test Framework
65
+
66
+ By default `fetty:setup` will asking you to setup Rspec / Cucumber,
67
+ and it also setup "guard-rspec" and "guard-cucumber".
63
68
 
64
69
  == Found a bug?
65
70
 
66
- This is stil under development mode, if you are regularly work with ERB template, this generators will works fine,
67
- But if you are having some problem with Fetty Generators, please submit an issue here.
71
+ This is stil under development mode, if you are having some problem with Fetty Generators,
72
+ please submit an issue here.
68
73
 
69
74
  http://github.com/fajrif/fetty-generators/issues
75
+
data/Rakefile CHANGED
@@ -1,3 +1 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
1
+ require 'bundler/gem_tasks'
@@ -1,22 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rubygems/command.rb'
3
+ require 'rubygems/dependency_installer.rb'
1
4
  require 'rails/generators/base'
5
+ require 'bundler'
2
6
 
3
7
  module Fetty
4
8
  module Generators
5
9
  class Base < Rails::Generators::Base #:nodoc:
10
+
6
11
  def self.source_root
7
- @_fetty_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'fetty', generator_name, 'templates'))
12
+ @_fetty_source_root = File.expand_path(File.join(File.dirname(__FILE__), 'fetty', generator_name, 'templates'))
8
13
  end
9
-
14
+
10
15
  def self.banner
11
16
  "rails generate fetty:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
17
  end
13
-
14
- protected
15
-
18
+
19
+ protected
20
+
16
21
  def add_gem(name, options = {})
17
- gemfile_content = File.read(destination_path("Gemfile"))
18
- File.open(destination_path("Gemfile"), 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
19
- gem name, options unless gemfile_content.include? name
22
+ unless gemfile_included? name
23
+ gemfile = File.expand_path(destination_path("Gemfile"), __FILE__)
24
+ gemfile_content = File.read(gemfile)
25
+ File.open(gemfile, 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
26
+
27
+ gem name, options
28
+
29
+ if bundle_need_refresh?
30
+ install_gem(name,options)
31
+ end
32
+ end
33
+ rescue Exception => e
34
+ raise e
35
+ end
36
+
37
+ def gemfile_included?(name)
38
+ file_contains?("Gemfile",name)
39
+ rescue Exception => e
40
+ raise e
41
+ end
42
+
43
+ def root_path(path)
44
+ File.expand_path(File.join(File.dirname(__FILE__), 'fetty', path))
20
45
  end
21
46
 
22
47
  def destination_path(path)
@@ -27,12 +52,137 @@ module Fetty
27
52
  File.exist? destination_path(path)
28
53
  end
29
54
 
30
- private
31
-
55
+ def folder_exists?(path)
56
+ File.directory? path
57
+ end
58
+
59
+ def destroy(path)
60
+ begin
61
+ if file_exists?(path)
62
+ print_notes("Destroying #{path}")
63
+ FileUtils.rm_r(destination_path(path), :force => true)
64
+ end
65
+ rescue Exception => e
66
+ raise e
67
+ end
68
+ end
69
+
70
+ def extract(filepath,destinationpath,foldername)
71
+ begin
72
+ print_notes("Extracting #{filepath}")
73
+ system("tar -C '#{destination_path(destinationpath)}' -xzf '#{root_path(filepath)}' #{foldername}/")
74
+ rescue Exception => e
75
+ raise e
76
+ end
77
+ end
78
+
79
+ def asking(messages,&block)
80
+ opt = ask("=> #{messages} [yes]")
81
+ if opt == "yes" || opt.blank?
82
+ yield
83
+ end
84
+ rescue Exception => e
85
+ raise e
86
+ end
87
+
88
+ def print_notes(message,notes = "notes",color = :yellow)
89
+ puts '', '='*80
90
+ say_status "#{notes}", "#{message}", color
91
+ puts '='*80, ''; sleep 0.5
92
+ end
93
+
32
94
  def print_usage
33
95
  self.class.help(Thor::Base.shell.new)
34
96
  exit
35
97
  end
98
+
99
+ def install_gem(name,options = {})
100
+ print_notes("Installing #{name}")
101
+ ::Bundler.with_clean_env do
102
+ unless options.empty?
103
+ system("gem install #{name} -v=#{options}")
104
+ else
105
+ system("gem install #{name}")
106
+ end
107
+ end
108
+ rescue Exception => e
109
+ raise e
110
+ end
111
+
112
+ def refresh_bundle
113
+ print_notes('Refresh bundle')
114
+ ::Bundler.with_clean_env do
115
+ `bundle install`
116
+ end
117
+ rescue Exception => e
118
+ raise e
119
+ end
120
+
121
+ def bundle_need_refresh?
122
+ ::Bundler.with_clean_env do
123
+ `bundle check`
124
+ end
125
+ $? == 0 ? false : true
126
+ rescue Exception => e
127
+ raise e
128
+ end
129
+
130
+ def file_contains?(filename,check_string)
131
+ file = File.expand_path(destination_path(filename), __FILE__)
132
+ if File.exist?(file)
133
+ file_content = File.read(file)
134
+ file_content.include?(check_string) ? true : false
135
+ else
136
+ false
137
+ end
138
+ rescue Exception => e
139
+ raise e
140
+ end
141
+
142
+ def must_load_lib_directory
143
+ unless file_contains?("config/application.rb",'config.autoload_paths += %W(#{config.root}/lib)')
144
+ inject_into_file "config/application.rb", :after => "Rails::Application" do
145
+ "\n\t\t" + 'config.autoload_paths += %W(#{config.root}/lib)'
146
+ end
147
+ end
148
+ rescue Exception => e
149
+ raise e
150
+ end
151
+
152
+ def using_cancan?
153
+ gemfile_included?("cancan") && file_exists?("app/models/ability.rb")
154
+ rescue Exception => e
155
+ raise e
156
+ end
157
+
158
+ def using_mongoid?
159
+ gemfile_included?("mongoid") && file_exists?("config/mongoid.yml")
160
+ rescue Exception => e
161
+ raise e
162
+ end
163
+
164
+ def using_test_unit?
165
+ folder_exists?("tests")
166
+ rescue Exception => e
167
+ raise e
168
+ end
169
+
170
+ def using_rspec?
171
+ gemfile_included?("rspec") && folder_exists?("spec")
172
+ rescue Exception => e
173
+ raise e
174
+ end
175
+
176
+ def using_fetty_authentication?
177
+ file_exists?("app/controllers/users_controller.rb") &&
178
+ file_exists?("app/controllers/sessions_controller.rb") &&
179
+ file_exists?("app/controllers/reset_passwords_controller.rb") &&
180
+ file_exists?("lib/users_authentication.rb")
181
+ rescue Exception => e
182
+ raise e
183
+ end
184
+
185
+
36
186
  end
37
187
  end
38
188
  end
@@ -0,0 +1,4 @@
1
+ Description:
2
+ The fetty:authentication generator creates a basic messaging system
3
+ between user in your app.
4
+
@@ -0,0 +1,171 @@
1
+ require 'generators/fetty'
2
+ require 'rails/generators/active_record'
3
+ require 'rails/generators/migration'
4
+ require 'rails/generators/generated_attribute'
5
+
6
+ module Fetty
7
+ module Generators
8
+ class AuthenticationGenerator < Base
9
+ include Rails::Generators::Migration
10
+
11
+ class_option :destroy, :desc => 'Destroy fetty:authentication', :type => :boolean, :default => false
12
+
13
+ def generate_authentication
14
+ if options.destroy?
15
+ destroy_authentication
16
+ else
17
+ unless using_fetty_authentication?
18
+ @orm = using_mongoid? ? 'mongoid' : 'active_record'
19
+ add_gem("bcrypt-ruby", :require => "bcrypt")
20
+ generate_users
21
+ generate_sessions
22
+ generate_reset_passwords
23
+ generate_mailers
24
+ edit_application_controller
25
+ must_load_lib_directory
26
+ add_routes
27
+ copy_file "views/layouts/application.html.erb", "app/views/layouts/application.html.erb"
28
+ generate_test_unit if using_test_unit?
29
+ generate_specs if using_rspec?
30
+ print_notes "Make sure you have defined root_url in your 'config/routes.rb.'"
31
+ else
32
+ raise "You already have User model, please remove first!!"
33
+ end
34
+ end
35
+ rescue Exception => e
36
+ print_notes(e.message,"error",:red)
37
+ end
38
+
39
+ private
40
+
41
+ def generate_users
42
+ copy_file "controllers/users_controller.rb", "app/controllers/users_controller.rb"
43
+ copy_file "helpers/users_helper.rb", "app/helpers/users_helper.rb"
44
+ copy_file "lib/users_authentication.rb", "lib/users_authentication.rb"
45
+ copy_file "models/#{@orm}/user.rb", "app/models/user.rb"
46
+ migration_template "models/#{@orm}/create_users.rb", "db/migrate/create_users.rb" unless using_mongoid?
47
+ copy_file "views/users/index.html.erb", "app/views/users/index.html.erb"
48
+ copy_file "views/users/index.js.erb", "app/views/users/index.js.erb"
49
+ copy_file "views/users/_table.html.erb", "app/views/users/_table.html.erb"
50
+ copy_file "views/users/new.html.erb", "app/views/users/new.html.erb"
51
+ copy_file "views/users/edit.html.erb", "app/views/users/edit.html.erb"
52
+ copy_file "views/users/show.html.erb", "app/views/users/show.html.erb"
53
+ rescue Exception => e
54
+ raise e
55
+ end
56
+
57
+ def generate_sessions
58
+ copy_file "controllers/sessions_controller.rb", "app/controllers/sessions_controller.rb"
59
+ copy_file "helpers/sessions_helper.rb", "app/helpers/sessions_helper.rb"
60
+ copy_file "lib/sessions_authentication.rb", "lib/sessions_authentication.rb"
61
+ copy_file "views/sessions/new.html.erb", "app/views/sessions/new.html.erb"
62
+ rescue Exception => e
63
+ raise e
64
+ end
65
+
66
+ def generate_reset_passwords
67
+ copy_file "controllers/reset_passwords_controller.rb", "app/controllers/reset_passwords_controller.rb"
68
+ copy_file "helpers/reset_passwords_helper.rb", "app/helpers/reset_passwords_helper.rb"
69
+ copy_file "views/reset_passwords/new.html.erb", "app/views/reset_passwords/new.html.erb"
70
+ copy_file "views/reset_passwords/edit.html.erb", "app/views/reset_passwords/edit.html.erb"
71
+ rescue Exception => e
72
+ raise e
73
+ end
74
+
75
+ def generate_mailers
76
+ copy_file "mailers/user_mailer.rb", "app/mailers/user_mailer.rb"
77
+ copy_file "mailers/setup_mail.rb", "config/initializers/setup_mail.rb"
78
+ print_notes "You need to change or edit 'config/initializers/setup_mail.rb'"
79
+ copy_file "views/user_mailer/user_activation.text.erb", "app/views/user_mailer/user_activation.text.erb"
80
+ copy_file "views/user_mailer/user_forgot_password.text.erb", "app/views/user_mailer/user_forgot_password.text.erb"
81
+ rescue Exception => e
82
+ raise e
83
+ end
84
+
85
+ def edit_application_controller
86
+ inject_into_class "app/controllers/application_controller.rb", ApplicationController do
87
+ " include SessionsAuthentication\n" +
88
+ " before_filter :authenticate_user!\n"
89
+ end
90
+ rescue Exception => e
91
+ raise e
92
+ end
93
+
94
+ def add_routes
95
+ inject_into_file "config/routes.rb", :after => "Application.routes.draw do" do
96
+ "\n\n\t resources :users do" +
97
+ "\n\t collection do" +
98
+ "\n\t get 'activate/:id/:token' => 'users#activate', :as => 'activate'" +
99
+ "\n\t resource :session, :only => [:new, :destroy, :create]" +
100
+ "\n\t resource :reset_password, :only => [:new, :create, :update] do" +
101
+ "\n\t get ':id/:token' => 'reset_passwords#edit', :on => :collection, :as => 'edit'" +
102
+ "\n\t end" +
103
+ "\n\t end" +
104
+ "\n\t end\n"
105
+ end
106
+ end
107
+
108
+ def generate_test_unit
109
+
110
+ end
111
+
112
+ def generate_specs
113
+ copy_file "spec/controllers/users_controller_spec.rb", "spec/controllers/users_controller_spec.rb"
114
+ copy_file "spec/models/user_spec.rb", "spec/models/user_spec.rb"
115
+ copy_file "spec/routing/users_routing_spec.rb", "spec/routing/users_routing_spec.rb"
116
+ copy_file "spec/support/user_factories.rb", "spec/support/user_factories.rb"
117
+ copy_file "spec/controllers/sessions_controller_spec.rb", "spec/controllers/sessions_controller_spec.rb"
118
+ copy_file "spec/routing/sessions_routing_spec.rb", "spec/routing/sessions_routing_spec.rb"
119
+ copy_file "spec/controllers/reset_passwords_controller_spec.rb", "spec/controllers/reset_passwords_controller_spec.rb"
120
+ copy_file "spec/routing/reset_passwords_routing_spec.rb", "spec/routing/reset_passwords_routing_spec.rb"
121
+ rescue Exception => e
122
+ raise e
123
+ end
124
+
125
+ def destroy_authentication
126
+ asking "Are you sure want to destroy fetty:authentication?" do
127
+ remove_file 'app/controllers/users_controller.rb'
128
+ remove_file 'app/helpers/users_helper.rb'
129
+ remove_file 'lib/users_authentication.rb'
130
+ remove_file 'app/models/user.rb'
131
+ run('rm db/migrate/*_create_users.rb')
132
+ remove_dir 'app/views/users'
133
+ remove_file 'app/controllers/sessions_controller.rb'
134
+ remove_file 'app/helpers/sessions_helper.rb'
135
+ remove_file 'lib/sessions_authentication.rb'
136
+ remove_dir 'app/views/sessions'
137
+ remove_file 'app/controllers/reset_passwords_controller.rb'
138
+ remove_file 'app/helpers/reset_passwords_helper.rb'
139
+ remove_dir 'app/views/reset_passwords'
140
+ remove_file 'app/mailers/user_mailer.rb'
141
+ remove_file 'config/initializers/setup_mail.rb'
142
+ remove_dir 'app/views/user_mailer'
143
+
144
+ gsub_file 'app/controllers/application_controller.rb', /include SessionsAuthentication.*:authenticate_user!/m, ''
145
+ gsub_file 'config/routes.rb', /resources :users.*(\s*end){3}/m, ''
146
+
147
+ if using_test_unit?
148
+
149
+ end
150
+
151
+ if using_rspec?
152
+ remove_file 'spec/controllers/users_controller_spec.rb'
153
+ remove_file 'spec/models/user_spec.rb'
154
+ remove_file 'spec/routing/users_routing_spec.rb'
155
+ remove_file 'spec/support/user_factories.rb'
156
+ remove_file 'spec/controllers/sessions_controller_spec.rb'
157
+ remove_file 'spec/routing/sessions_routing_spec.rb'
158
+ remove_file 'spec/controllers/reset_passwords_controller_spec.rb'
159
+ remove_file 'spec/routing/reset_passwords_routing_spec.rb'
160
+ end
161
+ end
162
+ end
163
+
164
+ # FIXME: Should be proxied to ActiveRecord::Generators::Base
165
+ # Implement the required interface for Rails::Generators::Migration.
166
+ def self.next_migration_number(dirname) #:nodoc:
167
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
168
+ end
169
+ end
170
+ end
171
+ end