Sha256: 1f1eebc3ca2ae5557c37b1c41964587233ed9b6f8fae8a0b656f1bbcee3021c5

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Sunrise
  module ManagerHelper
    
    def manage_form_for(object, *args, &block)
      options = args.extract_options!
      
      options[:builder] ||= Sunrise::Views::FormBuilder
      options[:url] ||= (object.new_record? ? new_path : edit_path(:id => object.id))
      
      simple_form_for(object, *(args << options), &block)
    end
    
    def manage_date_tag(datetime, options={})
      options = {:hide_time => datetime.is_a?(Date) }.merge(options)
      tags = []
      
      tags << content_tag(:div, datetime.strftime("%d.%m.%Y"), :class => 'date')
      tags << content_tag(:div, datetime.strftime("%H:%M"), :class => 'time') unless options[:hide_time]
      
      content_tag(:div, tags.join.html_safe, :class => 'date-time')
    end
    
    def render_field(field, record)
      item = record.send(field.name)
      
      if [Date, DateTime, Time].detect{|klass| item.is_a?(klass)}
        manage_date_tag(item)
      elsif item.is_a?(String)
        item =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i ? mail_to(item) : item
      else
        item.to_s
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sunrise-cms-0.3.0.rc app/helpers/sunrise/manager_helper.rb