focus-generator 0.0.1

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 (197) hide show
  1. data/Gemfile +2 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +109 -0
  4. data/Rakefile +10 -0
  5. data/features/fcus_authentication.feature +80 -0
  6. data/features/fcus_config.feature +17 -0
  7. data/features/fcus_layout.feature +20 -0
  8. data/features/fcus_scaffold.feature +80 -0
  9. data/features/step_definitions/common_steps.rb +62 -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/fcus.rb +28 -0
  14. data/lib/generators/fcus/authentication/USAGE +50 -0
  15. data/lib/generators/fcus/authentication/authentication_generator.rb +154 -0
  16. data/lib/generators/fcus/authentication/templates/authlogic_session.rb +2 -0
  17. data/lib/generators/fcus/authentication/templates/controller_authentication.rb +60 -0
  18. data/lib/generators/fcus/authentication/templates/fixtures.yml +24 -0
  19. data/lib/generators/fcus/authentication/templates/migration.rb +20 -0
  20. data/lib/generators/fcus/authentication/templates/sessions_controller.rb +41 -0
  21. data/lib/generators/fcus/authentication/templates/sessions_helper.rb +2 -0
  22. data/lib/generators/fcus/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  23. data/lib/generators/fcus/authentication/templates/tests/rspec/user.rb +83 -0
  24. data/lib/generators/fcus/authentication/templates/tests/rspec/users_controller.rb +56 -0
  25. data/lib/generators/fcus/authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  26. data/lib/generators/fcus/authentication/templates/tests/shoulda/user.rb +85 -0
  27. data/lib/generators/fcus/authentication/templates/tests/shoulda/users_controller.rb +61 -0
  28. data/lib/generators/fcus/authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  29. data/lib/generators/fcus/authentication/templates/tests/testunit/user.rb +88 -0
  30. data/lib/generators/fcus/authentication/templates/tests/testunit/users_controller.rb +53 -0
  31. data/lib/generators/fcus/authentication/templates/user.rb +38 -0
  32. data/lib/generators/fcus/authentication/templates/users_controller.rb +32 -0
  33. data/lib/generators/fcus/authentication/templates/users_helper.rb +2 -0
  34. data/lib/generators/fcus/authentication/templates/views/erb/_form.html.erb +20 -0
  35. data/lib/generators/fcus/authentication/templates/views/erb/edit.html.erb +3 -0
  36. data/lib/generators/fcus/authentication/templates/views/erb/login.html.erb +30 -0
  37. data/lib/generators/fcus/authentication/templates/views/erb/signup.html.erb +5 -0
  38. data/lib/generators/fcus/authentication/templates/views/haml/_form.html.haml +16 -0
  39. data/lib/generators/fcus/authentication/templates/views/haml/edit.html.haml +3 -0
  40. data/lib/generators/fcus/authentication/templates/views/haml/login.html.haml +26 -0
  41. data/lib/generators/fcus/authentication/templates/views/haml/signup.html.haml +5 -0
  42. data/lib/generators/fcus/config/USAGE +23 -0
  43. data/lib/generators/fcus/config/config_generator.rb +24 -0
  44. data/lib/generators/fcus/config/templates/config.yml +8 -0
  45. data/lib/generators/fcus/config/templates/load_config.rb +2 -0
  46. data/lib/generators/fcus/layout/USAGE +25 -0
  47. data/lib/generators/fcus/layout/layout_generator.rb +29 -0
  48. data/lib/generators/fcus/layout/templates/error_messages_helper.rb +23 -0
  49. data/lib/generators/fcus/layout/templates/layout.html.erb +19 -0
  50. data/lib/generators/fcus/layout/templates/layout.html.haml +21 -0
  51. data/lib/generators/fcus/layout/templates/layout_helper.rb +22 -0
  52. data/lib/generators/fcus/layout/templates/stylesheet.css +83 -0
  53. data/lib/generators/fcus/layout/templates/stylesheet.sass +73 -0
  54. data/lib/generators/fcus/scaffold/USAGE +51 -0
  55. data/lib/generators/fcus/scaffold/scaffold_generator.rb +318 -0
  56. data/lib/generators/fcus/scaffold/templates/actions/create.rb +8 -0
  57. data/lib/generators/fcus/scaffold/templates/actions/destroy.rb +5 -0
  58. data/lib/generators/fcus/scaffold/templates/actions/edit.rb +3 -0
  59. data/lib/generators/fcus/scaffold/templates/actions/index.rb +3 -0
  60. data/lib/generators/fcus/scaffold/templates/actions/new.rb +3 -0
  61. data/lib/generators/fcus/scaffold/templates/actions/show.rb +3 -0
  62. data/lib/generators/fcus/scaffold/templates/actions/update.rb +8 -0
  63. data/lib/generators/fcus/scaffold/templates/controller.rb +3 -0
  64. data/lib/generators/fcus/scaffold/templates/fixtures.yml +9 -0
  65. data/lib/generators/fcus/scaffold/templates/helper.rb +2 -0
  66. data/lib/generators/fcus/scaffold/templates/migration.rb +16 -0
  67. data/lib/generators/fcus/scaffold/templates/model.rb +4 -0
  68. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/create.rb +11 -0
  69. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  70. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  71. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/index.rb +4 -0
  72. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/new.rb +4 -0
  73. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/show.rb +4 -0
  74. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/update.rb +11 -0
  75. data/lib/generators/fcus/scaffold/templates/tests/rspec/controller.rb +8 -0
  76. data/lib/generators/fcus/scaffold/templates/tests/rspec/model.rb +7 -0
  77. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  78. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  79. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  80. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  81. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  82. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  83. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  84. data/lib/generators/fcus/scaffold/templates/tests/shoulda/controller.rb +5 -0
  85. data/lib/generators/fcus/scaffold/templates/tests/shoulda/model.rb +7 -0
  86. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/create.rb +11 -0
  87. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  88. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  89. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/index.rb +4 -0
  90. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/new.rb +4 -0
  91. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/show.rb +4 -0
  92. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/update.rb +11 -0
  93. data/lib/generators/fcus/scaffold/templates/tests/testunit/controller.rb +5 -0
  94. data/lib/generators/fcus/scaffold/templates/tests/testunit/model.rb +7 -0
  95. data/lib/generators/fcus/scaffold/templates/views/erb/_form.html.erb +10 -0
  96. data/lib/generators/fcus/scaffold/templates/views/erb/edit.html.erb +14 -0
  97. data/lib/generators/fcus/scaffold/templates/views/erb/index.html.erb +29 -0
  98. data/lib/generators/fcus/scaffold/templates/views/erb/new.html.erb +7 -0
  99. data/lib/generators/fcus/scaffold/templates/views/erb/show.html.erb +20 -0
  100. data/lib/generators/fcus/scaffold/templates/views/haml/_form.html.haml +9 -0
  101. data/lib/generators/fcus/scaffold/templates/views/haml/edit.html.haml +14 -0
  102. data/lib/generators/fcus/scaffold/templates/views/haml/index.html.haml +25 -0
  103. data/lib/generators/fcus/scaffold/templates/views/haml/new.html.haml +7 -0
  104. data/lib/generators/fcus/scaffold/templates/views/haml/show.html.haml +20 -0
  105. data/rails_generators/fcus_authentication/USAGE +50 -0
  106. data/rails_generators/fcus_authentication/fcus_authentication_generator.rb +128 -0
  107. data/rails_generators/fcus_authentication/lib/insert_commands.rb +74 -0
  108. data/rails_generators/fcus_authentication/templates/authentication.rb +61 -0
  109. data/rails_generators/fcus_authentication/templates/authlogic_session.rb +2 -0
  110. data/rails_generators/fcus_authentication/templates/fixtures.yml +24 -0
  111. data/rails_generators/fcus_authentication/templates/migration.rb +20 -0
  112. data/rails_generators/fcus_authentication/templates/sessions_controller.rb +45 -0
  113. data/rails_generators/fcus_authentication/templates/sessions_helper.rb +2 -0
  114. data/rails_generators/fcus_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  115. data/rails_generators/fcus_authentication/templates/tests/rspec/user.rb +83 -0
  116. data/rails_generators/fcus_authentication/templates/tests/rspec/users_controller.rb +26 -0
  117. data/rails_generators/fcus_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  118. data/rails_generators/fcus_authentication/templates/tests/shoulda/user.rb +85 -0
  119. data/rails_generators/fcus_authentication/templates/tests/shoulda/users_controller.rb +27 -0
  120. data/rails_generators/fcus_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  121. data/rails_generators/fcus_authentication/templates/tests/testunit/user.rb +88 -0
  122. data/rails_generators/fcus_authentication/templates/tests/testunit/users_controller.rb +23 -0
  123. data/rails_generators/fcus_authentication/templates/user.rb +42 -0
  124. data/rails_generators/fcus_authentication/templates/users_controller.rb +18 -0
  125. data/rails_generators/fcus_authentication/templates/users_helper.rb +2 -0
  126. data/rails_generators/fcus_authentication/templates/views/erb/login.html.erb +30 -0
  127. data/rails_generators/fcus_authentication/templates/views/erb/signup.html.erb +24 -0
  128. data/rails_generators/fcus_authentication/templates/views/haml/login.html.haml +30 -0
  129. data/rails_generators/fcus_authentication/templates/views/haml/signup.html.haml +24 -0
  130. data/rails_generators/fcus_config/USAGE +23 -0
  131. data/rails_generators/fcus_config/fcus_config_generator.rb +32 -0
  132. data/rails_generators/fcus_config/templates/config.yml +8 -0
  133. data/rails_generators/fcus_config/templates/load_config.rb +2 -0
  134. data/rails_generators/fcus_layout/USAGE +25 -0
  135. data/rails_generators/fcus_layout/fcus_layout_generator.rb +44 -0
  136. data/rails_generators/fcus_layout/templates/helper.rb +22 -0
  137. data/rails_generators/fcus_layout/templates/layout.html.erb +22 -0
  138. data/rails_generators/fcus_layout/templates/layout.html.haml +19 -0
  139. data/rails_generators/fcus_layout/templates/stylesheet.css +81 -0
  140. data/rails_generators/fcus_layout/templates/stylesheet.sass +67 -0
  141. data/rails_generators/fcus_scaffold/USAGE +51 -0
  142. data/rails_generators/fcus_scaffold/fcus_scaffold_generator.rb +232 -0
  143. data/rails_generators/fcus_scaffold/templates/actions/create.rb +9 -0
  144. data/rails_generators/fcus_scaffold/templates/actions/destroy.rb +6 -0
  145. data/rails_generators/fcus_scaffold/templates/actions/edit.rb +3 -0
  146. data/rails_generators/fcus_scaffold/templates/actions/index.rb +3 -0
  147. data/rails_generators/fcus_scaffold/templates/actions/new.rb +3 -0
  148. data/rails_generators/fcus_scaffold/templates/actions/show.rb +3 -0
  149. data/rails_generators/fcus_scaffold/templates/actions/update.rb +9 -0
  150. data/rails_generators/fcus_scaffold/templates/controller.rb +3 -0
  151. data/rails_generators/fcus_scaffold/templates/fixtures.yml +9 -0
  152. data/rails_generators/fcus_scaffold/templates/helper.rb +2 -0
  153. data/rails_generators/fcus_scaffold/templates/migration.rb +16 -0
  154. data/rails_generators/fcus_scaffold/templates/model.rb +3 -0
  155. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  156. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  157. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  158. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  159. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  160. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  161. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  162. data/rails_generators/fcus_scaffold/templates/tests/rspec/controller.rb +8 -0
  163. data/rails_generators/fcus_scaffold/templates/tests/rspec/model.rb +7 -0
  164. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  165. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  166. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  167. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  168. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  169. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  170. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  171. data/rails_generators/fcus_scaffold/templates/tests/shoulda/controller.rb +5 -0
  172. data/rails_generators/fcus_scaffold/templates/tests/shoulda/model.rb +7 -0
  173. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  174. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  175. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  176. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  177. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  178. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  179. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  180. data/rails_generators/fcus_scaffold/templates/tests/testunit/controller.rb +5 -0
  181. data/rails_generators/fcus_scaffold/templates/tests/testunit/model.rb +7 -0
  182. data/rails_generators/fcus_scaffold/templates/views/erb/_form.html.erb +10 -0
  183. data/rails_generators/fcus_scaffold/templates/views/erb/edit.html.erb +14 -0
  184. data/rails_generators/fcus_scaffold/templates/views/erb/index.html.erb +29 -0
  185. data/rails_generators/fcus_scaffold/templates/views/erb/new.html.erb +7 -0
  186. data/rails_generators/fcus_scaffold/templates/views/erb/show.html.erb +20 -0
  187. data/rails_generators/fcus_scaffold/templates/views/haml/_form.html.haml +10 -0
  188. data/rails_generators/fcus_scaffold/templates/views/haml/edit.html.haml +14 -0
  189. data/rails_generators/fcus_scaffold/templates/views/haml/index.html.haml +25 -0
  190. data/rails_generators/fcus_scaffold/templates/views/haml/new.html.haml +7 -0
  191. data/rails_generators/fcus_scaffold/templates/views/haml/show.html.haml +20 -0
  192. data/test/test_fcus_authentication_generator.rb +274 -0
  193. data/test/test_fcus_config_generator.rb +37 -0
  194. data/test/test_fcus_layout_generator.rb +42 -0
  195. data/test/test_fcus_scaffold_generator.rb +534 -0
  196. data/test/test_helper.rb +119 -0
  197. metadata +314 -0
