jekyll-generator-single-source 0.0.10 → 0.0.12

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: 7d35a6631597a818b3c93d374f7550943ef3d3df2ee06cfbf18ca9cfbf4f694c
4
- data.tar.gz: 1f7d48363f58103e6f014ecd685adc435d5f29b6caa0640917eb6fa8b539971f
3
+ metadata.gz: 5b4f9fdea43b8497d0e68de02c6180367cd80914fd39b01d376f3f3de18034a5
4
+ data.tar.gz: 47a20d4176618f8ab1fb176d84e08257bc219acd66feb937f6fbeb4174216812
5
5
  SHA512:
6
- metadata.gz: b5702e971c9711190b1bf9f3338838f5b0f636528bb535590d2935acbe82ccd0fdc7a74403ffa1c581e4728db75f0bce642506f93c8dcad3d148a0a82af3df04
7
- data.tar.gz: 4775af4aa98b4729ccde3d21677237ec202ae8fe954de6ee00bb7ff620dcd48388ea46481e216406391e0a5fb4dc8e823ed6b126285b55e51fd2be1176e2ab8a
6
+ metadata.gz: 11ef1d9c947cd3446fb3057d2ee29dba6540c09a302943a9c8c66384e444762d8f751693d7314abc6cefcb61c683ed4d1d105b4a13efd99d6c06d16d02cb48d4
7
+ data.tar.gz: 2fc4d5d3fda4efa776ef7228ba81d909a83112f3dd5e74b6c34fd53da8d203594bfb8752ed9e872d9942338886cda82c8b6889a737491e2dc024fb6ee4e22919
@@ -5,14 +5,15 @@ module Jekyll
5
5
  class DocNavConfig
6
6
  attr_reader :file_path, :site
7
7
 
8
- def initialize(file_path, site, versions_from_file)
8
+ def initialize(file_path, site)
9
9
  @file_path = file_path
10
10
  @site = site
11
- @versions_from_file = versions_from_file
12
11
  end
13
12
 
14
13
  def skip_generation?
15
- !(config.is_a?(Hash) && config['generate'])
14
+ # skip if release is not available because it
15
+ # was skipped using an ENV variable
16
+ !(config.is_a?(Hash) && config['generate']) || release.nil?
16
17
  end
17
18
 
18
19
  def assume_generated?
@@ -31,11 +32,13 @@ module Jekyll
31
32
  end
32
33
 
33
34
  def release
34
- @release ||= config['release']
35
+ @release ||= edition.releases.detect do |r|
36
+ r.value == config['release']
37
+ end
35
38
  end
36
39
 
37
40
  def versions
38
- @versions ||= Versions.extract(version)
41
+ @versions ||= release.versions
39
42
  end
40
43
 
41
44
  def generate_pages
@@ -54,10 +57,8 @@ module Jekyll
54
57
 
55
58
  private
56
59
 
57
- def version
58
- @version ||= @versions_from_file.detect do |v|
59
- v['edition'] == product && v['release'] == release
60
- end
60
+ def edition
61
+ @edition ||= Product::Edition.new(edition: product, site:)
61
62
  end
62
63
  end
63
64
  end
@@ -51,7 +51,9 @@ module Jekyll
51
51
  end
52
52
 
53
53
  def product_page?
54
- url == "/#{product}/" || url == "/#{product}/#{release}/"
54
+ url == "/#{product}/" ||
55
+ url == "/#{product}/#{release}/" ||
56
+ url == "/#{product}/#{release.value}/"
55
57
  end
56
58
  end
57
59
  end
@@ -9,7 +9,7 @@ module Jekyll
9
9
  config = GeneratorConfig.new(site)
10
10
 
11
11
  Dir.glob(File.join(config.docs_nav_folder, 'docs_nav_*.yml')).each do |f|
12
- DocNavConfig.new(f, site, config.versions).generate_pages
12
+ DocNavConfig.new(f, site).generate_pages
13
13
  end
14
14
  end
15
15
  end
@@ -11,10 +11,10 @@ module Jekyll
11
11
  @site = site
12
12
  end
13
13
 
14
- def versions
15
- @versions ||= SafeYAML.load(File.read(
14
+ def editions
15
+ @editions ||= SafeYAML.load(File.read(
16
16
  File.expand_path(versions_file, @site.source)
17
- ))
17
+ )).group_by { |e| e['edition'] }
18
18
  end
