jekyll-generator-single-source 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaa7fc639637793b289f7e6aa4d3789bfabaa63c98fcd60ddfb646c4fe3bd7a3
4
- data.tar.gz: d0a69a8d0b809d597af1d7136ab4ea61e2c1201b0be16217fb4669c035ef313f
3
+ metadata.gz: 6417de38be88c7bc196b618d92f9e1cd22ede431636f801d037ae8d9370d90b9
4
+ data.tar.gz: 1584dc91a34618375f740b22b68ee3e4f297bb0d004eb47a94076063f36ba5fc
5
5
  SHA512:
6
- metadata.gz: 5799ee54ea764e6486d6404a815b211dca85fbf37cf07a89c2215e3d622adab62dcb0330619dd21951d8bb47255702808a77709d81c3ed6632bbc74cf05ac27c
7
- data.tar.gz: d9b2463ea71fdd0e59f3bdfcd59a58d15de35a98fda8e3767f48f634a8d3879f336a433339806dd872db23a1f58de58baa49ef4b294b9ceb3e041de9ebc0b9bf
6
+ metadata.gz: 117c7d2fe0b1edf16e19ecaf941e48cf215ce801d2acc5b7ebbf004a3b2a5a114d336f14d524f7d9c367b40db32415441fa5d79b66fa829851c8b34281cd7a9b
7
+ data.tar.gz: 68d4f7f238f240ba854a97c8861c2da3ba446da7bac0ee86f23b7e07c355bc8e3acf3f5a540bb3e9bb3b5fd41b56e4719eab640760ee02ad1622539ed0cabb5a
data/README.md CHANGED
@@ -56,3 +56,108 @@ jekyll-generator-single-source:
56
56
  multiple_products: false
57
57
  base_dest_path: 'docs'
