Sha256: fcfe89c765f8c70193bdf1427bd3d461cbef0f5786041a9e0adde82e27671c12

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

module HomePage
  module ShowHelper
    def show_attributes(*attributes)
      result = ''
      
      attributes.each {|attribute| result += show_attribute attribute}
      
      raw result
    end
    
    def show_attribute(attribute, options = {})
      title = options[:title] || attribute_translation(attribute)
      value = options[:value] || resource.send(attribute)
      
      value.blank? ? '' : content_tag(:dt, title) + content_tag(:dd, value)
    end
    
    def show_associations(*associations)
      result = ''
      
      associations.each {|association| result += show_association association}
      
      raw result
    end
    
    def show_association(association)
      if association.to_s == association.to_s.pluralize
        return show_attribute(
          association,
          title: t("#{association}.index.title"), 
          value: raw(resource.send(association).map{|a| link_to a.name, a}.join(', '))
        )
      end
      
      title = if general_attribute?(:parent)
        t("attributes.#{association}")
      else
        if resource.send(association) 
          t("activerecord.models.#{root_model_class_name(resource.send(association)).underscore}")
        else 
          t("activerecord.models.#{association}")
        end
      end
      
      if resource.send(association)
        show_attribute(
          association,
          title: title, 
          value: link_to(resource.send(association).try(:name), resource.send(association))
        )  
      else
        ''
      end
    end
    
    def show_actions(options = {})
      result  = content_tag :dt, raw('&nbsp')
      result += content_tag :dd, render(
        partial: 'shared/resource/actions', locals: { 
          type: root_model_class_name(resource).tableize, resource: resource, namespace: options[:namespace] 
        }
      )
       
      raw result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
home_page-0.0.6 app/helpers/home_page/show_helper.rb