Class: BlogManager

Inherits:
Object
  • Object
show all
Includes:
BluxIndexer
Defined in:
lib/blog_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = {})
	@options = options
	@verbose = options[: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_dirObject

Returns the value of attribute blux_dir.



25
26
27
# File 'lib/blog_manager.rb', line 25

def blux_dir
  @blux_dir
end

#blux_rcObject

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_dirObject

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

#configObject

Returns the value of attribute config.



27
28
29
# File 'lib/blog_manager.rb', line 27

def config
  @config
end

#draft_dirObject

Returns the value of attribute draft_dir.



25
26
27
# File 'lib/blog_manager.rb', line 25

def draft_dir
  @draft_dir
end

#draft_managerObject

Returns the value of attribute draft_manager.



26
27
28
# File 'lib/blog_manager.rb', line 26

def draft_manager
  @draft_manager
end

#homeObject

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_configObject



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

#startObject



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