58
58
  ```
59
+
60
+ ### Inheriting configuration
61
+
62
+ It is sometimes useful to inherit documentation from else where.
63
+
64
+ To do this you can set in your config:
65
+
66
+ ```yaml
67
+ inherit:
68
+ path: /.repos/_src/
69
+ nav: ../_src/.repos/_data/docs_nav_kuma_2.0.x.yml
70
+ patches: [] # Array of modifications on your existing nav applied sequentially
71
+ ```
72
+
73
+ patches identify the section of the docs with an array `path` which lists the title in the doc tree.
74
+ For example if I have a doc:
75
+
76
+ ```yaml
77
+ items:
78
+ - title: foo
79
+ items:
80
+ - text: bar
81
+ - text: foo
82
+ ```
83
+ I can use the path: `[foo, bar]` to modify this subsection of the docs.
84
+
85
+ There are currently 4 types of patches:
86
+
87
+ #### delete
88
+
89
+ Here's a patch to delete that `bar` subsection of the docs.
90
+ ```yaml
91
+ action: delete
92
+ path: [foo]
93
+ entries: [bar] # list of subsection to delete
94
+ ```
95
+
96
+ The docs would look like:
97
+
98
+ ```yaml
99
+ items:
100
+ - title: foo
101
+ items:
102
+ - text: foo
103
+ ```
104
+
105
+ #### modify
106
+
107
+ Here's a patch to modify the `foo` section by changing the title.
108
+ ```yaml
109
+ action: modify
110
+ path: [foo]
111
+ title: foo2
112
+ ```
113
+
114
+ The docs would look like:
115
+
116
+ ```yaml
117
+ items:
118
+ - title: foo2
119
+ items:
120
+ - text: bar
121
+ - text: foo
122
+ ```
123
+
124
+ ### append
125
+
126
+ Add a subsection to the doc
127
+ ```yaml
128
+ action: append
129
+ path: [foo]
130
+ title: foo2
131
+ ```
132
+
133
+ The docs would look like:
134
+
135
+ ```yaml
136
+ items:
137
+ - title: foo
138
+ items:
139
+ - text: bar
140
+ - text: foo
141
+ - title: foo2
142
+ ```
143
+
144
+ ### insert
145
+
146
+ Add a subsection to the doc
147
+ ```yaml
148
+ action: insert
149
+ path: [foo]
150
+ index: 1 # where to insert the entry (if negative inserts from the end)
151
+ text: foo2
152
+ ```
153
+
154
+ The docs would look like:
155
+
156
+ ```yaml
157
+ items:
158
+ - title: foo
159
+ items:
160
+ - text: bar
161
+ - text: foo2
162
+ - text: foo
163
+ ```
@@ -45,8 +45,12 @@ module Jekyll
45
45
  items.map(&:generate_pages)
46
46
  end
47
47
 
48
- def nav
49
- @nav ||= file_path
48
+ def config
49
+ @config ||= begin
50
+ config = NavConfig::Base.process(@file_path)
51
+ Jekyll.logger.debug("generated config: #{config.to_json}")
52
+ config
53
+ end
50
54
  end
51
55
 
52
56
  private
@@ -56,11 +60,6 @@ module Jekyll
56
60
  v['edition'] == product && v['release'] == release
57
61
  end
58
62
  end
59
-
60
- def config
61
- @config ||= SafeYAML.load(File.read(@file_path))
62
- end
63
-
64
63
  end
65
64
  end
66
65
  end
@@ -17,7 +17,7 @@ module Jekyll
17
17
  end
18
18
  end
19
19
 
20
- def_delegators :@top_level_config, :site, :nav, :product,
20
+ def_delegators :@top_level_config, :site, :config, :product,
21
21
  :versions, :assume_generated?, :release
22
22
 
23
23
  def initialize(item_config, top_level_config)
@@ -71,11 +71,11 @@ module Jekyll
71
71
  end
72
72
 
73
73
  def source_path
74
- raise NotImplementedError.new('implement this in subclass')
74
+ raise NotImplementedError.new("implement this in subclass #{self.class}")
75
75
  end
76
76
 
77
77
  def dest_path
78
- raise NotImplementedError.new('implement this in subclass')
78
+ raise NotImplementedError.new("implement this in subclass #{self.class}")
79
79
  end
80
80
  end
81
81
  end
@@ -4,7 +4,7 @@ module Jekyll
4
4
  module GeneratorSingleSource
5
5
  module Liquid
6
6
  module Tags
7
- class VersionIs < ::Liquid::Block
7
+ class VersionIs < ::Liquid::Block
8
8
  def initialize(tag_name, markup, tokens)
9
9
  @tag = markup
10
10
 
@@ -25,19 +25,29 @@ module Jekyll
25
25
  # If there's an exact match, check only that
26
26
  if @params.key?(:eq)
27
27
  version = to_version(@params[:eq])
28
- return '' unless current_version == version
28
+ if Gem::Version.correct?(current_version)
29
+ return '' unless current_version == version
30
+ else
31
+ return '' unless version > to_version(page['latest_released_version'])
32
+ end
29
33
  end
30
34
 
31
35
  # If there's a greater than or equal to check, fail if it's lower
32
36
  if @params.key?(:gte)
33
37
  version = to_version(@params[:gte])
34
- return '' unless current_version >= version
38
+ if Gem::Version.correct?(current_version)
39
+ return '' unless current_version >= version
40
+ end
35
41
  end
36
42
 
37
43
  # If there's a less than or equal to heck, fail if it's higher
38
44
  if @params.key?(:lte)
39
45
  version = to_version(@params[:lte])
40
- return '' unless current_version <= version
46
+ if Gem::Version.correct?(current_version)
47
+ return '' unless current_version <= version
48
+ else
49
+ return '' unless version > to_version(page['latest_released_version'])
50
+ end
41
51
  end
42
52
 
43
53
  # Table rows (starts newline then |, ends with | then newline) need
@@ -60,7 +70,11 @@ module Jekyll
60
70
  end
61
71
 
62
72
  def to_version(input)
63
- Gem::Version.new(input.gsub(/\.x$/, '.0'))
73
+ if Gem::Version.correct?(input)
74
+ Gem::Version.new(input.gsub(/\.x$/, '.0'))
75
+ else
76
+ input
77
+ end
64
78
  end
65
79
  end
66
80
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module GeneratorSingleSource
5
+ module NavConfig
6
+ class Base
7
+ def self.process(file_path)
8
+ new(file_path).process
9
+ end
10
+
11
+ def initialize(file_path)
12
+ @file_path = file_path
13
+ end
14
+
15
+ def process
16
+ if config.is_a?(Array)
17
+ config
18
+ else
19
+ HashConfig.new(file_path: @file_path, config: config).process
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def config
26
+ @config = SafeYAML.load(File.read(@file_path))
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module GeneratorSingleSource
5
+ module NavConfig
6
+ class HashConfig
7
+ REGEXP = /docs_nav_(?<product>.+)_(?<release>.+).ya?ml/
8
+
9
+ def initialize(file_path:, config:)
10
+ @file_path = file_path
11
+ @config = config
12
+ end
13
+
14
+ def process
15
+ @config['product'] = product
16
+ @config['release'] = release
17
+
18
+ inherit!
19
+ trim_config!
20
+
21
+ @config
22
+ end
23
+
24
+ private
25
+
26
+ def product
27
+ @product ||= @config.fetch('product') do |_|
28
+ REGEXP.match(File.basename(@file_path))[:product]
29
+ end
30
+ end
31
+
32
+ def release
33
+ @release ||= @config.fetch('release') do |_|
34
+ REGEXP.match(File.basename(@file_path))[:release]
35
+ end
36
+ end
37
+
38
+ def inherit?
39
+ @config.fetch('inherit', false)
40
+ end
41
+
42
+ def inherit!
43
+ return unless inherit?
44
+
45
+ InheritedConfig.new(
46
+ base_config: @config,
47
+ file_path: @file_path
48
+ ).inherit!
49
+ end
50
+
51
+ def trim_config!
52
+ if @config.key?('max_depth')
53
+ Trimmer.new(@config).trim!
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module GeneratorSingleSource
5
+ module NavConfig
6
+ class InheritedConfig
7
+ def initialize(base_config:, file_path:)
8
+ @base_config = base_config
9
+ @file_path = file_path
10
+ end
11
+
12
+ def inherit!
13
+ rewrite_paths!
14
+ rewrite_items!
15
+ apply_patches!
16
+
17
+ @base_config.delete('inherit')
18
+
19
+ @base_config
20
+ end
21
+
22
+ private
23
+
24
+ def inherited_nav
25
+ # Load the base config as a relative path to the current config
26
+ @inherited_nav ||= SafeYAML.load(
27
+ File.read(
28
+ File.join(File.dirname(@file_path), @base_config['inherit']['nav'])
29
+ )
30
+ )
31
+ end
32
+
33
+ def inherit_path
34
+ @inherit_path ||= @base_config['inherit']['path']
35
+ end
36
+
37
+ def rewrite_paths!
38
+ inherited_nav['items'].map do |entry|
39
+ PathRewriter.new(new_path: inherit_path, entry: entry).rewrite!
40
+ end
41
+ end
42
+
43
+ def rewrite_items!
44
+ @base_config['items'] = inherited_nav['items']
45
+ end
46
+
47
+ def apply_patches!
48
+ @base_config['inherit']['patches']&.each do |patch|
49
+ Patch.new(patch, @base_config).apply
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module GeneratorSingleSource
5
+ module NavConfig
6
+ class Patch
7
+ ACTIONS = ['append', 'delete', 'modify', 'insert'].freeze
8
+
9
+ def initialize(patch, items)
10
+ @path = patch.fetch('path', [])
11
+ @action = patch.fetch('action', 'append')
12
+ @idx = patch.fetch('index', nil)
13
+ @entries = patch.fetch('entries', nil)
14
+ @items = items
15
+
16
+ unless ACTIONS.include? @action
17
+ raise ArgumentError.new("action can only be #{ACTIONS.join(', ')} got `#{@action}` for patch #{patch.inspect}")
18
+ end
19
+
20
+ if @action == 'insert' && @idx == nil
21
+ raise ArgumentError.new("when using insert action you must set 'index' for patch #{patch.inspect}")
22
+ end
23
+
24
+ if @action == 'delete' && @entries == nil
25
+ raise ArgumentError.new("when using delete action you must set 'entries' for patch #{patch.inspect}")
26
+ end
27
+
28
+ raise ArgumentError.new("path must be an array for patch #{patch.inspect}") unless @path.is_a?(Array)
29
+
30
+ @patch = patch.except('action', 'path', 'index')
31
+ end
32
+
33
+ def apply
34
+ @path.each do |p|
35
+ all = @items.fetch('items', []).select do |i|
36
+ (i.fetch('title') {|_| i.fetch('text')}) == p
37
+ end
38
+ @items = all.fetch(0) { raise "Couldn't find docs section with title or text '#{p}' to apply delete patch #{self.inspect}" }
39
+ end
40
+
41
+ if @action == "delete"
42
+ @entries.each do |entry|
43
+ idx = @items['items'].index {|item| (item.fetch('title') {|_| item.fetch('text')}) == entry}
44
+ raise "Couldn't find docs section with title or text '#{entry}' to apply delete patch #{self.inspect}" unless idx != nil
45
+ @items['items'].delete_at(idx)
46
+ end
47
+ elsif @action == "modify"
48
+ @items.merge!(@patch)
49
+ elsif @action == "insert"
50
+ @items['items'].insert(@idx, @patch)
51
+ elsif @action == "append"
52
+ @items['items'].push(@patch)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module GeneratorSingleSource
5
+ module NavConfig
6
+ class PathRewriter
7
+ def initialize(new_path:, entry:)
8
+ @new_path = new_path
9
+ @entry = entry
10
+ end
11
+
12
+ def rewrite_rec(entry)
13
+ entry['items'].map do |v|
14
+ next if v['absolute_url']
15
+ if v.has_key?('src')
16
+ original = v['src']
17
+ v['src'] = File.join(@new_path, original)
18
+ Jekyll.logger.debug("rewrote #{original} to #{v['src']}")
19
+ elsif v.has_key?('url')
20
+ original = v['url']
21
+ parts = v['url'].split('#', 2)
22
+ v['src'] = File.join(@new_path, parts[0])
23
+ Jekyll.logger.debug("rewrote #{original} to #{v['src']}")
24
+ end
25
+ rewrite_rec(v) if v.has_key?('items')
26
+ end
27
+ end
28
+
29
+ def rewrite!
30
+ rewrite_rec(@entry)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module GeneratorSingleSource
5
+ module NavConfig
6
+ class Trimmer
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def trim!
12
+ trim_depth(@config, max_depth)
13
+ end
14
+
15
+ private
16
+
17
+ def max_depth
18
+ @max_depth ||= @config.fetch('max_depth')
19
+ end
20
+
21
+ def trim_depth(entry, left)
22
+ if left == 0
23
+ entry.delete('items')
24
+ end
25
+ if entry['items']
26
+ entry['items'].each { |x| trim_depth(x, left - 1) }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -32,6 +32,7 @@ module Jekyll
32
32
  @data['release'] = nav_item.release
