diff --git a/app/decorators/application_decorator.rb b/app/decorators/application_decorator.rb index 7c9d9b0..fc2f267 100644 --- a/app/decorators/application_decorator.rb +++ b/app/decorators/application_decorator.rb @@ -1,30 +1,6 @@ -class ApplicationDecorator < Draper::Base - # 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 +class ApplicationDecorator < Draper::Decorator - # Shared Decorations - # 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 + delegate_all def as_json(*args) model.as_json(*args) @@ -33,4 +9,5 @@ class ApplicationDecorator < Draper::Base def markdown(text) MKD_SAFE_RENDERER.render(text).html_safe end + end diff --git a/app/decorators/asciicast_decorator.rb b/app/decorators/asciicast_decorator.rb index dae2e3b..60219a7 100644 --- a/app/decorators/asciicast_decorator.rb +++ b/app/decorators/asciicast_decorator.rb @@ -1,5 +1,4 @@ class AsciicastDecorator < ApplicationDecorator - decorates :asciicast decorates_association :user THUMBNAIL_WIDTH = 20 @@ -18,16 +17,16 @@ class AsciicastDecorator < ApplicationDecorator end def terminal_type - asciicast.terminal_type.presence || '?' + model.terminal_type.presence || '?' end def shell - File.basename(asciicast.shell.to_s) + File.basename(model.shell.to_s) end def title - if asciicast.title.present? - asciicast.title + if model.title.present? + model.title elsif command.present? "$ #{command}" else @@ -56,8 +55,8 @@ class AsciicastDecorator < ApplicationDecorator end def description - if asciicast.description.present? - text = asciicast.description.to_s + if model.description.present? + text = model.description.to_s markdown(text) else h.content_tag :em, 'No description.' @@ -83,7 +82,7 @@ class AsciicastDecorator < ApplicationDecorator def other_by_user if user AsciicastDecorator.decorate( - user.asciicasts.where('id <> ?', asciicast.id).limit(3) + user.asciicasts.where('id <> ?', model.id).limit(3) ) else [] @@ -93,8 +92,8 @@ class AsciicastDecorator < ApplicationDecorator def author if user user.nickname - elsif asciicast.username - "~#{asciicast.username}" + elsif model.username + "~#{model.username}" else 'anonymous' end @@ -111,4 +110,5 @@ class AsciicastDecorator < ApplicationDecorator line end end + end diff --git a/app/decorators/asciicast_json_decorator.rb b/app/decorators/asciicast_json_decorator.rb index 4fdc9a6..5b5fa4c 100644 --- a/app/decorators/asciicast_json_decorator.rb +++ b/app/decorators/asciicast_json_decorator.rb @@ -1,7 +1,6 @@ require 'base64' class AsciicastJSONDecorator < ApplicationDecorator - decorates :asciicast def as_json(*args) data = model.as_json(*args) @@ -47,4 +46,5 @@ class AsciicastJSONDecorator < ApplicationDecorator [data, saved_time] end + end diff --git a/app/decorators/comment_decorator.rb b/app/decorators/comment_decorator.rb index 29c2720..f70da65 100644 --- a/app/decorators/comment_decorator.rb +++ b/app/decorators/comment_decorator.rb @@ -1,5 +1,4 @@ class CommentDecorator < ApplicationDecorator - decorates :comment def created created_at && (h.time_ago_in_words(created_at) + " ago") diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index 6f7ada9..0b843ef 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -1,5 +1,4 @@ class UserDecorator < ApplicationDecorator - decorates :user def nickname "~#{user.nickname}" @@ -19,4 +18,5 @@ class UserDecorator < ApplicationDecorator h.avatar_image_tag(user) end end + end