splendeo-generators 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (20) hide show
  1. data/rails_generators/splendeo_authentication/templates/authentication.rb +1 -1
  2. data/rails_generators/splendeo_authentication/templates/sessions_controller.rb +6 -5
  3. data/rails_generators/splendeo_authentication/templates/user.rb +1 -1
  4. data/rails_generators/splendeo_authentication/templates/users_controller.rb +1 -1
  5. data/rails_generators/splendeo_authentication/templates/views/erb/login.html.erb +17 -16
  6. data/rails_generators/splendeo_authentication/templates/views/erb/signup.html.erb +13 -21
  7. data/rails_generators/splendeo_authentication/templates/views/haml/login.html.haml +12 -17
  8. data/rails_generators/splendeo_authentication/templates/views/haml/signup.html.haml +11 -22
  9. data/rails_generators/splendeo_layout/templates/config/locales/en.yml +27 -0
  10. data/rails_generators/splendeo_scaffold/splendeo_scaffold_generator.rb +4 -0
  11. data/rails_generators/splendeo_scaffold/templates/actions/destroy.rb +0 -1
  12. data/rails_generators/splendeo_scaffold/templates/actions/edit.rb +0 -1
  13. data/rails_generators/splendeo_scaffold/templates/actions/show.rb +0 -1
  14. data/rails_generators/splendeo_scaffold/templates/actions/update.rb +0 -1
  15. data/rails_generators/splendeo_scaffold/templates/controller.rb +20 -0
  16. data/rails_generators/splendeo_scaffold/templates/views/erb/_form.html.erb +1 -0
  17. data/rails_generators/splendeo_scaffold/templates/views/erb/index.html.erb +1 -1
  18. data/rails_generators/splendeo_scaffold/templates/views/haml/_form.html.haml +1 -0
  19. data/rails_generators/splendeo_scaffold/templates/views/haml/index.html.haml +1 -1
  20. metadata +2 -2
@@ -42,7 +42,7 @@ module Authentication
42
42
 
43
43
  def login_required
44
44
  unless logged_in?
45
- flash[:error] = "You must first log in or sign up before accessing this page."
45
+ flash[:error] = t('flash_error_login_required')
46
46
  store_target_location
47
47
  redirect_to login_url
48
48
  end
@@ -7,9 +7,10 @@ class <%= session_plural_class_name %>Controller < ApplicationController
7
7
  def create
8
8
  @<%= session_singular_name %> = <%= session_class_name %>.new(params[:<%= session_singular_name %>])
9
9
  if @<%= session_singular_name %>.save
10
- flash[:notice] = "Logged in successfully."
10
+ flash[:notice] = t('flash_notice_logged_in')
11
11
  redirect_to_target_or_default(root_url)
12
12
  else
13
+ flash.now[:error] = t('flash_error_invalid_login')
13
14
  render :action => 'new'
14
15
  end
15
16
  end
@@ -17,7 +18,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
17
18
  def destroy
18
19
  @<%= session_singular_name %> = <%= session_class_name %>.find
19
20
  @<%= session_singular_name %>.destroy
20
- flash[:notice] = "You have been logged out."
21
+ flash[:notice] = t('flash_notice_logged_out')
21
22
  redirect_to root_url
22
23
  end
23
24
  <%- else -%>
@@ -28,17 +29,17 @@ class <%= session_plural_class_name %>Controller < ApplicationController
28
29
  <%= user_singular_name %> = <%= user_class_name %>.authenticate(params[:login], params[:password])
29
30
  if <%= user_singular_name %>
30
31
  session[:<%= user_singular_name %>_id] = <%= user_singular_name %>.id
31
- flash[:notice] = "Logged in successfully."
32
+ flash[:notice] = t('flash_notice_logged_in')
32
33
  redirect_to_target_or_default(root_url)
33
34
  else
34
- flash.now[:error] = "Invalid login or password."
35
+ flash.now[:error] = t('flash_error_invalid_login')
35
36
  render :action => 'new'
36
37
  end
37
38
  end
38
39
 
39
40
  def destroy
40
41
  session[:<%= user_singular_name %>_id] = nil
