File: arg_parser.rb

package info (click to toggle)
ruby-jekyll-compose 0.12.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 108 kB
  • sloc: ruby: 712; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module Jekyll
  module Compose
    class ArgParser
      attr_reader :args, :options, :config

      # TODO: Remove `nil` parameter in v1.0
      def initialize(args, options, config = nil)
        @args = args
        @options = options
        @config = config || Jekyll.configuration(options)
      end

      def validate!
        raise ArgumentError, "You must specify a name." if args.empty?
      end

      def type
        options["extension"] || Jekyll::Compose::DEFAULT_TYPE
      end

      def layout
        options["layout"] || Jekyll::Compose::DEFAULT_LAYOUT
      end

      def title
        args.join " "
      end

      def force?
        !!options["force"]
      end

      def timestamp_format
        options["timestamp_format"] || Jekyll::Compose::DEFAULT_TIMESTAMP_FORMAT
      end

      def source
        File.join(config["source"], config["collections_dir"])
          .gsub(%r!^#{Regexp.quote(Dir.pwd)}/*!, "")
      end
    end
  end
end