Class: Middleman::Cli::Publish

Inherits:
Thor
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Tell Thor to exit with a nonzero exit code on failure

Returns:

  • (Boolean)


23
24
25
# File 'lib/middleman-blog-drafts/commands/publish.rb', line 23

def self.exit_on_failure?
  true
end

.source_rootString

Template files are relative to this file

Returns:

  • (String)


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 = options[:date] ? Time.zone.parse(options[:date]) : Time.zone.now
  @draft_path = File.expand_path draft_path

  create_file article_path, article_content
  remove_file draft_path
end