Class: Middleman::Cli::Draft

Inherits:
Thor
  • Object
show all
Includes:
Blog::UriTemplates, Thor::Actions
Defined in:
lib/middleman-blog-drafts/commands/draft.rb

Overview

This class provides a “draft” 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)


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

def self.exit_on_failure?
  true
end

.source_rootString

Template files are relative to this file

Returns:

  • (String)


17
18
19
# File 'lib/middleman-blog-drafts/commands/draft.rb', line 17

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#draft(title) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/middleman-blog-drafts/commands/draft.rb', line 27

def draft(title)
  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 create an article"
  end

  @title = title
  @slug = safe_parameterize title

  path_template = shared_instance.blog.drafts.source_template
  draft_path = apply_uri_template path_template, title: @slug
  draft_path << shared_instance.blog.options.default_extension

  template "draft.tt", File.join(shared_instance.source_dir, draft_path)
end