Class: Octopress::Draft
Constant Summary
Constants inherited from Page
Instance Attribute Summary
Attributes inherited from Page
Instance Method Summary collapse
- #default_template ⇒ Object
- #path ⇒ Object
-
#publish ⇒ Object
Create a new post from draft file.
- #set_default_options ⇒ Object
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_template ⇒ Object
63 64 65 |
# File 'lib/octopress/draft.rb', line 63 def default_template 'draft' end |
#path ⇒ Object
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 |
#publish ⇒ Object
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') = { '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, ).write # Remove the old draft file # FileUtils.rm @options['path'] end |
#set_default_options ⇒ Object
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 @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 |