lib/packnga/reference-task.rb in packnga-0.9.1 vs lib/packnga/reference-task.rb in packnga-0.9.2
- old
+ new
@@ -13,25 +13,32 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+require "erb"
+
module Packnga
# This class creates reference tasks.
# They generate, translate and prepare to publish references.
#
# @since 0.9.0
class ReferenceTask
include Rake::DSL
include ERB::Util
- # This attribute is path of base directory of document.
- # @param [String] path of base directory of document
+
+ # @return [String] path of base directory of document
attr_writer :base_dir
+
+ # @return [String] mode used in xml2po. The default is "docbook".
+ attr_writer :mode
+
# @private
def initialize(spec)
@spec = spec
@base_dir = nil
+ @mode = nil
@translate_languages = nil
@supported_languages = nil
@html_files = nil
@htaccess = nil
@po_dir = nil
@@ -54,10 +61,11 @@
end
private
def set_default_values
@base_dir ||= Pathname.new("doc")
+ @mode ||= "docbook"
@translate_languages ||= [:ja]
@supported_languages = [:en, *@translate_languages]
@html_files = FileList[(doc_en_dir + "**/*.html").to_s].to_a
@po_dir = "doc/po"
@pot_file = "#{@po_dir}/#{@spec.name}.pot"
@@ -93,10 +101,11 @@
namespace :pot do
directory @po_dir
file @pot_file => [@po_dir, *@html_files] do |t|
sh("xml2po",
"--keep-entities",
+ "--mode", @mode,
"--output", t.name,
*@html_files)
end
desc "Generates pot file."
@@ -113,10 +122,11 @@
if File.exist?(po_file)
file po_file => @html_files do |t|
sh("xml2po",
"--keep-entities",
+ "--mode", @mode,
"--update", t.name,
*@html_files)
end
else
file po_file => @pot_file do |t|
@@ -157,12 +167,16 @@
mkdir_p(translated_path)
next
end
case path.extname
when ".html"
- sh("xml2po --keep-entities " +
- "--po-file #{po_file} --language #{language} " +
- "#{path} > #{translated_path}")
+ sh("xml2po",
+ "--keep-entities",
+ "--mode", @mode,
+ "--po-file", po_file.to_s,
+ "--language", language.to_s,
+ "--output", translated_path.to_s,
+ path.to_s)
else
cp(path.to_s, translated_path, :preserve => true)
end
end
end