Move presentation to decorator

openid
Marcin Kulik 13 years ago
parent a8da5220be
commit 49c0d9f324

@ -1,23 +1,32 @@
class AsciicastsController < ApplicationController class AsciicastsController < ApplicationController
PER_PAGE = 20 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_authenticated!, :only => [:edit, :update, :destroy]
before_filter :ensure_owner!, :only => [:edit, :update, :destroy] before_filter :ensure_owner!, :only => [:edit, :update, :destroy]
respond_to :html, :json respond_to :html, :json
def index def index
@asciicasts = Asciicast. collection = Asciicast.
order("created_at DESC"). order("created_at DESC").
page(params[:page]). page(params[:page]).
per(PER_PAGE) per(PER_PAGE)
@asciicasts = AsciicastDecorator.decorate(collection)
end end
def show def show
@asciicast = AsciicastDecorator.find(params[:id]) respond_to do |format|
@title = @asciicast.smart_title format.html do
respond_with @asciicast.model @asciicast = AsciicastDecorator.new(@asciicast)
@title = @asciicast.smart_title
end
format.json do
respond_with @asciicast
end
end
end end
def edit def edit

@ -4,6 +4,30 @@ class AsciicastDecorator < ApplicationDecorator
THUMBNAIL_WIDTH = 20 THUMBNAIL_WIDTH = 20
THUMBNAIL_HEIGHT = 10 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 def thumbnail
if @thumbnail.nil? if @thumbnail.nil?
lines = model.snapshot.split("\n") lines = model.snapshot.split("\n")

@ -38,20 +38,6 @@ class Asciicast < ActiveRecord::Base
self.terminal_type = data['term']['type'] self.terminal_type = data['term']['type']
end 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 = {}) def as_json(opts = {})
super :methods => [:escaped_stdout_data, :stdout_timing_data] super :methods => [:escaped_stdout_data, :stdout_timing_data]
end end
@ -83,14 +69,4 @@ class Asciicast < ActiveRecord::Base
end end
end end
end end
def smart_title
if title.present?
title
elsif command.present?
"$ #{command}"
else
"##{id}"
end
end
end end

Loading…
Cancel
Save