Sha256: 35fb78502f74c09bccedeab418b5a58b4c43646c9212ba87e6cf732088edb67a

Contents?: true

Size: 1023 Bytes

Versions: 2

Compression:

Stored size: 1023 Bytes

Contents

# encoding: utf-8
module Sunrise
  module Models
    module Post
      def self.included(base)
        base.send :include, InstanceMethods
        base.send :extend,  ClassMethods
      end
      
      module ClassMethods
        def self.extended(base)
          base.send(:include, Utils::Header)
          base.class_eval do
            belongs_to :structure
            
            validates_presence_of :title, :content
	
	          before_save :make_date
          end
        end
      end
      
      module InstanceMethods
      
        def content_without_html
          return nil if self.content.blank?
          self.content.no_html
        end
        
        protected
    
          def make_date
            self.published_at ||= Time.now
      
            self.year  = self.published_at.year  if respond_to?(:year)
            self.month = self.published_at.month if respond_to?(:month)
            self.day   = self.published_at.day   if respond_to?(:day)
          end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sunrise-posts-0.1.4 lib/sunrise/models/post.rb
sunrise-posts-0.1.3 lib/sunrise/models/post.rb