Class: Jekyll::Commands::RenameArgParser

Inherits:
Jekyll::Compose::ArgParser show all
Defined in:
lib/jekyll/commands/rename.rb

Instance Attribute Summary

Attributes inherited from Jekyll::Compose::ArgParser

#args, #config, #options

Instance Method Summary collapse

Methods inherited from Jekyll::Compose::ArgParser

#force?, #initialize, #layout, #source, #timestamp_format, #type

Constructor Details

This class inherits a constructor from Jekyll::Compose::ArgParser

Instance Method Details

#basenameObject



59
60
61
# File 'lib/jekyll/commands/rename.rb', line 59

def basename
  @basename ||= File.basename(current_path)
end

#current_pathObject



47
48
49
# File 'lib/jekyll/commands/rename.rb', line 47

def current_path
  @current_path ||= args[0]
end

#dateObject



71
72
73
74
75
76
77
# File 'lib/jekyll/commands/rename.rb', line 71

def date
  @date ||= if options["now"]
              Time.now
            elsif options["date"]
              Date.parse(options["date"])
            end
end

#date_from_filenameObject



79
80
81
# File 'lib/jekyll/commands/rename.rb', line 79

def date_from_filename
  Date.parse(Regexp.last_match(1)) if basename =~ Jekyll::Document::DATE_FILENAME_MATCHER
end

#dirnameObject



55
56
57
# File 'lib/jekyll/commands/rename.rb', line 55

def dirname
  @dirname ||= File.dirname(current_path)
end

#draft?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/jekyll/commands/rename.rb', line 87

def draft?
  dirname == "_drafts"
end

#pathObject



51
52
53
# File 'lib/jekyll/commands/rename.rb', line 51

def path
  File.join(source, current_path).sub(%r!\A/!, "")
end

#post?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/jekyll/commands/rename.rb', line 83

def post?
  dirname == "_posts"
end

#titleObject



63
64
65
# File 'lib/jekyll/commands/rename.rb', line 63

def title
  @title ||= args.drop(1).join(" ")
end

#touch?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/jekyll/commands/rename.rb', line 67

def touch?
  !!options["date"] || options["now"]
end

#validate!Object

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
# File 'lib/jekyll/commands/rename.rb', line 39

def validate!
  raise ArgumentError, "You must specify current path and the new title." if args.length < 2

  if options.values_at("date", "now").compact.length > 1
    raise ArgumentError, "You can only specify one of --date DATE or --now."
  end
end