Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Enhance page title and stylesheet/javascript inclusion patterns inspi…

…red by Ryan Bates' nifty_generators.
  • Loading branch information...
commit 35b979163622657d717cf768467a8fd598c7c9b6 1 parent 985084d
@maxim maxim authored
Showing with 38 additions and 22 deletions.
  1. +1 −0  lark_template.rb
  2. +0 −3  patterns/default/app/controllers/accounts_controller.rb
  3. +0 −2  patterns/default/app/controllers/pages_controller.rb
  4. +0 −2  patterns/default/app/controllers/password_resets_controller.rb
  5. +0 −1  patterns/default/app/controllers/user_sessions_controller.rb
  6. +0 −4 patterns/default/app/controllers/users_controller.rb
  7. +19 −0 patterns/default/app/helpers/layout_helper.rb
  8. +6 −1 patterns/default/app/views/layouts/application.html.erb
  9. +1 −1  patterns/default/app/views/pages/css_test.html.erb
  10. +2 −0  patterns/default/app/views/pages/home.html.erb
  11. +1 −1  patterns/default/app/views/password_resets/edit.html.erb
  12. +1 −1  patterns/default/app/views/password_resets/new.html.erb
  13. +1 −1  patterns/default/app/views/user_sessions/new.html.erb
  14. +1 −1  patterns/default/app/views/users/edit.html.erb
  15. +1 −1  patterns/default/app/views/users/index.html.erb
  16. +1 −1  patterns/default/app/views/users/new.html.erb
  17. +2 −0  patterns/default/app/views/users/show.html.erb
  18. +0 −1  patterns/require_activation/app/controllers/activations_controller.rb
  19. +1 −1  patterns/require_activation/app/views/activations/new.html.erb
