diff --git a/app/controllers/asciicasts_controller.rb b/app/controllers/asciicasts_controller.rb index d5316cb..f73e682 100644 --- a/app/controllers/asciicasts_controller.rb +++ b/app/controllers/asciicasts_controller.rb @@ -1,23 +1,32 @@ class AsciicastsController < ApplicationController PER_PAGE = 20 - before_filter :load_resource, :only => [:edit, :update, :destroy] + before_filter :load_resource, :only => [:show, :edit, :update, :destroy] before_filter :ensure_authenticated!, :only => [:edit, :update, :destroy] before_filter :ensure_owner!, :only => [:edit, :update, :destroy] respond_to :html, :json def index - @asciicasts = Asciicast. - order("created_at DESC"). - page(params[:page]). - per(PER_PAGE) + collection = Asciicast. + order("created_at DESC"). + page(params[:page]). + per(PER_PAGE) + + @asciicasts = AsciicastDecorator.decorate(collection) end def show - @asciicast = AsciicastDecorator.find(params[:id]) - @title = @asciicast.smart_title - respond_with @asciicast.model + respond_to do |format| + format.html do + @asciicast = AsciicastDecorator.new(@asciicast) + @title = @asciicast.smart_title + end + + format.json do + respond_with @asciicast + end + end end def edit diff --git a/app/decorators/asciicast_decorator.rb b/app/decorators/asciicast_decorator.rb index 62b1a58..77878e7 100644 --- a/app/decorators/asciicast_decorator.rb +++ b/app/decorators/asciicast_decorator.rb @@ -4,6 +4,30 @@ class AsciicastDecorator < ApplicationDecorator THUMBNAIL_WIDTH = 20 THUMBNAIL_HEIGHT = 10 + def os + if uname =~ /Linux/ + 'Linux' + elsif uname =~ /Darwin/ + 'OSX' + else + uname.split(' ', 2)[0] + end + end + + def shell_name + File.basename(shell.to_s) + end + + def smart_title + if title.present? + title + elsif command.present? + "$ #{command}" + else + "##{id}" + end + end + def thumbnail if @thumbnail.nil? lines = model.snapshot.split("\n") diff --git a/app/models/asciicast.rb b/app/models/asciicast.rb index 20aaacc..16e948a 100644 --- a/app/models/asciicast.rb +++ b/app/models/asciicast.rb @@ -38,20 +38,6 @@ class Asciicast < ActiveRecord::Base self.terminal_type = data['term']['type'] end - def os - if uname =~ /Linux/ - 'Linux' - elsif uname =~ /Darwin/ - 'OSX' - else - uname.split(' ', 2)[0] - end - end - - def shell_name - File.basename(shell.to_s) - end - def as_json(opts = {}) super :methods => [:escaped_stdout_data, :stdout_timing_data] end @@ -83,14 +69,4 @@ class Asciicast < ActiveRecord::Base end end end - - def smart_title - if title.present? - title - elsif command.present? - "$ #{command}" - else - "##{id}" - end - end end