Class: Octopress::Draft

Inherits:
Post show all
Defined in:
lib/octopress/draft.rb

Constant Summary

Constants inherited from Page

Page::DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from Page

#site

Instance Method Summary collapse

Methods inherited from Post

#read, #read_post_content, #read_post_yaml, #unpublish

Methods inherited from Page

#content, #convert_date, #date_slug, #default_front_matter, #extension, #initialize, #parse_template, #path_slug, #print_collection_tip, #relative_path, #title_slug, #write

Constructor Details

This class inherits a constructor from Octopress::Page

Instance Method Details

#default_templateObject



63
64
65
# File 'lib/octopress/draft.rb', line 63

def default_template
  'draft'
end

#pathObject



23
24
25
26
27
28
29
30
# File 'lib/octopress/draft.rb', line 23

def path
  name = if @options['path']
    "#{path_slug(@options['path'])}.#{File.extname(@options['path']).sub(/^\./, '')}"
  else
    "#{title_slug}.#{extension}"
  end
  File.join(site.source, '_drafts', name)
end

#publishObject

Create a new post from draft file

Sets post options based on draft file contents and options passed to the publish command



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/octopress/draft.rb', line 37

def publish
  @options['date'] ||= read_post_yaml('date') || Time.now.iso8601
  @options['title'] = read_post_yaml('title')

  post_options = {
    'title'     => @options['title'],
    'date'      => @options['date'],
    'slug'      => path_slug(@options['path']),
    'extension' => File.extname(@options['path']).sub(/^\./, ''),
    'content'   => read_post_content,
    'dir'       => @options['dir'],
    'type'      => "post from draft",
    'write_message' => "Published: #{relative_path(path)}",
    'force'     => @options['force']
  }

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

end

#set_default_optionsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/octopress/draft.rb', line 5

def set_default_options
  @options['type']      ||= 'draft' 
  @options['write_message'] ||= 'New 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['draft_template']

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