Permalink
Browse files

Enhance page title and stylesheet/javascript inclusion patterns inspi…

…red by Ryan Bates' nifty_generators.
  • Loading branch information...
1 parent 985084d commit 35b979163622657d717cf768467a8fd598c7c9b6 @maxim maxim committed Sep 7, 2009
View
@@ -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')
@@ -4,21 +4,18 @@ class AccountsController < ApplicationController
def new
@user = User.new
- @page_title = "Create Account"
render :template => "users/new"
end
#{account_create_block}
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
@@ -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
@@ -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
@@ -3,7 +3,6 @@ class UserSessionsController < ApplicationController
before_filter :require_user, :only => :destroy
def new
- @page_title = "Login"
@user_session = UserSession.new
end
@@ -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
@@ -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
@@ -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}">
@@ -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>
@@ -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 %>
@@ -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 %>
@@ -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 />
@@ -1,4 +1,4 @@
-<h1>Login</h1>
+<% title "Login" %>
<% semantic_form_for @user_session, :url => user_session_path do |f| %>
<%= f.error_messages %>
@@ -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 %>
@@ -1,4 +1,4 @@
-<h1>Listing users</h1>
+<% title "All Users" %>
<table>
<tr>
@@ -1,4 +1,4 @@
-<h1>Register</h1>
+<% title "Register" %>
<% semantic_form_for @user, :url => account_path, :live_validations => true do |f| %>
<%= f.error_messages %>
@@ -1,3 +1,5 @@
+<% title "My Account" %>
+
<p>
<b>Login:</b>
<%=h @user.login %>
@@ -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
@@ -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>

0 comments on commit 35b9791

Please sign in to comment.