Sha256: 65aaf5cd776d9a1cd5e77e5447468284469fbe64ed683c0144fff67d792e7acd

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

module Middleman
  module Blog
    module Drafts
      class Options
        attr_accessor :sources, :layout, :permalink, :build

        def initialize(options={})
          options.each do |k,v|
            self.send(:"#{k}=", v)
          end
        end
      end

      class << self
        # Called when user `activate`s your extension
        def registered(app, options_hash={}, &block)
          require 'middleman-blog/extension'
          require 'middleman-blog/blog_data'
          require 'middleman-blog-drafts/draft_article'
          require 'middleman-blog-drafts/blog_data_extensions'

          options = Options.new(options_hash)
          yield options if block_given?

          options.sources   ||= "drafts/:title.html"
          options.permalink ||= "/drafts/:title.html"

          ::Middleman::Blog::BlogData.send :include, BlogDataExtensions
          app.send :include, Helpers

          app.after_configuration do
            options.layout = blog.options.layout
            blog.drafts(self, options)

            sitemap.register_resource_list_manipulator(
                                                     :blog_drafts,
                                                     blog.drafts,
                                                     false
                                                     )
          end
        end
        alias :included :registered
      end

      module Helpers
        # Get a {Resource} with mixed in {BlogArticle} methods representing the current article.
        # @return [Middleman::Sitemap::Resource]
        def current_article
          super || blog.draft(current_resource.path)
        end


        # Returns the list of drafts on the site.
        # @return [Array<Middleman::Sitemap::Resource>]
        def drafts
          blog.drafts.articles
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-blog-drafts-0.1.0 lib/middleman-blog-drafts/extension.rb