19
19
 
20
20
  def layout
@@ -3,9 +3,18 @@
3
3
  Jekyll::Hooks.register :pages, :pre_render do |page|
4
4
  # Replace double line breaks when using if_version when
5
5
  # combined with <pre> blocks. This is usually in code samples
6
- page.content = page.content.gsub(/\n(\s*{% if_version)/, '\1')
7
- page.content = page.content.gsub("{% endif_version %}\n\n", "{% endif_version %}\n")
6
+ # TODO: comment this for now, I need to double-check if we need it
7
+ # page.content = page.content.gsub(/\n(\s*{% if_version)/, '\1')
8
+ # page.content = page.content.gsub("{% endif_version %}\n\n", "{% endif_version %}\n")
8
9
 
9
10
  # Also allow for a newline after endif_version when in a table
10
- page.content = page.content.gsub("{% endif_version %}\n|", '{% endif_version %}|')
11
+ # strip extra new lines
12
+ page.content = page.content.gsub(/\|\s*\n\n\s*{% if_version /, "|\n{% if_version ")
13
+ page.content = page.content.gsub(/\|\s*\n{% endif_version %}\n+\|/, "|\n{% endif_version -%}\n\|")
14
+ page.content = page.content.gsub(/\|\s*\n{% endif_version %}\n+\s*{% if_version (.*) %}\n/) do |_match|
15
+ "|\n{% endif_version -%}\n{% if_version #{$1} -%}\n"
16
+ end
17
+ page.content = page.content.gsub(/\|\s*\n+{% if_version (.*) %}\n/) do |_match|
18
+ "|\n{% if_version #{$1} -%}\n"
19
+ end
11
20
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module GeneratorSingleSource
5
+ module Liquid
6
+ module Drops
7
+ class Release < ::Liquid::Drop
8
+ extend Forwardable
9
+
10
+ attr_reader :release
11
+
12
+ def initialize(release)
13
+ @release = release
14
+ end
15
+
16
+ def_delegators :@release, :value, :label, :latest?, :to_s, :to_str, :versions
17
+
18
+ def hash
19
+ @hash ||= "#{@release.edition}-#{@release.value}".hash
20
+ end
21
+
22
+ def ==(other)
23
+ return @release.value == other if other.is_a?(String)
24
+
25
+ @release.to_h == other.release.to_h
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -5,83 +5,126 @@ module Jekyll
5
5
  module Liquid
6
6
  module Tags
7
7
  class VersionIs < ::Liquid::Block
8
- def initialize(tag_name, markup, tokens)
9
- @tag = markup
8
+ attr_reader :blocks
10
9
 
11
- @params = {}
12
- markup.scan(::Liquid::TagAttributes) do |key, value|
13
- @params[key.to_sym] = value
14
- end
10
+ def initialize(tag_name, markup, options)
15
11
  super
12
+ @blocks = []
13
+ push_block('if_version'.freeze, markup)
16
14
  end
17
15
 
18
- def render(context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
19
- page = context.environments.first['page']
16
+ def nodelist
17
+ @blocks.map(&:attachment)
18
+ end
20
19
 
21
- current_version = to_version(page['kong_version'] || page['version'])
20
+ def parse(tokens)
21
+ while parse_body(@blocks.last.attachment, tokens)
22
+ end
23
+ end
22
24
 
23
- # If there's an exact match, check only that
24
- if @params.key?(:eq)
25
- version = to_version(@params[:eq])
26
- if Gem::Version.correct?(current_version)
27
- return '' unless current_version == version
28
- else
29
- return '' unless version > to_version(page['latest_released_version'])
30
- end
25
+ def unknown_tag(tag, markup, tokens)
26
+ if 'else'.freeze == tag
27
+ push_block(tag, markup)
28
+ else
29
+ super
31
30
  end
31
+ end
32
32
 
33
- # If there's a greater than or equal to check, fail if it's lower
34
- if @params.key?(:gte)
35
- version = to_version(@params[:gte])
36
- if Gem::Version.correct?(current_version)
37
- return '' unless current_version >= version
33
+ def render(context)
34
+ context.stack do
35
+ @blocks.each do |block|
36
+ if block.evaluate(context)
37
+ return block.attachment.render(context)
38
+ end
38
39
  end
40
+ ''.freeze
39
41
  end
42
+ end
40
43
 
41
- # If there's a less than or equal to heck, fail if it's higher
42
- if @params.key?(:lte)
43
- version = to_version(@params[:lte])
44
- if Gem::Version.correct?(current_version)
45
- return '' unless current_version <= version
46
- else
47
- return '' unless version > to_version(page['latest_released_version'])
48
- end
44
+ private
45
+
46
+ def push_block(tag, markup)
47
+ block = if tag == 'else'.freeze
48
+ ::Liquid::ElseCondition.new
49
+ else
50
+ parse_with_selected_parser(markup)
51
+ end
52
+
53
+ @blocks.push(block)
54
+ block.attach(::Liquid::BlockBody.new)
55
+ end
56
+
57
+ def lax_parse(markup)
58
+ parse_condition(markup)
59
+ end
60
+
61
+ def strict_parse(markup)
62
+ parse_condition(markup)
63
+ end
64
+
65
+ def parse_condition(markup)
66
+ IfVersionCondition.new(markup)
67
+ end
68
+
69
+ class IfVersionCondition < ::Liquid::Condition
70
+ # Extracted from:
71
+ # https://github.com/Shopify/liquid/blob/ae3057e94b7c4d657e6bc02e1d50398e34cc6ed7/lib/liquid.rb#L37
72
+ # and modified to support comma-separated values
73
+ TAG_ATTRIBUTES = /(\w+)\s*\:\s*((?-mix:(?-mix:"[^"]*"|'[^']*')|(?:[^\s\|'"]|(?-mix:"[^"]*"|'[^']*'))+))/o
74
+
75
+ def else?
76
+ false
49
77
  end
50
78
 
51
- # Don't evaluate the liquid block unconditionally,
52
- # only evaluate it if the version matches
53
- contents = super
79
+ def evaluate(context)
80
+ params = {}
81
+ @left.scan(TAG_ATTRIBUTES) do |key, value|
82
+ params[key.to_sym] = value
83
+ end
54
84
 
55
- # Table rows (starts newline then |, ends with | then newline) need
56
- # special handline
57
- is_table_row = /^\n\s*\|/.match(contents) && /\|\s*\n$/.match(contents)
85
+ page = context.environments.first['page']
58
86
 
59
- # Remove the leading whitespace and return
60
- # We can't use .strip as that removes all leading whitespace,
61
- # including indentation
62
- contents = contents.sub(/^\n/, '')
87
+ current_version = to_version(page['release'].value)
63
88
 
64
- # Remove the trailing whitespace
65
- # But ONLY if it's not a table row
66
- contents = contents.sub(/\n$/, '') unless is_table_row
89
+ if params.key? :eq
90
+ # If there's an exact match, check only that
91
+ versions = params[:eq].split(',').map { |v| to_version(v) }
92
+ return false unless versions.any? { |v| v == current_version }
93
+ end
94
+ if params.key? :gte
95
+ # If there's a greater than or equal to check, fail if it's lower
96
+ version = to_version(params[:gte])
97
+ return false unless current_version >= version
98
+ end
99
+ if params.key? :lte
100
+ # If there's a less than or equal to check, fail if it's higher
101
+ version = to_version(params[:lte])
102
+ return false unless current_version <= version
103
+ end
104
+ if params.key? :neq
105
+ # If there's a not-equal to check, fail if they are equal
106
+ version = to_version(params[:neq])
107
+ return false if current_version == version
108
+ end
67
109
 
68
- # If it's not a table row, put the \n that we removed in pre_render back
69
- contents = "\n#{contents}\n" unless is_table_row || @params[:inline]
110
+ true
111
+ end
70
112
 
71
- contents
113
+ def to_version(input)
114
+ Gem::Version.new(input.to_s.gsub(/\.x$/, '.0'))
115
+ end
72
116
  end
73
117
 
74
- def to_version(input)
75
- if Gem::Version.correct?(input)
76
- Gem::Version.new(input.gsub(/\.x$/, '.0'))
77
- else
78
- input
118
+ class ParseTreeVisitor < ::Liquid::ParseTreeVisitor
119
+ def children
120
+ @node.blocks
79
121
  end
80
122
  end
81
123
  end
124
+
82
125
  end
83
126
  end
84
127
  end
85
128
  end
86
129
 
87
- Liquid::Template.register_tag('if_version', Jekyll::GeneratorSingleSource::Liquid::Tags::VersionIs)
130
+ ::Liquid::Template.register_tag('if_version'.freeze, Jekyll::GeneratorSingleSource::Liquid::Tags::VersionIs)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module GeneratorSingleSource
5
+ module Product
6
+ class Edition
7
+
8
+ def self.all(site:)
9
+ GeneratorConfig.new(site).editions
10
+ end
11
+
12
+ def initialize(edition:, site:)
13
+ @edition = edition
14
+ @site = site
15
+ end
16
+
17
+ def releases
18
+ @releases ||= releases_data
19
+ .map { |r| Product::Release.new(r) }
20
+ .reject do |r|
21
+ r.label && ENV["SKIP_#{name.upcase.gsub('-','_')}_#{r.label.upcase}"]
22
+ end
23
+ end
24
+
25
+ def latest_release
26
+ @latest_release ||= releases.detect(&:latest?)
27
+ end
28
+
29
+ def name
30
+ @name ||= @edition
31
+ end
32
+
33
+ private
34
+
35
+ def releases_data
36
+ @releases_data ||= self.class.all(site: @site).fetch(@edition, [])
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module GeneratorSingleSource
5
+ module Product
6
+ class Release
7
+ attr_reader :release_hash
8
+
9
+ def initialize(release_hash)
10
+ @release_hash = release_hash
11
+
12
+ validate!
13
+ end
14
+
15
+ def edition
16
+ @edition ||= @release_hash.fetch('edition')
17
+ end
18
+
19
+ def value
20
+ @value ||= @release_hash['release']
21
+ end
22
+
23
+ def latest?
24
+ @release_hash['latest']
25
+ end
26
+
27
+ def label
28
+ @label ||= @release_hash['label']
29
+ end
30
+
31
+ def versions
32
+ @versions ||= begin
33
+ if @release_hash.has_key?('version')
34
+ { 'default' => @release_hash['version'] }
35
+ else
36
+ versions_without_suffix
37
+ end
38
+ end
39
+ end
40
+
41
+ def default_version
42
+ @default_version ||= versions['default']
43
+ end
44
+
45
+ def to_str
46
+ if @release_hash.key?('label')
47
+ label
48
+ else
49
+ value
50
+ end
51
+ end
52
+ alias :to_s :to_str
53
+
54
+ def to_semver
55
+ value.gsub('-x', '.x').gsub(/\.x/, '.0')
56
+ end
57
+
58
+ def to_liquid
59
+ Liquid::Drops::Release.new(self)
60
+ end
61
+
62
+ def to_h
63
+ @release_hash
64
+ end
65
+
66
+ private
67
+
68
+ def validate!
69
+ if @release_hash.has_key?('version') &&
70
+ @release_hash.keys.any? { |k| k.end_with?('-version') }
71
+ raise SyntaxError.new(
72
+ "Invalid config. `version` and `*-version` present in #{@release_hash}."
73
+ )
74
+ end
75
+ end
76
+
77
+ def versions_without_suffix
78
+ @versions_without_suffix ||= @release_hash.each_with_object({}) do |(k, v), h|
79
+ if k.end_with?('-version')
80
+ h[k.sub('-version', '')] = v
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -29,16 +29,19 @@ module Jekyll
29
29
  @data['is_dir_index'] = nav_item.source.dir?
30
30
 
31
31
  # Set the current release and concrete version
32
- @data['release'] = nav_item.release
33
- @data['version'] = nav_item.versions['default']
34
- @data['versions'] = nav_item.versions
32
+ release = nav_item.release
33
+ @data['release'] = Liquid::Drops::Release.new(release)
34
+ @data['edition'] = release.edition
35
+ @data['version'] = release.default_version
36
+ @data['versions'] = release.versions
37
+
35
38
  @data['nav_items'] = nav_item.config
36
39
 
37
40
  # Set the layout if it's not already provided
38
41
  @data['layout'] ||= GeneratorConfig.new(@site).layout
39
42
 
40
43
  # Apply any overrides
41
- current = to_version(@data['release'])
44
+ current = to_version(release.value)
42
45
  @data['overrides']&.each do |key, entries|
43
46
  entries.each do |value, conditions|
44
47
  gte = conditions['gte'] ? to_version(conditions['gte']) : nil
@@ -63,12 +66,8 @@ module Jekyll
63
66
  @relative_path = nav_item.source.file_path
64
67
  end
65
68
 
66
- def to_version(input)
67
- if Gem::Version.correct?(input)
68
- Gem::Version.new(input.gsub(/\.x$/, '.0'))
69
- else
70
- input
71
- end
69
+ def to_version(input)
70
+ Gem::Version.new(input.to_s.gsub(/\.x$/, '.0'))
72
71
  end
73
72
  end
74
73
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module GeneratorSingleSource
5
- VERSION = '0.0.10'
5
+ VERSION = '0.0.12'
6
6
  end
7
7
  end
@@ -18,4 +18,6 @@ require_relative 'generator-single-source/generator_config'
18
18
  require_relative 'generator-single-source/generator'
19
19
  require_relative 'generator-single-source/single_source_page'
20
20
  require_relative 'generator-single-source/version'
21
- require_relative 'generator-single-source/versions'
21
+ require_relative 'generator-single-source/product/release'
22
+ require_relative 'generator-single-source/product/edition'
23
+ require_relative 'generator-single-source/liquid/drops/release'
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.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabian Rodriguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-06 00:00:00.000000000 Z
11
+ date: 2024-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -93,6 +93,7 @@ files:
93
93
  - lib/jekyll/generator-single-source/generator.rb
94
94
  - lib/jekyll/generator-single-source/generator_config.rb
95
95
  - lib/jekyll/generator-single-source/hooks/version_is.rb
96
+ - lib/jekyll/generator-single-source/liquid/drops/release.rb
96
97
  - lib/jekyll/generator-single-source/liquid/tags/version_is.rb
97
98
  - lib/jekyll/generator-single-source/nav_config/base.rb
98
99
  - lib/jekyll/generator-single-source/nav_config/hash_config.rb
@@ -100,12 +101,13 @@ files:
100
101
  - lib/jekyll/generator-single-source/nav_config/patch.rb
101
102
  - lib/jekyll/generator-single-source/nav_config/path_rewriter.rb
102
103
  - lib/jekyll/generator-single-source/nav_config/trimmer.rb
104
+ - lib/jekyll/generator-single-source/product/edition.rb
105
+ - lib/jekyll/generator-single-source/product/release.rb
103
106
  - lib/jekyll/generator-single-source/single_source_page.rb
104
107
  - lib/jekyll/generator-single-source/source/base.rb
105
108
  - lib/jekyll/generator-single-source/source/dir_source.rb
106
109
  - lib/jekyll/generator-single-source/source/file_source.rb
107
110
  - lib/jekyll/generator-single-source/version.rb
108
- - lib/jekyll/generator-single-source/versions.rb
109
111
  homepage: https://github.com/kong/jekyll-generator-single-source
110
112
  licenses:
111
113
  - Apache-2.0
@@ -118,14 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
120
  requirements:
119
121
  - - ">="
120
122
  - !ruby/object:Gem::Version
121
- version: 3.1.2
123
+ version: 3.2.2
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.3.24
130
+ rubygems_version: 3.4.20
129
131
  signing_key:
130
132
  specification_version: 4
131
133
  summary: A Jekyll plugin to dynamically generate pages from a single source file
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module GeneratorSingleSource
5
- class Versions
6
- def self.extract(version_hash)
7
- new(version_hash).versions
8
- end
9
-
10
- def initialize(version)
11
- @version = version
12
-
13
- validate!
14
- end
15
-
16
- def versions
17
- if @version.has_key?('version')
18
- { 'default' => @version['version'] }
19
- else
20
- versions_without_suffix
21
- end
22
- end
23
-
24
- private
25
-
26
- def validate!
27
- if @version.has_key?('version') &&
28
- @version.keys.any? { |k| k.end_with?('-version') }
29
- raise SyntaxError.new(
30
- "Invalid config. `version` and `*-version` present in #{@version}."
31
- )
32
- end
33
- end
34
-
35
- def versions_without_suffix
36
- @versions_without_suffix ||= @version.each_with_object({}) do |(k, v), h|
37
- if k.end_with?('-version')
38
- h[k.sub('-version', '')] = v
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end