lib/rabbit/command/rabbit.rb in rabbit-2.1.1 vs lib/rabbit/command/rabbit.rb in rabbit-2.1.2
- old
+ new
@@ -1,8 +1,7 @@
+# Copyright (C) 2004-2013 Kouhei Sutou <kou@cozmixng.org>
#
-# Copyright (C) 2004-2012 Kouhei Sutou <kou@cozmixng.org>
-#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
@@ -47,21 +46,15 @@
@options, @logger = parse_command_line_arguments(arguments)
require "rabbit/canvas"
GC.enable
- if @options.save_as_image
- do_save_as_image
- elsif @options.print
- do_print
- elsif @options.server
- do_server
- else
- do_display
- end
+ succeeded = __send__("do_#{@options.action}")
::Rabbit.cleanup
+
+ succeeded
end
private
def parse_command_line_arguments(arguments)
Console.parse!(arguments) do |parser, options|
@@ -80,10 +73,11 @@
options.after_hooks << lambda do |console, _, _|
adjust_rest_arguments(console, parser, options)
end
+ options.action = :display
options.options_file = ".rabbit"
options.theme = "default"
options.theme_specified = false
options.comment_theme = nil
options.allotted_time = ENV["RABBIT_ALLOTTED_TIME"]
@@ -94,18 +88,16 @@
options.geometry = nil
options.width = 800
options.height = 600
options.paper_width = nil
options.paper_height = nil
- options.save_as_image = false
options.saved_image_base_name = nil
options.saved_image_type = "png"
options.output_html = false
options.output_index_html = false
options.rss_base_uri = nil
options.encoding = nil
- options.print = false
options.print_out_filename = nil
options.slides_per_page = 1
options.draw_scaled_image = nil
options.margin_left = nil
options.margin_right = nil
@@ -121,11 +113,10 @@
options.soap_host = "0.0.0.0"
options.soap_port = 10103
options.use_xmlrpc = false
options.xmlrpc_host = "0.0.0.0"
options.xmlrpc_port = 10104
- options.server = false
options.default_public_level = "all"
options.public_level = nil
options.migemo_dictionary_search_path = [
File.join(RbConfig::CONFIG["prefix"], "share"),
File.join("", "usr", "local", "share"),
@@ -262,11 +253,11 @@
parser.category _("Save")
parser.on("-s", "--save-as-image",
_("Save as image and exit.")) do
- options.save_as_image = true
+ options.action = :save_as_image
end
parser.on("-i", "--saved-image-type=TYPE",
_("Specify saved image type as [TYPE]."),
"(#{options.saved_image_type})") do |t|
@@ -307,11 +298,11 @@
parser.category _("Print")
parser.on("-p", "--print",
_("Print and exit.")) do
- options.print = true
+ options.action = :print
end
parser.on("-o", "--output-filename=FILENAME",
_("Specify printed out filename as [FILENAME]."),
"(\#{%s}.pdf)" % _("Title of slide")) do |f|
@@ -512,14 +503,14 @@
options.xmlrpc_port = port
end
parser.category _("Server")
- parser.on("--[no-]server",
+ parser.on("--server",
_("Specify whether to run as server."),
- "(#{options.server})") do |bool|
- options.server = bool
+ "(#{options.server})") do
+ options.action = :server
end
parser.category _("Public level")
levels = Front::PublicLevel.constants.sort_by do |const|
@@ -589,15 +580,20 @@
options.keep_above = bool
end
parser.category _("Others")
+ parser.on("--check-syntax",
+ _("Check slide source syntax and exit.")) do
+ options.action = :check_syntax
+ end
+
parser.on("--[no-]show-native-window-id",
_("Show a native window ID of the Rabbit window if available."),
_("e.g. The ID is the ID of X resource on X window system."),
"(#{options.show_native_window_id})") do |bool|
- options.show_native_window_id = bool
+ options.show_native_window_id = bool
end
end
end
def adjust_rest_arguments(console, parser, options)
@@ -805,12 +801,14 @@
setup_3d_info(canvas)
apply_theme_if_need(canvas)
parse(canvas, source)
canvas.print
canvas.quit
+ true
rescue ::Rabbit::NoPrintSupportError
@logger.error($!.message)
+ false
end
def do_save_as_image
Renderer::Pixmap.init
::Rabbit.gui_init
@@ -825,10 +823,12 @@
apply_theme_if_need(canvas)
parse(canvas, source)
canvas.activate("ToggleIndexMode") if @options.index_mode
canvas.save_as_image
canvas.quit
+
+ true
end
def do_display
display_init_options = {}
if @options.use_gl
@@ -861,10 +861,13 @@
setup_druby(front) if @options.use_druby
setup_soap(front) if @options.use_soap
setup_xmlrpc(front) if @options.use_xmlrpc
Gtk.main
+
+ true
+ false
end
def do_server
::Rabbit.gui_init
@@ -901,9 +904,32 @@
DRb.thread.exit
@logger.info(_("DRb.thread done."))
trap(:INT, prev)
end
DRb.thread.join
+ end
+
+ true
+ end
+
+ def do_check_syntax
+ source = make_source
+ renderer = Renderer.printable_renderer(1)
+ canvas = make_canvas(renderer)
+ exception = nil
+ begin
+ canvas.parse(source) do |_exception|
+ exception = _exception
+ end
+ rescue
+ exception = $!
+ end
+
+ if exception
+ @logger.info(exception.message)
+ false
+ else
+ true
end
end
end
end
end