Blux 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig CHANGED
Binary file
@@ -2,17 +2,18 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{Blux}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Louis Salin"]
9
9
  s.cert_chain = ["/home/louis/Documents/gem_keys/gem-public_cert.pem"]
10
- s.date = %q{2010-10-10}
10
+ s.date = %q{2010-10-23}
11
+ s.default_executable = %q{blux}
11
12
  s.description = %q{An offline blog manager}
12
13
  s.email = %q{louis.phil@gmail.com}
13
- s.executables = ["blux", "blux_textile_to_html", "blux_wp_publish"]
14
- s.extra_rdoc_files = ["COPYING", "README.markdown", "bin/blux", "bin/blux_textile_to_html", "bin/blux_wp_publish", "lib/blog_manager.rb", "lib/blux_config_reader.rb", "lib/blux_option_parser.rb", "lib/draft_manager.rb", "lib/indexer.rb"]
15
- s.files = ["COPYING", "Manifest", "README.markdown", "Rakefile", "bin/blux", "bin/blux_textile_to_html", "bin/blux_wp_publish", "lib/blog_manager.rb", "lib/blux_config_reader.rb", "lib/blux_option_parser.rb", "lib/draft_manager.rb", "lib/indexer.rb", "spec/blog_manager_spec.rb", "spec/blux_config_reader_spec.rb", "spec/draft_manager_spec.rb", "Blux.gemspec"]
14
+ s.executables = ["blux"]
15
+ s.extra_rdoc_files = ["COPYING", "README.markdown", "bin/blux", "lib/textile_to_html.rb", "lib/wp_publish.rb", "lib/blog_manager.rb", "lib/blux_config_reader.rb", "lib/blux_option_parser.rb", "lib/draft_manager.rb", "lib/indexer.rb"]
16
+ s.files = ["COPYING", "Manifest", "README.markdown", "Rakefile", "bin/blux", "lib/textile_to_html.rb", "lib/wp_publish.rb", "lib/blog_manager.rb", "lib/blux_config_reader.rb", "lib/blux_option_parser.rb", "lib/draft_manager.rb", "lib/indexer.rb", "spec/blog_manager_spec.rb", "spec/blux_config_reader_spec.rb", "spec/draft_manager_spec.rb", "Blux.gemspec"]
16
17
  s.homepage = %q{http://github.com/louissalin/blux}
17
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Blux", "--main", "README.markdown"]
18
19
  s.require_paths = ["lib"]
data/Manifest CHANGED
@@ -3,8 +3,8 @@ Manifest
3
3
  README.markdown
4
4
  Rakefile
5
5
  bin/blux
6
- bin/blux_textile_to_html
7
- bin/blux_wp_publish
6
+ lib/textile_to_html.rb
7
+ lib/wp_publish.rb
8
8
  lib/blog_manager.rb
9
9
  lib/blux_config_reader.rb
10
10
  lib/blux_option_parser.rb
@@ -10,7 +10,6 @@ That's it!
10
10
  Blux reads its configuration info from ~/.bluxrc. The first time you run blux, it will create this file for you, but will immediately complain about missing configuration items. Use the following configuration example for a Wordpress blog and edit each line as needed:
11
11
 
12
12
  editor: vim
13
- html_converter: blux_textile_to_html
14
13
 
15
14
  blog: myWordpressBlog
16
15
  author_name: Mr. Author
@@ -19,8 +18,6 @@ Blux reads its configuration info from ~/.bluxrc. The first time you run blux,
19
18
 
20
19
  **editor:** this is the shell command that will be executed to launch your editor of choice
21
20
 
22
- **html_converter:** Blux will use this shell command to convert your blog draft to html. In the example above, Blux will use the blux_textile_to_html script, which is included with this application. The script will transform your post, written in the textile markup language, and convert it to html.
23
-
24
21
  **blog:** this is your Wordpress blog ID
25
22
 
26
23
  **author_name:** the name of the author
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('Blux', '0.0.3') do |p|
5
+ Echoe.new('Blux', '0.0.4') do |p|
6
6
  p.description = 'An offline blog manager'
7
7
  p.url = 'http://github.com/louissalin/blux'
8
8
  p.author = 'Louis Salin'
data/bin/blux CHANGED
@@ -18,6 +18,7 @@
18
18
  # You should have received a copy of the GNU General Public License
19
19
  # along with Blux. If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
+ require 'atom/entry' # sudo gem install atom-tools
21
22
  require "#{File.dirname(__FILE__)}/../lib/blux_option_parser.rb"
22
23
  require "#{File.dirname(__FILE__)}/../lib/blog_manager.rb"
23
24
 
@@ -25,7 +26,8 @@ def validate_command(options)
25
26
  if (options.command != nil)
26
27
  yield options
27
28
  else
28
- STDERR << "No command specified. Use -h for a list of possible commands\n"
29
+ msg = "No command specified. Use -h for a list of possible commands"
30
+ raise RuntimeError, msg
29
31
  end
30
32
  end
31
33
 
@@ -33,7 +35,8 @@ def validate_set_options(options)
33
35
  if options.attributes.length.modulo(2) == 0
34
36
  yield options.attributes[0], options.attributes[1]
35
37
  else
36
- STDERR << "Attribute error: you must specify an attribute name and a value."
38
+ msg = "Attribute error: you must specify an attribute name and a value."
39
+ raise RuntimeError, msg
37
40
  end
38
41
  end
39
42
 
@@ -46,62 +49,105 @@ def check_filename(options, blog_manager)
46
49
  if filename != nil
47
50
  yield filename
48
51
  else
49
- STDERR << "Please specify the draft file you want to work with. If you want to work with the latest created/edited draft, use the --latest option. You can also tell blux to get a draft with a specific title with --title."
52
+ msg = "Please specify the draft file you want to work with.\n"
53
+ msg = msg + " Try using the --latest option to use the latest draft.\n"
54
+ msg = msg + " Or try to get a draft with a specific title with the --title option."
55
+
56
+ raise RuntimeError, msg
50
57
  end
51
58
  end
52
59
 
53
- validate_command(BluxOptionParser.parse(ARGV)) do |options|
54
- puts "#{options}" if options.verbose
55
-
56
- draft_manager = DraftManager.new
57
- mgr = BlogManager.new(draft_manager, :verbose => options.verbose)
58
- mgr.load_config
59
- mgr.start
60
+ begin
61
+ validate_command(BluxOptionParser.parse(ARGV)) do |options|
62
+ draft_manager = DraftManager.new
63
+ mgr = BlogManager.new(draft_manager, :verbose => options.verbose)
64
+ mgr.load_config
65
+ mgr.start
60
66
 
61
- case options.command
62
- when :new
63
- mgr.draft_manager.create_draft
64
- when :edit
65
- check_filename(options, mgr) do |filename|
66
- mgr.draft_manager.edit_draft filename
67
- end
68
- when :list
69
- mgr.draft_manager.list.each do |item|
70
- break if options.filename != nil && options.filename != item
71
- puts "#{item}"
72
- puts " #{mgr.draft_manager.show_info(item)}" if options.list_details
73
- puts " #{mgr.draft_manager.show_preview(item)}" if options.list_preview
74
- end
75
- when :set
76
- check_filename(options, mgr) do |filename|
77
- validate_set_options(options) do |attribute, value|
78
- mgr.draft_manager.set_attribute(filename, attribute, value)
67
+ case options.command
68
+ when :new
69
+ mgr.draft_manager.create_draft
70
+ when :edit
71
+ check_filename(options, mgr) do |filename|
72
+ mgr.draft_manager.edit_draft filename
79
73
  end
80
- end
81
- when :out
82
- check_filename(options, mgr) do |filename|
83
- STDOUT.puts(mgr.draft_manager.output filename)
84
- end
85
- when :convert
86
- check_filename(options, mgr) do |filename|
87
- system "blux --out -f #{filename} | #{mgr.config.html_converter_cmd}"
88
- end
89
- when :publish
90
- check_filename(options, mgr) do |filename|
91
- puts "publishing" if options.verbose
92
- mgr.publish filename
93
- end
94
- when :update
95
- check_filename(options, mgr) do |filename|
96
- puts "updating" if options.verbose
97
- mgr.update filename
98
- end
99
- when :set_edit_url
100
- check_filename(options, mgr) do |filename|
101
- ARGF.each do |url|
74
+ when :list
75
+ mgr.draft_manager.list.each do |item|
76
+ break if options.filename != nil && options.filename != item
77
+ puts "#{item}"
78
+ puts " #{mgr.draft_manager.show_info(item)}" if options.list_details
79
+ puts " #{mgr.draft_manager.show_preview(item)}" if options.list_preview
80
+ end
81
+ when :set
82
+ check_filename(options, mgr) do |filename|
83
+ validate_set_options(options) do |attribute, value|
84
+ mgr.draft_manager.set_attribute(filename, attribute, value)
85
+ end
86
+ end
87
+ when :out
88
+ check_filename(options, mgr) do |filename|
89
+ STDOUT.puts(mgr.draft_manager.output filename)
90
+ end
91
+ when :convert
92
+ check_filename(options, mgr) do |filename|
93
+ convert_cmd = "ruby #{File.dirname(__FILE__)}/../lib/textile_to_html.rb"
94
+ system "blux --out -f #{filename} | #{convert_cmd}"
95
+ end
96
+ when :publish
97
+ check_filename(options, mgr) do |filename|
98
+ puts "publishing" if options.verbose
99
+ mgr.publish filename
100
+ end
101
+ when :update
102
+ check_filename(options, mgr) do |filename|
103
+ puts "updating" if options.verbose
104
+ mgr.update filename
105
+ end
106
+ when :set_edit_url
107
+ check_filename(options, mgr) do |filename|
108
+ switch = nil
109
+ entry = Array.new
110
+ response = Array.new
111
+ url = ""
112
+
113
+ ARGF.each do |line|
114
+ if line == "--entry--\n"
115
+ switch = :entry
116
+ next
117
+ elsif line == "--response--\n"
118
+ switch = :response
119
+ next
120
+ elsif line == "--url--\n"
121
+ switch = :url
122
+ next
123
+ end
124
+
125
+ case (switch)
126
+ when :entry
127
+ entry << line
128
+ when :response
129
+ response << line
130
+ when :url
131
+ url = line
132
+ end
133
+ end
134
+
135
+ entry_text = entry.join
136
+ puts "entry:" if options.verbose
137
+ puts entry_text if options.verbose
138
+
139
+ response_text = response.join
140
+ puts "response:" if options.verbose
141
+ puts response_text if options.verbose
142
+
102
143
  mgr.set_attribute(filename, 'edit_url', url.strip)
103
144
  end
145
+ when :version
146
+ puts "0.0.4"
104
147
  end
105
148
  end
149
+ rescue
150
+ STDERR << "fatal error: #{$!}\n"
151
+ exit 1
106
152
  end
107
153
 
@@ -45,21 +45,20 @@ class BlogManager
45
45
 
46
46
  def start
47
47
  unless Dir.exists?(@blux_dir)
48
- puts "creating #{@blux_dir}\n" if @verbose
49
48
  Dir.mkdir(@blux_dir)
50
49
  end
51
50
 
52
51
  unless Dir.exists?(@draft_dir)
53
- puts "creating #{@draft_dir}\n" if @verbose
54
52
  Dir.mkdir(@draft_dir)
55
53
  end
56
54
 
57
55
  unless Dir.exists?(@blux_tmp_dir)
58
- puts "creating #{@blux_tmp_dir}\n" if @verbose
59
56
  Dir.mkdir(@blux_tmp_dir)
60
57
  end
61
58
 
62
59
  load_index
60
+ puts "blog index:\n" if @verbose
61
+ print_index if @verbose
63
62
  end
64
63
 
65
64
  def load_config
@@ -72,14 +71,25 @@ class BlogManager
72
71
  def publish(filename)
73
72
  title = @draft_manager.get_attribute(filename, "title") || 'no title'
74
73
 
75
- cmd = "blux --convert -f #{filename} | blux_wp_publish -t #{title} --config #{@blux_rc} | blux --set_edit_url -f #{filename}"
74
+ convert_cmd = "blux --convert -f #{filename}"
75
+ publish_cmd = "ruby #{File.dirname(__FILE__)}/wp_publish.rb -t \"#{title}\" --config #{@blux_rc}"
76
+ set_url_cmd = "blux --set_edit_url -f #{filename}"
77
+
78
+ cmd = "#{convert_cmd} | #{publish_cmd} | #{set_url_cmd}"
76
79
  cmd = cmd + " --verbose" if @verbose
77
80
 
78
- puts cmd if @verbose
79
- system cmd
80
-
81
- load_index
82
- set_attribute(filename, :published_time, Time.now)
81
+ if system cmd
82
+ load_index
83
+ set_attribute(filename, :published_time, Time.now)
84
+ else
85
+ msg = "failed to publish...\n"
86
+ msg = msg + ' use the --verbose option for more information' if !@verbose
87
+
88
+ raise SystemExit, msg
89
+ end
90
+
91
+ puts "blog index:\n" if @verbose
92
+ print_index if @verbose
83
93
  end
84
94
 
85
95
  def update(filename)
@@ -88,12 +98,19 @@ class BlogManager
88
98
 
89
99
  raise "couldn't find an edit url for the draft: #{filename}" unless url
90
100
 
91
- cmd = "blux --convert -f #{filename} | blux_wp_publish.rb -t #{title} --update #{url} --config #{@blux_rc}"
101
+ publish_cmd = "ruby #{File.dirname(__FILE__)}/wp_publish.rb"
102
+ cmd = "blux --convert -f #{filename} | #{publish_cmd} -t \"#{title}\" --update #{url} --config #{@blux_rc}"
103
+
104
+ if system cmd
105
+ set_attribute(filename, :published_time, Time.now)
106
+ else
107
+ msg = "failed to update...\n"
108
+ msg = msg + ' use the --verbose option for more information' if !@verbose
109
+
110
+ raise SystemExit, msg
111
+ end
92
112
 
93
- puts cmd if @verbose
94
- system cmd
95
-
96
- set_attribute(filename, :published_time, Time.now)
113
+ puts "blog index:\n" if @verbose
114
+ print_index if @verbose
97
115
  end
98
-
99
116
  end
@@ -17,12 +17,11 @@
17
17
  # You should have received a copy of the GNU General Public License
18
18
  # along with Blux. If not, see <http://www.gnu.org/licenses/>.
19
19
  class BluxConfigurationReader
20
- attr_reader :launch_editor_cmd, :html_converter_cmd
20
+ attr_reader :launch_editor_cmd
21
21
  attr_reader :blog, :author_name, :user_name, :password
22
22
 
23
23
  def load_config(blux_rc, verbose = false)
24
24
  unless File.exists? blux_rc
25
- puts "creating #{blux_rc}\n" if verbose
26
25
  system "touch #{blux_rc}"
27
26
  end
28
27
 
@@ -30,10 +29,6 @@ class BluxConfigurationReader
30
29
  match = line =~ /^editor:\s(.+)$/
31
30
  @launch_editor_cmd = $1
32
31
 
33
- line = `grep html_converter: #{blux_rc}`
34
- match = line =~ /^html_converter:\s(.+)$/
35
- @html_converter_cmd = $1
36
-
37
32
  line = `grep blog: #{blux_rc}`
38
33
  match = line =~ /^blog:\s(.+)$/
39
34
  @blog = $1
@@ -50,34 +45,34 @@ class BluxConfigurationReader
50
45
  match = line =~ /^password:\s(.+)$/
51
46
  @password = $1
52
47
 
53
- puts "editor command: #{@launch_editor_cmd}\n" if verbose
54
48
  validate
55
49
  end
56
50
 
57
51
  private
58
52
  def validate
59
53
  if (@launch_editor_cmd == nil)
60
- STDERR.puts "please specify an editor in .bluxrc: editor: [your editor of choice]\n"
61
- end
62
-
63
- if (@html_converter_cmd == nil)
64
- STDERR.puts "please specify an html converter in .bluxrc: html_converter: [your converter command of choice]\n"
54
+ msg = "please specify an editor in .bluxrc:\n editor: [your editor of choice]"
55
+ raise RuntimeError, msg
65
56
  end
66
57
 
67
58
  if (@blog == nil)
68
- STDERR.puts "please specify your wordpress blog name in .bluxrc: blog: [your blog]\n"
59
+ msg = "please specify your wordpress blog name in .bluxrc:\n blog: [your blog]"
60
+ raise RuntimeError, msg
69
61
  end
70
62
 
71
63
  if (@author_name == nil)
72
- STDERR.puts "please specify an author name in .bluxrc: author_name: [your name]\n"
64
+ msg = "please specify an author name in .bluxrc:\n author_name: [your name]"
65
+ raise RuntimeError, msg
73
66
  end
74
67
 
75
68
  if (@user_name == nil)
76
- STDERR.puts "please specify your wordpress user name in .bluxrc: user_name: [your user name]\n"
69
+ msg = "please specify your wordpress user name in .bluxrc:\n user_name: [your user name]"
70
+ raise RuntimeError, msg
77
71
  end
78
72
 
79
73
  if (@password == nil)
80
- STDERR.puts "please specify your wordpress password in .bluxrc: password: [your password]\n"
74
+ msg = "please specify your wordpress password in .bluxrc:\n password: [your password]"
75
+ raise RuntimeError, msg
81
76
  end
82
77
  end
83
78
  end
@@ -90,6 +90,10 @@ class BluxOptionParser
90
90
  options.verbose = true
91
91
  end
92
92
 
93
+ opts.on("--version", "print version information") do
94
+ options.command = :version
95
+ end
96
+
93
97
  opts.on_tail("-h", "--help", "show this message") do
94
98
  puts opts
95
99
  exit
@@ -26,6 +26,7 @@ class DraftManager
26
26
  attr_reader :launch_editor_cmd
27
27
  attr_reader :temp_dir, :draft_dir
28
28
  attr_reader :index
29
+ attr_reader :index_file
29
30
 
30
31
  include BluxIndexer
31
32
 
@@ -37,39 +38,56 @@ class DraftManager
37
38
  @draft_dir = draft_dir
38
39
  @index_file = "#{@draft_dir}/.draft_index"
39
40
 
40
- system "touch #{@index_file}" unless File.exists? @index_file
41
+ value = true
42
+ value = system "touch #{@index_file}" unless File.exists? @index_file
41
43
 
42
- load_index
44
+ if value
45
+ load_index
46
+ print_index if @verbose
47
+ else
48
+ msg = 'could not create the draft index file'
49
+ raise RuntimeError, msg
50
+ end
43
51
  end
44
52
 
45
53
  def create_draft
46
54
  temp_file = Tempfile.new('draft', @temp_dir)
47
55
  temp_file.close
48
56
 
49
- puts "created temp file #{temp_file.path}\nlaunching editor\n" if @verbose
50
-
51
- system "#{@launch_editor_cmd} #{temp_file.path}"
52
-
53
- puts "editor closed. File size: #{temp_file.size}\n" if @verbose
54
- if temp_file.size > 0
55
- system "mv #{temp_file.path} #{@draft_dir}"
57
+ if system "#{@launch_editor_cmd} #{temp_file.path}"
58
+ if temp_file.size > 0
59
+ move_temp_file temp_file.path
60
+ end
61
+ else
62
+ msg = "couldn't launch editor with command #{@launch_editor_cmd}"
63
+ raise RuntimeError, msg
64
+ end
56
65
 
57
- index_key = File.basename(temp_file.path)
58
- puts "adding #{index_key} to draft index\n" if @verbose
66
+ print_index if @verbose
67
+ end
68
+
69
+ def move_temp_file(tempfile)
70
+ if system "mv #{tempfile} #{@draft_dir}"
71
+ index_key = File.basename(tempfile)
59
72
  @index[index_key] = {:creation_time => Time.now.to_s}
60
73
  save_index
74
+ else
75
+ msg = "failed to move the temp file to the draft folder"
76
+ raise RuntimeError, msg
61
77
  end
62
78
  end
63
79
 
64
80
  def edit_draft(filename)
65
- puts "editing draft #{filename}" if @verbose
66
-
67
81
  check_filename(filename) do |draft_filename|
68
- puts "editing: #{@launch_editor_cmd} #{draft_filename}" if @verbose
69
-
70
- system "#{@launch_editor_cmd} #{draft_filename}"
71
- set_attribute(filename, "edited_time", Time.now.to_s)
82
+ if system "#{@launch_editor_cmd} #{draft_filename}"
83
+ set_attribute(filename, "edited_time", Time.now.to_s)
84
+ else
85
+ msg = "couldn't launch editor with command #{@launch_editor_cmd}"
86
+ raise RuntimeError, msg
87
+ end
72
88
  end
89
+
90
+ print_index if @verbose
73
91
  end
74
92
 
75
93
  def list
@@ -25,12 +25,13 @@ module BluxIndexer
25
25
  end
26
26
 
27
27
  def check_filename(filename)
28
- draft_filename = "#{@draft_dir}/#{filename}"
28
+ draft_filename = "#{self.draft_dir}/#{filename}"
29
29
 
30
30
  if (File.exists?(draft_filename))
31
31
  yield draft_filename
32
32
  else
33
- STDERR.puts "draft filename #{filename} does not exist\n"
33
+ msg = "draft filename #{filename} does not exist"
34
+ raise RuntimeError, msg
34
35
  end
35
36
  end
36
37
 
@@ -42,14 +43,13 @@ module BluxIndexer
42
43
  unique_title = false if (@index[key][attr_key.to_s] == attr_val)
43
44
  end
44
45
 
45
- STDERR.puts "title '#{attr_val}' is not unique\n" unless unique_title
46
- unique_title
46
+ STDERR << "warning: title '#{attr_val}' is not unique\n" unless unique_title
47
+ true
47
48
  end
48
49
 
49
50
  def set_attribute(filename, key, val)
50
51
  check_index(filename) do |index|
51
52
  if check_title(filename, key, val)
52
- puts "setting attribute #{key} to #{val} in index #{@index_file}" if @verbose
53
53
  index[key.to_s] = val
54
54
  save_index
55
55
  end
@@ -73,12 +73,12 @@ module BluxIndexer
73
73
  if @index.keys.length > 0
74
74
  yield
75
75
  else
76
- STDERR.puts "there is currently no saved index\n"
76
+ msg = "there is currently no saved index"
77
+ raise RuntimeError, msg
77
78
  end
78
79
  end
79
80
 
80
81
  def load_index
81
- puts "creating #{@index_file}\n" if @verbose
82
82
  system "touch #{@index_file}" unless File.exists? @index_file
83
83
 
84
84
  str = ''
@@ -90,9 +90,12 @@ module BluxIndexer
90
90
  end
91
91
 
92
92
  def save_index
93
- puts "saving index: #{@index.to_json}\n" if @verbose
94
93
  File.open(@index_file, 'w') do |f|
95
94
  f.write(@index.to_json) if @index
96
95
  end
97
96
  end
97
+
98
+ def print_index
99
+ puts @index.to_json + "\n" if @verbose
100
+ end
98
101
  end
@@ -10,7 +10,7 @@ require 'optparse'
10
10
  require 'net/http'
11
11
  require 'atom/entry' # sudo gem install atom-tools
12
12
  require 'atom/collection'
13
- require "#{File.dirname(__FILE__)}/../lib/blux_config_reader"
13
+ require "#{File.dirname(__FILE__)}/blux_config_reader"
14
14
 
15
15
 
16
16
  #
@@ -134,6 +134,13 @@ h.always_auth = :basic
134
134
  c = Atom::Collection.new(base + "/posts", h)
135
135
  if command == :post
136
136
  res = c.post! entry
137
+ puts "--entry--"
138
+ puts entry
139
+
140
+ puts "--response--"
141
+ puts res
142
+
143
+ puts "--url--"
137
144
  puts Atom::Entry.parse(res.read_body).edit_url
138
145
  elsif command == :put
139
146
  entry.edit_url = entry_id
@@ -9,6 +9,7 @@ describe BlogManager do
9
9
  @draft_dir = "#{@blux_dir}/draft"
10
10
 
11
11
  Dir.mkdir(@blux) unless Dir.exists?(@blux)
12
+ Dir.mkdir(@draft_dir) unless Dir.exists?(@draft_dir)
12
13
 
13
14
  def STDERR.puts(str) end
14
15
 
@@ -26,7 +27,7 @@ describe BlogManager do
26
27
 
27
28
  context "loading with no config file" do
28
29
  before :each do
29
- @manager.load_config
30
+ lambda {@manager.load_config}.should raise_error
30
31
  end
31
32
 
32
33
  it "should create an empty config file it doesn't exist" do
@@ -103,22 +104,25 @@ describe BlogManager do
103
104
  f.write('{"draft5.67":{"a":1,"b":2}}')
104
105
  end
105
106
 
107
+ @draft_mgr.stub!(:get_attribute).and_return("title")
108
+
106
109
  @manager.load_config
107
110
  @manager.start
108
- @manager.stub!(:system).and_return(nil)
109
111
 
110
112
  system "touch #{@manager.draft_dir}/draft5.67"
113
+
114
+ @manager.stub!(:system).and_return(true)
111
115
  end
112
116
 
113
117
  it "should send the proper command" do
114
- @manager.should_receive(:system).with("blux --convert -f draft5.67 | blux_wp_publish -t no title --config #{@blux_rc} | blux --set_edit_url -f draft5.67")
118
+ @manager.should_receive(:system).with("blux --convert -f draft5.67 | ruby #{File.dirname(__FILE__)[0..-6]}/lib/wp_publish.rb -t title --config #{@blux_rc} | blux --set_edit_url -f draft5.67")
115
119
  @manager.publish 'draft5.67'
116
120
  end
117
121
 
118
122
  it "should send the command with the title included if it exists" do
119
123
  @draft_mgr.stub!(:get_attribute).and_return('bla')
120
124
 
121
- @manager.should_receive(:system).with("blux --convert -f draft5.67 | blux_wp_publish -t bla --config #{@blux_rc} | blux --set_edit_url -f draft5.67")
125
+ @manager.should_receive(:system).with("blux --convert -f draft5.67 | ruby #{File.dirname(__FILE__)[0..-6]}/lib/wp_publish.rb -t bla --config #{@blux_rc} | blux --set_edit_url -f draft5.67")
122
126
  @manager.publish 'draft5.67'
123
127
  end
124
128
 
@@ -145,6 +149,11 @@ describe BlogManager do
145
149
  File.open(@blux_rc, 'w') do |f|
146
150
  f.puts "editor: gedit"
147
151
  f.puts "html_converter: blux_textile_to_html"
152
+
153
+ f.puts "blog: louis"
154
+ f.puts "author_name: louis"
155
+ f.puts "user_name: louis"
156
+ f.puts "password: password"
148
157
  end
149
158
  end
150
159
  end
@@ -22,10 +22,6 @@ describe BluxConfigurationReader do
22
22
  @reader.launch_editor_cmd.should == 'gedit'
23
23
  end
24
24
 
25
- it "should read the html_converter from the config file" do
26
- @reader.html_converter_cmd.should == 'ruby textile_to_html.rb'
27
- end
28
-
29
25
  it "should read the blog from the config file" do
30
26
  @reader.blog.should == 'myownblog'
31
27
  end
@@ -43,23 +39,55 @@ describe BluxConfigurationReader do
43
39
  end
44
40
  end
45
41
 
46
- context "loading the editor from the config file when it doesn't exist" do
42
+ context "loading the config with missing items" do
47
43
  before :each do
48
44
  @blux_rc = "#{File.dirname(__FILE__)}/.bluxrc"
45
+ @reader = BluxConfigurationReader.new
46
+ end
47
+
48
+ it "should raise an exception when the editor is missing" do
49
49
  create_empty_config
50
+ lambda {@reader.load_config @blux_rc}.should raise_error("please specify an editor in .bluxrc:\n editor: [your editor of choice]")
51
+ end
50
52
 
51
- @reader = BluxConfigurationReader.new
52
- @reader.load_config @blux_rc
53
+ it "should raise an exception when the blog name is missing" do
54
+ lines = ["editor: gedit",
55
+ "author_name: Author Bob",
56
+ "user_name: this_user",
57
+ "password: pass123"]
58
+
59
+ create_config_with lines
60
+ lambda {@reader.load_config @blux_rc}.should raise_error("please specify your wordpress blog name in .bluxrc:\n blog: [your blog]")
53
61
  end
54
62
 
55
- it "should show a warning" do
56
- STDERR.should_receive(:puts).with("please specify an editor in .bluxrc: editor: [your editor of choice]\n")
57
- STDERR.should_receive(:puts).with("please specify an html converter in .bluxrc: html_converter: [your converter command of choice]\n")
58
- STDERR.should_receive(:puts).with("please specify your wordpress blog name in .bluxrc: blog: [your blog]\n")
59
- STDERR.should_receive(:puts).with("please specify an author name in .bluxrc: author_name: [your name]\n")
60
- STDERR.should_receive(:puts).with("please specify your wordpress user name in .bluxrc: user_name: [your user name]\n")
61
- STDERR.should_receive(:puts).with("please specify your wordpress password in .bluxrc: password: [your password]\n")
62
- @reader.load_config @blux_rc
63
+ it "should raise an exception when the author name is missing" do
64
+ lines = ["editor: gedit",
65
+ "blog: myownblog",
66
+ "user_name: this_user",
67
+ "password: pass123"]
68
+
69
+ create_config_with lines
70
+ lambda {@reader.load_config @blux_rc}.should raise_error("please specify an author name in .bluxrc:\n author_name: [your name]")
71
+ end
72
+
73
+ it "should raise an exception when the user name is missing" do
74
+ lines = ["editor: gedit",
75
+ "blog: myownblog",
76
+ "author_name: Author Bob",
77
+ "password: pass123"]
78
+
79
+ create_config_with lines
80
+ lambda {@reader.load_config @blux_rc}.should raise_error("please specify your wordpress user name in .bluxrc:\n user_name: [your user name]")
81
+ end
82
+
83
+ it "should raise an exception when the password is missing" do
84
+ lines = ["editor: gedit",
85
+ "blog: myownblog",
86
+ "author_name: Author Bob",
87
+ "user_name: this_user"]
88
+
89
+ create_config_with lines
90
+ lambda {@reader.load_config @blux_rc}.should raise_error("please specify your wordpress password in .bluxrc:\n password: [your password]")
63
91
  end
64
92
  end
65
93
 
@@ -68,6 +96,12 @@ describe BluxConfigurationReader do
68
96
  end
69
97
  end
70
98
 
99
+ def create_config_with(lines)
100
+ File.open(@blux_rc, 'w') do |f|
101
+ lines.each {|l| f.puts l}
102
+ end
103
+ end
104
+
71
105
  def create_config
72
106
  File.open(@blux_rc, 'w') do |f|
73
107
  f.puts "editor: gedit"
@@ -10,7 +10,7 @@ describe DraftManager do
10
10
  Dir.mkdir(@blux_dir) unless Dir.exists?(@blux_dir)
11
11
  Dir.mkdir(@temp_dir) unless Dir.exists?(@temp_dir)
12
12
  Dir.mkdir(@draft_dir) unless Dir.exists?(@draft_dir)
13
-
13
+
14
14
  def STDERR.puts(str) end
15
15
  @manager = DraftManager.new()
16
16
  @manager.setup('gedit', @temp_dir, @draft_dir)
@@ -47,7 +47,7 @@ describe DraftManager do
47
47
 
48
48
  context "when creating a new draft" do
49
49
  before :each do
50
- @manager.stub!(:system).and_return(nil)
50
+ @manager.stub!(:system).and_return(true)
51
51
  end
52
52
 
53
53
  after :each do
@@ -91,7 +91,7 @@ describe DraftManager do
91
91
 
92
92
  context "when saving a new draft" do
93
93
  before :each do
94
- @manager.stub!(:system).and_return(nil)
94
+ @manager.stub!(:system).and_return(true)
95
95
 
96
96
  class Tempfile
97
97
  def size() 123 end
@@ -123,7 +123,7 @@ describe DraftManager do
123
123
 
124
124
  @manager = DraftManager.new
125
125
  @manager.setup('gedit', @temp_dir, @draft_dir)
126
- @manager.stub!(:system).and_return(nil)
126
+ @manager.stub!(:system).and_return(true)
127
127
  end
128
128
 
129
129
  it "should call the editor command" do
@@ -134,8 +134,7 @@ describe DraftManager do
134
134
  end
135
135
 
136
136
  it "should show an error if the file doesn't exist" do
137
- STDERR.should_receive(:puts).with("draft filename asdf.asf does not exist\n")
138
- @manager.edit_draft('asdf.asf')
137
+ lambda {@manager.edit_draft('asdf.asf')}.should raise_error("draft filename asdf.asf does not exist")
139
138
  end
140
139
 
141
140
  it "should add the edited time to the attributes of that draft" do
@@ -177,8 +176,7 @@ describe DraftManager do
177
176
  end
178
177
 
179
178
  it "should output an error message if the file does not exist" do
180
- STDERR.should_receive(:puts).with("draft filename asdf.asf does not exist\n")
181
- @manager.edit_draft('asdf.asf')
179
+ lambda {@manager.edit_draft('asdf.asf')}.should raise_error("draft filename asdf.asf does not exist")
182
180
  end
183
181
  end
184
182
 
@@ -255,8 +253,7 @@ describe DraftManager do
255
253
  end
256
254
 
257
255
  it "should output an error message if the file does not exist" do
258
- STDERR.should_receive(:puts).with("draft filename asdf.asf does not exist\n")
259
- @manager.set_attribute('asdf.asf', "attr", "456")
256
+ lambda {@manager.set_attribute('asdf.asf', "attr", "456")}.should raise_error("draft filename asdf.asf does not exist")
260
257
  end
261
258
 
262
259
  it "should save the draft index to disk" do
@@ -277,19 +274,19 @@ describe DraftManager do
277
274
  @manager.setup('gedit', @temp_dir, @draft_dir)
278
275
  end
279
276
 
280
- it "should output an error message if the title is not unique" do
277
+ it "should output an warning message if the title is not unique" do
281
278
  @manager.set_attribute('draft.1', "title", 'title')
282
279
 
283
- STDERR.should_receive(:puts).with("title 'title' is not unique\n")
280
+ STDERR.should_receive(:<<).with("warning: title 'title' is not unique\n")
284
281
  @manager.set_attribute('draft.2', "title", 'title')
285
282
  end
286
283
 
287
- it "should not change the value of the previous title" do
284
+ it "should still change the value of the previous title" do
288
285
  @manager.set_attribute('draft.1', 'title', 'title')
289
286
  @manager.set_attribute('draft.2', 'title', 'title2')
290
287
  @manager.set_attribute('draft.2', 'title', 'title')
291
288
 
292
- @manager.index['draft.2']["title"].should == 'title2'
289
+ @manager.index['draft.2']["title"].should == 'title'
293
290
  end
294
291
  end
295
292
 
@@ -310,8 +307,7 @@ describe DraftManager do
310
307
  end
311
308
 
312
309
  it "should output an error message if the file does not exist" do
313
- STDERR.should_receive(:puts).with("draft filename asdf.asf does not exist\n")
314
- @manager.delete_attribute('asdf.asf', :attr)
310
+ lambda {@manager.delete_attribute('asdf.asf', :attr)}.should raise_error("draft filename asdf.asf does not exist")
315
311
  end
316
312
 
317
313
  it "should save the draft index to disk" do
@@ -335,8 +331,7 @@ describe DraftManager do
335
331
  end
336
332
 
337
333
  it "should output an error message if there are no drafts saved" do
338
- STDERR.should_receive(:puts).with("there is currently no saved index\n")
339
- @manager.get_latest_created_draft
334
+ lambda {@manager.get_latest_created_draft}.should raise_error("there is currently no saved index")
340
335
  end
341
336
  end
342
337
 
@@ -355,8 +350,7 @@ describe DraftManager do
355
350
  end
356
351
 
357
352
  it "should output an error message if there are no drafts saved" do
358
- STDERR.should_receive(:puts).with("there is currently no saved index\n")
359
- @manager.get_draft_by_title("title2")
353
+ lambda {@manager.get_draft_by_title("title2")}.should raise_error("there is currently no saved index")
360
354
  end
361
355
  end
362
356
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Louis Salin
@@ -35,7 +35,7 @@ cert_chain:
35
35
  1GuoIVBODMvF3w==
36
36
  -----END CERTIFICATE-----
37
37
 
38
- date: 2010-10-10 00:00:00 -05:00
38
+ date: 2010-10-23 00:00:00 -05:00
39
39
  default_executable:
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
@@ -162,16 +162,14 @@ description: An offline blog manager
162
162
  email: louis.phil@gmail.com
163
163
  executables:
164
164
  - blux
165
- - blux_textile_to_html
166
- - blux_wp_publish
167
165
  extensions: []
168
166
 
169
167
  extra_rdoc_files:
170
168
  - COPYING
171
169
  - README.markdown
172
170
  - bin/blux
173
- - bin/blux_textile_to_html
174
- - bin/blux_wp_publish
171
+ - lib/textile_to_html.rb
172
+ - lib/wp_publish.rb
175
173
  - lib/blog_manager.rb
176
174
  - lib/blux_config_reader.rb
177
175
  - lib/blux_option_parser.rb
@@ -183,8 +181,8 @@ files:
183
181
  - README.markdown
184
182
  - Rakefile
185
183
  - bin/blux
186
- - bin/blux_textile_to_html
187
- - bin/blux_wp_publish
184
+ - lib/textile_to_html.rb
185
+ - lib/wp_publish.rb
188
186
  - lib/blog_manager.rb
189
187
  - lib/blux_config_reader.rb
190
188
  - lib/blux_option_parser.rb
metadata.gz.sig CHANGED
Binary file