seivan-generators 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGELOG +156 -0
  2. data/Gemfile +2 -0
  3. data/LICENSE +23 -0
  4. data/README.rdoc +38 -0
  5. data/Rakefile +10 -0
  6. data/features/seivan_authentication.feature +52 -0
  7. data/features/seivan_config.feature +17 -0
  8. data/features/seivan_html5_haml.feature +47 -0
  9. data/features/step_definitions/common_steps.rb +44 -0
  10. data/features/step_definitions/rails_setup_steps.rb +6 -0
  11. data/features/support/env.rb +6 -0
  12. data/features/support/matchers.rb +7 -0
  13. data/lib/generators/seivan.rb +15 -0
  14. data/lib/generators/seivan/authentication/USAGE +50 -0
  15. data/lib/generators/seivan/authentication/authentication_generator.rb +123 -0
  16. data/lib/generators/seivan/authentication/templates/controller_authentication.rb +61 -0
  17. data/lib/generators/seivan/authentication/templates/fixtures.yml +24 -0
  18. data/lib/generators/seivan/authentication/templates/migration.rb +20 -0
  19. data/lib/generators/seivan/authentication/templates/sessions_controller.rb +45 -0
  20. data/lib/generators/seivan/authentication/templates/sessions_helper.rb +2 -0
  21. data/lib/generators/seivan/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  22. data/lib/generators/seivan/authentication/templates/tests/rspec/user.rb +83 -0
  23. data/lib/generators/seivan/authentication/templates/tests/rspec/users_controller.rb +56 -0
  24. data/lib/generators/seivan/authentication/templates/user.rb +42 -0
  25. data/lib/generators/seivan/authentication/templates/users_controller.rb +34 -0
  26. data/lib/generators/seivan/authentication/templates/users_helper.rb +2 -0
  27. data/lib/generators/seivan/config/USAGE +23 -0
  28. data/lib/generators/seivan/config/config_generator.rb +24 -0
  29. data/lib/generators/seivan/config/templates/config.yml +8 -0
  30. data/lib/generators/seivan/config/templates/load_config.rb +2 -0
  31. data/lib/generators/seivan/html5/USAGE +25 -0
  32. data/lib/generators/seivan/html5/html5_generator.rb +32 -0
  33. data/lib/generators/seivan/html5/templates/_errors.html.haml +7 -0
  34. data/lib/generators/seivan/html5/templates/_flashes.html.haml +4 -0
  35. data/lib/generators/seivan/html5/templates/_footer.html.haml +2 -0
  36. data/lib/generators/seivan/html5/templates/_head.html.haml +27 -0
  37. data/lib/generators/seivan/html5/templates/_header.html.haml +1 -0
  38. data/lib/generators/seivan/html5/templates/_javascripts.html.haml +16 -0
  39. data/lib/generators/seivan/html5/templates/_stylesheets.html.haml +8 -0
  40. data/lib/generators/seivan/html5/templates/application.html.haml +15 -0
  41. data/lib/generators/seivan/html5/templates/jquery.js +155 -0
  42. data/lib/generators/seivan/html5/templates/jquery_ujs.js +132 -0
  43. data/test/test_helper.rb +119 -0
  44. data/test/test_nifty_authentication_generator.rb +274 -0
  45. data/test/test_nifty_config_generator.rb +37 -0
  46. data/test/test_nifty_layout_generator.rb +42 -0
  47. metadata +199 -0
