Class: BlogManager
Instance Attribute Summary collapse
-
#blux_dir ⇒ Object
Returns the value of attribute blux_dir.
-
#blux_rc ⇒ Object
Returns the value of attribute blux_rc.
-
#blux_tmp_dir ⇒ Object
Returns the value of attribute blux_tmp_dir.
-
#config ⇒ Object
Returns the value of attribute config.
-
#draft_dir ⇒ Object
Returns the value of attribute draft_dir.
-
#draft_manager ⇒ Object
Returns the value of attribute draft_manager.
-
#home ⇒ Object
Returns the value of attribute home.
Instance Method Summary collapse
- #delete(filename) ⇒ Object
-
#initialize(draft_manager, options = {}) ⇒ BlogManager
constructor
A new instance of BlogManager.
- #load_config ⇒ Object
- #publish(filename) ⇒ Object
- #start ⇒ Object
- #update(filename) ⇒ Object
Methods included from BluxIndexer
#check_count, #check_filename, #check_index, #delete_attribute, #delete_index, #ensure_not_deleted, #get_attribute, #load_index, #print_index, #save_index, #set_attribute
Constructor Details
#initialize(draft_manager, options = {}) ⇒ BlogManager
Returns a new instance of BlogManager.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/blog_manager.rb', line 31 def initialize(draft_manager, = {}) @options = @verbose = [:verbose] ||= false @home = ENV['HOME'] @blux_dir = "#{@home}/.blux" @draft_dir = "#{@blux_dir}/draft" @blux_tmp_dir = "#{@blux_dir}/tmp" @blux_rc = "#{@home}/.bluxrc" @draft_manager = draft_manager end |
Instance Attribute Details
#blux_dir ⇒ Object
Returns the value of attribute blux_dir.
25 26 27 |
# File 'lib/blog_manager.rb', line 25 def blux_dir @blux_dir end |
#blux_rc ⇒ Object
Returns the value of attribute blux_rc.
25 26 27 |
# File 'lib/blog_manager.rb', line 25 def blux_rc @blux_rc end |
#blux_tmp_dir ⇒ Object
Returns the value of attribute blux_tmp_dir.
25 26 27 |
# File 'lib/blog_manager.rb', line 25 def blux_tmp_dir @blux_tmp_dir end |
#config ⇒ Object
Returns the value of attribute config.
27 28 29 |
# File 'lib/blog_manager.rb', line 27 def config @config end |
#draft_dir ⇒ Object
Returns the value of attribute draft_dir.
25 26 27 |
# File 'lib/blog_manager.rb', line 25 def draft_dir @draft_dir end |
#draft_manager ⇒ Object
Returns the value of attribute draft_manager.
26 27 28 |
# File 'lib/blog_manager.rb', line 26 def draft_manager @draft_manager end |
#home ⇒ Object
Returns the value of attribute home.
25 26 27 |
# File 'lib/blog_manager.rb', line 25 def home @home end |
Instance Method Details
#delete(filename) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/blog_manager.rb', line 102 def delete(filename) url = @draft_manager.get_attribute(filename, "edit_url") raise "couldn't find an edit url for the draft: #{filename}" unless url publish_cmd = "ruby #{File.dirname(__FILE__)}/publishing/wp_publish.rb" post_cmd = "blux --post-cmd" cmd = "#{publish_cmd} --delete #{url} --config #{@blux_rc} | #{post_cmd}" cmd = cmd + " --verbose" if @verbose send_publish_command(cmd, filename, "failed to delete...") do @draft_manager.delete_draft(filename) end end |
#load_config ⇒ Object
58 59 60 61 62 63 |
# File 'lib/blog_manager.rb', line 58 def load_config @config = BluxConfigurationReader.new @config.load_config @blux_rc, @verbose @draft_manager.setup(@config.launch_editor_cmd, @blux_tmp_dir, @draft_dir, @options) end |
#publish(filename) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/blog_manager.rb', line 65 def publish(filename) raise "this draft has already been published" if published?(filename) title = @draft_manager.get_attribute(filename, "title") || 'no title' categories = @draft_manager.get_attribute(filename, "categories") convert_cmd = "blux --convert -f #{filename}" categories_cmd = categories ? "-c \"#{categories}\"" : "" publish_cmd = "ruby #{File.dirname(__FILE__)}/publishing/wp_publish.rb -t \"#{title}\" --config #{@blux_rc} #{categories_cmd}" set_url_cmd = "blux --set_edit_url -f #{filename}" cmd = "#{convert_cmd} | #{publish_cmd} | #{set_url_cmd}" cmd = cmd + " --verbose" if @verbose send_publish_command(cmd, filename, "failed to publish...") do @draft_manager.set_attribute(filename, "published_time", Time.now) end end |
#start ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/blog_manager.rb', line 44 def start unless Dir.exists?(@blux_dir) Dir.mkdir(@blux_dir) end unless Dir.exists?(@draft_dir) Dir.mkdir(@draft_dir) end unless Dir.exists?(@blux_tmp_dir) Dir.mkdir(@blux_tmp_dir) end end |
#update(filename) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/blog_manager.rb', line 84 def update(filename) title = @draft_manager.get_attribute(filename, "title") || 'no title' categories = @draft_manager.get_attribute(filename, "categories") url = @draft_manager.get_attribute(filename, "edit_url") raise "couldn't find an edit url for the draft: #{filename}" unless url publish_cmd = "ruby #{File.dirname(__FILE__)}/publishing/wp_publish.rb" categories_cmd = categories ? "-c \"#{categories}\"" : "" post_cmd = "blux --post-cmd" cmd = "blux --convert -f #{filename} | #{publish_cmd} -t \"#{title}\" --update #{url} --config #{@blux_rc} #{categories_cmd} | #{post_cmd}" cmd = cmd + " --verbose" if @verbose send_publish_command(cmd, filename, "failed to update...") do @draft_manager.set_attribute(filename, "published_time", Time.now) end end |