Class: Khaleesi::CLI::Generate
- Inherits:
-
Khaleesi::CLI
- Object
- Khaleesi::CLI
- Khaleesi::CLI::Generate
- Defined in:
- lib/khaleesi/cli.rb
Direct Known Subclasses
Class Method Summary collapse
- .cmd_name ⇒ Object
- .desc ⇒ Object
- .doc {|"usage: khaleesi #{cmd_name} [options...]"| ... } ⇒ Object
- .parse(argv) ⇒ Object
Instance Method Summary collapse
- #handle_raw_files(raw_dir) ⇒ Object
-
#initialize(opts = {}) ⇒ Generate
constructor
A new instance of Generate.
- #run ⇒ Object
Methods inherited from Khaleesi::CLI
class_from_arg, #create_file_p, normalize_syntax
Constructor Details
#initialize(opts = {}) ⇒ Generate
Returns a new instance of Generate.
501 502 503 |
# File 'lib/khaleesi/cli.rb', line 501 def initialize(opts={}) @opts = opts end |
Class Method Details
.cmd_name ⇒ Object
424 425 426 |
# File 'lib/khaleesi/cli.rb', line 424 def self.cmd_name self.name.to_s[/(.+)::(.+)/, 2].downcase end |
.desc ⇒ Object
420 421 422 |
# File 'lib/khaleesi/cli.rb', line 420 def self.desc "#{cmd_name} whole site for specify directory" end |
.doc {|"usage: khaleesi #{cmd_name} [options...]"| ... } ⇒ Object
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# 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 |
.parse(argv) ⇒ Object
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# 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 |
Instance Method Details
#handle_raw_files(raw_dir) ⇒ Object
538 539 540 541 542 543 544 |
# 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 ⇒ Object
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# 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 |