@@ -0,0 +1,32 @@
1
+ class <%= user_plural_class_name %>Controller < ApplicationController
2
+ before_filter :login_required, :except => [:new, :create]
3
+
4
+ def new
5
+ @<%= user_singular_name %> = <%= user_class_name %>.new
6
+ end
7
+
8
+ def create
9
+ @<%= user_singular_name %> = <%= user_class_name %>.new(params[:<%= user_singular_name %>])
10
+ if @<%= user_singular_name %>.save
11
+ <%- unless options[:authlogic] -%>
12
+ session[:<%= user_singular_name %>_id] = @<%= user_singular_name %>.id
13
+ <%- end -%>
14
+ redirect_to root_url, :notice => "Thank you for signing up! You are now logged in."
15
+ else
16
+ render :new
17
+ end
18
+ end
19
+
20
+ def edit
21
+ @<%= user_singular_name %> = current_<%= user_singular_name %>
22
+ end
23
+
24
+ def update
25
+ @<%= user_singular_name %> = current_<%= user_singular_name %>
26
+ if @<%= user_singular_name %>.update_attributes(params[:<%= user_singular_name %>])
27
+ redirect_to root_url, :notice => "Your profile has been updated."
28
+ else
29
+ render :edit
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,2 @@
1
+ module <%= user_plural_class_name %>Helper
2
+ end
@@ -0,0 +1,20 @@
1
+ <%%= form_for @<%= user_singular_name %> do |f| %>
2
+ <%%= f.error_messages %>
3
+ <div class="field">
4
+ <%%= f.label :username %>
5
+ <%%= f.text_field :username %>
6
+ </div>
7
+ <div class="field">
8
+ <%%= f.label :email, "Email Address" %>
9
+ <%%= f.text_field :email %>
10
+ </div>
11
+ <div class="field">
12
+ <%%= f.label :password %>
13
+ <%%= f.password_field :password %>
14
+ </div>
15
+ <div class="field">
16
+ <%%= f.label :password_confirmation, "Confirm Password" %>
17
+ <%%= f.password_field :password_confirmation %>
18
+ </div>
19
+ <div class="actions"><%%= f.submit (@<%= user_singular_name %>.new_record? ? "Sign up" : "Update") %></div>
20
+ <%% end %>
@@ -0,0 +1,3 @@
1
+ <%% title "Update Profile" %>
2
+
3
+ <%%= render "form" %>
@@ -0,0 +1,30 @@
1
+ <%% title "Log in" %>
2
+
3
+ <p>Don't have an account? <%%= link_to "Sign up!", signup_path %></p>
4
+
5
+ <%- if options[:authlogic] -%>
6
+ <%%= form_for @<%= session_singular_name %> do |f| %>
7
+ <%%= f.error_messages %>
8
+ <div class="field">
9
+ <%%= f.label :username %>
10
+ <%%= f.text_field :username %>
11
+ </div>
12
+ <div class="field">
13
+ <%%= f.label :password %>
14
+ <%%= f.password_field :password %>
15
+ </div>
16
+ <div class="actions"><%%= f.submit "Log in" %></div>
17
+ <%% end %>
18
+ <%- else -%>
19
+ <%%= form_tag <%= session_plural_name %>_path do %>
20
+ <div class="field">
21
+ <%%= label_tag :login, "Username or Email Address" %>
22
+ <%%= text_field_tag :login, params[:login] %>
23
+ </div>
24
+ <div class="field">
25
+ <%%= label_tag :password %>
26
+ <%%= password_field_tag :password %>
27
+ </div>
28
+ <div class="actions"><%%= submit_tag "Log in" %></div>
29
+ <%% end %>
30
+ <%- end -%>
@@ -0,0 +1,5 @@
1
+ <%% title "Sign up" %>
2
+
3
+ <p>Already have an account? <%%= link_to "Log in", login_path %>.</p>
4
+
5
+ <%%= render "form" %>
@@ -0,0 +1,16 @@
1
+ = form_for @<%= user_singular_name %> do |f|
2
+ = f.error_messages
3
+ .field
4
+ = f.label :username
5
+ = f.text_field :username
6
+ .field
7
+ = f.label :email, "Email Address"
8
+ = f.text_field :email
9
+ .field
10
+ = f.label :password
11
+ = f.password_field :password
12
+ .field
13
+ = f.label :password_confirmation, "Confirm Password"
14
+ = f.password_field :password_confirmation
15
+ .actions
16
+ = f.submit (@<%= user_singular_name %>.new_record? ? "Sign up" : "Update")
@@ -0,0 +1,3 @@
1
+ - title "Sign up"
2
+
3
+ = render "form"
@@ -0,0 +1,26 @@
1
+ - title "Log in"
2
+
3
+ %p== Don't have an account? #{link_to "Sign up!", signup_path}
4
+
5
+ <%- if options[:authlogic] -%>
6
+ = form_for @<%= session_singular_name %> do |f|
7
+ = f.error_messages
8
+ .field
9
+ = f.label :username
10
+ = f.text_field :username
11
+ .field
12
+ = f.label :password
13
+ = f.password_field :password
14
+ .actions
15
+ = f.submit "Log in"
16
+ <%- else -%>
17
+ - form_tag <%= session_plural_name %>_path do
18
+ .field
19
+ = label_tag :login, "Username or Email Address"
20
+ = text_field_tag :login, params[:login]
21
+ .field
22
+ = label_tag :password
23
+ = password_field_tag :password
24
+ .actions
25
+ = submit_tag "Log in"
26
+ <%- end -%>
@@ -0,0 +1,5 @@
1
+ - title "Sign up"
2
+
3
+ %p== Already have an account? #{link_to "Log in", login_path}.
4
+
5
+ = render "form"
@@ -0,0 +1,23 @@
1
+ Description:
2
+ The fcus_config generator creates YAML file in your config
3
+ directory and an initializer to load this config. The config has a
4
+ separate section for each environment. This is a great place to put
5
+ any config settings you don't want in your app.
6
+
7
+ The config is loaded into a constant called APP_CONFIG by default,
8
+ this changes depending on the name you choose to pass the generator.
9
+ Use this constant to access the config settings like this.
10
+
11
+ APP_CONFIG[:some_setting]
12
+
13
+
14
+ Examples:
15
+ rails generate fcus:config
16
+
17
+ Config: config/app_config.yml
18
+ Initializer: config/initializers/load_app_config.rb
19
+
20
+ rails generate fcus:config passwords
21
+
22
+ Config: config/passwords_config.yml
23
+ Initializer: config/initializers/load_passwords_config.rb
@@ -0,0 +1,24 @@
1
+ require 'generators/fcus'
2
+
3
+ module Fcus
4
+ module Generators
5
+ class ConfigGenerator < Base
6
+ argument :config_name, :type => :string, :default => 'app', :banner => 'config_name'
7
+
8
+ def create_config
9
+ template "load_config.rb", "config/initializers/load_#{file_name}_config.rb"
10
+ copy_file "config.yml", "config/#{file_name}_config.yml"
11
+ end
12
+
13
+ private
14
+
15
+ def file_name
16
+ config_name.underscore
17
+ end
18
+
19
+ def constant_name
20
+ config_name.underscore.upcase
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ development:
2
+ domain: localhost:3000
3
+
4
+ test:
5
+ domain: test.host
6
+
7
+ production:
8
+ domain: example.com
@@ -0,0 +1,2 @@
1
+ raw_config = File.read("#{Rails.root}/config/<%= file_name %>_config.yml")
2
+ <%= constant_name %>_CONFIG = YAML.load(raw_config)[Rails.env].symbolize_keys
@@ -0,0 +1,25 @@
1
+ Description:
2
+ The fcus_layout generator creates a basic layout, stylesheet and
3
+ helper which will give some structure to a starting Rails app.
4
+
5
+ The generator takes one argument which will be the name of the
6
+ layout and stylesheet files. If no argument is passed then it defaults
7
+ to "application".
8
+
9
+ The helper module includes some methods which can be called in any
10
+ template or partial to set variables to be used in the layout, such as
11
+ page title and javascript/stylesheet includes.
12
+
13
+ Examples:
14
+ rails generate fcus:layout
15
+
16
+ Layout: app/views/layouts/application.html.erb
17
+ Stylesheet: public/stylesheets/application.css
18
+ Helper: app/helpers/layout_helper.rb
19
+
20
+
21
+ rails generate fcus:layout admin
22
+
23
+ Layout: app/views/layouts/admin.html.erb
24
+ Stylesheet: public/stylesheets/admin.css
25
+ Helper: app/helpers/layout_helper.rb
@@ -0,0 +1,29 @@
1
+ require 'generators/fcus'
2
+
3
+ module Fcus
4
+ module Generators
5
+ class LayoutGenerator < Base
6
+ argument :layout_name, :type => :string, :default => 'application', :banner => 'layout_name'
7
+
8
+ class_option :haml, :desc => 'Generate HAML for view, and SASS for stylesheet.', :type => :boolean
9
+
10
+ def create_layout
11
+ if options.haml?
12
+ template 'layout.html.haml', "app/views/layouts/#{file_name}.html.haml"
13
+ copy_file 'stylesheet.sass', "public/stylesheets/sass/#{file_name}.sass"
14
+ else
15
+ template 'layout.html.erb', "app/views/layouts/#{file_name}.html.erb"
16
+ copy_file 'stylesheet.css', "public/stylesheets/#{file_name}.css"
17
+ end
18
+ copy_file 'layout_helper.rb', 'app/helpers/layout_helper.rb'
19
+ copy_file 'error_messages_helper.rb', 'app/helpers/error_messages_helper.rb'
20
+ end
21
+
22
+ private
23
+
24
+ def file_name
25
+ layout_name.underscore
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module ErrorMessagesHelper
2
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
3
+ def error_messages_for(*objects)
4
+ options = objects.extract_options!
5
+ options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
6
+ options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
7
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
8
+ unless messages.empty?
9
+ content_tag(:div, :class => "error_messages") do
10
+ list_items = messages.map { |msg| content_tag(:li, msg.html_safe) }
11
+ content_tag(:h2, options[:header_message].html_safe) + content_tag(:p, options[:message].html_safe) + content_tag(:ul, list_items.join.html_safe)
12
+ end
13
+ end
14
+ end
15
+
16
+ module FormBuilderAdditions
17
+ def error_messages(options = {})
18
+ @template.error_messages_for(@object, options)
19
+ end
20
+ end
21
+ end
22
+
23
+ ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
5
+ <%%= stylesheet_link_tag "<%= file_name %>" %>
6
+ <%%= javascript_include_tag :defaults %>
7
+ <%%= csrf_meta_tag %>
8
+ <%%= yield(:head) %>
9
+ </head>
10
+ <body>
11
+ <div id="container">
12
+ <%% flash.each do |name, msg| %>
13
+ <%%= content_tag :div, msg, :id => "flash_#{name}" %>
14
+ <%% end %>
15
+ <%%= content_tag :h1, yield(:title) if show_title? %>
16
+ <%%= yield %>
17
+ </div>
18
+ </body>
19
+ </html>
@@ -0,0 +1,21 @@
1
+ !!!
2
+ %html
3
+
4
+ %head
5
+ %title
6
+ = content_for?(:title) ? yield(:title) : "Untitled"
7
+ %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
8
+ = stylesheet_link_tag "<%= file_name %>"
9
+ = javascript_include_tag :defaults
10
+ = csrf_meta_tag
11
+ = yield(:head)
12
+
13
+ %body
14
+ #container
15
+ - flash.each do |name, msg|
16
+ = content_tag :div, msg, :id => "flash_#{name}"
17
+
18
+ - if show_title?
19
+ %h1= yield(:title)
20
+
21
+ = yield
@@ -0,0 +1,22 @@
1
+ # These helper methods can be called in your template to set variables to be used in the layout
2
+ # This module should be included in all views globally,
3
+ # to do so you may need to add this line to your ApplicationController
4
+ # helper :layout
5
+ module LayoutHelper
6
+ def title(page_title, show_title = true)
7
+ content_for(:title) { h(page_title.to_s) }
8
+ @show_title = show_title
9
+ end
10
+
11
+ def show_title?
12
+ @show_title
13
+ end
14
+
15
+ def stylesheet(*args)
16
+ content_for(:head) { stylesheet_link_tag(*args) }
17
+ end
18
+
19
+ def javascript(*args)
20
+ content_for(:head) { javascript_include_tag(*args) }
21
+ end
22
+ end
@@ -0,0 +1,83 @@
1
+ html, body {
2
+ background-color: #4B7399;
3
+ font-family: Verdana, Helvetica, Arial;
4
+ font-size: 14px;
5
+ }
6
+
7
+ a img {
8
+ border: none;
9
+ }
10
+
11
+ a {
12
+ color: #0000FF;
13
+ }
14
+
15
+ .clear {
16
+ clear: both;
17
+ height: 0;
18
+ overflow: hidden;
19
+ }
20
+
21
+ #container {
22
+ width: 75%;
23
+ margin: 0 auto;
24
+ background-color: #FFF;
25
+ padding: 20px 40px;
26
+ border: solid 1px black;
27
+ margin-top: 20px;
28
+ }
29
+
30
+ #flash_notice, #flash_error, #flash_alert {
31
+ padding: 5px 8px;
32
+ margin: 10px 0;
33
+ }
34
+
35
+ #flash_notice {
36
+ background-color: #CFC;
37
+ border: solid 1px #6C6;
38
+ }
39
+
40
+ #flash_error, #flash_alert {
41
+ background-color: #FCC;
42
+ border: solid 1px #C66;
43
+ }
44
+
45
+ .error_messages {
46
+ width: 400px;
47
+ border: 2px solid #CF0000;
48
+ padding: 0px;
49
+ padding-bottom: 12px;
50
+ margin-bottom: 20px;
51
+ background-color: #f0f0f0;
52
+ font-size: 12px;
53
+ }
54
+
55
+ .error_messages h2 {
56
+ text-align: left;
57
+ font-weight: bold;
58
+ padding: 5px 10px;
59
+ font-size: 12px;
60
+ margin: 0;
61
+ background-color: #c00;
62
+ color: #fff;
63
+ }
64
+
65
+ .error_messages p {
66
+ margin: 8px 10px;
67
+ }
68
+
69
+ .error_messages ul {
70
+ margin: 0;
71
+ }
72
+
73
+ .field_with_errors {
74
+ display: inline;
75
+ }
76
+
77
+ form .field, form .actions {
78
+ margin: 10px 0;
79
+ }
80
+
81
+ form label {
82
+ display: block;
83
+ }