From 4e959c1fd2bb892102186610ab447f969bd158f4 Mon Sep 17 00:00:00 2001 From: hassaku Date: Tue, 30 Sep 2014 22:07:52 +0900 Subject: [PATCH] Refactor logic in view using decorator. --- app/controllers/plugins_controller.rb | 2 +- app/decorators/plugin_decorator.rb | 13 +++++++++++++ app/models/plugin.rb | 1 + app/views/plugins/recommended.html.haml | 7 +------ 4 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 app/decorators/plugin_decorator.rb diff --git a/app/controllers/plugins_controller.rb b/app/controllers/plugins_controller.rb index c7210ea..6a7b4de 100644 --- a/app/controllers/plugins_controller.rb +++ b/app/controllers/plugins_controller.rb @@ -8,7 +8,7 @@ class PluginsController < ApplicationController end def recommended - @plugins = Plugin.recommended + @plugins = PluginDecorator.decorate_collection(Plugin.recommended) end def updated diff --git a/app/decorators/plugin_decorator.rb b/app/decorators/plugin_decorator.rb new file mode 100644 index 0000000..b8f4529 --- /dev/null +++ b/app/decorators/plugin_decorator.rb @@ -0,0 +1,13 @@ +class PluginDecorator < Draper::Decorator + delegate_all + + def status + if installed? + I18n.t("terms.installed") + elsif processing? + I18n.t("terms.processing") + else + I18n.t("terms.not_installed") + end + end +end diff --git a/app/models/plugin.rb b/app/models/plugin.rb index e3a6a79..1ed7328 100644 --- a/app/models/plugin.rb +++ b/app/models/plugin.rb @@ -8,6 +8,7 @@ class Plugin WORKING = [] include ActiveModel::Model + include Draper::Decoratable attr_accessor :gem_name, :version, :category validates :gem_name, presence: true diff --git a/app/views/plugins/recommended.html.haml b/app/views/plugins/recommended.html.haml index 1a1fcfd..ed1393d 100644 --- a/app/views/plugins/recommended.html.haml +++ b/app/views/plugins/recommended.html.haml @@ -20,12 +20,7 @@ %td = plugin.category %td - - if plugin.installed? - = t("terms.installed") - - elsif plugin.processing? - = t("terms.processing") - - else - = t("terms.not_installed") + = plugin.status %td = link_to t('plugins.view_on_rubygems_org'), plugin.rubygems_org_page, target: "_blank"