41
- flash[:notice] = "You have been logged out."
42
+ flash[:notice] = t('flash_notice_logged_out')
42
43
  redirect_to root_url
43
44
  end
44
45
  <%- end -%>
@@ -10,7 +10,7 @@ class <%= user_class_name %> < ActiveRecord::Base
10
10
 
11
11
  validates_presence_of :username
12
12
  validates_uniqueness_of :username, :email, :allow_blank => true
13
- validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@"
13
+ validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => t('username_validation_message')
14
14
  validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
15
15
  validates_presence_of :password, :on => :create
16
16
  validates_confirmation_of :password
@@ -9,7 +9,7 @@ class <%= user_plural_class_name %>Controller < ApplicationController
9
9
  <%- unless options[:authlogic] -%>
10
10
  session[:<%= user_singular_name %>_id] = @<%= user_singular_name %>.id
11
11
  <%- end -%>
12
- flash[:notice] = "Thank you for signing up! You are now logged in."
12
+ flash[:notice] = t('flash_notice_signed_up')
13
13
  redirect_to root_url
14
14
  else
15
15
  render :action => 'new'
@@ -1,30 +1,31 @@
1
- <%% title "Log in" %>
1
+ <%% title t('log_in_title') %>
2
2
 
3
- <p>Don't have an account? <%%= link_to "Sign up!", signup_path %></p>
3
+ <p><%%= t('sign_up_message', :url => signup_path) %></p>
4
4
 
5
5
  <%- if options[:authlogic] -%>
6
- <%% form_for @<%= session_singular_name %> do |f| %>
7
- <%%= f.error_messages %>
8
- <p>
9
- <%%= f.label :username %><br />
10
- <%%= f.text_field :username %>
11
- </p>
12
- <p>
13
- <%%= f.label :password %><br />
14
- <%%= f.password_field :password %>
15
- </p>
16
- <p><%%= f.submit "Log in" %></p>
6
+ <%% semantic_form_for @<%= session_singular_name %> do |f| %>
7
+ <%= f.error_message_on :base %>
8
+
9
+ <%% f.inputs do %>
10
+ <%%= f.input :username %>
11
+ <%%= f.input :password %>
12
+ <%% end %>
13
+
14
+ <%% f.buttons do %>
15
+ <%%= f.commit_button t('log_in_button') %>
16
+ <%% end %>
17
+
17
18
  <%% end %>
18
19
  <%- else -%>
19
20
  <%% form_tag <%= session_plural_name %>_path do %>
20
21
  <p>
21
- <%%= label_tag :login, "Username or Email Address" %><br />
22
+ <%%= label_tag :login, t('login_label') %><br />
22
23
  <%%= text_field_tag :login, params[:login] %>
23
24
  </p>
24
25
  <p>
25
- <%%= label_tag :password %><br />
26
+ <%%= label_tag :password, t('password_label') %><br />
26
27
  <%%= password_field_tag :password %>
27
28
  </p>
28
- <p><%%= submit_tag "Log in" %></p>
29
+ <p><%%= submit_tag t('log_in_button') %></p>
29
30
  <%% end %>
30
31
  <%- end -%>
@@ -1,24 +1,16 @@
1
- <%% title "Sign up" %>
1
+ <%% title t('sign_up_title') %>
2
2
 
3
- <p>Already have an account? <%%= link_to "Log in", login_path %>.</p>
3
+ <p><%%= t('log_in_message', :url => login_path) %></p>
4
4
 
5
- <%% form_for @<%= user_singular_name %> do |f| %>
6
- <%%= f.error_messages %>
7
- <p>
8
- <%%= f.label :username %><br />
9
- <%%= f.text_field :username %>
10
- </p>
11
- <p>
12
- <%%= f.label :email, "Email Address" %><br />
13
- <%%= f.text_field :email %>
14
- </p>
15
- <p>
16
- <%%= f.label :password %><br />
17
- <%%= f.password_field :password %>
18
- </p>
19
- <p>
20
- <%%= f.label :password_confirmation, "Confirm Password" %><br />
21
- <%%= f.password_field :password_confirmation %>
22
- </p>
23
- <p><%%= f.submit "Sign up" %></p>
5
+ <%% semantic_form_for @<%= user_singular_name %> do |f| %>
6
+ <%%= f.error_message_on :base %>
7
+ <%% f.inputs do %>
8
+ <%%= f.input :username %>
9
+ <%%= f.input :email %>
10
+ <%%= f.input :password %>
11
+ <%%= f.input :password_confirmation %>
12
+ <%% end %>
13
+ <%% f.buttons do %>
14
+ <%%= f.commit_button t('sign_up_button') %>
15
+ <%% end %>
24
16
  <%% end %>
