Update decorators to use new Draper API
This commit is contained in:
parent
4b23abe988
commit
5f53c66639
@ -1,30 +1,6 @@
|
|||||||
class ApplicationDecorator < Draper::Base
|
class ApplicationDecorator < Draper::Decorator
|
||||||
# Lazy Helpers
|
|
||||||
# PRO: Call Rails helpers without the h. proxy
|
|
||||||
# ex: number_to_currency(model.price)
|
|
||||||
# CON: Add a bazillion methods into your decorator's namespace
|
|
||||||
# and probably sacrifice performance/memory
|
|
||||||
#
|
|
||||||
# Enable them by uncommenting this line:
|
|
||||||
# lazy_helpers
|
|
||||||
|
|
||||||
# Shared Decorations
|
delegate_all
|
||||||
# Consider defining shared methods common to all your models.
|
|
||||||
#
|
|
||||||
# Example: standardize the formatting of timestamps
|
|
||||||
#
|
|
||||||
# def formatted_timestamp(time)
|
|
||||||
# h.content_tag :span, time.strftime("%a %m/%d/%y"),
|
|
||||||
# :class => 'timestamp'
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# def created_at
|
|
||||||
# formatted_timestamp(model.created_at)
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# def updated_at
|
|
||||||
# formatted_timestamp(model.updated_at)
|
|
||||||
# end
|
|
||||||
|
|
||||||
def as_json(*args)
|
def as_json(*args)
|
||||||
model.as_json(*args)
|
model.as_json(*args)
|
||||||
@ -33,4 +9,5 @@ class ApplicationDecorator < Draper::Base
|
|||||||
def markdown(text)
|
def markdown(text)
|
||||||
MKD_SAFE_RENDERER.render(text).html_safe
|
MKD_SAFE_RENDERER.render(text).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
class AsciicastDecorator < ApplicationDecorator
|
class AsciicastDecorator < ApplicationDecorator
|
||||||
decorates :asciicast
|
|
||||||
decorates_association :user
|
decorates_association :user
|
||||||
|
|
||||||
THUMBNAIL_WIDTH = 20
|
THUMBNAIL_WIDTH = 20
|
||||||
@ -18,16 +17,16 @@ class AsciicastDecorator < ApplicationDecorator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def terminal_type
|
def terminal_type
|
||||||
asciicast.terminal_type.presence || '?'
|
model.terminal_type.presence || '?'
|
||||||
end
|
end
|
||||||
|
|
||||||
def shell
|
def shell
|
||||||
File.basename(asciicast.shell.to_s)
|
File.basename(model.shell.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def title
|
def title
|
||||||
if asciicast.title.present?
|
if model.title.present?
|
||||||
asciicast.title
|
model.title
|
||||||
elsif command.present?
|
elsif command.present?
|
||||||
"$ #{command}"
|
"$ #{command}"
|
||||||
else
|
else
|
||||||
@ -56,8 +55,8 @@ class AsciicastDecorator < ApplicationDecorator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
if asciicast.description.present?
|
if model.description.present?
|
||||||
text = asciicast.description.to_s
|
text = model.description.to_s
|
||||||
markdown(text)
|
markdown(text)
|
||||||
else
|
else
|
||||||
h.content_tag :em, 'No description.'
|
h.content_tag :em, 'No description.'
|
||||||
@ -83,7 +82,7 @@ class AsciicastDecorator < ApplicationDecorator
|
|||||||
def other_by_user
|
def other_by_user
|
||||||
if user
|
if user
|
||||||
AsciicastDecorator.decorate(
|
AsciicastDecorator.decorate(
|
||||||
user.asciicasts.where('id <> ?', asciicast.id).limit(3)
|
user.asciicasts.where('id <> ?', model.id).limit(3)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
@ -93,8 +92,8 @@ class AsciicastDecorator < ApplicationDecorator
|
|||||||
def author
|
def author
|
||||||
if user
|
if user
|
||||||
user.nickname
|
user.nickname
|
||||||
elsif asciicast.username
|
elsif model.username
|
||||||
"~#{asciicast.username}"
|
"~#{model.username}"
|
||||||
else
|
else
|
||||||
'anonymous'
|
'anonymous'
|
||||||
end
|
end
|
||||||
@ -111,4 +110,5 @@ class AsciicastDecorator < ApplicationDecorator
|
|||||||
line
|
line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
require 'base64'
|
require 'base64'
|
||||||
|
|
||||||
class AsciicastJSONDecorator < ApplicationDecorator
|
class AsciicastJSONDecorator < ApplicationDecorator
|
||||||
decorates :asciicast
|
|
||||||
|
|
||||||
def as_json(*args)
|
def as_json(*args)
|
||||||
data = model.as_json(*args)
|
data = model.as_json(*args)
|
||||||
@ -47,4 +46,5 @@ class AsciicastJSONDecorator < ApplicationDecorator
|
|||||||
|
|
||||||
[data, saved_time]
|
[data, saved_time]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
class CommentDecorator < ApplicationDecorator
|
class CommentDecorator < ApplicationDecorator
|
||||||
decorates :comment
|
|
||||||
|
|
||||||
def created
|
def created
|
||||||
created_at && (h.time_ago_in_words(created_at) + " ago")
|
created_at && (h.time_ago_in_words(created_at) + " ago")
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
class UserDecorator < ApplicationDecorator
|
class UserDecorator < ApplicationDecorator
|
||||||
decorates :user
|
|
||||||
|
|
||||||
def nickname
|
def nickname
|
||||||
"~#{user.nickname}"
|
"~#{user.nickname}"
|
||||||
@ -19,4 +18,5 @@ class UserDecorator < ApplicationDecorator
|
|||||||
h.avatar_image_tag(user)
|
h.avatar_image_tag(user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user