data/CHANGELOG ADDED
@@ -0,0 +1,156 @@
1
+ 0.4.2 (October 15, 2010)
2
+
3
+ * adding mocha to Gemfile automatically if it's not there already
4
+
5
+ * switching to BCrypt for user password encryption on nifty:authentication - issue #53
6
+
7
+ * adding Gemfile, now just run "bunde" and "rake" to get cucumber features running - issue #56
8
+
9
+ * renaming Authentication module to ControllerAuthentication to avoid conflicts in nifty:authentication - issue #57
10
+
11
+ * automatically use RSpec when there's a spec directory - issue #50
12
+
13
+ * escaping page title in layout helper (thanks cbmeeks) - issue #52
14
+
15
+ * adding edit profile page to nifty:authentication - closes #54
16
+
17
+
18
+ 0.4.1 (September 23rd, 2010)
19
+
20
+ * fixing frozen hash error when not passing additional arguments to nifty:scaffold - issue #35
21
+
22
+ * fixing rendering of default title in nifty:layout - issue #36
23
+
24
+ * fixing integrate_views error in nifty:scaffold specs - issue #43
25
+
26
+ * updating SASS syntax (thanks semaperepelitsa) - issue #46
27
+
28
+
29
+ 0.4.0 (April 19th, 2010)
30
+
31
+ * adding error_messages_for and f.error_messages helper for Rails 3 nifty:layout
32
+
33
+ * adding initial Rails 3 support (thanks Henrik Hodne)
34
+
35
+ * adding xmlns to <head> element in nifty_layout
36
+
37
+
38
+ 0.3.2 (February 16th, 2010)
39
+
40
+ * Including all files in gem, was missing files in rails_generator directory
41
+
42
+
43
+ 0.3.1 (February 16th, 2010)
44
+
45
+ * improving documentation
46
+
47
+ * fixing name of generated session model for authlogic in nifty_authorization
48
+
49
+ * use "username" instead of "login" for authlogic haml form template in nifty_authorization
50
+
51
+
52
+ 0.3.0 (August 15th, 2009)
53
+
54
+ * adding attr_accessible to models in nifty_scaffold
55
+
56
+ * adding authlogic support with --authlogic option in nifty_authentication
57
+
58
+ * pluralize second argument for controller in nifty_authentication
59
+
60
+ * don't convert javascript/stylesheet arguments to strings in nifty_layout
61
+
62
+ * store request location and redirect to it when logging in under nifty_authentication
63
+
64
+
65
+ 0.2.4 (May 5th, 2009)
66
+
67
+ * using root_url when no index action in nifty_scaffold
68
+
69
+ * making password editable in user model in nifty_authentication
70
+
71
+ * adding filter_parameter_logging :password in nifty_authentication
72
+
73
+
74
+ 0.2.3 (February 20th, 2009)
75
+
76
+ * fixing nifty_authentication to work with Rails 2.3 application_controller.rb
77
+
78
+ * fixing password field in HAML signup page in nifty_authentication
79
+
80
+
81
+ 0.2.2 (November 11th, 2008)
82
+
83
+ * fixing sessions_path reference in nifty_authentication
84
+
85
+ * adding more validations to user model in nifty_authentication
86
+
87
+ * cleaning up nifty_layout stylesheet
88
+
89
+
90
+ 0.2.1 (November 10th, 2008)
91
+
92
+ * adding missing nifty_authentication files
93
+
94
+
95
+ 0.2.0 (November 4th, 2008)
96
+
97
+ * adding nifty_authentication
98
+
99
+
100
+ 0.1.8 (October 3rd, 2008)
101
+
102
+ * compatibility with RubyGems 1.3
103
+
104
+ * using f.error_messages instead of error_messages_for (thanks Zach Langley)
105
+
106
+
107
+ 0.1.7 (August 15th, 2008)
108
+
109
+ * fixing shoulda tests
110
+
111
+
112
+ 0.1.6 (August 7th, 2008)
113
+
114
+ * adding option to specify Shoulda as testing framework in nifty_scaffold generator
115
+
116
+ * adding options to manually specify rspec or testunit framework in nifty_scaffold generator
117
+
118
+
119
+ 0.1.5 (August 7th, 2008)
120
+
121
+ * adding option to nifty layout to generate HAML views and SASS stylesheets
122
+
123
+ * adding option to nifty scaffold to generate HAML views
124
+
125
+
126
+ 0.1.4 (July 21st, 2008)
127
+
128
+ * using same logic as model spec in model test for scaffold
129
+
130
+ * simplifying model spec generated by scaffold
131
+
132
+ * adding error_messages_for to form partial
133
+
134
+
135
+ 0.1.3 (June 20th, 2008)
136
+
137
+ * using _url in controllers instead of _path
138
+
139
+ * improving the nifty_config default example YAML file
140
+
141
+
142
+ 0.1.2 (May 16th, 2008)
143
+
144
+ * mentioning nifty_layout in nifty_scaffold generator
145
+
146
+ * adding nifty_config generator
147
+
148
+
149
+ 0.1.1 (May 9th, 2008)
150
+
151
+ * adding tests and specs to scaffold generator
152
+
153
+
154
+ 0.1.0 (May 8th, 2008)
155
+
156
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2010 Seivan Heidari
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.
21
+ By reading this fine print your soul is now the exclusive property of WeDoBDD Productions and its Subsidiaries.
22
+ Unauthorized use of seivan gems, images, materials, souls, odors and oxygen is strongly discouraged. We know where you sleep.
23
+ Also, your mum & bring back prop8
data/README.rdoc ADDED
@@ -0,0 +1,38 @@
1
+ == Install
2
+
3
+ gem install seivan-generators
4
+
5
+
6
+ == Usage
7
+ == Included Generators
8
+
9
+ * seivan_html5: generates generic layout, stylesheet, and helper files.
10
+ * seivan_config: generates a config YAML file and loader.
11
+ * seivan_authentication: generates user model with sign up and log in.
12
+
13
+ (TODO)
14
+ * seivan_omniauth: generates initializer with data from config.
15
+
16
+ == Rails 3
17
+
18
+ To use Nifty Generators with Rails 3 you will need to include it in your Gemfile.
19
+
20
+ gem "seivan-generators"
21
+
22
+ The generators use a colon as the separator instead of an underscore.
23
+
24
+ rails g seivan:html5 --haml (no erb so far)
25
+
26
+ rails g seivan:config
27
+ or
28
+ rails g seivan:config google
29
+ then edit the config/google.yml so you can use the GOOGLE[:...] constant
30
+
31
+ rails g seivan:authentication
32
+ Creates user model, users_controller and sessions_controller
33
+
34
+ rails g seivan:authentication account
35
+ Creates account model, accounts_controller and sessions_controller.
36
+
37
+ rails g nifty:authentication Account UserSession
38
+ Creates account model, accounts_controller and user_sessions_controller.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'cucumber'
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:features) do |t|
7
+ t.cucumber_opts = "features --format progress"
8
+ end
9
+
10
+ task :default => :features
@@ -0,0 +1,52 @@
1
+ Feature: Seivan Authentication Generator
2
+ In order to authenticate users
3
+ As a rails developer
4
+ I want to generate some user authentication
5
+
6
+ Scenario: Generate default authentication
7
+ Given a new Rails app
8
+ When I run "rails g seivan:authentication"
9
+ Then I should see the following files
10
+ | app/models/user.rb |
11
+ | app/controllers/users_controller.rb |
12
+ | app/helpers/users_helper.rb |
13
+ | app/controllers/sessions_controller.rb |
14
+ | app/helpers/sessions_helper.rb |
15
+ | lib/controller_authentication.rb |
16
+ | db/migrate |
17
+ And I should see the following in file "config/routes.rb"
18
+ | resources :sessions |
19
+ | resources :users |
20
+ | match 'login' => 'sessions#new', :as => :login |
21
+ | match 'logout' => 'sessions#destroy', :as => :logout |
22
+ | match 'signup' => 'users#new', :as => :signup |
23
+ | match 'user/edit' => 'users#edit', :as => :edit_user |
24
+ And I should see "include ControllerAuthentication" in file "app/controllers/application_controller.rb"
25
+ And I should see "gem "mocha", :group => :test" in file "Gemfile"
26
+ And I should see "gem "bcrypt-ruby", :require => "bcrypt"" in file "Gemfile"
27
+
28
+ Scenario: Generate named authentication
29
+ Given a new Rails app
30
+ When I run "rails g seivan:authentication Account CurrentSession"
31
+ Then I should see the following files
32
+ | app/models/account.rb |
33
+ | app/controllers/accounts_controller.rb |
34
+ | app/helpers/accounts_helper.rb |
35
+ | app/controllers/current_sessions_controller.rb |
36
+ | app/helpers/current_sessions_helper.rb |
37
+ And I should see the following in file "config/routes.rb"
38
+ | resources :current_sessions |
39
+ | resources :accounts |
40
+ | match 'login' => 'current_sessions#new', :as => :login |
41
+ | match 'logout' => 'current_sessions#destroy', :as => :logout |
42
+ | match 'signup' => 'accounts#new', :as => :signup |
43
+ | match 'account/edit' => 'accounts#edit', :as => :edit_account |
44
+
45
+ Scenario: Generate named authentication with rspec
46
+ Given a new Rails app
47
+ When I run "rails g seivan:authentication Account CurrentSession --rspec"
48
+ Then I should see the following files
49
+ | spec/models/account_spec.rb |
50
+ | spec/controllers/accounts_controller_spec.rb |
51
+ | spec/controllers/current_sessions_controller_spec.rb |
52
+
@@ -0,0 +1,17 @@
1
+ Feature: Seivan Config Generator
2
+ In order to have configure an app
3
+ As a rails developer
4
+ I want to generate a config file and manager
5
+
6
+ Scenario: Generate normal config
7
+ Given a new Rails app
8
+ When I run "rails g seivan:config"
9
+ Then I should see file "config/app_config.yml"
10
+ And I should see file "config/initializers/load_app_config.rb"
11
+
12
+ Scenario: Generate named config
13
+ Given a new Rails app
14
+ When I run "rails g seivan:config FooBar"
15
+ Then I should see "FOO_BAR_CONFIG" in file "config/initializers/load_foo_bar_config.rb"
16
+ And I should see "config/foo_bar_config.yml" in file "config/initializers/load_foo_bar_config.rb"
17
+ And I should see file "config/foo_bar_config.yml"
@@ -0,0 +1,47 @@
1
+ Feature: Seivan HTML5 Generator with HAML
2
+ In order to have a layout in HTML5 with HAML
3
+ As a rails developer
4
+ I want to generate a simple layout in HTML5 with HAML
5
+ Background:
6
+ Given a new Rails app
7
+ When I run "rails g seivan:html5 --haml -f"
8
+
9
+ Scenario: Generate application layout with HTMl5 boilerplate
10
+ Then I should see file "app/views/layouts/application.html.haml"
11
+ And I should see "!!! 5" in file "app/views/layouts/application.html.haml"
12
+ And I should see "= render :partial => 'layouts/head'" in file "app/views/layouts/application.html.haml"
13
+ And I should see "= render :partial => 'layouts/header'" in file "app/views/layouts/application.html.haml"
14
+ And I should see "= render :partial => 'layouts/flashes'" in file "app/views/layouts/application.html.haml"
15
+ And I should see "= render :partial => 'layouts/footer'" in file "app/views/layouts/application.html.haml"
16
+ And I should see "= render :partial => 'layouts/javascripts'" in file "app/views/layouts/application.html.haml"
17
+
18
+ Scenario: Generate head partial with rendering stylesheets with a yield :stylesheets
19
+ Then I should see file "app/views/layouts/_head.html.haml"
20
+ And I should see "= render :partial => 'layouts/stylesheets'" in file "app/views/layouts/_head.html.haml"
21
+
22
+ Scenario: Generate stylesheet partial with a yield stylesheet
23
+ Then I should see file "app/views/layouts/_stylesheets.html.haml"
24
+ And I should see "= yield :stylesheets" in file "app/views/layouts/_stylesheets.html.haml"
25
+
26
+ Scenario: Generate header partial inside the header tag
27
+ Then I should see file "app/views/layouts/_header.html.haml"
28
+ And I should see "%header#header" in file "app/views/layouts/application.html.haml"
29
+
30
+ Scenario: Generate flashes partial
31
+ Then I should see file "app/views/layouts/_flashes.html.haml"
32
+ And I should see "%section#flash" in file "app/views/layouts/_flashes.html.haml"
33
+
34
+ Scenario: Generate footer partial under %footer#footer
35
+ Then I should see file "app/views/layouts/_footer.html.haml"
36
+ And I should see "%footer#footer" in file "app/views/layouts/application.html.haml"
37
+ And I should see "%small.copyright" in file "app/views/layouts/_footer.html.haml"
38
+
39
+ Scenario: Generate javascripts partial with a yield :javascripts
40
+ Then I should see file "app/views/layouts/_javascripts.html.haml"
41
+ And I should see "= yield :javascripts" in file "app/views/layouts/_javascripts.html.haml"
42
+
43
+ Scenario: Generate jQuery with jQuery UJS and include them
44
+ Then I should see file "public/javascripts/jquery.js"
45
+ And I should see file "public/javascripts/jquery_ujs.js"
46
+ And I should see "= javascript_include_tag 'jquery.js', 'jquery_ujs', 'application', :cache => true" in file "app/views/layouts/_javascripts.html.haml"
47
+
@@ -0,0 +1,44 @@
1
+ When /^I run "([^\"]*)"$/ do |command|
2
+ system("cd #{@current_directory} && #{command}").should be_true
3
+ end
4
+
5
+ When /^I add "([^\"]*)" to file "([^\"]*)"$/ do |content, short_path|
6
+ path = File.join(@current_directory, short_path)
7
+ File.should exist(path)
8
+ File.open(path, 'a') { |f| f.write(content + "\n") }
9
+ end
10
+
11
+ When /^I replace "([^\"]*)" with "([^\"]*)" in file "([^\"]*)"$/ do |old_content, new_content, short_path|
12
+ path = File.join(@current_directory, short_path)
13
+ File.should exist(path)
14
+ content = File.read(path).gsub(old_content, new_content)
15
+ File.open(path, 'w') { |f| f.write(content) }
16
+ end
17
+
18
+ Then /^I should see file "([^\"]*)"$/ do |path|
19
+ File.should exist(File.join(@current_directory, path))
20
+ end
21
+
22
+ Then /^I should see "(.*)" in file "([^\"]*)"$/ do |content, short_path|
23
+ path = File.join(@current_directory, short_path)
24
+ File.should exist(path)
25
+ File.readlines(path).join.should include(content)
26
+ end
27
+
28
+ Then /^I should see the following files$/ do |table|
29
+ table.raw.flatten.each do |path|
30
+ File.should exist(File.join(@current_directory, path))
31
+ end
32
+ end
33
+
34
+ Then /^I should see the following in file "([^\"]*)"$/ do |short_path, table|
35
+ path = File.join(@current_directory, short_path)
36
+ File.should exist(path)
37
+ table.raw.flatten.each do |content|
38
+ File.readlines(path).join.should include(content)
39
+ end
40
+ end
41
+
42
+ Then /^I should successfully run "([^\"]*)"$/ do |command|
43
+ system("cd #{@current_directory} && #{command}").should be_true
44
+ end
@@ -0,0 +1,6 @@
1
+ Given /^a new Rails app$/ do
2
+ FileUtils.mkdir_p("tmp")
3
+ system("rails new tmp/rails_app").should be_true
4
+ system("ln -s ../../../lib/generators tmp/rails_app/lib/generators").should be_true
5
+ @current_directory = File.expand_path("tmp/rails_app")
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'cucumber'
2
+ require 'rspec'
3
+
4
+ Before do
5
+ FileUtils.rm_rf "tmp/rails_app"
6
+ end
@@ -0,0 +1,7 @@
1
+ RSpec::Matchers.define :exist do |path|
2
+ match do
3
+ File.exist?(path)
4
+ end
5
+ failure_message_for_should { "Expected #{path} to exist but no file found" }
6
+ failure_message_for_should_not { "Expected #{path} to not exist but file was found" }
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Seivan
4
+ module Generators
5
+ class Base < Rails::Generators::Base #:nodoc:
6
+ def self.source_root
7
+ @_seivan_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'seivan', generator_name, 'templates'))
8
+ end
9
+
10
+ def self.banner
11
+ "#{$0} seivan:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
+ end
13
+ end
14
+ end
15
+ end