Sha256: 4df945cd922ab026889ff25d5a250062dd775c3e73d7cba5e723e0b6d60cd5a2

Contents?: true

Size: 1.68 KB

Versions: 8

Compression:

Stored size: 1.68 KB

Contents

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("activerecord.attributes.general.#{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
    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 
      }
    )
     
    raw result
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
voluntary-0.1.0 app/helpers/show_helper.rb
voluntary-0.1.0.rc4 app/helpers/show_helper.rb
voluntary-0.1.0.rc3 app/helpers/show_helper.rb
voluntary-0.1.0.rc2 app/helpers/show_helper.rb
voluntary-0.1.0.rc1 app/helpers/show_helper.rb
voluntary-0.0.3 app/helpers/show_helper.rb
voluntary-0.0.2 app/helpers/show_helper.rb
voluntary-0.0.1 app/helpers/show_helper.rb