somatics3-generators 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/bin/somatics +21 -0
- data/bin/somatify +21 -0
- data/lib/generators/somatics/authenticated/authenticated_generator.rb +220 -0
- data/lib/generators/somatics/authenticated/templates/mailer.rb +25 -0
- data/lib/generators/somatics/authenticated/templates/migration.rb +26 -0
- data/lib/generators/somatics/authenticated/templates/model.rb +83 -0
- data/lib/generators/somatics/authenticated/templates/observer.rb +11 -0
- data/lib/generators/somatics/authenticated/templates/test/mailer_test.rb +31 -0
- data/lib/generators/somatics/authenticated/templates/test/model_functional_test.rb +93 -0
- data/lib/generators/somatics/authenticated/templates/test/sessions_functional_test.rb +82 -0
- data/lib/generators/somatics/authenticated/templates/test/unit_test.rb +164 -0
- data/lib/generators/somatics/authenticated/templates/test/users.yml +60 -0
- data/lib/generators/somatics/authenticated_controller/authenticated_controller_generator.rb +323 -0
- data/lib/generators/somatics/authenticated_controller/templates/_model_partial.html.erb +8 -0
- data/lib/generators/somatics/authenticated_controller/templates/activation.erb +3 -0
- data/lib/generators/somatics/authenticated_controller/templates/authenticated_system.rb +189 -0
- data/lib/generators/somatics/authenticated_controller/templates/authenticated_test_helper.rb +10 -0
- data/lib/generators/somatics/authenticated_controller/templates/config/initializers/site_keys.rb +38 -0
- data/lib/generators/somatics/authenticated_controller/templates/controller.rb +55 -0
- data/lib/generators/somatics/authenticated_controller/templates/helper.rb +91 -0
- data/lib/generators/somatics/authenticated_controller/templates/login.html.erb +29 -0
- data/lib/generators/somatics/authenticated_controller/templates/mailer.rb +25 -0
- data/lib/generators/somatics/authenticated_controller/templates/migration.rb +26 -0
- data/lib/generators/somatics/authenticated_controller/templates/model.rb +83 -0
- data/lib/generators/somatics/authenticated_controller/templates/observer.rb +11 -0
- data/lib/generators/somatics/authenticated_controller/templates/session_helper.rb +2 -0
- data/lib/generators/somatics/authenticated_controller/templates/sessions_controller.rb +43 -0
- data/lib/generators/somatics/authenticated_controller/templates/signup.html.erb +19 -0
- data/lib/generators/somatics/authenticated_controller/templates/signup_notification.erb +8 -0
- data/lib/generators/somatics/authenticated_controller/templates/test/mailer_test.rb +31 -0
- data/lib/generators/somatics/authenticated_controller/templates/test/model_functional_test.rb +93 -0
- data/lib/generators/somatics/authenticated_controller/templates/test/sessions_functional_test.rb +82 -0
- data/lib/generators/somatics/authenticated_controller/templates/test/unit_test.rb +164 -0
- data/lib/generators/somatics/authenticated_controller/templates/test/users.yml +60 -0
- data/lib/generators/somatics/helper/helper_generator.rb +16 -0
- data/lib/generators/somatics/install/install_generator.rb +65 -0
- data/lib/generators/somatics/install/templates/config/locales/somatics_en.yml +33 -0
- data/lib/generators/somatics/install/templates/config/locales/somatics_zh-TW.yml +33 -0
- data/lib/generators/somatics/install/templates/controller_admin.rb +16 -0
- data/lib/generators/somatics/install/templates/controller_home.rb +4 -0
- data/lib/generators/somatics/install/templates/helper_admin.rb +68 -0
- data/lib/generators/somatics/install/templates/layout_admin.html.erb +88 -0
- data/lib/generators/somatics/install/templates/lib/somatic_link_renderer.rb +42 -0
- data/lib/generators/somatics/install/templates/partial_menu.html.erb +1 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/add.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/arrow_collapsed.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/arrow_expanded.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/attachment.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_arrow_left.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_arrow_right.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_diamond.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_end.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_go.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_toggle_minus.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/bullet_toggle_plus.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/c.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/cancel.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/changeset.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/comment.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/comments.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/content-left.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/content-right.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/copy.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/csharp.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/database_key.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/default.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/delete.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/document.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/draft.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/duplicate.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/edit.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/exclamation.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/external.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/fav.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/fav_off.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/feed.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/folder.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/folder_open.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/footer-bg.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/footer-left.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/footer-right.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/group.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/help.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/history.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/image.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/lightning.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/link.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/loading.gif +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/locked.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/message.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/milestone.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/move.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/news.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/openid-bg.gif +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/package.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/pdf.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/php.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/plugin.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/projects.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/rails.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/reload.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/report.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ruby.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/save.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/sort_asc.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/sort_desc.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/stats.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/table_multiple.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/task_done.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/task_late.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/task_parent_end.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/task_todo.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/text.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/text_list_bullets.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/textfield.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket_checked.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket_edit.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket_go.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/ticket_note.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/time.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/time_add.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/toggle_check.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/true.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/unlock.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/user.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/warning.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/wiki_edit.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/xml.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/zip.png +0 -0
- data/lib/generators/somatics/install/templates/public/images/somatics/zoom_in.png +0 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/base.js +231 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/context_menu.js +237 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/controls.js +965 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/dragdrop.js +974 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/effects.js +1123 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/prototype.js +6001 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/rails.js +175 -0
- data/lib/generators/somatics/install/templates/public/javascripts/somatics/select_list_move.js +82 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/somatics/base.css +948 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/somatics/context_menu.css +52 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/somatics/csshover.htc +122 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/somatics/jstoolbar.css +95 -0
- data/lib/generators/somatics/install/templates/view_index.html.erb +1 -0
- data/lib/generators/somatics/scaffold/scaffold_generator.rb +25 -0
- data/lib/generators/somatics/scaffold/templates/_form.html.erb +23 -0
- data/lib/generators/somatics/scaffold/templates/edit.html.erb +6 -0
- data/lib/generators/somatics/scaffold/templates/index.html.erb +27 -0
- data/lib/generators/somatics/scaffold/templates/new.html.erb +5 -0
- data/lib/generators/somatics/scaffold/templates/show.html.erb +12 -0
- data/lib/generators/somatics/scaffold_controller/USAGE +20 -0
- data/lib/generators/somatics/scaffold_controller/scaffold_controller_generator.rb +137 -0
- data/lib/generators/somatics/scaffold_controller/templates/builder_index.pdf.prawn +25 -0
- data/lib/generators/somatics/scaffold_controller/templates/builder_index.xls.builder +24 -0
- data/lib/generators/somatics/scaffold_controller/templates/builder_index.xml.builder +10 -0
- data/lib/generators/somatics/scaffold_controller/templates/controller.rb +140 -0
- data/lib/generators/somatics/scaffold_controller/templates/locales_en.yml +17 -0
- data/lib/generators/somatics/scaffold_controller/templates/locales_zh-TW.yml +20 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_bulk.html.erb +12 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_edit.html.erb +7 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_form.html.erb +13 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_list.html.erb +42 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_menu.html.erb +1 -0
- data/lib/generators/somatics/scaffold_controller/templates/partial_show.html.erb +31 -0
- data/lib/generators/somatics/scaffold_controller/templates/view_edit.html.erb +24 -0
- data/lib/generators/somatics/scaffold_controller/templates/view_index.html.erb +28 -0
- data/lib/generators/somatics/scaffold_controller/templates/view_new.html.erb +14 -0
- data/lib/generators/somatics/scaffold_controller/templates/view_show.html.erb +24 -0
- data/lib/generators/somatics.rb +95 -0
- data/lib/somatics3-generators.rb +19 -0
- data/somatics3-generators.gemspec +223 -0
- data/templates/somatics.rb +128 -0
- data/test/helper.rb +10 -0
- data/test/test_somatics3-generators.rb +7 -0
- metadata +301 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 tkwong
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= somatics3-generators
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 tkwong. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "somatics3-generators"
|
8
|
+
gem.summary = %Q{Somatics - Adminable Resource generators}
|
9
|
+
gem.description = %Q{Somatics 3 generators is used to generate a resource with skeleton admin panel}
|
10
|
+
gem.email = "tkwong@inspiresynergy.com"
|
11
|
+
gem.homepage = "http://github.com/inspiresynergy/somatics3-generators"
|
12
|
+
gem.authors = ["Benjamin Wong"]
|
13
|
+
# gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.rdoc_options += FileList['lib/**/templates/*'].to_a.collect{|f| "--exclude=#{f}" }
|
15
|
+
# gem.rdoc_options << "--exclude='lib/**/templates/*'"
|
16
|
+
gem.rubyforge_project = 'somatics3'
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
20
|
+
rubyforge.doc_task = "rdoc"
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
end
|
41
|
+
rescue LoadError
|
42
|
+
task :rcov do
|
43
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
task :test => :check_dependencies
|
48
|
+
|
49
|
+
task :default => :test
|
50
|
+
|
51
|
+
require 'rake/rdoctask'
|
52
|
+
Rake::RDocTask.new do |rdoc|
|
53
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "somatics3-generators #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
rdoc.rdoc_files.exclude('lib/**/templates/*')
|
60
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/bin/somatics
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
template_path = File.expand_path(File.dirname(__FILE__) + '/../templates')
|
7
|
+
|
8
|
+
|
9
|
+
# require 'somatics'
|
10
|
+
|
11
|
+
args = ARGV.dup
|
12
|
+
ARGV.clear
|
13
|
+
# path = args.shift.strip rescue '.'
|
14
|
+
|
15
|
+
# a = File.expand_path(path)
|
16
|
+
template = File.join(template_path,'somatics.rb')
|
17
|
+
|
18
|
+
# puts "#{path} #{a} #{args.join(',')} #{template}"
|
19
|
+
system "rails #{args.join(' ')} -m #{template}"
|
20
|
+
|
21
|
+
exit
|
data/bin/somatify
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
template_path = File.expand_path(File.dirname(__FILE__) + '/../templates')
|
7
|
+
|
8
|
+
|
9
|
+
# require 'somatics'
|
10
|
+
|
11
|
+
args = ARGV.dup
|
12
|
+
ARGV.clear
|
13
|
+
path = args.shift.strip rescue '.'
|
14
|
+
|
15
|
+
a = File.expand_path(path)
|
16
|
+
template = File.join(template_path,'somatics.rb')
|
17
|
+
|
18
|
+
# puts "#{path} #{a} #{args.join(',')} #{template}"
|
19
|
+
system "rake rails:template LOCATION=#{template}"
|
20
|
+
|
21
|
+
exit
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require 'generators/somatics'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
require 'rails/generators/resource_helpers'
|
4
|
+
require 'digest/sha1'
|
5
|
+
require 'rails/generators/migration'
|
6
|
+
|
7
|
+
module Somatics
|
8
|
+
module Generators
|
9
|
+
class AuthenticatedGenerator < Rails::Generators::NamedBase
|
10
|
+
extend TemplatePath
|
11
|
+
include Rails::Generators::ResourceHelpers
|
12
|
+
include Rails::Generators::Migration
|
13
|
+
|
14
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
15
|
+
class_option :namespace, :banner => "NAME", :type => :string, :default => ''
|
16
|
+
|
17
|
+
class_option :skip_routes, :type => :boolean, :desc => "Don't generate a resource line in config/routes.rb."
|
18
|
+
class_option :skip_migration, :type => :boolean, :desc => "Don't generate a migration file for this model."
|
19
|
+
class_option :aasm, :type => :boolean, :desc => "Works the same as stateful but uses the updated aasm gem"
|
20
|
+
class_option :stateful, :type => :boolean, :desc => "Builds in support for acts_as_state_machine and generatesactivation code."
|
21
|
+
class_option :rspec, :type => :boolean, :desc => "Generate RSpec tests and Stories in place of standard rails tests."
|
22
|
+
class_option :old_passwords, :type => :boolean, :desc => "Use the older password scheme"
|
23
|
+
class_option :include_activation, :type => :boolean, :desc => "Skip the code for a ActionMailer and its respective Activation Code through email"
|
24
|
+
class_option :dump_generator_attrs, :type => :boolean, :desc => "Dump Generator Attrs"
|
25
|
+
|
26
|
+
|
27
|
+
def create_model_files
|
28
|
+
template 'model.rb', File.join('app/models', class_path, "#{ file_name }.rb")
|
29
|
+
if options.include_activation?
|
30
|
+
# Check for class naming collisions.
|
31
|
+
class_collisions "#{class_name}Mailer", "#{class_name}MailerTest", "#{class_name}Observer"
|
32
|
+
template "mailer.rb", File.join('app/mailers', class_path, "#{ file_name }_mailer.rb")
|
33
|
+
template "observer.rb", File.join('app/models', class_path, "#{ file_name }_observer.rb")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_model_and_migration
|
38
|
+
template 'model.rb', "app/model/#{singular_name}.rb"
|
39
|
+
unless options.skip_migration?
|
40
|
+
migration_template 'migration.rb', "db/migrate/create_#{ migration_file_name }.rb"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def dump_generator_attribute_names
|
45
|
+
generator_attribute_names = [
|
46
|
+
:table_name,
|
47
|
+
:file_name,
|
48
|
+
:class_name,
|
49
|
+
:sessions_controller_name,
|
50
|
+
:sessions_controller_class_path,
|
51
|
+
:sessions_controller_file_path,
|
52
|
+
# :sessions_controller_class_nesting,
|
53
|
+
# :sessions_controller_class_nesting_depth,
|
54
|
+
:sessions_controller_class_name,
|
55
|
+
:sessions_controller_singular_name,
|
56
|
+
:sessions_controller_plural_name,
|
57
|
+
:sessions_controller_routing_name, # new_session_path
|
58
|
+
:sessions_controller_routing_path, # /session/new
|
59
|
+
:sessions_controller_controller_name, # sessions
|
60
|
+
:sessions_controller_file_name,
|
61
|
+
:sessions_controller_table_name,
|
62
|
+
:controller_name,
|
63
|
+
:controller_class_path,
|
64
|
+
:controller_file_path,
|
65
|
+
# :controller_class_nesting,
|
66
|
+
# :controller_class_nesting_depth,
|
67
|
+
# :controller_class_name,
|
68
|
+
# :controller_singular_name,
|
69
|
+
:controller_plural_name,
|
70
|
+
:controller_routing_name, # new_user_path
|
71
|
+
# :controller_routing_path, # /users/new
|
72
|
+
# :controller_controller_name, # users
|
73
|
+
# :controller_file_name,
|
74
|
+
# :controller_singular_name,
|
75
|
+
# :controller_table_name,
|
76
|
+
# :controller_plural_name,
|
77
|
+
]
|
78
|
+
|
79
|
+
generator_attribute_names.each do |attr|
|
80
|
+
puts "%-40s %s" % ["#{attr}:", self.send(attr.to_s)] # instance_variable_get("@#{attr.to_s}"
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
# rails g authenticated FoonParent::Foon SporkParent::Spork -p --force --rspec --dump-generator-attrs
|
86
|
+
# table_name: foon_parent_foons
|
87
|
+
# file_name: foon
|
88
|
+
# class_name: FoonParent::Foon
|
89
|
+
# controller_name: SporkParent::Sporks
|
90
|
+
# controller_class_path: spork_parent
|
91
|
+
# controller_file_path: spork_parent/sporks
|
92
|
+
# controller_class_nesting: SporkParent
|
93
|
+
# controller_class_nesting_depth: 1
|
94
|
+
# controller_class_name: SporkParent::Sporks
|
95
|
+
# controller_singular_name: spork
|
96
|
+
# controller_plural_name: sporks
|
97
|
+
# controller_routing_name: spork
|
98
|
+
# controller_routing_path: spork_parent/spork
|
99
|
+
# controller_controller_name: sporks
|
100
|
+
# controller_file_name: sporks
|
101
|
+
# controller_table_name: sporks
|
102
|
+
# controller_plural_name: sporks
|
103
|
+
# model_controller_name: FoonParent::Foons
|
104
|
+
# model_controller_class_path: foon_parent
|
105
|
+
# model_controller_file_path: foon_parent/foons
|
106
|
+
# model_controller_class_nesting: FoonParent
|
107
|
+
# model_controller_class_nesting_depth: 1
|
108
|
+
# model_controller_class_name: FoonParent::Foons
|
109
|
+
# model_controller_singular_name: foons
|
110
|
+
# model_controller_plural_name: foons
|
111
|
+
# model_controller_routing_name: foon_parent_foons
|
112
|
+
# model_controller_routing_path: foon_parent/foons
|
113
|
+
# model_controller_controller_name: foons
|
114
|
+
# model_controller_file_name: foons
|
115
|
+
# model_controller_singular_name: foons
|
116
|
+
# model_controller_table_name: foons
|
117
|
+
# model_controller_plural_name: foons
|
118
|
+
|
119
|
+
|
120
|
+
protected
|
121
|
+
|
122
|
+
def namespace_class
|
123
|
+
# options[:namespace].classify
|
124
|
+
end
|
125
|
+
|
126
|
+
def namespace_name
|
127
|
+
# options[:namespace].underscore
|
128
|
+
end
|
129
|
+
|
130
|
+
def sessions_controller_name
|
131
|
+
file_name + '_sessions'
|
132
|
+
end
|
133
|
+
|
134
|
+
def sessions_controller_class_path
|
135
|
+
class_path
|
136
|
+
end
|
137
|
+
|
138
|
+
def sessions_controller_file_path
|
139
|
+
controller_file_path
|
140
|
+
end
|
141
|
+
|
142
|
+
def sessions_controller_singular_name
|
143
|
+
controller_name
|
144
|
+
end
|
145
|
+
|
146
|
+
def sessions_controller_plural_name
|
147
|
+
controller_name
|
148
|
+
end
|
149
|
+
|
150
|
+
def sessions_controller_routing_name
|
151
|
+
singular_name
|
152
|
+
end
|
153
|
+
|
154
|
+
def sessions_controller_routing_path
|
155
|
+
sessions_controller_file_path.singularize
|
156
|
+
end
|
157
|
+
|
158
|
+
def sessions_controller_class_name
|
159
|
+
class_name + 'Session'
|
160
|
+
end
|
161
|
+
|
162
|
+
def sessions_controller_controller_name
|
163
|
+
controller_plural_name
|
164
|
+
end
|
165
|
+
|
166
|
+
def sessions_controller_file_name
|
167
|
+
file_name + '_session'
|
168
|
+
end
|
169
|
+
|
170
|
+
def sessions_controller_table_name
|
171
|
+
controller_plural_name
|
172
|
+
end
|
173
|
+
|
174
|
+
def controller_plural_name
|
175
|
+
plural_name
|
176
|
+
end
|
177
|
+
|
178
|
+
def controller_routing_name
|
179
|
+
controller_plural_name
|
180
|
+
end
|
181
|
+
|
182
|
+
def migration_name
|
183
|
+
"Create#{ class_name.pluralize.gsub(/::/, '') }"
|
184
|
+
end
|
185
|
+
|
186
|
+
def migration_file_name
|
187
|
+
"#{ file_path.gsub(/\//, '_').pluralize }"
|
188
|
+
end
|
189
|
+
|
190
|
+
#
|
191
|
+
# Implement the required interface for Rails::Generators::Migration.
|
192
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
193
|
+
#
|
194
|
+
def self.next_migration_number(dirname) #:nodoc:
|
195
|
+
if ActiveRecord::Base.timestamped_migrations
|
196
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
197
|
+
else
|
198
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# !! These must match the corresponding routines in by_password.rb !!
|
204
|
+
#
|
205
|
+
def secure_digest(*args)
|
206
|
+
Digest::SHA1.hexdigest(args.flatten.join('--'))
|
207
|
+
end
|
208
|
+
def make_token
|
209
|
+
secure_digest(Time.now, (1..10).map{ rand.to_s })
|
210
|
+
end
|
211
|
+
def password_digest(password, salt)
|
212
|
+
digest = $rest_auth_site_key_from_generator
|
213
|
+
$rest_auth_digest_stretches_from_generator.times do
|
214
|
+
digest = secure_digest(digest, salt, password, $rest_auth_site_key_from_generator)
|
215
|
+
end
|
216
|
+
digest
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class <%= class_name %>Mailer < ActionMailer::Base
|
2
|
+
def signup_notification(<%= file_name %>)
|
3
|
+
setup_email(<%= file_name %>)
|
4
|
+
@subject += 'Please activate your new account'
|
5
|
+
<% if options[:include_activation] %>
|
6
|
+
@body[:url] = "http://YOURSITE/activate/#{<%= file_name %>.activation_code}"
|
7
|
+
<% else %>
|
8
|
+
@body[:url] = "http://YOURSITE/login/" <% end %>
|
9
|
+
end
|
10
|
+
|
11
|
+
def activation(<%= file_name %>)
|
12
|
+
setup_email(<%= file_name %>)
|
13
|
+
@subject += 'Your account has been activated!'
|
14
|
+
@body[:url] = "http://YOURSITE/"
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def setup_email(<%= file_name %>)
|
19
|
+
@recipients = "#{<%= file_name %>.email}"
|
20
|
+
@from = "ADMINEMAIL"
|
21
|
+
@subject = "[YOURSITE] "
|
22
|
+
@sent_on = Time.now
|
23
|
+
@body[:<%= file_name %>] = <%= file_name %>
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table "<%= table_name %>", :force => true do |t|
|
4
|
+
t.column :login, :string, :limit => 40
|
5
|
+
t.column :name, :string, :limit => 100, :default => '', :null => true
|
6
|
+
t.column :email, :string, :limit => 100
|
7
|
+
t.column :crypted_password, :string, :limit => 40
|
8
|
+
t.column :salt, :string, :limit => 40
|
9
|
+
t.column :created_at, :datetime
|
10
|
+
t.column :updated_at, :datetime
|
11
|
+
t.column :remember_token, :string, :limit => 40
|
12
|
+
t.column :remember_token_expires_at, :datetime
|
13
|
+
<% if options[:include_activation] -%>
|
14
|
+
t.column :activation_code, :string, :limit => 40
|
15
|
+
t.column :activated_at, :datetime<% end %>
|
16
|
+
<% for attribute in attributes -%>
|
17
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
18
|
+
<% end -%>
|
19
|
+
end
|
20
|
+
add_index :<%= table_name %>, :login, :unique => true
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
drop_table "<%= table_name %>"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
class <%= class_name %> < ActiveRecord::Base
|
4
|
+
include Authentication
|
5
|
+
include Authentication::ByPassword
|
6
|
+
include Authentication::ByCookieToken
|
7
|
+
<% if options[:aasm] -%>
|
8
|
+
include Authorization::AasmRoles
|
9
|
+
<% elsif options[:stateful] -%>
|
10
|
+
include Authorization::StatefulRoles<% end %>
|
11
|
+
validates_presence_of :login
|
12
|
+
validates_length_of :login, :within => 3..40
|
13
|
+
validates_uniqueness_of :login
|
14
|
+
validates_format_of :login, :with => Authentication.login_regex, :message => Authentication.bad_login_message
|
15
|
+
|
16
|
+
validates_format_of :name, :with => Authentication.name_regex, :message => Authentication.bad_name_message, :allow_nil => true
|
17
|
+
validates_length_of :name, :maximum => 100
|
18
|
+
|
19
|
+
validates_presence_of :email
|
20
|
+
validates_length_of :email, :within => 6..100 #r@a.wk
|
21
|
+
validates_uniqueness_of :email
|
22
|
+
validates_format_of :email, :with => Authentication.email_regex, :message => Authentication.bad_email_message
|
23
|
+
|
24
|
+
<% if options[:include_activation] && !options[:stateful] %>before_create :make_activation_code <% end %>
|
25
|
+
|
26
|
+
# HACK HACK HACK -- how to do attr_accessible from here?
|
27
|
+
# prevents a user from submitting a crafted form that bypasses activation
|
28
|
+
# anything else you want your user to change should be added here.
|
29
|
+
attr_accessible :login, :email, :name, :password, :password_confirmation
|
30
|
+
|
31
|
+
<% if options[:include_activation] && !options[:stateful] %>
|
32
|
+
# Activates the user in the database.
|
33
|
+
def activate!
|
34
|
+
@activated = true
|
35
|
+
self.activated_at = Time.now.utc
|
36
|
+
self.activation_code = nil
|
37
|
+
save(false)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns true if the user has just been activated.
|
41
|
+
def recently_activated?
|
42
|
+
@activated
|
43
|
+
end
|
44
|
+
|
45
|
+
def active?
|
46
|
+
# the existence of an activation code means they have not activated yet
|
47
|
+
activation_code.nil?
|
48
|
+
end<% end %>
|
49
|
+
|
50
|
+
# Authenticates a user by their login name and unencrypted password. Returns the user or nil.
|
51
|
+
#
|
52
|
+
# uff. this is really an authorization, not authentication routine.
|
53
|
+
# We really need a Dispatch Chain here or something.
|
54
|
+
# This will also let us return a human error message.
|
55
|
+
#
|
56
|
+
def self.authenticate(login, password)
|
57
|
+
return nil if login.blank? || password.blank?
|
58
|
+
u = <% if options[:stateful] %>find_in_state :first, :active, :conditions => {:login => login.downcase}<%
|
59
|
+
elsif options[:include_activation] %>find :first, :conditions => ['login = ? and activated_at IS NOT NULL', login]<%
|
60
|
+
else %>find_by_login(login.downcase)<% end %> # need to get the salt
|
61
|
+
u && u.authenticated?(password) ? u : nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def login=(value)
|
65
|
+
write_attribute :login, (value ? value.downcase : nil)
|
66
|
+
end
|
67
|
+
|
68
|
+
def email=(value)
|
69
|
+
write_attribute :email, (value ? value.downcase : nil)
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
|
74
|
+
<% if options[:include_activation] -%>
|
75
|
+
def make_activation_code
|
76
|
+
<% if options[:stateful] -%>
|
77
|
+
self.deleted_at = nil
|
78
|
+
<% end -%>
|
79
|
+
self.activation_code = self.class.make_token
|
80
|
+
end
|
81
|
+
<% end %>
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= class_name %>Observer < ActiveRecord::Observer
|
2
|
+
def after_create(<%= file_name %>)
|
3
|
+
<%= class_name %>Mailer.deliver_signup_notification(<%= file_name %>)
|
4
|
+
end
|
5
|
+
|
6
|
+
def after_save(<%= file_name %>)
|
7
|
+
<% if options[:include_activation] %>
|
8
|
+
<%= class_name %>Mailer.deliver_activation(<%= file_name %>) if <%= file_name %>.recently_activated?
|
9
|
+
<% end %>
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require '<%= file_name %>_mailer'
|
3
|
+
|
4
|
+
class <%= class_name %>MailerTest < Test::Unit::TestCase
|
5
|
+
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
|
6
|
+
CHARSET = "utf-8"
|
7
|
+
|
8
|
+
include ActionMailer::Quoting
|
9
|
+
|
10
|
+
def setup
|
11
|
+
ActionMailer::Base.delivery_method = :test
|
12
|
+
ActionMailer::Base.perform_deliveries = true
|
13
|
+
ActionMailer::Base.deliveries = []
|
14
|
+
|
15
|
+
@expected = TMail::Mail.new
|
16
|
+
@expected.set_content_type "text", "plain", { "charset" => CHARSET }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_dummy_test
|
20
|
+
#do nothing
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def read_fixture(action)
|
25
|
+
IO.readlines("#{FIXTURES_PATH}/<%= file_name %>_mailer/#{action}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def encode(subject)
|
29
|
+
quoted_printable(subject, CHARSET)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require '<%= model_controller_file_name %>_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class <%= model_controller_class_name %>Controller; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class <%= model_controller_class_name %>ControllerTest < ActionController::TestCase
|
8
|
+
# Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead
|
9
|
+
# Then, you can remove it from this and the units test.
|
10
|
+
include <%= class_name %>AuthenticatedTestHelper
|
11
|
+
|
12
|
+
fixtures :<%= table_name %>
|
13
|
+
|
14
|
+
def test_should_allow_signup
|
15
|
+
assert_difference '<%= class_name %>.count' do
|
16
|
+
create_<%= file_name %>
|
17
|
+
assert_response :redirect
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_require_login_on_signup
|
22
|
+
assert_no_difference '<%= class_name %>.count' do
|
23
|
+
create_<%= file_name %>(:login => nil)
|
24
|
+
assert assigns(:<%= file_name %>).errors.on(:login)
|
25
|
+
assert_response :success
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_require_password_on_signup
|
30
|
+
assert_no_difference '<%= class_name %>.count' do
|
31
|
+
create_<%= file_name %>(:password => nil)
|
32
|
+
assert assigns(:<%= file_name %>).errors.on(:password)
|
33
|
+
assert_response :success
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_require_password_confirmation_on_signup
|
38
|
+
assert_no_difference '<%= class_name %>.count' do
|
39
|
+
create_<%= file_name %>(:password_confirmation => nil)
|
40
|
+
assert assigns(:<%= file_name %>).errors.on(:password_confirmation)
|
41
|
+
assert_response :success
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_require_email_on_signup
|
46
|
+
assert_no_difference '<%= class_name %>.count' do
|
47
|
+
create_<%= file_name %>(:email => nil)
|
48
|
+
assert assigns(:<%= file_name %>).errors.on(:email)
|
49
|
+
assert_response :success
|
50
|
+
end
|
51
|
+
end
|
52
|
+
<% if options[:stateful] %>
|
53
|
+
def test_should_sign_up_user_in_pending_state
|
54
|
+
create_<%= file_name %>
|
55
|
+
assigns(:<%= file_name %>).reload
|
56
|
+
assert assigns(:<%= file_name %>).pending?
|
57
|
+
end<% end %>
|
58
|
+
|
59
|
+
<% if options[:include_activation] %>
|
60
|
+
def test_should_sign_up_user_with_activation_code
|
61
|
+
create_<%= file_name %>
|
62
|
+
assigns(:<%= file_name %>).reload
|
63
|
+
assert_not_nil assigns(:<%= file_name %>).activation_code
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_should_activate_user
|
67
|
+
assert_nil <%= class_name %>.authenticate('aaron', 'test')
|
68
|
+
get :activate, :activation_code => <%= table_name %>(:aaron).activation_code
|
69
|
+
assert_redirected_to '/<%= controller_routing_path %>/new'
|
70
|
+
assert_not_nil flash[:notice]
|
71
|
+
assert_equal <%= table_name %>(:aaron), <%= class_name %>.authenticate('aaron', 'monkey')
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_should_not_activate_user_without_key
|
75
|
+
get :activate
|
76
|
+
assert_nil flash[:notice]
|
77
|
+
rescue ActionController::RoutingError
|
78
|
+
# in the event your routes deny this, we'll just bow out gracefully.
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_should_not_activate_user_with_blank_key
|
82
|
+
get :activate, :activation_code => ''
|
83
|
+
assert_nil flash[:notice]
|
84
|
+
rescue ActionController::RoutingError
|
85
|
+
# well played, sir
|
86
|
+
end<% end %>
|
87
|
+
|
88
|
+
protected
|
89
|
+
def create_<%= file_name %>(options = {})
|
90
|
+
post :create, :<%= file_name %> => { :login => 'quire', :email => 'quire@example.com',
|
91
|
+
:password => 'quire69', :password_confirmation => 'quire69' }.merge(options)
|
92
|
+
end
|
93
|
+
end
|