Module: Juli::Command

Defined in:
lib/juli/command.rb,
lib/juli/command/tag.rb,
lib/juli/command/sitemap.rb,
lib/juli/command/file_entry.rb,
lib/juli/command/recent_update.rb

Overview

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

Defined Under Namespace

Classes: Error, FileEntry, RecentUpdate, Sitemap, Tag

Constant Summary collapse

OUTPUT_TOP_COMMENT =
<<EOM
# Juli-repo config file.
#
# This is YAML format.
#
# Starting '#' at each line means just comment.
# You can delete these comments.
#
# The commented-out settings shown in this file represent the default values.


# Locale(default = en)
#
#locale: en

# show_indent_toggle_button (default = true) to show/hide the toggle button
# for indented scope of the text.  NOTE: toggle action still works even
# though button is hidden.
#
#show_indent_toggle_button: true

# When set to '1st-only' (default), wikiname auto-link is applied at ONLY 1st
# occurence in a text, otherwise is applied at every occurence:
#
#link_wikiname_on:          1st-only

# Specify output top directory (default = ../html).

EOM
TEMPLATE_COMMENT =
<<EOM

# Specify html template when generating (default = 'default.html', which 
# means that RUBY_LIB/juli/template/default.html is used).
#
# Current available templates are under RUBY_LIB/juli/template/, where
# RUBY_LIB is the directory which juli library is installed
# (e.g. /usr/local/lib/ruby/site_ruby/1.9/).
#
# You can put your customized template under JULI_REPO/.juli/
# rather than ruby standard library directory.  For example,
# if you want to use your customized template 'blue_ocean.html',
# create it under JULI_REPO/ and specify it at config as follows:
#
#   $ cp RUBY_LIB/juli/template/default.html JULI_REPO/.juli/blue_ocean.html
#   (edit JULI_REPO/.juli/blue_ocean.html as you like)
#   (edit JULI_REPO/.juli/config as follows:
#
#   template: blue_ocean.html
#
# File extention (e.g. .html) is required in this config.
# -t option at 'juli gen' command line execution can be also supported.
# 

EOM
EXT_COMMENT =
<<EOM

# Generated file's extention (default = .shtml).
# The reason why '.shtml' is because to use SSI (server side include)
# for recent_update.  Of course, it depends on web-server configuration and
# you may not use SSI.  In such a case, you can change to '.html'.

EOM

Instance Method Summary collapse

Instance Method Details

#gen(opts) ⇒ Object

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)



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# 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) ⇒ Object

init does:

  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



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# 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 = {}) ⇒ Object

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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