jekyll-compose 0.8.0 → 0.9.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: 1ca9572a408add00659eda3cf8a665db468237f764891adc47e99e12402d189d
4
- data.tar.gz: a93e1531716af74a8c3cf3b014654c32d84cca05a6261613c29b7e4ff0a82ed1
3
+ metadata.gz: f9995b4922a0106ef44e69e728eec77c84c8aed6bc7d3aac7e010f22b6793f45
4
+ data.tar.gz: 02361f4e0b266ceffefeedcd9878b4722d2506bf254a15676f5f506ee4b5dcb7
5
5
  SHA512:
6
- metadata.gz: e6791215e2abbcd23e6e9a83e8fa0002e2f3d6a1f9326655b30bd674d937a1b76d655a8ccfc3963da80cd81afa82a1c15e7b69ac2cdd83f0fdb9ce93b3933561
7
- data.tar.gz: ecfc55570fbae9dd1d71940ec0a7019c25497f445118c3fd4973ef42b1d318f6dfa600d6c835aad364393cb0dfff9de0d4bee430698aaf6d3ab2693dec8fd451
6
+ metadata.gz: 6fac7f63a40345d1ea77a85a2d2416a7acca893c4b70286b80dcc5e98ba09f0f5528dd8a1262b684275d7fbde09d6206d573414516c2f98544d5f0f65fb9968b
7
+ data.tar.gz: c7987e77b4b08d12bb5ffbe5ec181016079d494912a901d2b1187dfc0a6a087de10fa17f17f389ec32d03fe4e71a414d56fe20e55c9c5717bd895271936ba685
@@ -10,9 +10,11 @@ require "jekyll-compose/file_editor"
10
10
 
11
11
  module Jekyll
12
12
  module Compose
13
- DEFAULT_TYPE = "md".freeze
14
- DEFAULT_LAYOUT = "post".freeze
15
- DEFAULT_LAYOUT_PAGE = "page".freeze
13
+ DEFAULT_TYPE = "md"
14
+ DEFAULT_LAYOUT = "post"
15
+ DEFAULT_LAYOUT_PAGE = "page"
16
+ DEFAULT_DATESTAMP_FORMAT = "%Y-%m-%d"
17
+ DEFAULT_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M %z"
16
18
  end
17
19
  end
18
20
 
@@ -1,34 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Jekyll::Compose::ArgParser
4
- attr_reader :args, :options, :config
5
- def initialize(args, options)
6
- @args = args
7
- @options = options
8
- @config = Jekyll.configuration(options)
9
- end
3
+ module Jekyll
4
+ module Compose
5
+ class ArgParser
6
+ attr_reader :args, :options, :config
10
7
 
11
- def validate!
12
- raise ArgumentError, "You must specify a name." if args.empty?
13
- end
8
+ # TODO: Remove `nil` parameter in v1.0
9
+ def initialize(args, options, config = nil)
10
+ @args = args
11
+ @options = options
12
+ @config = config || Jekyll.configuration(options)
13
+ end
14
14
 
15
- def type
16
- options["extension"] || Jekyll::Compose::DEFAULT_TYPE
17
- end
15
+ def validate!
16
+ raise ArgumentError, "You must specify a name." if args.empty?
17
+ end
18
18
 
19
- def layout
20
- options["layout"] || Jekyll::Compose::DEFAULT_LAYOUT
21
- end
19
+ def type
20
+ options["extension"] || Jekyll::Compose::DEFAULT_TYPE
21
+ end
22
22
 
23
- def title
24
- args.join " "
25
- end
23
+ def layout
24
+ options["layout"] || Jekyll::Compose::DEFAULT_LAYOUT
25
+ end
26
26
 
27
- def force?
28
- !!options["force"]
29
- end
27
+ def title
28
+ args.join " "
29
+ end
30
+
31
+ def force?
32
+ !!options["force"]
33
+ end
30
34
 
