Module: Yass::CLI::Helpers

Defined in:
lib/yass/cli/helpers.rb

Class Method Summary collapse

Class Method Details

.default_configObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/yass/cli/helpers.rb', line 59

def self.default_config
  Config.new({
    cwd: Pathname.new(Dir.pwd),
    src: "site",
    layouts: "layouts",
    templates: "templates",
    dest: "dist",
    clean: false,
    include_drafts: false,
    strip_index: true,
    stdout: $stdout,
    stderr: $stderr,
    debug: false,
  })
end

.find_path(path, cwd:) ⇒ Object



13
14
15
16
# File 'lib/yass/cli/helpers.rb', line 13

def self.find_path(path, cwd:)
  path = Pathname.new(path)
  path.relative? ? Pathname.new(cwd).join(path) : path
end

.get_cmd(argv) ⇒ Object



6
# File 'lib/yass/cli/helpers.rb', line 6

def self.get_cmd(argv) = argv[0].to_s.to_sym

.get_opts!Object



18
19
20
21
22
23
# File 'lib/yass/cli/helpers.rb', line 18

def self.get_opts!
  config = default_config
  parser = option_parser config
  parser.parse!
  config
end

.get_working_dir!(argv) ⇒ Object



8
9
10
11
# File 'lib/yass/cli/helpers.rb', line 8

def self.get_working_dir!(argv)
  dir = argv[1] || Dir.pwd
  find_path(dir, cwd: Dir.pwd)
end

.help!Object



25
26
27
28
29
30
# File 'lib/yass/cli/helpers.rb', line 25

def self.help!
  config = default_config
  parser = option_parser config
  config.stdout.puts parser.help
  exit 1
end

.option_parser(config) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/yass/cli/helpers.rb', line 32

def self.option_parser(config)
  OptionParser.new { |opts|
    opts.banner = %(
Yet Another Static Site (generator) v#{VERSION}

yass <command> [path/to/dir] [options]

  Build the site:
yass build [path/to/dir] [options]

  Auto-build when files change:
yass watch [path/to/dir] [options]

  Create a new site:
yass init [path/to/dir]

  Options:
    ).strip
    opts.on("--clean", "Remove unknown files from dist/ when bulding") { config.clean = true }
    opts.on("--dest=DIR", "Build to a different directory") { |dir| config.dest = find_path(dir, cwd: Dir.pwd) }
    opts.on("--drafts", "Include unpublished files in build") { config.include_drafts = true }
    opts.on("--no-strip-index", "Disable the strip_index Liquid filter") { config.strip_index = false }
    opts.on("--debug", "Print stack traces") { config.debug = true }
    opts.on("-h", "--help", "Prints this help") { config.stdout.puts opts; exit }
  }
end