#!/usr/bin/env ruby # # Copyright (c) 2013-2014 Masanori Kado # # This program is free software. # You can distribute or modify this program under the terms of # the GNU LGPL, Lesser General Public License version 2.1. # For details of the GNU LGPL, see the file "COPYING". require 'fileutils' require 'optparse' require 'pathname' bindir = Pathname.new(__FILE__).realpath.dirname $LOAD_PATH.unshift((bindir + '../lib').realpath) require 'review/version' def main opts = OptionParser.new opts.version = ReVIEW::VERSION opts.banner = "Usage: #{File.basename($0)} [option] dirname" opts.on('-h', '--help', 'print this message and quit.') { puts opts.help exit 0 } opts.on('-f', '--force', 'generate files (except *.re) if directory has already existed.') { @force = true } opts.on('-l', '--locale', 'generate locale.yml file.') { @locale = true } begin opts.parse! rescue OptionParser::ParseError => err $stderr.puts err.message $stderr.puts opts.help exit 1 end if ARGV.empty? $stderr.puts opts.help exit 1 end initdir = File.expand_path(ARGV.shift) @review_dir = File.dirname(File.expand_path(__FILE__ + "./../")) generate_dir(initdir) do |dir| generate_catalog_file(dir) generate_sample(dir) generate_images_dir(dir) generate_cover_image(dir) generate_layout(dir) generate_style(dir) generate_texmacro(dir) generate_config(dir) generate_locale(dir) if @locale generate_rakefile(dir) end end def generate_dir(dir) if File.exist?(dir) && !@force puts "#{dir} already exists." exit end FileUtils.mkdir_p dir yield dir end def generate_sample(dir) if !@force File.open("#{dir}/#{File.basename(dir)}.re", "w") do |file| file.write("= ") end end end def generate_layout(dir) FileUtils.mkdir_p dir + '/layouts' File.open("#{dir}/layouts/layout.html.erb", "w") do |file| file.write <<-EOS