33
33
  @data['version'] = nav_item.versions['default']
34
34
  @data['versions'] = nav_item.versions
35
+ @data['nav_items'] = nav_item.config
35
36
 
36
37
  # Set the layout if it's not already provided
37
38
  @data['layout'] ||= GeneratorConfig.new(@site).layout
@@ -63,7 +64,11 @@ module Jekyll
63
64
  end
64
65
 
65
66
  def to_version(input)
66
- Gem::Version.new(input.gsub(/\.x$/, '.0'))
67
+ if Gem::Version.correct?(input)
68
+ Gem::Version.new(input.gsub(/\.x$/, '.0'))
69
+ else
70
+ input
71
+ end
67
72
  end
68
73
  end
69
74
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module GeneratorSingleSource
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.6'
6
6
  end
7
7
  end
@@ -8,6 +8,12 @@ require_relative 'generator-single-source/source/base'
8
8
  require_relative 'generator-single-source/source/dir_source'
9
9
  require_relative 'generator-single-source/source/file_source'
10
10
  require_relative 'generator-single-source/doc_nav_config'
11
+ require_relative 'generator-single-source/nav_config/base'
12
+ require_relative 'generator-single-source/nav_config/hash_config'
13
+ require_relative 'generator-single-source/nav_config/inherited_config'
14
+ require_relative 'generator-single-source/nav_config/patch'
15
+ require_relative 'generator-single-source/nav_config/path_rewriter'
16
+ require_relative 'generator-single-source/nav_config/trimmer'
11
17
  require_relative 'generator-single-source/generator_config'
