Sha256: 70f8e54362c636f663ba681154953ea11e81a75bf4e05c91b94c8ff4da69e385

Contents?: true

Size: 1.97 KB

Versions: 8

Compression:

Stored size: 1.97 KB

Contents

module Voluntary
  module Helpers
    module Show
      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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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