View
1  lark_template.rb
@@ -436,6 +436,7 @@ def install_rails (options)
file 'app/controllers/application_controller.rb', load_pattern('app/controllers/application_controller.rb')
file 'app/helpers/application_helper.rb', load_pattern('app/helpers/application_helper.rb')
+file 'app/helpers/layout_helper.rb', load_pattern('app/helpers/layout_helper.rb')
# initializers
initializer 'requires.rb', load_pattern('config/initializers/requires.rb')
View
3  patterns/default/app/controllers/accounts_controller.rb
@@ -4,7 +4,6 @@ class AccountsController < ApplicationController
def new
@user = User.new
- @page_title = "Create Account"
render :template => "users/new"
end
@@ -12,13 +11,11 @@ def new
def show
find_user
- @page_title = "\#{@user.login} details"
render :template => "users/show"
end
def edit
find_user
- @page_title = "Edit \#{@user.login}"
render :template => "users/edit"
end
View
2  patterns/default/app/controllers/pages_controller.rb
@@ -1,11 +1,9 @@
class PagesController < ApplicationController
def home
- @page_title = '#{current_app_name}'
end
def css_test
- @page_title = "CSS Test"
end
def kaboom
View
2  patterns/default/app/controllers/password_resets_controller.rb
@@ -2,7 +2,6 @@ class PasswordResetsController < ApplicationController
before_filter :load_user_using_perishable_token, :only => [:edit, :update]
def new
- @page_title = "Forgot Password?"
end
def create
@@ -19,7 +18,6 @@ def create
end
def edit
- @page_title = "Select a New Password"
end
def update
View
1  patterns/default/app/controllers/user_sessions_controller.rb
@@ -3,7 +3,6 @@ class UserSessionsController < ApplicationController
before_filter :require_user, :only => :destroy
def new
- @page_title = "Login"
@user_session = UserSession.new
end
View
4 patterns/default/app/controllers/users_controller.rb
@@ -5,24 +5,20 @@ class UsersController < ApplicationController
def index
@users = User.all
- @page_title = "All Users"
end
def new
@user = User.new
- @page_title = "Create Account"
end
#{user_create_block}
def show
find_user
- @page_title = "\#{@user.login} details"
end
def edit
find_user
- @page_title = "Edit \#{@user.login}"
end
def update
View
19 patterns/default/app/helpers/layout_helper.rb
@@ -0,0 +1,19 @@
+module LayoutHelper
+ def title(page_title, show_title = true)
+ @content_for_title = page_title.to_s
+ @show_title = show_title
+ end
+
+ def show_title?
+ @show_title
+ end
+
+ def stylesheet(*args)
+ content_for(:head) { stylesheet_link_tag(*args.map(&:to_s)) }
+ end
+
+ def javascript(*args)
+ args = args.map { |arg| arg == :defaults ? arg : arg.to_s }
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+end
View
7 patterns/default/app/views/layouts/application.html.erb
@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
- <title><%= @page_title || controller.action_name %></title>
+ <title><%= h(yield(:title) || controller.action_name) %></title>
#{extra_stylesheet_tags}
<%= stylesheet_link_tag 'formtastic', 'formtastic_changes', 'application', :media => 'all', :cache => true %>
#{javascript_include_tags}
@@ -13,6 +13,11 @@
<div class="container">
<%= yield :top_menu %>
<%= render :partial => 'layouts/flashes' -%>
+
+ <% if show_title? %>
+ <h1><%=h yield(:title) %></h1>
+ <% end %>
+
<%= yield %>
<div id="footer" class="#{footer_class}">
View
2  patterns/default/app/views/pages/css_test.html.erb
@@ -1,5 +1,5 @@
<!-- Sample Content to Plugin to Template -->
-<h1>CSS Basic Elements</h1>
+<% title 'CSS Basic Elements' %>
<p>The purpose of this HTML is to help determine what default settings are with CSS and to make sure that all possible HTML Elements are included in this HTML so as to not miss any possible Elements when designing a site.</p>
View
2  patterns/default/app/views/pages/home.html.erb
@@ -1,3 +1,5 @@
+<% title '#{current_app_name}', :false %>
+
<% content_for :top_menu do %>
<div id="top_menu" class="#{top_menu_class}">
<% anonymous_only do %>
View
2  patterns/default/app/views/password_resets/edit.html.erb
@@ -1,4 +1,4 @@
-<h1>Change My Password</h1>
+<% title 'Change My Password' %>
<% semantic_form_for @user, :url => password_reset_path, :method => :put, :live_validations => true do |f| %>
<%= f.error_messages %>
View
2  patterns/default/app/views/password_resets/new.html.erb
@@ -1,4 +1,4 @@
-<h1>Reset Password</h1>
+<% title "Forgot Password?" %>
Fill out the form below and instructions to reset your password will be emailed to you:<br />
<br />
View
2  patterns/default/app/views/user_sessions/new.html.erb
@@ -1,4 +1,4 @@
-<h1>Login</h1>
+<% title "Login" %>
<% semantic_form_for @user_session, :url => user_session_path do |f| %>
<%= f.error_messages %>
View
2  patterns/default/app/views/users/edit.html.erb
@@ -1,4 +1,4 @@
-<h1>Edit My Account</h1>
+<% title "Edit My Account" %>
<% semantic_form_for @user, :url => account_path, :live_validations => true do |f| %>
<%= f.error_messages %>
View
2  patterns/default/app/views/users/index.html.erb
@@ -1,4 +1,4 @@
-<h1>Listing users</h1>
+<% title "All Users" %>
<table>
<tr>
View
2  patterns/default/app/views/users/new.html.erb
@@ -1,4 +1,4 @@
-<h1>Register</h1>
+<% title "Register" %>
<% semantic_form_for @user, :url => account_path, :live_validations => true do |f| %>
<%= f.error_messages %>
View
2  patterns/default/app/views/users/show.html.erb
@@ -1,3 +1,5 @@
+<% title "My Account" %>
+
<p>
<b>Login:</b>
<%=h @user.login %>
View
1  patterns/require_activation/app/controllers/activations_controller.rb
@@ -4,7 +4,6 @@ class ActivationsController < ApplicationController
def new
@user = User.find_using_perishable_token(params[:activation_code], 1.week)
raise Exception unless @user && !@user.active?
- @page_title = "Activate Your Account"
end
# TODO: Reset token and resend email on expired token
View
2  patterns/require_activation/app/views/activations/new.html.erb
@@ -1,4 +1,4 @@
-<h1>Activate your account</h1>
+<% title "Activate Your Account" %>
<p>Set your password and click Activate to log in to the site.</p>
Please sign in to comment.
Something went wrong with that request. Please try again.