You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
asciinema.org/app/controllers/asciicasts_controller.rb

102 lines
2.2 KiB
Ruby

13 years ago
class AsciicastsController < ApplicationController
before_filter :load_resource, except: [:index]
before_filter :ensure_authenticated!, only: [:edit, :update, :destroy]
respond_to :html, :json
13 years ago
attr_reader :asciicast
13 years ago
def index
render locals: {
page: BrowsePagePresenter.build(
policy_scope(Asciicast),
params[:category],
params[:order],
params[:page]
)
}
end
def show
respond_to do |format|
format.html do
view_counter.increment(asciicast, cookies)
render locals: {
page: AsciicastPagePresenter.build(self, asciicast, current_user, params)
}
end
format.json do
opts = if params[:dl]
{ query: { "response-content-disposition" => "attachment; filename=#{asciicast.download_filename}" } }
else
{}
end
redirect_to asciicast.data_url(opts)
end
format.png do
asciicast_image_generator.generate(asciicast) if asciicast.image_stale?
redirect_to asciicast.image_url
end
end
end
def example
render layout: 'example'
end
def edit
10 years ago
authorize asciicast
end
def update
10 years ago
authorize asciicast
if asciicast_updater.update(asciicast, update_params)
redirect_to asciicast_path(asciicast),
:notice => 'Asciicast was updated.'
else
render :edit
end
end
def destroy
10 years ago
authorize asciicast
if asciicast.destroy
redirect_to profile_path(current_user),
:notice => 'Asciicast was deleted.'
else
redirect_to asciicast_path(asciicast),
12 years ago
:alert => "Oops, we couldn't remove this asciicast. " \
"Try again later."
end
end
private
def load_resource
@asciicast = Asciicast.find_by_id_or_secret_token!(params[:id])
end
def view_counter
@view_counter ||= ViewCounter.new
end
def update_params
10 years ago
params.require(:asciicast).permit(*policy(asciicast).permitted_attributes)
end
def asciicast_updater
AsciicastUpdater.new
end
def asciicast_image_generator
AsciicastImageGenerator.new(self)
end
13 years ago
end