fingerrails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +3 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +28 -0
  4. data/VERSION +1 -0
  5. data/bin/fingerrails +9 -0
  6. data/fingerrails.gemspec +90 -0
  7. data/fingertips.rb +181 -0
  8. data/templates/.kick +22 -0
  9. data/templates/Rakefile +23 -0
  10. data/templates/app/controllers/application_controller.rb +51 -0
  11. data/templates/app/controllers/members_controller.rb +32 -0
  12. data/templates/app/controllers/passwords_controller.rb +46 -0
  13. data/templates/app/controllers/sessions_controller.rb +26 -0
  14. data/templates/app/helpers/application_helper.rb +20 -0
  15. data/templates/app/models/mailer.rb +8 -0
  16. data/templates/app/models/member.rb +10 -0
  17. data/templates/app/models/member/authentication.rb +44 -0
  18. data/templates/app/views/layouts/_application_javascript_includes.html.erb +3 -0
  19. data/templates/app/views/layouts/_head.html.erb +3 -0
  20. data/templates/app/views/layouts/application.html.erb +25 -0
  21. data/templates/app/views/mailer/reset_password_message.erb +8 -0
  22. data/templates/app/views/members/edit.html.erb +21 -0
  23. data/templates/app/views/members/new.html.erb +26 -0
  24. data/templates/app/views/members/show.html.erb +3 -0
  25. data/templates/app/views/passwords/edit.html.erb +22 -0
  26. data/templates/app/views/passwords/new.html.erb +22 -0
  27. data/templates/app/views/passwords/reset.html.erb +9 -0
  28. data/templates/app/views/passwords/sent.html.erb +11 -0
  29. data/templates/app/views/sessions/_form.html.erb +22 -0
  30. data/templates/app/views/sessions/_status.html.erb +9 -0
  31. data/templates/app/views/sessions/new.html.erb +5 -0
  32. data/templates/config/database.yml +18 -0
  33. data/templates/lib/active_record_ext.rb +26 -0
  34. data/templates/lib/token.rb +9 -0
  35. data/templates/public/403.html +29 -0
  36. data/templates/public/javascripts/ready.js +9 -0
  37. data/templates/public/stylesheets/default.css +143 -0
  38. data/templates/public/stylesheets/reset.css +52 -0
  39. data/templates/test/ext/authentication.rb +24 -0
  40. data/templates/test/ext/file_fixtures.rb +8 -0
  41. data/templates/test/ext/time.rb +8 -0
  42. data/templates/test/fixtures/members.yml +8 -0
  43. data/templates/test/functional/application_controller_test.rb +104 -0
  44. data/templates/test/functional/members_controller_test.rb +71 -0
  45. data/templates/test/functional/passwords_controller_test.rb +95 -0
  46. data/templates/test/functional/sessions_controller_test.rb +68 -0
  47. data/templates/test/lib/active_record_ext_test.rb +13 -0
  48. data/templates/test/lib/token_test.rb +17 -0
  49. data/templates/test/test_helper.rb +32 -0
  50. data/templates/test/unit/helpers/application_helper_test.rb +44 -0
  51. data/templates/test/unit/mailer_test.rb +13 -0
  52. data/templates/test/unit/member/authentication_test.rb +73 -0
  53. data/templates/test/unit/member_test.rb +32 -0
  54. metadata +108 -0
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ vendor_cache
2
+ test_app
3
+ pkg
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ Usage:
2
+
3
+ rails APP_NAME -m http://github.com/Fingertips/rails-template/raw/master/fingertips.rb
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |s|
4
+ s.name = "fingerrails"
5
+ s.summary = s.description = "A self contained version of the Fingertips Rails template"
6
+ s.email = "eloy@fngtps.com"
7
+ s.homepage = "http://github.com/Fingertips/rails-template"
8
+ s.authors = ["Manfred Stienstra", "Eloy Duran"]
9
+
10
+ s.require_paths = ['bin']
11
+ end
12
+ rescue LoadError
13
+ end
14
+
15
+ desc 'Drops the databases and removes the test app.'
16
+ task :clean do
17
+ if File.exist? 'test_app'
18
+ sh 'cd test_app && rake db:drop:all' rescue nil
19
+ rm_rf 'test_app'
20
+ end
21
+ end
22
+
23
+ desc 'Runs the template with the proper env so that it caches the rails checkout.'
24
+ task :test_template => :clean do
25
+ sh 'env TEST_TEMPLATE=true ruby ./bin/fingerrails test_app'
26
+ end
27
+
28
+ task :default => :test_template
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/fingerrails ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV.empty?
4
+ puts "Usage: #{$0} /path/to/your/app [options]"
5
+ else
6
+ ENV['TEMPLATE_HOME'] = File.expand_path('../../templates', __FILE__)
7
+ template = File.expand_path('../../fingertips.rb', __FILE__)
8
+ exec 'rails', '-m', template, *ARGV
9
+ end
@@ -0,0 +1,90 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{fingerrails}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Manfred Stienstra", "Eloy Duran"]
12
+ s.date = %q{2009-10-28}
13
+ s.default_executable = %q{fingerrails}
14
+ s.description = %q{A self contained version of the Fingertips Rails template}
15
+ s.email = %q{eloy@fngtps.com}
16
+ s.executables = ["fingerrails"]
17
+ s.extra_rdoc_files = [
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/fingerrails",
26
+ "fingerrails.gemspec",
27
+ "fingertips.rb",
28
+ "templates/.kick",
29
+ "templates/Rakefile",
30
+ "templates/app/controllers/application_controller.rb",
31
+ "templates/app/controllers/members_controller.rb",
32
+ "templates/app/controllers/passwords_controller.rb",
33
+ "templates/app/controllers/sessions_controller.rb",
34
+ "templates/app/helpers/application_helper.rb",
35
+ "templates/app/models/mailer.rb",
36
+ "templates/app/models/member.rb",
37
+ "templates/app/models/member/authentication.rb",
38
+ "templates/app/views/layouts/_application_javascript_includes.html.erb",
39
+ "templates/app/views/layouts/_head.html.erb",
40
+ "templates/app/views/layouts/application.html.erb",
41
+ "templates/app/views/mailer/reset_password_message.erb",
42
+ "templates/app/views/members/edit.html.erb",
43
+ "templates/app/views/members/new.html.erb",
44
+ "templates/app/views/members/show.html.erb",
45
+ "templates/app/views/passwords/edit.html.erb",
46
+ "templates/app/views/passwords/new.html.erb",
47
+ "templates/app/views/passwords/reset.html.erb",
48
+ "templates/app/views/passwords/sent.html.erb",
49
+ "templates/app/views/sessions/_form.html.erb",
50
+ "templates/app/views/sessions/_status.html.erb",
51
+ "templates/app/views/sessions/new.html.erb",
52
+ "templates/config/database.yml",
53
+ "templates/lib/active_record_ext.rb",
54
+ "templates/lib/token.rb",
55
+ "templates/public/403.html",
56
+ "templates/public/javascripts/ready.js",
57
+ "templates/public/stylesheets/default.css",
58
+ "templates/public/stylesheets/reset.css",
59
+ "templates/test/ext/authentication.rb",
60
+ "templates/test/ext/file_fixtures.rb",
61
+ "templates/test/ext/time.rb",
62
+ "templates/test/fixtures/members.yml",
63
+ "templates/test/functional/application_controller_test.rb",
64
+ "templates/test/functional/members_controller_test.rb",
65
+ "templates/test/functional/passwords_controller_test.rb",
66
+ "templates/test/functional/sessions_controller_test.rb",
67
+ "templates/test/lib/active_record_ext_test.rb",
68
+ "templates/test/lib/token_test.rb",
69
+ "templates/test/test_helper.rb",
70
+ "templates/test/unit/helpers/application_helper_test.rb",
71
+ "templates/test/unit/mailer_test.rb",
72
+ "templates/test/unit/member/authentication_test.rb",
73
+ "templates/test/unit/member_test.rb"
74
+ ]
75
+ s.homepage = %q{http://github.com/Fingertips/rails-template}
76
+ s.rdoc_options = ["--charset=UTF-8"]
77
+ s.require_paths = ["bin"]
78
+ s.rubygems_version = %q{1.3.5}
79
+ s.summary = %q{A self contained version of the Fingertips Rails template}
80
+
81
+ if s.respond_to? :specification_version then
82
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
83
+ s.specification_version = 3
84
+
85
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
86
+ else
87
+ end
88
+ else
89
+ end
90
+ end
data/fingertips.rb ADDED
@@ -0,0 +1,181 @@
1
+ # * Use plugins or gems?
2
+ # * Add an option which prepares the app for svn usage.
3
+
4
+ require 'fileutils'
5
+
6
+ TEMPLATE_HOME = ENV['TEMPLATE_HOME'] ||
7
+ 'http://github.com/Fingertips/rails-template/raw/master/templates/'
8
+
9
+ class Rails::TemplateRunner
10
+ def name
11
+ File.basename(root)
12
+ end
13
+
14
+ def template_file(template)
15
+ contents = open(File.join(TEMPLATE_HOME, template)).read
16
+ contents.gsub!('{{app_name}}', name)
17
+ contents.gsub!('{{AppName}}', name.camelize)
18
+ file template, contents
19
+ end
20
+ end
21
+
22
+ def test_cache(dir)
23
+ if ENV['TEST_TEMPLATE'] && File.exist?(File.join('../vendor_cache', dir))
24
+ puts "[!] Using #{dir} cache..."
25
+ FileUtils.cp_r "../vendor_cache/#{dir}", "vendor"
26
+ else
27
+ yield
28
+ if ENV['TEST_TEMPLATE']
29
+ puts "[!] Creating #{dir} cache..."
30
+ FileUtils.mkdir_p "../vendor_cache"
31
+ FileUtils.cp_r "vendor/#{dir}", "../vendor_cache"
32
+ end
33
+ end
34
+ end
35
+
36
+ ####
37
+ #
38
+ # Skeleton template
39
+ #
40
+
41
+ # Setup
42
+
43
+ template_file 'config/database.yml'
44
+
45
+ # Gems
46
+
47
+ environment "gem 'test-spec', :version => '~> 0.10.0', :lib => 'test/spec'", :env => :test
48
+ rake 'gems:install', :env => :test, :sudo => true
49
+
50
+ # Rails
51
+
52
+ test_cache 'rails' do
53
+ # On 2.3.4 the git command is broken as it only executes in_root
54
+ inside 'vendor' do
55
+ Git.run 'clone git://github.com/Fingertips/rails.git'
56
+ run 'cd rails && git remote add rails git://github.com/rails/rails.git'
57
+ end
58
+ end
59
+
60
+ # Plugins
61
+
62
+ test_cache 'plugins' do
63
+ plugin 'authentication-needed-san', :git => 'git://github.com/Fingertips/authentication-needed-san.git'
64
+ plugin 'authorization-san', :git => 'git://github.com/Fingertips/authorization-san.git'
65
+ plugin 'generator-san', :git => 'git://github.com/Fingertips/generator-san.git'
66
+ plugin 'on-test-spec', :git => 'git://github.com/Fingertips/on-test-spec.git'
67
+ plugin 'peiji-san', :git => 'git://github.com/Fingertips/peiji-san.git'
68
+ plugin 'risosu-san', :git => 'git://github.com/Fingertips/risosu-san.git'
69
+ plugin 'validates_email-san', :git => 'git://github.com/Fingertips/validates_email-san.git'
70
+ end
71
+
72
+ # Misc
73
+
74
+ template_file '.kick'
75
+ template_file 'Rakefile'
76
+
77
+ # Test
78
+
79
+ template_file 'test/test_helper.rb'
80
+ template_file 'test/ext/authentication.rb'
81
+ template_file 'test/ext/file_fixtures.rb'
82
+ template_file 'test/ext/time.rb'
83
+
84
+ # Lib
85
+
86
+ initializer 'core_ext.rb',
87
+ %{require 'active_record_ext'
88
+
89
+ ActiveRecord::Base.send(:extend, ActiveRecord::Ext)
90
+ ActiveRecord::Base.send(:include, ActiveRecord::BasicScopes)}
91
+
92
+ template_file 'lib/active_record_ext.rb'
93
+ template_file 'test/lib/active_record_ext_test.rb'
94
+
95
+ template_file 'lib/token.rb'
96
+ template_file 'test/lib/token_test.rb'
97
+
98
+ ####
99
+ #
100
+ # Application template
101
+ #
102
+
103
+ initializer 'application.rb', %{SYSTEM_EMAIL_ADDRESS = '#{name.camelize} Support <support@example.com>'}
104
+
105
+ # Routes
106
+
107
+ # For some reason these routes are generated in the reversed order...
108
+ route 'map.root :controller => "members", :action => "new"'
109
+ route 'map.resource :session, :collection => { :clear => :get }'
110
+ route 'map.resources :passwords'
111
+ route 'map.resources :members'
112
+
113
+ # Models
114
+
115
+ generate :model_san, 'member role:string email:string hashed_password:string reset_password_token:string'
116
+
117
+ template_file 'app/models/member.rb'
118
+ template_file 'test/unit/member_test.rb'
119
+ template_file 'test/fixtures/members.yml'
120
+
121
+ template_file 'app/models/member/authentication.rb'
122
+ template_file 'test/unit/member/authentication_test.rb'
123
+
124
+ template_file 'app/models/mailer.rb'
125
+ template_file 'test/unit/mailer_test.rb'
126
+
127
+ # Controllers
128
+
129
+ initializer 'mime_types.rb', %{Mime::Type.register 'image/jpeg', :jpg}
130
+
131
+ template_file 'app/controllers/application_controller.rb'
132
+ template_file 'test/functional/application_controller_test.rb'
133
+
134
+ template_file 'app/controllers/members_controller.rb'
135
+ template_file 'test/functional/members_controller_test.rb'
136
+
137
+ template_file 'app/controllers/passwords_controller.rb'
138
+ template_file 'test/functional/passwords_controller_test.rb'
139
+
140
+ template_file 'app/controllers/sessions_controller.rb'
141
+ template_file 'test/functional/sessions_controller_test.rb'
142
+
143
+ # Helpers
144
+
145
+ template_file 'app/helpers/application_helper.rb'
146
+ template_file 'test/unit/helpers/application_helper_test.rb'
147
+
148
+ # Views
149
+
150
+ run 'rm public/index.html'
151
+
152
+ template_file 'public/403.html'
153
+ template_file 'public/stylesheets/default.css'
154
+ template_file 'public/stylesheets/reset.css'
155
+ template_file 'public/javascripts/ready.js'
156
+
157
+ template_file 'app/views/layouts/application.html.erb'
158
+ template_file 'app/views/layouts/_application_javascript_includes.html.erb'
159
+ template_file 'app/views/layouts/_head.html.erb'
160
+
161
+ template_file 'app/views/members/new.html.erb'
162
+ template_file 'app/views/members/show.html.erb'
163
+ template_file 'app/views/members/edit.html.erb'
164
+
165
+ template_file 'app/views/passwords/new.html.erb'
166
+ template_file 'app/views/passwords/sent.html.erb'
167
+ template_file 'app/views/passwords/edit.html.erb'
168
+ template_file 'app/views/passwords/reset.html.erb'
169
+
170
+ template_file 'app/views/sessions/new.html.erb'
171
+ template_file 'app/views/sessions/_form.html.erb'
172
+ template_file 'app/views/sessions/_status.html.erb'
173
+
174
+ template_file 'app/views/mailer/reset_password_message.erb'
175
+
176
+ # Finalize
177
+
178
+ rake 'db:create:all'
179
+ rake 'db:migrate'
180
+
181
+ exec 'rake test'
data/templates/.kick ADDED
@@ -0,0 +1,22 @@
1
+ # require 'ignore'
2
+ # ignore(//)
3
+
4
+ # App specific mappings
5
+ process do |files|
6
+ test_files = files.take_and_map do |file|
7
+ case file
8
+ when %r{^app/views/mailer/\w+\.erb$}
9
+ 'test/unit/mailer_test.rb'
10
+ end
11
+ end
12
+
13
+ run_ruby_tests test_files
14
+ end
15
+
16
+ require 'rails'
17
+ require 'jstest'
18
+
19
+ # Update stories
20
+ # process do |files|
21
+ # execute "rake stories:convert" if files.delete('design/requirements.txt')
22
+ # end
@@ -0,0 +1,23 @@
1
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+ require 'tasks/rails'
7
+
8
+ namespace :test do
9
+ desc "Run the javascript tests in test/javascripts"
10
+ task :javascripts do
11
+ sh "jstest #{Dir['test/javascripts/*.html'].join(' ')}"
12
+ end
13
+
14
+ Rake::TestTask.new('lib') do |t|
15
+ t.test_files = FileList['test/lib/**/*_test.rb']
16
+ t.verbose = true
17
+ end
18
+ end
19
+
20
+ task :test do
21
+ Rake::Task['test:lib'].invoke
22
+ Rake::Task['test:javascripts'].invoke
23
+ end
@@ -0,0 +1,51 @@
1
+ class ApplicationController < ActionController::Base
2
+ helper :all
3
+ protect_from_forgery
4
+ filter_parameter_logging :password
5
+ before_filter :find_authenticated, :block_access, :set_actionmailer_host
6
+ # report_errors_to 'http://forestwatcher.example.com/{{app_name}}', :username => 'forestwatcher', :password => 'secret'
7
+
8
+ protected
9
+
10
+ # Responds with a http status code and an error document
11
+ def send_response_document(status)
12
+ format = (request.format === [Mime::XML, Mime::JSON]) ? request.format : Mime::HTML
13
+ status = interpret_status(status)
14
+ send_file "#{RAILS_ROOT}/public/#{status.to_i}.#{format.to_sym}",
15
+ :status => status,
16
+ :type => "#{format}; charset=utf-8",
17
+ :disposition => 'inline',
18
+ :stream => false
19
+ end
20
+
21
+ def find_authenticated
22
+ @authenticated = Member.find_by_id(request.session[:member_id]) unless request.session[:member_id].blank?
23
+ end
24
+
25
+ # Handles interaction when the client may not access the current resource
26
+ def access_forbidden
27
+ if !@authenticated.nil?
28
+ send_response_document :forbidden
29
+ else
30
+ flash.keep
31
+ authentication_needed!
32
+ end
33
+ end
34
+
35
+ def when_authentication_needed
36
+ redirect_to new_session_url
37
+ end
38
+
39
+ # Set the hostname of the server on ActionMailer
40
+ def set_actionmailer_host
41
+ ActionMailer::Base.default_url_options[:host] = request.host_with_port
42
+ end
43
+
44
+ def login(member)
45
+ request.session[:member_id] = member.id
46
+ end
47
+
48
+ def logout
49
+ request.session.delete(:member_id)
50
+ end
51
+ end
@@ -0,0 +1,32 @@
1
+ class MembersController < ApplicationController
2
+ allow_access(:authenticated) { @authenticated.to_param == params[:id] }
3
+ allow_access :all, :only => [:new, :create, :show]
4
+
5
+ before_filter :find_member, :only => [:show, :edit, :update]
6
+
7
+ def new
8
+ @member = Member.new
9
+ end
10
+
11
+ def create
12
+ @member = Member.new(params[:member])
13
+
14
+ if @member.save
15
+ login(@member)
16
+ redirect_to root_url
17
+ else
18
+ render :new
19
+ end
20
+ end
21
+
22
+ def update
23
+ @member.update_attributes(params[:member])
24
+ redirect_to member_url(@member)
25
+ end
26
+
27
+ private
28
+
29
+ def find_member
30
+ @member = Member.find(params[:id])
31
+ end
32
+ end