31
- def source
32
- config["source"].gsub(%r!^#{Regexp.quote(Dir.pwd)}!, "")
35
+ def source
36
+ File.join(config["source"], config["collections_dir"])
37
+ .gsub(%r!^#{Regexp.quote(Dir.pwd)}/*!, "")
38
+ end
39
+ end
33
40
  end
34
41
  end
@@ -11,25 +11,31 @@ module Jekyll
11
11
  end
12
12
 
13
13
  def create!
14
- validate_should_write!
14
+ return unless create?
15
+
15
16
  ensure_directory_exists
16
17
  write_file
17
18
  end
18
19
 
19
20
  def file_path
20
21
  return file.path if root.nil? || root.empty?
21
- return File.join(root, file.path)
22
+
23
+ File.join(root, file.path)
22
24
  end
23
25
 
24
26
  private
25
27
 
26
- def validate_should_write!
27
- raise ArgumentError, "A #{file.resource_type} already exists at #{file_path}" if File.exist?(file_path) && !force
28
+ def create?
29
+ return true if force
30
+ return true unless File.exist?(file_path)
31
+
32
+ Jekyll.logger.warn "A #{file.resource_type} already exists at #{file_path}"
33
+ false
28
34
  end
29
35
 
30
36
  def ensure_directory_exists
31
37
  dir = File.dirname file_path
32
- Dir.mkdir(dir) unless Dir.exist?(dir)
38
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
33
39
  end
34
40
 
35
41
  def write_file
@@ -37,7 +43,7 @@ module Jekyll
37
43
  f.puts(file.content)
38
44
  end
39
45
 
40
- puts "New #{file.resource_type} created at #{file_path}."
46
+ Jekyll.logger.info "New #{file.resource_type} created at #{file_path.cyan}"
41
47
  end
42
48
  end
43
49
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  #
3
4
  # This class is aimed to open the created file in the selected editor.
4
5
  # To use this feature specify at Jekyll config:
@@ -15,6 +16,13 @@ module Jekyll
15
16
  module Compose
16
17
  class FileEditor
17
18
  class << self
19
+ attr_reader :compose_config
20
+ alias_method :jekyll_compose_config, :compose_config
21
+
22
+ def bootstrap(config)
23
+ @compose_config = config["jekyll_compose"] || {}
24
+ end
25
+
18
26
  def open_editor(filepath)
19
27
  run_editor(post_editor, File.expand_path(filepath)) if post_editor
20
28
  end
@@ -25,18 +33,14 @@ module Jekyll
25
33
 
26
34
  def post_editor
27
35
  return unless auto_open?
28
- ENV['JEKYLL_EDITOR'] || ENV['EDITOR']
29
- end
30
36
 
31
- def auto_open?
32
- jekyll_compose_config && jekyll_compose_config['auto_open']
37
+ ENV["JEKYLL_EDITOR"] || ENV["EDITOR"]
33
38
  end
34
39
 
35
- def jekyll_compose_config
36
- @jekyll_compose_config ||= Jekyll.configuration['jekyll_compose']
40
+ def auto_open?
41
+ compose_config["auto_open"]
37
42
  end
38
43
  end
39
44
  end
40
45
  end
41
46
  end
42
-
@@ -1,22 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Jekyll::Compose::FileInfo
4
- attr_reader :params
5
- def initialize(params)
6
- @params = params
7
- end
3
+ module Jekyll
4
+ module Compose
5
+ class FileInfo
6
+ attr_reader :params
7
+ def initialize(params)
8
+ @params = params
9
+ end
8
10
 
9
- def file_name
10
- name = Jekyll::Utils.slugify params.title
11
- "#{name}.#{params.type}"
12
- end
11
+ def file_name
12
+ name = Jekyll::Utils.slugify params.title
13
+ "#{name}.#{params.type}"
14
+ end
13
15
 
14
- def content(custom_front_matter = {})
15
- front_matter = YAML.dump({
16
- "layout" => params.layout,
17
- "title" => params.title,
18
- }.merge(custom_front_matter))
16
+ def content(custom_front_matter = {})
17
+ front_matter = YAML.dump({
18
+ "layout" => params.layout,
19
+ "title" => params.title,
20
+ }.merge(custom_front_matter))
19
21
 
20
- front_matter + "---\n"
22
+ front_matter + "---\n"
23
+ end
24
+ end
21
25
  end
22
26
  end
@@ -19,8 +19,8 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def move
22
- validate_source
23
- validate_should_write!
22
+ return unless valid_source? && valid_destination?
23
+
24
24
  ensure_directory_exists
25
25
  move_file
26
26
  end
@@ -40,10 +40,29 @@ module Jekyll
40
40
 
41
41
  def move_file
42
42
  FileUtils.mv(from, to)
43
- puts "#{resource_type_from.capitalize} #{from} was moved to #{to}"
43
+ Jekyll.logger.info "#{resource_type_from.capitalize} #{from} was moved to #{to}"
44
44
  end
45
45
 
46
46
  private
47
+
48
+ def valid_source?
49
+ return true if File.exist?(from)
50
+
51
+ invalidate_with "There was no #{resource_type_from} found at '#{from}'."
52
+ end
53
+
54
+ def valid_destination?
55
+ return true if force
56
+ return true unless File.exist?(to)
57
+
58
+ invalidate_with "A #{resource_type_to} already exists at #{to}"
59
+ end
60
+
61
+ def invalidate_with(msg)
62
+ Jekyll.logger.warn msg
63
+ false
64
+ end
65
+
47
66
  def from
48
67
  movement.from
49
68
  end
@@ -54,7 +73,8 @@ module Jekyll
54
73
 
55
74
  def file_path(path)
56
75
  return path if root.nil? || root.empty?
57
- return File.join(root, path)
76
+
77
+ File.join(root, path)
58
78
  end
59
79
  end
60
80
  end
@@ -3,13 +3,12 @@
3
3
  module Jekyll
4
4
  module Compose
5
5
  class MovementArgParser < ArgParser
6
-
7
6
  def validate!
8
7
  raise ArgumentError, "You must specify a #{resource_type} path." if args.empty?
9
8
  end
10
9
 
11
10
  def path
12
- args.join " "
11
+ File.join(source, args.join(" ")).sub(%r!\A/!, "")
13
12
  end
14
13
  end
15
14
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Compose
5
- VERSION = "0.8.0".freeze
5
+ VERSION = "0.9.0"
6
6
  end
7
7
  end
@@ -25,12 +25,17 @@ module Jekyll
25
25
  end
26
26
 
27
27
  def self.process(args = [], options = {})
28
- params = Compose::ArgParser.new args, options
28
+ config = configuration_from_options(options)
29
+ params = Compose::ArgParser.new args, options, config
29
30
  params.validate!
30
31
 
31
32
  draft = DraftFileInfo.new params
32
33
 
33
- Compose::FileCreator.new(draft, params.force?, params.source).create!
34
+ file_creator = Compose::FileCreator.new(draft, params.force?, params.source)
35
+ file_creator.create!
36
+
37
+ Compose::FileEditor.bootstrap(config)
38
+ Compose::FileEditor.open_editor(file_creator.file_path)
34
39
  end
35
40
 
36
41
  class DraftFileInfo < Compose::FileInfo
@@ -41,6 +46,13 @@ module Jekyll
41
46
  def path
42
47
  "_drafts/#{file_name}"
43
48
  end
49
+
50
+ def content(custom_front_matter = {})
51
+ default_front_matter = params.config.dig("jekyll_compose", "draft_default_front_matter")
52
+ custom_front_matter.merge!(default_front_matter) if default_front_matter.is_a?(Hash)
53
+
54
+ super(custom_front_matter)
55
+ end
44
56
  end
45
57
  end
46
58
  end
@@ -25,7 +25,8 @@ module Jekyll
25
25
  end
26
26
 
27
27
  def self.process(args = [], options = {})
28
- params = PageArgParser.new args, options
28
+ config = configuration_from_options(options)
29
+ params = PageArgParser.new args, options, config
29
30
  params.validate!
30
31
 
31
32
  page = PageFileInfo.new params
@@ -26,13 +26,16 @@ module Jekyll
26
26
  end
27
27
 
28
28
  def self.process(args = [], options = {})
29
- params = PostArgParser.new args, options
29
+ config = configuration_from_options(options)
30
+ params = PostArgParser.new args, options, config
30
31
  params.validate!
31
32
 
32
33
  post = PostFileInfo.new params
33
34
 
34
35
  file_creator = Compose::FileCreator.new(post, params.force?, params.source)
35
36
  file_creator.create!
37
+
38
+ Compose::FileEditor.bootstrap(config)
36
39
  Compose::FileEditor.open_editor(file_creator.file_path)
37
40
  end
38
41
 
@@ -56,14 +59,17 @@ module Jekyll
56
59
  end
57
60
 
58
61
  def _date_stamp
59
- @params.date.strftime "%Y-%m-%d"
62
+ @params.date.strftime Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT
60
63
  end
61
64
 
62
65
  def _time_stamp
63
- @params.date.strftime("%Y-%m-%d %H:%M %z")
66
+ @params.date.strftime Jekyll::Compose::DEFAULT_TIMESTAMP_FORMAT
64
67
  end
65
68
 
66
69
  def content(custom_front_matter = {})
70
+ default_front_matter = params.config.dig("jekyll_compose", "post_default_front_matter")
71
+ custom_front_matter.merge!(default_front_matter) if default_front_matter.is_a?(Hash)
72
+
67
73
  super({ "date" => _time_stamp }.merge(custom_front_matter))
68
74
  end
69
75
  end
@@ -20,7 +20,8 @@ module Jekyll
20
20
  end
21
21
 
22
22
  def self.process(args = [], options = {})
23
- params = PublishArgParser.new args, options
23
+ config = configuration_from_options(options)
24
+ params = PublishArgParser.new args, options, config
24
25
  params.validate!
25
26
 
26
27
  movement = DraftMovementInfo.new params
@@ -55,7 +56,7 @@ module Jekyll
55
56
  end
56
57
 
57
58
  def to
58
- date_stamp = params.date.strftime "%Y-%m-%d"
59
+ date_stamp = params.date.strftime Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT
59
60
  "_posts/#{date_stamp}-#{params.name}"
60
61
  end
61
62
  end
@@ -64,6 +65,7 @@ module Jekyll
64
65
  def resource_type_from
65
66
  "draft"
66
67
  end
68
+
67
69
  def resource_type_to
68
70
  "post"
69
71
  end
@@ -19,7 +19,8 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def self.process(args = [], options = {})
22
- params = UnpublishArgParser.new args, options
22
+ config = configuration_from_options(options)
23
+ params = UnpublishArgParser.new args, options, config
23
24
  params.validate!
24
25
 
25
26
  movement = PostMovementInfo.new params
@@ -58,6 +59,7 @@ module Jekyll
58
59
  def resource_type_from
59
60
  "post"
60
61
  end
62
+
61
63
  def resource_type_to
62
64
  "draft"
63
65
  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.8.0
4
+ version: 0.9.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: 2018-03-24 00:00:00.000000000 Z
11
+ date: 2018-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop
70
+ name: rubocop-jekyll
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.51'
75
+ version: '0.4'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.51'
82
+ version: '0.4'
83
83
  description: Streamline your writing in Jekyll with these commands.
84
84
  email:
85
85
  - parkrmoore@gmail.com
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
114
114
  - !ruby/object:Gem::Version
115
- version: '0'
115
+ version: 2.3.0
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - ">="
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.7.6
123
+ rubygems_version: 3.0.0.beta3
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Streamline your writing in Jekyll with these commands.