Sha256: 501c103e74131538548518a6c20047f30964b210a93769c4738a202eddb86300

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

module WakuwakuModule
  module PostStatus
    class << self
      def list_status(str)
        case str
        when 'approved'    then { text: generate_status(str), klass: 'tag tag-green' }
        when 'repost'      then { text: generate_status(str), klass: 'tag tag-blue' }
        when 'newpost'     then { text: generate_status(str), klass: 'tag tag-blue' }
        when 'rejected'    then { text: generate_status(str), klass: 'tag tag-red' }
        when 'published'   then { text: generate_status(str), klass: 'tag tag-green' }
        when 'reviewing'   then { text: generate_status(str), klass: 'tag tag-yellow' }
        when 'draft'       then { text: generate_status(str), klass: 'tag tag-gray' }
        when 'need_review' then { text: generate_status(str), klass: 'tag tag-yellow' }
        when 'unvailable'  then { text: generate_status(str), klass: 'tag tag-gray' }
        when 'waiting'     then { text: generate_status(str), klass: 'tag tag-red' }
        end
      end
    
      def status_view_editor(post)
        status = post.status
        status = 'newpost'    if status == 'reviewing' && post.count_submit <= 1
        status = 'repost'     if status == 'reviewing' && post.count_submit > 1
        status = 'unvailable' if status.nil?
        generate_span_status(status)
      end
    
      def status_view_translator(status)
        status = 'waiting' if status.nil?
        generate_span_status(status)
      end
    
      def status_view_writer(post)
        status = post.status
        status = 'approved' if status == 'need_review'
        generate_span_status(status)
      end
    
      private
    
      def generate_span_status(status)
        text  = list_status(status).fetch(:text)
        klass = list_status(status).fetch(:klass)
    
        content_tag(:span, text, class: klass)
      end
    
      def generate_status(str)
        I18n.t(".post_status.status.#{str}")
      end
    end
  end  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wakuwaku_module-0.1.5 lib/wakuwaku_module/post_status.rb