jekyll-compose 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1017cc00ab44265c4d810de87d46661bdf7feecacbe6da5a54f1b11b9bf3edf
4
- data.tar.gz: c6e896c66c7e5c4be5bb613a84307c2cff9bb872a687764a12e5c147422028bc
3
+ metadata.gz: f35d4f81f06174cdacefa7f2f2fe3fb898ff6d2c8b8f2d0e46aefcfd65cbba30
4
+ data.tar.gz: 0e0b229dc0ac7dd8bcdd3ad86b256efa3b3e3d598ca32ffb645ff831e0585013
5
5
  SHA512:
6
- metadata.gz: b4aaf2b87dbb6d61a8c5710b9c8a2b239116517dc946b36c09d802021f1233fc5c906a94c9a0723536ff970e8b588481cd0501a5cf03ceae58e7c9cf62b13ded
7
- data.tar.gz: c5878411cdc0255d180839c4798c6b86d438a08b466f502cbea4c2de048dcba7f77f3f0df187ff14874eb95907a2027b547add8d5667afc2bc7f300ff5c543ea
6
+ metadata.gz: aa508789af2d826d4484cd55ba6d683d1873f2e057012fd8db7ef5c1e4015f601be03c58e796ee8d3c57291b4ae187260456dc862862222e5b68e5311507f4f1
7
+ data.tar.gz: e4af651d1996f403268202a1ce27e595881ed25dc10fbfef5d354abba16d9bcc70f3461a104754e187dd9268d6549bf50c1be9cb25260f142c30882a8fb6061b
@@ -18,6 +18,6 @@ module Jekyll
18
18
  end
19
19
  end
20
20
 
21
- %w(draft post publish unpublish page).each do |file|
21
+ %w(draft post publish unpublish page rename compose).each do |file|
22
22
  require File.expand_path("jekyll/commands/#{file}.rb", __dir__)
23
23
  end
@@ -32,6 +32,10 @@ module Jekyll
32
32
  !!options["force"]
33
33
  end
34
34
 
35
+ def timestamp_format
36
+ options["timestamp_format"] || Jekyll::Compose::DEFAULT_TIMESTAMP_FORMAT
37
+ end
38
+
35
39
  def source
36
40
  File.join(config["source"], config["collections_dir"])
