Sha256: 33f742fb423d8520dfa2021e9af2b0dae0915b3d19ad151dc735e9d5c969f7c2

Contents?: true

Size: 1.94 KB

Versions: 5

Compression:

Stored size: 1.94 KB

Contents

# encoding: UTF-8

module Spontaneous::Plugins::Site
  module Publishing
    extend ActiveSupport::Concern

    module ClassMethods
      def default_publishing_method
        resolve_publishing_method(Spontaneous::Site.config.publishing_method || :immediate)
      end

      def publishing_method
        @publishing_method ||= default_publishing_method
      end

      def publishing_method=(method)
        @publishing_method = resolve_publishing_method(method)
      end

      def resolve_publishing_method(method)
        klass_name = method.to_s.camelize
        begin
          S::Publishing.const_get(klass_name)
        rescue NameError => e
          puts "Unknown method #{method} (#{klass_name})"
          S::Publishing::Immediate
        end
      end

      def publish_pages(page_list=nil)
        publishing_method.new(self.revision).publish_pages(page_list)
      end

      def publish_all
        publishing_method.new(self.revision).publish_all
      end

      def rerender
        publishing_method.new(self.published_revision).rerender_revision
      end

      def publishing_status
        status = rest = nil
        # if r = S::Site.pending_revision
        status, *rest = publishing_method.status.split(':')
        rest = rest.join(':')
        # end
        Hash[[:status, :progress].zip([status, rest])] rescue ""
      end

      def publishing_status=(status)
        publishing_method.status = status
      end

      def with_published(&block)
        S::Content.with_published(&block)
      end

      protected

      def set_published_revision(revision)
        instance = S::State.instance
        instance.published_revision = revision
        instance.revision = revision + 1
        instance.save
      end

      def pending_revision=(revision)
        instance = S::State.instance
        instance.pending_revision = revision
        instance.save
      end
    end # ClassMethods
  end # Publishing
end # Spontaneous::Plugins::Site

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha7 lib/spontaneous/plugins/site/publishing.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/plugins/site/publishing.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/plugins/site/publishing.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/plugins/site/publishing.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/plugins/site/publishing.rb