@@ -1,30 +1,25 @@
1
- - title "Log in"
1
+ - title t('log_in_title')
2
2
 
3
- %p== Don't have an account? #{link_to "Sign up!", signup_path}
3
+ %p== t('sign_up_message', :url => signup_path)
4
4
 
5
5
  <%- if options[:authlogic] -%>
6
- - form_for @<%= session_singular_name %> do |f|
7
- = f.error_messages
8
- %p
9
- = f.label :username
10
- %br
11
- = f.text_field :username
12
- %p
13
- = f.label :password
14
- %br
15
- = f.password_field :password
16
- %p
17
- = f.submit "Log in"
6
+ - semantic_form_for @<%= session_singular_name %> do |f|
7
+ = f.error_message_on :base
8
+ - f.inputs do
9
+ = f.input :username
10
+ = f.input :password
11
+ - f.buttons do
12
+ = f.commit_button t('log_in_button')
18
13
  <%- else -%>
19
14
  - form_tag <%= session_plural_name %>_path do
20
15
  %p
21
- = label_tag :login, "Username or Email Address"
16
+ = label_tag :login, t('login_label')
22
17
  %br
23
18
  = text_field_tag :login, params[:login]
24
19
  %p
25
- = label_tag :password
20
+ = label_tag :password, t('password_label')
26
21
  %br
27
22
  = password_field_tag :password
28
23
  %p
29
- = submit_tag "Log in"
24
+ = submit_tag t('log_in_button')
30
25
  <%- end -%>
@@ -1,24 +1,13 @@
1
- - title "Sign up"
1
+ - title t('sign_up_title')
2
2
 
3
- %p== Already have an account? #{link_to "Log in", login_path}.
3
+ %p=t('log_in_message', :url => login_path)
4
4
 
5
- - form_for @<%= user_singular_name %> do |f|
6
- = f.error_messages
7
- %p
8
- = f.label :username
9
- %br
10
- = f.text_field :username
11
- %p
12
- = f.label :email, "Email Address"
13
- %br
14
- = f.text_field :email
15
- %p
16
- = f.label :password
17
- %br
18
- = f.password_field :password
19
- %p
20
- = f.label :password_confirmation, "Confirm Password"
21
- %br
22
- = f.password_field :password_confirmation
23
- %p
24
- = f.submit "Sign up"
5
+ - semantic_form_for @<%= user_singular_name %> do |f|
6
+ = f.error_message_on :base
7
+ - f.inputs do
8
+ = f.input :username
9
+ = f.input :email
10
+ = f.input :password
11
+ = f.input :password_confirmation
12
+ - f.buttons do
13
+ = f.commit_button t('sign_up_button')
@@ -12,3 +12,30 @@ en:
12
12
  flash_notice_successfully_created: "Successfully created {{model}}"
13
13
  flash_notice_successfully_destroyed: "Successfully destroyed {{model}}"
14
14
  flash_notice_successfully_updated: "Successfully destroyed {{model}}"