37
41
  .gsub(%r!^#{Regexp.quote(Dir.pwd)}/*!, "")
@@ -9,7 +9,7 @@
9
9
  # auto_open: true
10
10
  # ```
11
11
  #
12
- # And make sure, that you have JEKYLL_EDITOR or EDITOR environment variables set up.
12
+ # And make sure, that you have JEKYLL_EDITOR, VISUAL, or EDITOR environment variables set up.
13
13
  # This will allow to open the file in your default editor automatically.
14
14
 
15
15
  module Jekyll
@@ -34,7 +34,7 @@ module Jekyll
34
34
  def post_editor
35
35
  return unless auto_open?
36
36
 
37
- ENV["JEKYLL_EDITOR"] || ENV["EDITOR"]
37
+ ENV["JEKYLL_EDITOR"] || ENV["VISUAL"] || ENV["EDITOR"]
38
38
  end
39
39
 
40
40
  def auto_open?
@@ -21,6 +21,12 @@ module Jekyll
21
21
 
22
22
  front_matter + "---\n"
23
23
  end
24
+
25
+ private
26
+
27
+ def front_matter_defaults_for(key)
28
+ params.config.dig("jekyll_compose", "default_front_matter", key)
29
+ end
24
30
  end
25
31
  end
26
32
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Compose
5
- VERSION = "0.11.0"
5
+ VERSION = "0.12.0"
6
6
  end
7
7
  end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Commands
5
+ class ComposeCommand < Command
6
+ def self.init_with_program(prog)
7
+ prog.command(:compose) do |c|
8
+ c.syntax "compose NAME"
9
+ c.description "Creates a new document with the given NAME"
10
+
11
+ options.each { |opt| c.option(*opt) }
12
+
13
+ c.action { |args, options| process(args, options) }
14
+ end
15
+ end
16
+
17
+ def self.options
18
+ [
19
+ ["extension", "-x EXTENSION", "--extension EXTENSION", "Specify the file extension"],
20
+ ["layout", "-l LAYOUT", "--layout LAYOUT", "Specify the document layout"],
21
+ ["force", "-f", "--force", "Overwrite a document if it already exists"],
22
+ ["date", "-d DATE", "--date DATE", "Specify the document date"],
23
+ ["collection", "-c COLLECTION", "--collection COLLECTION", "Specify the document collection"],
24
+ ["post", "--post", "Create a new post (default)"],
25
+ ["draft", "--draft", "Create a new draft"],
26
+ ["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
27
+ ]
28
+ end
29
+
30
+ def self.process(args = [], options = {})
31
+ config = configuration_from_options(options)
32
+ params = ComposeCommandArgParser.new(args, options, config)
33
+ params.validate!
34
+
35
+ document = ComposeCommandFileInfo.new(params)
36
+
37
+ file_creator = Compose::FileCreator.new(document, params.force?, params.source)
38
+ file_creator.create!
39
+
40
+ Compose::FileEditor.bootstrap(config)
41
+ Compose::FileEditor.open_editor(file_creator.file_path)
42
+ end
43
+
44
+ class ComposeCommandArgParser < Compose::ArgParser
45
+ def validate!
46
+ if options.values_at("post", "draft", "collection").compact.length > 1
47
+ raise ArgumentError, "You can only specify one of --post, --draft, or --collection COLLECTION."
48
+ end
49
+
50
+ super
51
+ end
52
+
53
+ def date
54
+ @date ||= options["date"] ? Date.parse(options["date"]) : Time.now
55
+ end
56
+
57
+ def collection
58
+ if (coll = options["collection"])
59
+ coll
60
+ elsif options["draft"]
61
+ "drafts"
62
+ else
63
+ "posts"
64
+ end
65
+ end
66
+ end
67
+
68
+ class ComposeCommandFileInfo < Compose::FileInfo
69
+ def initialize(params)
70
+ @params = params
71
+ @collection = params.collection
72
+ end
73
+
74
+ def resource_type
75
+ case @collection
76
+ when "posts" then "post"
77
+ when "drafts" then "draft"
78
+ else
79
+ "file"
80
+ end
81
+ end
82
+
83
+ def path
84
+ File.join("_#{@collection}", file_name)
85
+ end
86
+
87
+ def file_name
88
+ @collection == "posts" ? "#{date_stamp}-#{super}" : super
89
+ end
90
+
91
+ def content(custom_front_matter = {})
92
+ default_front_matter = front_matter_defaults_for(@collection)
93
+ custom_front_matter.merge!(default_front_matter) if default_front_matter.is_a?(Hash)
94
+
95
+ super({ "date" => time_stamp }.merge!(custom_front_matter))
96
+ end
97
+
98
+ private
99
+
100
+ def date_stamp
101
+ @params.date.strftime(Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT)
102
+ end
103
+
104
+ def time_stamp
105
+ @params.date.strftime(Jekyll::Compose::DEFAULT_TIMESTAMP_FORMAT)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -8,9 +8,9 @@ module Jekyll
8
8
  c.syntax "draft NAME"
9
9
  c.description "Creates a new draft post with the given NAME"
10
10
 
11
- options.each { |opt| c.option *opt }
11
+ options.each { |opt| c.option(*opt) }
12
12
 
13
- c.action { |args, options| process args, options }
13
+ c.action { |args, options| process(args, options) }
14
14
  end
15
15
  end
16
16
 
@@ -20,16 +20,15 @@ module Jekyll
20
20
  ["layout", "-l LAYOUT", "--layout LAYOUT", "Specify the draft layout"],
21
21
  ["force", "-f", "--force", "Overwrite a draft if it already exists"],
22
22
  ["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
23
- ["source", "-s", "--source SOURCE", "Custom source directory"],
24
23
  ]
25
24
  end
26
25
 
27
26
  def self.process(args = [], options = {})
28
27
  config = configuration_from_options(options)
29
- params = Compose::ArgParser.new args, options, config
28
+ params = Compose::ArgParser.new(args, options, config)
30
29
  params.validate!
31
30
 
32
- draft = DraftFileInfo.new params
31
+ draft = DraftFileInfo.new(params)
33
32
 
34
33
  file_creator = Compose::FileCreator.new(draft, params.force?, params.source)
35
34
  file_creator.create!
@@ -48,7 +47,7 @@ module Jekyll
48
47
  end
49
48
 
50
49
  def content(custom_front_matter = {})
51
- default_front_matter = params.config.dig("jekyll_compose", "draft_default_front_matter")
50
+ default_front_matter = front_matter_defaults_for("drafts")
52
51
  custom_front_matter.merge!(default_front_matter) if default_front_matter.is_a?(Hash)
53
52
 
54
53
  super(custom_front_matter)
@@ -8,9 +8,9 @@ module Jekyll
8
8
  c.syntax "page NAME"
9
9
  c.description "Creates a new page with the given NAME"
10
10
 
11
- options.each { |opt| c.option *opt }
11
+ options.each { |opt| c.option(*opt) }
12
12
 
13
- c.action { |args, options| process args, options }
13
+ c.action { |args, options| process(args, options) }
14
14
  end
15
15
  end
16
16
 
@@ -20,16 +20,15 @@ module Jekyll
20
20
  ["layout", "-l LAYOUT", "--layout LAYOUT", "Specify the page layout"],
21
21
  ["force", "-f", "--force", "Overwrite a page if it already exists"],
22
22
  ["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
23
- ["source", "-s", "--source SOURCE", "Custom source directory"],
24
23
  ]
25
24
  end
26
25
 
27
26
  def self.process(args = [], options = {})
28
27
  config = configuration_from_options(options)
29
- params = PageArgParser.new args, options, config
28
+ params = PageArgParser.new(args, options, config)
30
29
  params.validate!
31
30
 
32
- page = PageFileInfo.new params
31
+ page = PageFileInfo.new(params)
33
32
 
34
33
  Compose::FileCreator.new(page, params.force?, params.source).create!
35
34
  end
@@ -8,9 +8,9 @@ module Jekyll
8
8
  c.syntax "post NAME"
9
9
  c.description "Creates a new post with the given NAME"
10
10
 
11
- options.each { |opt| c.option *opt }
11
+ options.each { |opt| c.option(*opt) }
12
12
 
13
- c.action { |args, options| process args, options }
13
+ c.action { |args, options| process(args, options) }
14
14
  end
15
15
  end
16
16
 
@@ -21,16 +21,16 @@ module Jekyll
21
21
  ["force", "-f", "--force", "Overwrite a post if it already exists"],
22
22
  ["date", "-d DATE", "--date DATE", "Specify the post date"],
23
23
  ["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
24
- ["source", "-s", "--source SOURCE", "Custom source directory"],
24
+ ["timestamp_format", "--timestamp-format FORMAT", "Custom timestamp format"],
25
25
  ]
26
26
  end
27
27
 
28
28
  def self.process(args = [], options = {})
29
29
  config = configuration_from_options(options)
30
- params = PostArgParser.new args, options, config
30
+ params = PostArgParser.new(args, options, config)
31
31
  params.validate!
32
32
 
33
- post = PostFileInfo.new params
33
+ post = PostFileInfo.new(params)
34
34
 
35
35
  file_creator = Compose::FileCreator.new(post, params.force?, params.source)
36
36
  file_creator.create!
@@ -41,7 +41,7 @@ module Jekyll
41
41
 
42
42
  class PostArgParser < Compose::ArgParser
43
43
  def date
44
- options["date"].nil? ? Time.now : Date.parse(options["date"])
44
+ @date ||= options["date"] ? Date.parse(options["date"]) : Time.now
45
45
  end
46
46
  end
47
47
 
@@ -63,11 +63,11 @@ module Jekyll
63
63
  end
64
64
 
65
65
  def _time_stamp
66
- @params.date.strftime Jekyll::Compose::DEFAULT_TIMESTAMP_FORMAT
66
+ @params.date.strftime @params.timestamp_format
67
67
  end
68
68
 
69
69
  def content(custom_front_matter = {})
70
- default_front_matter = params.config.dig("jekyll_compose", "post_default_front_matter")
70
+ default_front_matter = front_matter_defaults_for("posts")
71
71
  custom_front_matter.merge!(default_front_matter) if default_front_matter.is_a?(Hash)
72
72
 
73
73
  super({ "date" => _time_stamp }.merge(custom_front_matter))
@@ -8,17 +8,21 @@ module Jekyll
8
8
  c.syntax "publish DRAFT_PATH"
9
9
  c.description "Moves a draft into the _posts directory and sets the date"
10
10
 
11
- c.option "date", "-d DATE", "--date DATE", "Specify the post date"
12
- c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"
13
- c.option "force", "-f", "--force", "Overwrite a post if it already exists"
14
- c.option "source", "-s", "--source SOURCE", "Custom source directory"
15
-
16
- c.action do |args, options|
17
- Jekyll::Commands::Publish.process(args, options)
18
- end
11
+ options.each { |opt| c.option(*opt) }
12
+
13
+ c.action { |args, options| process(args, options) }
19
14
  end
20
15
  end
21
16
 
17
+ def self.options
18
+ [
19
+ ["date", "-d DATE", "--date DATE", "Specify the post date"],
20
+ ["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
21
+ ["force", "-f", "--force", "Overwrite a post if it already exists"],
22
+ ["timestamp_format", "--timestamp-format FORMAT", "Custom timestamp format"],
23
+ ]
24
+ end
25
+
22
26
  def self.process(args = [], options = {})
23
27
  config = configuration_from_options(options)
24
28
  params = PublishArgParser.new args, options, config
@@ -37,7 +41,7 @@ module Jekyll
37
41
  end
38
42
 
39
43
  def date
40
- options["date"].nil? ? Time.now : Date.parse(options["date"])
44
+ @date ||= options["date"] ? Date.parse(options["date"]) : Time.now
41
45
  end
42
46
 
43
47
  def name
@@ -61,7 +65,7 @@ module Jekyll
61
65
  end
62
66
 
63
67
  def front_matter(data)
64
- data["date"] ||= params.date.strftime("%Y-%m-%d %H:%M %z")
68
+ data["date"] ||= params.date.strftime(params.timestamp_format)
65
69
  data
66
70
  end
67
71
  end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Commands
5
+ class Rename < Command
6
+ def self.init_with_program(prog)
7
+ prog.command(:rename) do |c|
8
+ c.syntax "rename PATH NAME"
9
+ c.description "Moves a file to a given NAME and sets the title and date"
10
+
11
+ options.each { |opt| c.option(*opt) }
12
+
13
+ c.action { |args, options| process(args, options) }
14
+ end
15
+ end
16
+
17
+ def self.options
18
+ [
19
+ ["force", "-f", "--force", "Overwrite a post if it already exists"],
20
+ ["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
21
+ ["date", "-d DATE", "--date DATE", "Specify the date"],
22
+ ["now", "--now", "Specify the date as now"],
23
+ ]
24
+ end
25
+
26
+ def self.process(args = [], options = {})
27
+ config = configuration_from_options(options)
28
+ params = RenameArgParser.new(args, options, config)
29
+ params.validate!
30
+
31
+ movement = RenameMovementInfo.new(params)
32
+
33
+ mover = RenameMover.new(movement, params.force?, params.source)
34
+ mover.move
35
+ end
36
+ end
37
+
38
+ class RenameArgParser < Compose::ArgParser
39
+ def validate!
40
+ raise ArgumentError, "You must specify current path and the new title." if args.length < 2
41
+
42
+ if options.values_at("date", "now").compact.length > 1
43
+ raise ArgumentError, "You can only specify one of --date DATE or --now."
44
+ end
45
+ end
46
+
47
+ def current_path
48
+ @current_path ||= args[0]
49
+ end
50
+
51
+ def path
52
+ File.join(source, current_path).sub(%r!\A/!, "")
53
+ end
54
+
55
+ def dirname
56
+ @dirname ||= File.dirname(current_path)
57
+ end
58
+
59
+ def basename
60
+ @basename ||= File.basename(current_path)
61
+ end
62
+
63
+ def title
64
+ @title ||= args.drop(1).join(" ")
65
+ end
66
+
67
+ def touch?
68
+ !!options["date"] || options["now"]
69
+ end
70
+
71
+ def date
72
+ @date ||= if options["now"]
73
+ Time.now
74
+ elsif options["date"]
75
+ Date.parse(options["date"])
76
+ end
77
+ end
78
+
79
+ def date_from_filename
80
+ Date.parse(Regexp.last_match(1)) if basename =~ Jekyll::Document::DATE_FILENAME_MATCHER
81
+ end
82
+
83
+ def post?
84
+ dirname == "_posts"
85
+ end
86
+
87
+ def draft?
88
+ dirname == "_drafts"
89
+ end
90
+ end
91
+
92
+ class RenameMovementInfo < Compose::FileInfo
93
+ attr_reader :params
94
+ def initialize(params)
95
+ @params = params
96
+ end
97
+
98
+ def from
99
+ params.path
100
+ end
101
+
102
+ def resource_type
103
+ if @params.post?
104
+ "post"
105
+ elsif @params.draft?
106
+ "draft"
107
+ else
108
+ "file"
109
+ end
110
+ end
111
+
112
+ def to
113
+ if @params.post?
114
+ File.join(@params.dirname, "#{date_stamp}-#{file_name}")
115
+ else
116
+ File.join(@params.dirname, file_name)
117
+ end
118
+ end
119
+
120
+ def front_matter(data)
121
+ data["title"] = params.title
122
+ data["date"] = time_stamp if @params.touch?
123
+ data
124
+ end
125
+
126
+ private
127
+
128
+ def date_stamp
129
+ if @params.touch?
130
+ @params.date.strftime Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT
131
+ else
132
+ @params.date_from_filename.strftime Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT
133
+ end
134
+ end
135
+
136
+ def time_stamp
137
+ @params.date.strftime Jekyll::Compose::DEFAULT_TIMESTAMP_FORMAT
138
+ end
139
+ end
140
+
141
+ class RenameMover < Compose::FileMover
142
+ def resource_type_from
143
+ @movement.resource_type
144
+ end
145
+ alias_method :resource_type_to, :resource_type_from
146
+ end
147
+ end
148
+ end
@@ -8,24 +8,27 @@ module Jekyll
8
8
  c.syntax "unpublish POST_PATH"
9
9
  c.description "Moves a post back into the _drafts directory"
10
10
 
11
- c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"
12
- c.option "force", "-f", "--force", "Overwrite a draft if it already exists"
13
- c.option "source", "-s", "--source SOURCE", "Custom source directory"
11
+ options.each { |opt| c.option(*opt) }
14
12
 
15
- c.action do |args, options|
16
- process(args, options)
17
- end
13
+ c.action { |args, options| process(args, options) }
18
14
  end
19
15
  end
20
16
 
17
+ def self.options
18
+ [
19
+ ["config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"],
20
+ ["force", "-f", "--force", "Overwrite a draft if it already exists"],
21
+ ]
22
+ end
23
+
21
24
  def self.process(args = [], options = {})
22
25
  config = configuration_from_options(options)
23
- params = UnpublishArgParser.new args, options, config
26
+ params = UnpublishArgParser.new(args, options, config)
24
27
  params.validate!
25
28
 
26
- movement = PostMovementInfo.new params
29
+ movement = PostMovementInfo.new(params)
27
30
 
28
- mover = PostMover.new movement, params.force?, params.source
31
+ mover = PostMover.new(movement, params.force?, params.source)
29
32
  mover.move
30
33
  end
31
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-compose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-04 00:00:00.000000000 Z
11
+ date: 2019-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -101,10 +101,12 @@ files:
101
101
  - lib/jekyll-compose/file_mover.rb
102
102
  - lib/jekyll-compose/movement_arg_parser.rb
103
103
  - lib/jekyll-compose/version.rb
104
+ - lib/jekyll/commands/compose.rb
104
105
  - lib/jekyll/commands/draft.rb
105
106
  - lib/jekyll/commands/page.rb
106
107
  - lib/jekyll/commands/post.rb
107
108
  - lib/jekyll/commands/publish.rb
109
+ - lib/jekyll/commands/rename.rb
108
110
  - lib/jekyll/commands/unpublish.rb
109
111
  homepage: https://github.com/jekyll/jekyll-compose
110
112
  licenses:
@@ -118,14 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
120
  requirements:
119
121
  - - ">="
120
122
  - !ruby/object:Gem::Version
121
- version: 2.3.0
123
+ version: 2.4.0
122
124
  required_rubygems_version: !ruby/object:Gem::Requirement
123
125
  requirements:
124
126
  - - ">="
125
127
  - !ruby/object:Gem::Version
126
128
  version: '0'
127
129
  requirements: []
128
- rubygems_version: 3.0.3
130
+ rubygems_version: 3.0.6
129
131
  signing_key:
130
132
  specification_version: 4
131
133
  summary: Streamline your writing in Jekyll with these commands.