Skip to content

Commit

Permalink
added clearance_views generator. by default, creates formtastic views…
Browse files Browse the repository at this point in the history
… which pass all tests and features.
  • Loading branch information
Dan Croak committed Aug 4, 2009
1 parent 73a4612 commit cd85f72
Show file tree
Hide file tree
Showing 25 changed files with 5,017 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ test/rails_root/log/*.log
*.swp
.rake_tasks
test/rails_root/*
!test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1
*.gem
7 changes: 7 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
h2. 0.7.0 (08/04/2009)

* Redirect signed in user who clicks confirmation link again. (Dan Croak)
* Redirect signed out user who clicks confirmation link again. (Dan Croak)
* Added signed_out? convenience method for controllers, helpers, views. (Dan
Croak)

h2. 0.6.9 (07/04/2009)

* Added timestamps to create users migration. (Dan Croak)
Expand Down
45 changes: 36 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ require 'rake/testtask'
require 'cucumber/rake/task'

namespace :test do
Rake::TestTask.new(:all => ["generator:cleanup",
"generator:generate"]) do |task|
Rake::TestTask.new(:basic => ["generator:cleanup",
"generator:clearance",
"generator:clearance_features"]) do |task|
task.libs << "lib"
task.libs << "test"
task.pattern = "test/**/*_test.rb"
task.verbose = false
end

Rake::TestTask.new(:views => ["generator:clearance_views"]) do |task|
task.libs << "lib"
task.libs << "test"
task.pattern = "test/**/*_test.rb"
Expand All @@ -17,9 +25,14 @@ namespace :test do
t.cucumber_opts = "--format progress"
t.feature_pattern = "test/rails_root/features/*.feature"
end

Cucumber::Rake::Task.new(:features_for_views) do |t|
t.cucumber_opts = "--format progress"
t.feature_pattern = "test/rails_root/features/*.feature"
end
end

generators = %w(clearance clearance_features)
generators = %w(clearance clearance_features clearance_views)

namespace :generator do
desc "Cleans up the test app before running the generator"
Expand All @@ -34,22 +47,36 @@ namespace :generator do
FileList["test/rails_root/db/**/*"].each do |each|
FileUtils.rm_rf(each)
end

FileUtils.rm_rf("test/rails_root/vendor/plugins/clearance")
FileUtils.mkdir_p("test/rails_root/vendor/plugins")
clearance_root = File.expand_path(File.dirname(__FILE__))
system("ln -s #{clearance_root} test/rails_root/vendor/plugins/clearance")

FileUtils.rm_rf("test/rails_root/app/views/passwords")
FileUtils.rm_rf("test/rails_root/app/views/sessions")
FileUtils.rm_rf("test/rails_root/app/views/users")
end

desc "Run the generator on the tests"
task :generate do
generators.each do |generator|
system "cd test/rails_root && ./script/generate #{generator} && rake db:migrate db:test:prepare"
end
desc "Run the clearance generator"
task :clearance do
system "cd test/rails_root && ./script/generate clearance && rake db:migrate db:test:prepare"
end

desc "Run the clearance features generator"
task :clearance_features do
system "cd test/rails_root && ./script/generate clearance_features"
end

desc "Run the clearance views generator"
task :clearance_views do
system "cd test/rails_root && ./script/generate clearance_views"
end
end

desc "Run the test suite"
task :default => ['test:all', 'test:features']
task :default => ['test:basic', 'test:features',
'test:views', 'test:features_for_views']

gem_spec = Gem::Specification.new do |gem_spec|
gem_spec.name = "clearance"
Expand Down
6 changes: 3 additions & 3 deletions generators/clearance_features/clearance_features_generator.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class ClearanceFeaturesGenerator < Rails::Generator::Base

def manifest
record do |m|
m.directory File.join("features", "step_definitions")
m.directory File.join("features", "support")

