Sha256: 1224392f78f79b922ecbb7ad5b9520025d3d49a050ed35fb643788a3417fee4b

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

require 'middleman-core/cli'

module Middleman
  module Cli
    # This class provides a "draft" command for the middleman CLI.
    class Draft < Thor
      include Thor::Actions

      check_unknown_options!

      namespace :draft

      # Template files are relative to this file
      # @return [String]
      def self.source_root
        File.dirname(__FILE__)
      end

      # Tell Thor to exit with a nonzero exit code on failure
      def self.exit_on_failure?
        true
      end

      desc "draft TITLE", "Create a new draft for a blog article"
      def draft(title)
        shared_instance = ::Middleman::Application.server.inst

        # This only exists when the config.rb sets it!
        if shared_instance.blog.respond_to? :drafts
          @title = title
          @slug = title.parameterize

          draft_path = shared_instance.blog.drafts.options.sources.
            sub(':title', @slug)

          template "draft.tt", File.join(shared_instance.source_dir, draft_path + shared_instance.blog.options.default_extension)
        else
          raise Thor::Error.new "You need to activate the drafts extension in config.rb before you can create an article"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
middleman-blog-drafts-0.1.0 lib/middleman-blog-drafts/commands/draft.rb
middleman-blog-drafts-0.0.2 lib/middleman-blog-drafts/commands/draft.rb
middleman-blog-drafts-0.0.1 lib/middleman-blog-drafts/commands/draft.rb