class Khaleesi::CLI::Generate

Public Class Methods

cmd_name() click to toggle source
# File lib/khaleesi/cli.rb, line 424
def self.cmd_name
  self.name.to_s[/(.+)::(.+)/, 2].downcase
end
desc() click to toggle source
# File lib/khaleesi/cli.rb, line 420
def self.desc
  "#{cmd_name} whole site for specify directory"
end
doc() { |"usage: khaleesi #{cmd_name} [options...]"| ... } click to toggle source
# File lib/khaleesi/cli.rb, line 428
def self.doc
  return enum_for(:doc) unless block_given?

  yield "usage: khaleesi #{cmd_name} [options...]"
  yield ''
  yield '--src-dir        required, specify a source directory path(must be absolutely), khaleesi shall generating via this site source.'
  yield ''
  yield '--dest-dir       required, specify a destination directory path(must be absolutely), all generated file will put there.'
  yield ''
  yield '--line-numbers   (true|false) enable or disable output source code line numbers.'
  yield '                 the default value is "false", which means no line numbers at all.'
  yield ''
  yield '--css-class      specify source code syntax highlight\'s css class, default is \'highlight\'.'
  yield ''
  yield '--time-pattern   specify which time pattern would be used, If not provided, khaleesi will use \'%a %e %b %H:%M %Y\' as default,'
  yield '                 see http://www.ruby-doc.org/core-2.1.2/Time.html#strftime-method for pattern details.'
  yield ''
  yield '--date-pattern   specify which date pattern would be used, If not provided, khaleesi will use \'%F\' as default,'
  yield '                 see http://www.ruby-doc.org/core-2.1.2/Time.html#strftime-method for pattern details.'
  yield ''
  yield '--diff-plus      (true|false) if given the value is \'true\', khaleesi will only generate local repository(git) changed'
  yield '                 but has not yet been versionadded\'s pages. If the whole site was too many pages or some pages had time-consuming'
  yield '                 operation in building, it would be expensively when you want just focusing on those pages you frequently changing on,'
  yield '                 e.g you are writing a new post, you probably just care what looks would post be at all,'
  yield '                 so this setting let\'s avoid to generating extra pages which never changes.'
  yield ''
  yield '--highlighter    (pygments|rouge) tells khaleesi what syntax highlighter you prefer to use,'
  yield '                 every value except \'pygments\' means the same as \'rouge\'.'
  yield ''
  yield '--toc-selection  specify which headers will generate an "Table of Contents" id,'
  yield '                 default is empty, that means disable TOC generation.'
  yield '                 Enable values including "h1,h2,h3,h4,h5,h6", use comma as separator'
  yield '                 to tell Khaleesi which html headers you want to have ids.'
  yield '                 If enable to generate ids, Khaleesi will deal with header\'s text finally produce an id'
  yield '                 that only contain [lowercase-alpha, digit, dashes, underscores] characters.'
  yield '                 According this rule, Khaleesi may hunting down your texts when they don\'t write correctly.'
  yield '                 That shall cause the generated text become meaningless and even very easy to being duplicate.'
  yield '                 In case your texts aren\'t write in a good form, you still have a setting to force Khaleesi'
  yield '                 to generate an unique ids instead that uncomfortable generated texts.'
  yield '                 Just append "[unique]" identifier at the end, e.g "h1,h2[unique]", Khaleesi will generating'
  yield '                 ids like these : "header-1", "header-2", "header-3", "header-4".'
end
new(opts={}) click to toggle source
# File lib/khaleesi/cli.rb, line 501
def initialize(opts={})
  @opts = opts
end
parse(argv) click to toggle source
# File lib/khaleesi/cli.rb, line 471
def self.parse(argv)
  opts = {}
  argv = normalize_syntax(argv)
  until argv.empty?
    arg = argv.shift
    case arg
      when 'src-dir'
        opts[:src_dir] = argv.shift.dup
      when 'dest-dir'
        opts[:dest_dir] = argv.shift.dup
      when 'line-numbers'
        opts[:line_numbers] = argv.shift.dup
      when 'css-class'
        opts[:css_class] = argv.shift.dup
      when 'time-pattern'
        opts[:time_pattern] = argv.shift.dup
      when 'date-pattern'
        opts[:date_pattern] = argv.shift.dup
      when 'diff-plus'
        opts[:diff_plus] = argv.shift.dup
      when 'highlighter'
        opts[:highlighter] = argv.shift.dup
      when 'toc-selection'
        opts[:toc_selection] = argv.shift.dup
    end
  end

  new(opts)
end

Public Instance Methods

handle_raw_files(raw_dir) click to toggle source
# File lib/khaleesi/cli.rb, line 538
def handle_raw_files(raw_dir)
  # make symbolic links of "_raw" directory
  Dir.chdir(@opts[:dest_dir]) do
    %x[ln -sf #{raw_dir << '/*'} .]
  end
  # FileUtils.ln_s site_dir << '/*', @dest_dir, :verbose => true
end
run() click to toggle source
# File lib/khaleesi/cli.rb, line 505
def run
  details = " Please point \"khaleesi help #{self.class.to_s[/(.+)::(.+)/, 2].downcase}\" in terminal for more details."

  dest_dir = @opts[:dest_dir]
  src_dir = @opts[:src_dir]

  unless src_dir and File.directory?(src_dir) and File.readable?(src_dir)
    abort "Source directory : #{src_dir} invalid." << details
  end

  unless dest_dir and File.directory?(dest_dir) and File.writable?(dest_dir)
    abort "Destination directory : #{dest_dir} invalid." << details
  end

  site_dir = src_dir + '/_decorators'
  unless File.directory?(site_dir)
    abort "Source directory : #{src_dir} haven't _decorators folder."
  end

  site_dir = src_dir + '/_pages'
  unless File.directory?(site_dir)
    abort "Source directory : #{src_dir} haven't _pages folder."
  end

  site_dir = src_dir + '/_raw'
  unless File.directory?(site_dir)
    abort "Source directory : #{src_dir} haven't _raw folder."
  end

  Generator.new(@opts).generate
  handle_raw_files(site_dir)
end