From 8b504d8feaf753cf5cef4e0bd300a2a1b11a136e Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 5 Apr 2012 21:35:21 +0200 Subject: [PATCH] Use asciicast title in page title --- app/controllers/asciicasts_controller.rb | 1 + app/helpers/asciicasts_helper.rb | 10 ---------- app/models/asciicast.rb | 10 ++++++++++ app/views/asciicasts/_preview.html.erb | 2 +- app/views/asciicasts/show.html.erb | 2 +- app/views/home/show.html.erb | 2 +- app/views/layouts/application.html.erb | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/controllers/asciicasts_controller.rb b/app/controllers/asciicasts_controller.rb index 0f61582..6e35a51 100644 --- a/app/controllers/asciicasts_controller.rb +++ b/app/controllers/asciicasts_controller.rb @@ -15,6 +15,7 @@ class AsciicastsController < ApplicationController end def show + @title = @asciicast.smart_title respond_with @asciicast end diff --git a/app/helpers/asciicasts_helper.rb b/app/helpers/asciicasts_helper.rb index 1ad0ddd..ecdb47d 100644 --- a/app/helpers/asciicasts_helper.rb +++ b/app/helpers/asciicasts_helper.rb @@ -1,15 +1,5 @@ module AsciicastsHelper - def asciicast_title(asciicast) - if asciicast.title.present? - asciicast.title - elsif asciicast.command.present? - "$ #{asciicast.command}" - else - "##{asciicast.id}" - end - end - def profile_link(asciicast, options = {}) if asciicast.user if options[:avatar] diff --git a/app/models/asciicast.rb b/app/models/asciicast.rb index eb8c35e..20aaacc 100644 --- a/app/models/asciicast.rb +++ b/app/models/asciicast.rb @@ -83,4 +83,14 @@ class Asciicast < ActiveRecord::Base end end end + + def smart_title + if title.present? + title + elsif command.present? + "$ #{command}" + else + "##{id}" + end + end end diff --git a/app/views/asciicasts/_preview.html.erb b/app/views/asciicasts/_preview.html.erb index 4b9553c..f962fa2 100644 --- a/app/views/asciicasts/_preview.html.erb +++ b/app/views/asciicasts/_preview.html.erb @@ -1,6 +1,6 @@
  • - <%= link_to asciicast_title(asciicast), asciicast %> + <%= link_to asciicast.smart_title, asciicast %> <% if asciicast.user || asciicast.username %> diff --git a/app/views/asciicasts/show.html.erb b/app/views/asciicasts/show.html.erb index bb609fe..aa8046b 100644 --- a/app/views/asciicasts/show.html.erb +++ b/app/views/asciicasts/show.html.erb @@ -1,6 +1,6 @@