lib/repl.rb in runeblog-0.1.4 vs lib/repl.rb in runeblog-0.1.5

- old
+ new

@@ -1,25 +1,38 @@ require 'runeblog' require 'ostruct' require 'helpers-repl' # FIXME structure -make_exception(:PublishError, "Error during publishing") -make_exception(:EditorProblem, "Could not edit $1") +make_exception(:PublishError, "Error during publishing") +# make_exception(:EditorProblem, "Could not edit $1") module RuneBlog::REPL + def edit_file(file) + result = system("#{blog.editor} #{file}") + raise EditorProblem(file) unless result + STDSCR.clear + end + def cmd_quit(arg) check_empty(arg) - system("tput rmcup") +# system("tput rmcup") + RubyText.stop abort "\n " end + def cmd_clear(arg) + check_empty(arg) + STDSCR.cwin.clear + STDSCR.cwin.refresh + end + def cmd_version(arg) reset_output check_empty(arg) output RuneBlog::VERSION - return @out + [true, @out] end def cmd_config(arg) check_empty(arg) dir = @blog.view.dir @@ -27,21 +40,21 @@ "custom/blog_header.html", "custom/blog_trailer.html", "custom/post_template.html"] puts "\nEdit which file?" # FIXME use @out for testing later fname = dumb_menu(items) - system("#{@blog.editor} #{dir}/#{fname}") + edit_file("#{dir}/#{fname}") end def cmd_browse(arg) reset_output check_empty(arg) url = @blog.view.publisher.url # FIXME Bad logic here. if url.nil? output! "Publish first." - return @out + return [true, @out] end result = system("open '#{url}'") raise CantOpen(url) unless result nil end @@ -57,17 +70,17 @@ def cmd_publish(arg) # FIXME non-string return expected in caller? reset_output check_empty(arg) unless @blog.view.can_publish? output! "Can't publish without entries in #{@blog.view.name}/publish" - return @out + return [true, @out] end @blog.view.publish user, server, sroot, spath = *@publish[@blog.view] if files.empty? # FIXME baloney output! "No files to publish" - return @out + return [true, @out] end output "Files:" files.each {|f| output " #{f}\n" } output_newline @@ -81,11 +94,11 @@ result = system(cmd) raise PublishError unless result dump(files, "#{vdir}/last_published") output! "...finished.\n" - @out + return [true, @out] end def cmd_rebuild(arg) reset_output check_empty(arg) @@ -105,18 +118,18 @@ def cmd_change_view(arg) reset_output # Simplify this if arg.nil? output bold(@blog.view) - return @out + return [true, @out] else if @blog.view?(arg) @blog.view = arg # reads config output red("View: ") + bold(@blog.view.name.to_s) # FIXME? end end - @out + return [true, @out] end def cmd_new_view(arg) reset_output @blog.create_view(arg) @@ -131,10 +144,11 @@ check_empty(arg) title = ask("\nTitle: ") meta = OpenStruct.new meta.title = title @blog.create_new_post(meta) + STDSCR.clear nil end def cmd_kill(arg) reset_output @@ -142,25 +156,22 @@ args.each do |x| # FIXME ret = cmd_remove_post(x.to_i, false) output ret end - @out + return [true, @out] end #-- FIXME affects linking, building, publishing... def cmd_remove_post(arg, safe=true) # FIXME - 'safe' is no longer a thing reset_output id = get_integer(arg) result = @blog.remove_post(id) - if result.nil? - output! "Post #{id} not found" - return @out - end - @out + output! "Post #{id} not found" if result.nil? + return [true, @out] end #-- FIXME affects linking, building, publishing... def cmd_edit_post(arg) @@ -169,72 +180,83 @@ # Simplify this tag = "#{'%04d' % id}" files = Find.find(@blog.root+"/src").to_a files = files.grep(/#{tag}-/) files = files.map {|f| File.basename(f) } - return red("Multiple files: #{files}") if files.size > 1 - return red("\n Can't edit post #{id}") if files.empty? + return [true, "Multiple files: #{files}"] if files.size > 1 + return [true, "\n Can't edit post #{id}"] if files.empty? file = files.first - result = system("vi #{@blog.root}/src/#{file}") - raise EditorProblem(file) unless result - + result = edit_file("#{@blog.root}/src/#{file}") @blog.rebuild_post(file) nil end def cmd_list_views(arg) reset_output("\n") check_empty(arg) - debug "curr view = #{@blog.view.name.inspect}" puts @blog.views.each do |v| v = v.to_s v = fx(v, :bold) if v == @blog.view.name - debug "v = #{v.inspect} - #{v.fx.inspect rescue 'no fx'}" print " " puts v end - debug "out = #{@out.inspect}" - @out - "" + puts + return [false, @out] end def cmd_list_posts(arg) reset_output check_empty(arg) posts = @blog.posts # current view str = @blog.view.name + ":\n" output str + puts + print " " + puts fx(str, :bold) if posts.empty? output! bold("No posts") + puts fx(" No posts", :bold) else posts.each do |post| outstr " #{colored_slug(post)}\n" + base = post.sub(/.lt3$/, "") + num, rest = base[0..3], base[4..-1] + print " " + puts fx(num, Red), fx(rest, Blue) end end - @out + puts + return [false, @out] end def cmd_list_drafts(arg) reset_output check_empty(arg) drafts = @blog.drafts # current view if drafts.empty? output! "No drafts" - return @out + puts " No drafts" + return [true, @out] else + puts drafts.each do |draft| outstr " #{colored_slug(draft.sub(/.lt3$/, ""))}\n" + base = draft.sub(/.lt3$/, "") + num, rest = base[0..3], base[4..-1] + print " " + puts fx(num, Red), fx(rest, Blue) end end - @out + puts + return [false, @out] end def cmd_INVALID(arg) reset_output "\n Command '#{red(arg)}' was not understood." - return @out + return [true, @out] end def cmd_help(arg) reset_output check_empty(arg) @@ -269,9 +291,9 @@ #{red('browse ')} Look at current (published) view in browser #{red('relink ')} Regenerate index for all views #{red('rebuild ')} Regenerate all posts and relink #{red('publish ')} Publish (current view) EOS - @out + return [true, @out] end end