Sha256: dd1df21519d35eb16a982270d44763307b6fb9dfb3df79435dcec5f619b8df98

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

module Octopress
  class Draft < Post

    def set_default_options
      @options['type']      ||= 'draft' 

      if @options['title'].nil? && @options[:type] == 'post'
        raise "Draft not created: Please choose a title.\n".red + "  For example: " + "octopress new draft 'The merits of napping'".yellow
      end

      @options['layout']      = @config['post_layout']
      @options['dir']       ||= ''
      @options['extension'] ||= @config['post_ext']
      @options['template']  ||= @config['post_template']

      if @options['date']
        @options['date'] = convert_date @options['date']
      end
    end

    def path
      name = "#{title_slug}.#{extension}"
      File.join(site.source, '_drafts', name)
    end

    # Create a new post from draft file
    #
    # Sets post options based on draft file contents
    # and options passed to the publish command
    #
    def publish
      @options['date'] ||= read_post_date || Time.now.iso8601
      @options['title'] = read_post_title

      post_options = {
        'title'   => @options['title'],
        'date'    => @options['date'],
        'slug'    => title_slug,
        'content' => read_post_content,
        'dir'     => @options['dir'],
        'type'    => 'post from draft'
      }

      # Create a new post file
      #
      Post.new(site, post_options).write
      
      # Remove the old draft file
      #
      FileUtils.rm @options['path']

    end

    def default_template
      'draft'
    end

    # Draft template defaults
    #
    def default_content

      if @options['date']
        front_matter %w{layout title date}
      else
        front_matter %w{layout title}
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
octopress-3.0.0.rc.26 lib/octopress/draft.rb