lib/middleman-blog-drafts/extension.rb in middleman-blog-drafts-0.1.0 vs lib/middleman-blog-drafts/extension.rb in middleman-blog-drafts-0.2.0
- old
+ new
@@ -1,61 +1,29 @@
+require 'middleman-blog-drafts/helpers'
+
module Middleman
module Blog
- module Drafts
- class Options
- attr_accessor :sources, :layout, :permalink, :build
+ class DraftsExtension < ::Middleman::Extension
+ self.supports_multiple_instances = false
- def initialize(options={})
- options.each do |k,v|
- self.send(:"#{k}=", v)
- end
- end
- end
+ option :sources, 'drafts/{title}.html', 'Pattern for matching draft articles (no template extensions)'
+ option :permalink, '/drafts/{title}.html', 'Path draft are served from'
+ option :build, false, 'Whether to include drafts when building the site'
- 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'
+ self.defined_helpers = [ ::Middleman::Blog::Drafts::Helpers ]
- 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
+ def initialize(app, options_hash={}, &block)
+ super
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
+ def after_configuration
+ require 'middleman-blog/blog_data'
+ require 'middleman-blog-drafts/blog_data_extensions'
-
- # Returns the list of drafts on the site.
- # @return [Array<Middleman::Sitemap::Resource>]
- def drafts
- blog.drafts.articles
- end
+ ::Middleman::Blog::BlogData.send :include, Drafts::BlogDataExtensions
+ app.blog.drafts(app, options)
+ app.sitemap.register_resource_list_manipulator(:blog_drafts,
+ app.blog.drafts, false)
end
end
end
-end
+end
\ No newline at end of file