Class: NanDoc::CreateNanDocSite

Inherits:
Nanoc3::CLI::Commands::CreateSite
  • Object
show all
Includes:
NanDoc::Cli::CommandMethods, NanDoc::Cli::OptionMethods
Defined in:
lib/nandoc/commands/create-nandoc-site.rb

Defined Under Namespace

Classes: StdErrListener, SupremeStderrHack

Instance Method Summary collapse

Methods included from NanDoc::Cli::OptionMethods

#exclusive_opt_flags, #normalize_opt_key, #normalize_opts, #option_enum, #unnormalize_opt_key, #unnormalize_opt_keys

Methods included from NanDoc::Cli::CommandMethods

#command_abort, #command_name, #command_path_assert, #invite_to_more_command_help, #invocation_name

Instance Method Details

#aliasesObject

override create_site short!



15
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 15

def aliases; [ 'cnds', 'cns', 'cs' ] end

#long_descObject



21
22
23
24
25
26
27
28
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 21

def long_desc
  prefix = NanDoc::Config.option_prefix
  <<-D.gsub(/\n +/,' ')
  #{prefix}Create a new site at the given path. This builds on the
  create_site nanoc3 command.  Please see that for more
  information.  Run this next to your README.md file.
  D
end

#nameObject



13
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 13

def name; 'create_nandoc_site' end

#option_definitionsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 32

def option_definitions
  @opt_defs ||= begin
    prefix = NanDoc::Config.option_prefix
    [
      { :long => 'patch-hack', :short => 'p', :argument => :none,
        :desc => "#{prefix} use files not patches when necessary" },

      { :long => 'merge-hack', :short => 'm', :argument => :none,
        :desc =>
          "#{prefix}when site already exists do something clever"
      },
      { :long => 'merge-hack-reverse', :short => 'M', :argument => :none,
        :desc =>
          "#{prefix}show the reverse diff of above."
      },
      { :long => 'prototype', :short=>'t', :argument => :required,
        :default => 'default',
        :desc => "#{prefix}the name of the site prototype to use"
      }
    ]
  end
end

#run(opts, args, method_opts = {:_merge=>true}) ⇒ Object

On the _merge option: when we are doing a merge with a generated site and we want to generate a fresh site, we want to turn the below stderr hack off.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 60

def run(opts, args, method_opts={:_merge=>true})
  args = store_extra_args(args)
  opts = normalize_opts opts
  run_opts_process opts

  return prototype_run_without_nanoc(args) unless
    @treebis_task.lay_over_nanoc_site?

  #
  # awful: see if nanoc triggers the error message about site
  # already existing, then take action
  #
  if method_opts[:_merge]
    StdErrListener.new do |listener|
      listener.when(/A site at '.*' already exists/) do
        throw :nandoc_hack, :site_already_exists
      end
    end
  end
  ret = nil
  thing = catch(:nandoc_hack) do
    ret = super(opts, args)
    :normal
  end
  case thing
  when :site_already_exists
    site_already_exists opts, args
  when :normal
    ret
  else
    fail("hack fail: #{thing.inspect}")
  end
end

#short_descObject



17
18
19
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 17

def short_desc
  "#{NanDoc::Config.option_prefix}create a nandoc site"
end

#usageObject



30
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 30

def usage; "nandoc create_nandoc_site [-m] <path>" end