module Juli::Command

This is a top level module for juli(1) command execution. Each juli(1) command corresponds to each method here.

Constants

EXT_COMMENT
OUTPUT_TOP_COMMENT
TEMPLATE_COMMENT

Public Instance Methods

gen(opts) click to toggle source

generate command

OPTIONS

-g generator

specify generator

-f

force update

-t template

specify template

-o output_path

specify output file path (only non-bulk-mode)

# File lib/juli/command.rb, line 136
def gen(opts)
  o = opts.dup
  o.delete(:g)
  # executes each generator's init here:
  v = visitor(opts[:g]).new(o)

  if ARGV.empty?
    print "bulk mode\n"
    if opts[:o]
      STDERR.print "ERROR: -o #{opts[:o]} is specified in bulk-mode\n"
    else
      v.run_bulk
    end
  else
    for file in ARGV do
      Juli::Parser.new.parse(file, v)
    end
  end
end
init(opts) click to toggle source
  1. create juli-repository at the current directory, if not yet.

  2. create config file under the juli-repo, if not yet. This stores juli-repo dependent information.

  3. if parameters are specified, store it in config file under juli-repo.

OPTIONS

-o output_top -t template -e ext

# File lib/juli/command.rb, line 105
def init(opts)
  if !File.directory?(Juli::REPO)
    FileUtils.mkdir(Juli::REPO)
  else
    STDERR.print "WARN: juli-repo is already created\n"
  end

  config_file = File.join(Juli::REPO, 'config')
  if !File.exist?(config_file)
    File.open(config_file, 'w') do |f|
      f.print OUTPUT_TOP_COMMENT
      write_config(f, 'output_top', opts[:o])
      f.print TEMPLATE_COMMENT
      write_config(f, 'template',   opts[:t])
      f.print EXT_COMMENT
      write_config(f, 'ext',        opts[:e])
      write_macro_conf(f)
      write_helper_conf(f)
    end
  else
    STDERR.print "WARN: config file is already created\n"
  end
end
run(command_str, opts = {}) click to toggle source

top level command execution. command_str will be checked and dispatched to each method.

# File lib/juli/command.rb, line 15
def run(command_str, opts = {})
  if command_str == 'init'
    init(opts)
  else
    Juli::Util::JuliI18n.new(conf, juli_repo)
    case command_str
    when 'gen';           gen(opts)
    when 'sitemap';       Juli::Command::Sitemap.new.run(opts)
    when 'recent_update'; Juli::Command::RecentUpdate.new.run(opts)
    when 'tag';           Juli::Command::Tag.new.run(opts)
    else
      STDERR.print "Unknown juli command: '#{command_str}'\n\n", usage, "\n"
      raise Error
    end
  end
end

Private Instance Methods

write_config(f, key, value) click to toggle source
# File lib/juli/command.rb, line 157
def write_config(f, key, value)
  if value
    f.printf("%s: %s\n", key, value)
  end
end
write_helper_conf(f) click to toggle source

write each helper conf sample to initial .juli/conf file by calling 'conf_template' method on each macro.

# File lib/juli/command.rb, line 175
def write_helper_conf(f)
  for helper_symbol in Juli::Visitor::Html::Helper.constants do
    next if helper_symbol == :AbstractHelper
    helper_class = Juli::Visitor::Html::Helper.module_eval(helper_symbol.to_s)
    f.print "\n", helper_class.conf_template
  end
end
write_macro_conf(f) click to toggle source

write each macro conf sample to initial .juli/conf file by calling 'conf_template' method on each macro.

# File lib/juli/command.rb, line 165
def write_macro_conf(f)
  for macro_symbol in Juli::Macro.constants do
    next if macro_symbol == :Base
    macro_class = Juli::Macro.module_eval(macro_symbol.to_s)
    f.print "\n", macro_class.conf_template
  end
end