["features/step_definitions/clearance_steps.rb",
"features/step_definitions/factory_girl_steps.rb",
"features/support/paths.rb",
Expand All @@ -16,5 +16,5 @@ def manifest
end
end
end

end
Empty file.
27 changes: 27 additions & 0 deletions generators/clearance_views/clearance_views_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class ClearanceViewsGenerator < Rails::Generator::Base

def manifest
record do |m|
strategy = "formtastic"
template_strategy = "erb"

m.directory File.join("app", "views", "users")
m.file "#{strategy}/users/new.html.#{template_strategy}",
"app/views/users/new.html.#{template_strategy}"
m.file "#{strategy}/users/_inputs.html.#{template_strategy}",
"app/views/users/_inputs.html.#{template_strategy}"

m.directory File.join("app", "views", "sessions")
m.file "#{strategy}/sessions/new.html.#{template_strategy}",
"app/views/sessions/new.html.#{template_strategy}"

m.directory File.join("app", "views", "passwords")
m.file "#{strategy}/passwords/new.html.#{template_strategy}",
"app/views/passwords/new.html.#{template_strategy}"
m.file "#{strategy}/passwords/edit.html.#{template_strategy}",
"app/views/passwords/edit.html.#{template_strategy}"
end
end

end

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h2>Change your password</h2>

<p>
Your password has been reset. Choose a new password below.
</p>

<% semantic_form_for(:user,
:url => user_password_path(@user, :token => @user.token),
:html => { :method => :put }) do |form| %>
<%= form.error_messages %>
<% form.inputs do -%>
<%= form.input :password, :as => :password,
:label => "Choose password" %>
<%= form.input :password_confirmation, :as => :password,
:label => "Confirm password" %>
<% end -%>
<% form.buttons do -%>
<%= form.commit_button "Save this password" %>
<% end -%>
<% end %>

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h2>Reset your password</h2>

<p>
We will email you a link to reset your password.
</p>

<% semantic_form_for :password, :url => passwords_path do |form| -%>
<% form.inputs do -%>
<%= form.input :email, :label => "Email address" %>
<% end -%>
<% form.buttons do -%>
<%= form.commit_button "Reset password" %>
<% end -%>
<% end -%>

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<h2>Sign in</h2>

<% semantic_form_for :session, :url => session_path do |form| %>
<% form.inputs do %>
<%= form.input :email %>
<%= form.input :password, :as => :password %>
<%= form.input :remember_me, :as => :boolean, :required => false %>
<% end %>
<% form.buttons do %>
<%= form.commit_button "Sign in" %>
<% end %>
<% end %>

<ul>
<li>
<%= link_to "Sign up", new_user_path %>
</li>
<li>
<%= link_to "Forgot password?", new_password_path %>
</li>
</ul>

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% form.inputs do %>
<%= form.input :email %>
<%= form.input :password %>
<%= form.input :password_confirmation, :label => "Confirm password" %>
<% end %>

10 changes: 10 additions & 0 deletions generators/clearance_views/templates/formtastic/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h2>Sign up</h2>

<% semantic_form_for @user do |form| %>
<%= form.error_messages %>
<%= render :partial => "/users/inputs", :locals => { :form => form } %>
<% form.buttons do %>
<%= form.commit_button "Sign up" %>
<% end %>
<% end %>

3 changes: 3 additions & 0 deletions test/rails_root/config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
:session_key => "_clearance_session",
:secret => ['clearance', 'random', 'words', 'here'].map {|k| Digest::MD5.hexdigest(k) }.join
}
config.gem "justinfrench-formtastic",
:lib => 'formtastic',
:source => 'http://gems.github.com'
end

DO_NOT_REPLY = "donotreply@example.com"
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--- !ruby/object:Gem::Specification
name: justinfrench-formtastic
version: !ruby/object:Gem::Version
version: 0.2.1
platform: ruby
authors:
- Justin French
autorequire: formtastic
bindir: bin
cert_chain: []

date: 2009-06-17 00:00:00 -04:00
default_executable:
dependencies: []

description: A Rails form builder plugin/gem with semantically rich and accessible markup
email: justin@indent.com.au
executables: []

extensions: []

extra_rdoc_files:
- README.textile
files:
- MIT-LICENSE
- README.textile
- Rakefile
- generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb
- generators/formtastic_stylesheets/templates/formtastic.css
- generators/formtastic_stylesheets/templates/formtastic_changes.css
- lib/formtastic.rb
- lib/justin_french/formtastic.rb
- lib/locale/en.yml
- rails/init.rb
- spec/formtastic_spec.rb
- spec/test_helper.rb
has_rdoc: true
homepage: http://github.com/justinfrench/formtastic/tree/master
licenses: []

post_install_message:
rdoc_options:
- --charset=UTF-8
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
version:
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
version:
requirements: []

rubyforge_project:
rubygems_version: 1.3.4
signing_key:
specification_version: 3
summary: A Rails form builder plugin/gem with semantically rich and accessible markup
test_files:
- spec/formtastic_spec.rb
- spec/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2008 Justin French

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit cd85f72

Please sign in to comment.