15
+
16
+ # Formtastic buttons
17
+ formtastic:
18
+ actions:
19
+ create: "Create {{model}}"
20
+ update: "Update {{model}}"
21
+
22
+ # Authentication
23
+ log_in_button: "Log In"
24
+ log_in_message: "Already have an account? <a href='{{url}}>Log in!</a>"
25
+ log_in_title: "Log In"
26
+ sign_up_button: "Sign Up"
27
+ sign_up_message: "Don't have an account? <a href='{{url}}'>Sign up!</a>"
28
+ sign_up_title: "Sign Up"
29
+ login_label: "Login"
30
+ password_label: "Password"
31
+
32
+ flash_notice_logged_in: "Logged in successfully."
33
+ flash_notice_logged_out: "You have been logged out."
34
+ flash_notice_signed_up: "Thank you for signing up! You are now logged in."
35
+ flash_error_login_required: "You must first log in or sign up before accessing this page."
36
+ flash_error_invalid_login: "Invalid login or password."
37
+
38
+ username_validation_message: "should only contain letters, numbers, or .-_@"
39
+
40
+
41
+
@@ -109,6 +109,10 @@ class SplendeoScaffoldGenerator < Rails::Generator::Base
109
109
  names.all? { |n| action? n.to_s }
110
110
  end
111
111
 
112
+ def actions_with_find
113
+ %w[ show edit update destroy ].select{|a| action?(a)}
114
+ end
115
+
112
116
  def singular_name
113
117
  name.underscore
114
118
  end
@@ -1,5 +1,4 @@
1
1
  def destroy
2
- @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
2
  @<%= singular_name %>.destroy
4
3
  flash[:notice] = t('flash_notice_successfully_destroyed', :model => <%=class_name%>.human_name)
5
4
  redirect_to <%= items_path('url') %>
@@ -1,3 +1,2 @@
1
1
  def edit
2
- @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
2
  end
@@ -1,3 +1,2 @@
1
1
  def show
2
- @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
2
  end
@@ -1,5 +1,4 @@
1
1
  def update
2
- @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
2
  if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
4
3
  flash[:notice] = t('flash_notice_successfully_updated', :model => <%=class_name%>.human_name)
5
4
  redirect_to <%= item_path('url') %>
@@ -1,3 +1,23 @@
1
1
  class <%= plural_class_name %>Controller < ApplicationController
2
+
3
+ <%- if actions_with_find.length > 0 -%>
4
+ before_filter :find_<%= singular_name %>, :only => [ <%= actions_with_find.collect{|a| ":#{a}"}.join(', ') %> ]
5
+ <%- end -%>
6
+
2
7
  <%= controller_methods :actions %>
8
+
9
+ <%- if actions_with_find.length > 0 -%>
10
+ protected
11
+
12
+ def find_<%= singular_name %>
13
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
14
+ rescue ActiveRecord::RecordNotFound => msg
15
+ flash[:error] = msg
16
+ <%- if action?(:index) -%>
17
+ redirect_to :action => :index
18
+ <%- else -%>
19
+ redirect_to root_path
20
+ <%- end -%>
21
+ end
22
+ <%- end -%>
3
23
  end
@@ -1,4 +1,5 @@
1
1
  <%% semantic_form_for @<%= singular_name %> do |f| %>
2
+ <%%= f.error_message_on :base %>
2
3
  <%% f.inputs do %>
3
4
  <%- for attribute in attributes -%>
4
5
  <%%= f.input :<%= attribute.name %> %>
@@ -3,7 +3,7 @@
3
3
  <table>
4
4
  <tr>
5
5
  <%- for attribute in attributes -%>
6
- <th><%= attribute.column.human_name.titleize %></th>
6
+ <th><%%= <%= class_name %>.human_attribute_name('<%= attribute.name %>') %></th>
7
7
  <%- end -%>
8
8
  </tr>
9
9
  <%% for <%= singular_name %> in @<%= plural_name %> %>
@@ -1,4 +1,5 @@
1
1
  - semantic_form_for @<%= singular_name %> do |f|
2
+ = f.error_message_on :base
2
3
  - f.inputs do
3
4
  <%- for attribute in attributes -%>
4
5
  = f.input :<%= attribute.name %>
@@ -3,7 +3,7 @@
3
3
  %table
4
4
  %tr
5
5
  <%- for attribute in attributes -%>
6
- %th <%= attribute.column.human_name %>
6
+ %th= <%= class_name %>.human_attribute_name('<%= attribute.name %>')
7
7
  <%- end -%>
8
8
  - for <%= singular_name %> in @<%= plural_name %>
9
9
  %tr
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Bates