Class: Middleman::Cli::Publish
- Inherits:
-
Thor
- Object
- Thor
- Middleman::Cli::Publish
- Includes:
- Blog::UriTemplates, Thor::Actions
- Defined in:
- lib/middleman-blog-drafts/commands/publish.rb
Overview
This class provides a “publish” command for the middleman CLI.
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Tell Thor to exit with a nonzero exit code on failure.
-
.source_root ⇒ String
Template files are relative to this file.
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
Tell Thor to exit with a nonzero exit code on failure
23 24 25 |
# File 'lib/middleman-blog-drafts/commands/publish.rb', line 23 def self.exit_on_failure? true end |
.source_root ⇒ String
Template files are relative to this file
18 19 20 |
# File 'lib/middleman-blog-drafts/commands/publish.rb', line 18 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#publish(draft_path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/middleman-blog-drafts/commands/publish.rb', line 31 def publish(draft_path) @shared_instance = ::Middleman::Application.server.inst # This only exists when the config.rb sets it! unless @shared_instance.blog.respond_to? :drafts raise Thor::Error.new "You need to activate the drafts extension in config.rb before you can publish an article" end @slug = safe_parameterize draft_path.split('/').last.split('.').first @date = [:date] ? Time.zone.parse([:date]) : Time.zone.now @draft_path = File. draft_path create_file article_path, article_content remove_file draft_path end |