Skip to content

Commit

Permalink
Enhance page title and stylesheet/javascript inclusion patterns inspi…
Browse files Browse the repository at this point in the history
…red by Ryan Bates' nifty_generators.
  • Loading branch information
maxim committed Sep 7, 2009
1 parent 985084d commit 35b9791
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 22 deletions.
1 change: 1 addition & 0 deletions lark_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 0 additions & 3 deletions patterns/default/app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions patterns/default/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +18,6 @@ def create
end

def edit
@page_title = "Select a New Password"
end

def update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class UserSessionsController < ApplicationController
before_filter :require_user, :only => :destroy

def new
@page_title = "Login"
@user_session = UserSession.new
end

Expand Down
4 changes: 0 additions & 4 deletions patterns/default/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions patterns/default/app/helpers/layout_helper.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion patterns/default/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}">
Expand Down
2 changes: 1 addition & 1 deletion patterns/default/app/views/pages/css_test.html.erb
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
2 changes: 2 additions & 0 deletions patterns/default/app/views/pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
Expand Down
2 changes: 1 addition & 1 deletion patterns/default/app/views/password_resets/edit.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
Expand Down
2 changes: 1 addition & 1 deletion patterns/default/app/views/password_resets/new.html.erb
Original file line number Diff line number Diff line change
@@ -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 />
Expand Down
2 changes: 1 addition & 1 deletion patterns/default/app/views/user_sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Login</h1>
<% title "Login" %>
<% semantic_form_for @user_session, :url => user_session_path do |f| %>
<%= f.error_messages %>
Expand Down
2 changes: 1 addition & 1 deletion patterns/default/app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
Expand Down
2 changes: 1 addition & 1 deletion patterns/default/app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Listing users</h1>
<% title "All Users" %>

<table>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion patterns/default/app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Register</h1>
<% title "Register" %>
<% semantic_form_for @user, :url => account_path, :live_validations => true do |f| %>
<%= f.error_messages %>
Expand Down
2 changes: 2 additions & 0 deletions patterns/default/app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% title "My Account" %>

<p>
<b>Login:</b>
<%=h @user.login %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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>

Expand Down

0 comments on commit 35b9791

Please sign in to comment.