2011-11-23 21:30:09 +00:00
|
|
|
class AsciicastsController < ApplicationController
|
2012-03-04 14:18:09 +00:00
|
|
|
|
2014-02-01 09:29:49 +00:00
|
|
|
before_filter :load_resource, except: [:index]
|
|
|
|
before_filter :ensure_authenticated!, only: [:edit, :update, :destroy]
|
2012-04-03 17:57:47 +00:00
|
|
|
|
2014-06-22 09:44:40 +00:00
|
|
|
respond_to :html, :json
|
2011-11-23 21:30:09 +00:00
|
|
|
|
2014-01-18 10:44:13 +00:00
|
|
|
attr_reader :asciicast
|
|
|
|
|
2011-11-23 21:30:09 +00:00
|
|
|
def index
|
2013-11-18 13:29:18 +00:00
|
|
|
render locals: {
|
2014-02-01 00:26:58 +00:00
|
|
|
page: BrowsePagePresenter.build(params[:category], params[:order],
|
|
|
|
params[:page])
|
2013-11-18 13:29:18 +00:00
|
|
|
}
|
2012-07-25 18:24:20 +00:00
|
|
|
end
|
|
|
|
|
2011-11-27 12:54:10 +00:00
|
|
|
def show
|
2012-08-22 18:26:20 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2014-01-18 10:44:13 +00:00
|
|
|
view_counter.increment(asciicast, cookies)
|
2014-01-18 13:12:10 +00:00
|
|
|
render locals: {
|
2015-03-30 10:02:21 +00:00
|
|
|
page: AsciicastPagePresenter.build(self, asciicast, current_user, params)
|
2014-01-18 13:12:10 +00:00
|
|
|
}
|
2012-08-22 18:26:20 +00:00
|
|
|
end
|
2014-06-22 09:44:40 +00:00
|
|
|
|
|
|
|
format.json do
|
|
|
|
render json: asciicast
|
|
|
|
end
|
2015-03-27 11:35:34 +00:00
|
|
|
|
|
|
|
format.png do
|
2015-03-30 10:27:59 +00:00
|
|
|
asciicast_image_generator.generate(asciicast) if asciicast.image_stale?
|
2015-03-27 11:35:34 +00:00
|
|
|
redirect_to asciicast.image_url
|
|
|
|
end
|
2012-08-22 18:26:20 +00:00
|
|
|
end
|
2012-11-19 22:10:21 +00:00
|
|
|
end
|
2012-08-22 18:26:20 +00:00
|
|
|
|
2013-11-22 20:10:40 +00:00
|
|
|
def example
|
|
|
|
render layout: 'example'
|
|
|
|
end
|
|
|
|
|
2012-04-03 18:47:59 +00:00
|
|
|
def edit
|
2014-07-05 12:59:42 +00:00
|
|
|
authorize asciicast
|
2012-04-03 18:47:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-07-05 12:59:42 +00:00
|
|
|
authorize asciicast
|
|
|
|
|
2014-11-27 12:30:08 +00:00
|
|
|
if asciicast_updater.update(asciicast, update_params)
|
2014-01-18 10:44:13 +00:00
|
|
|
redirect_to asciicast_path(asciicast),
|
2012-12-09 20:25:45 +00:00
|
|
|
:notice => 'Asciicast was updated.'
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
2012-04-03 18:47:59 +00:00
|
|
|
end
|
|
|
|
|
2012-04-03 17:57:47 +00:00
|
|
|
def destroy
|
2014-07-05 12:59:42 +00:00
|
|
|
authorize asciicast
|
|
|
|
|
2014-01-18 10:44:13 +00:00
|
|
|
if asciicast.destroy
|
2012-04-03 17:57:47 +00:00
|
|
|
redirect_to profile_path(current_user),
|
2012-07-25 18:24:20 +00:00
|
|
|
:notice => 'Asciicast was deleted.'
|
2012-04-03 17:57:47 +00:00
|
|
|
else
|
2014-01-18 10:44:13 +00:00
|
|
|
redirect_to asciicast_path(asciicast),
|
2012-07-29 17:43:03 +00:00
|
|
|
:alert => "Oops, we couldn't remove this asciicast. " \
|
|
|
|
"Try again later."
|
2012-04-03 17:57:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_resource
|
|
|
|
@asciicast = Asciicast.find(params[:id])
|
|
|
|
end
|
2012-04-03 18:47:59 +00:00
|
|
|
|
2013-09-25 14:58:44 +00:00
|
|
|
def view_counter
|
|
|
|
@view_counter ||= ViewCounter.new
|
|
|
|
end
|
|
|
|
|
2014-02-12 19:22:20 +00:00
|
|
|
def update_params
|
2014-07-05 12:59:42 +00:00
|
|
|
params.require(:asciicast).permit(*policy(asciicast).permitted_attributes)
|
2014-02-12 19:22:20 +00:00
|
|
|
end
|
|
|
|
|
2014-11-27 12:30:08 +00:00
|
|
|
def asciicast_updater
|
|
|
|
AsciicastUpdater.new
|
|
|
|
end
|
|
|
|
|
2015-03-30 10:27:59 +00:00
|
|
|
def asciicast_image_generator
|
|
|
|
AsciicastImageGenerator.new(self)
|
2015-03-27 11:35:34 +00:00
|
|
|
end
|
|
|
|
|
2011-11-23 21:30:09 +00:00
|
|
|
end
|