12
18
  require_relative 'generator-single-source/generator'
13
19
  require_relative 'generator-single-source/single_source_page'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-generator-single-source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabian Rodriguez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-09 00:00:00.000000000 Z
11
+ date: 2023-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '12.0'
53
+ version: '13.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '12.0'
60
+ version: '13.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -72,7 +72,7 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '3.11'
75
- description:
75
+ description:
76
76
  email:
77
77
  - fabian.rodriguez@konghq.com
78
78
  executables: []
@@ -94,6 +94,12 @@ files:
94
94
  - lib/jekyll/generator-single-source/generator_config.rb
95
95
  - lib/jekyll/generator-single-source/hooks/version_is.rb
96
96
  - lib/jekyll/generator-single-source/liquid/tags/version_is.rb
97
+ - lib/jekyll/generator-single-source/nav_config/base.rb
98
+ - lib/jekyll/generator-single-source/nav_config/hash_config.rb
99
+ - lib/jekyll/generator-single-source/nav_config/inherited_config.rb
100
+ - lib/jekyll/generator-single-source/nav_config/patch.rb
101
+ - lib/jekyll/generator-single-source/nav_config/path_rewriter.rb
102
+ - lib/jekyll/generator-single-source/nav_config/trimmer.rb
97
103
  - lib/jekyll/generator-single-source/single_source_page.rb
98
104
  - lib/jekyll/generator-single-source/source/base.rb
99
105
  - lib/jekyll/generator-single-source/source/dir_source.rb
@@ -104,7 +110,7 @@ homepage: https://github.com/kong/jekyll-generator-single-source
104
110
  licenses:
105
111
  - Apache-2.0
106
112
  metadata: {}
107
- post_install_message:
113
+ post_install_message:
108
114
  rdoc_options: []
109
115
  require_paths:
110
116
  - lib
@@ -119,8 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
125
  - !ruby/object:Gem::Version
120
126
  version: '0'
121
127
  requirements: []
122
- rubygems_version: 3.0.3.1
123
- signing_key:
128
+ rubygems_version: 3.3.24
129
+ signing_key:
124
130
  specification_version: 4
125
131
  summary: A Jekyll plugin to dynamically generate pages from a single source file
126
132
  test_files: []