jekyll-generator-single-source 0.0.11 → 0.0.13
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 +4 -4
- data/lib/jekyll/generator-single-source/hooks/version_is.rb +12 -3
- data/lib/jekyll/generator-single-source/liquid/drops/release.rb +1 -1
- data/lib/jekyll/generator-single-source/liquid/tags/version_is.rb +97 -40
- data/lib/jekyll/generator-single-source/product/release.rb +4 -0
- data/lib/jekyll/generator-single-source/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d938be264eb53f48ab4f3a85dcc1dc2a5c92879454e682ea81bb5d1abf29dcf2
|
4
|
+
data.tar.gz: b61ee8aa0ee3817b032ba99a4c756a5b93a564cd817511da7db85a9a133160cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a982ea197e630d41bb73170a61b21f1386eaa363dfa81848615d8814fcd704214ef3d2181f4a79971913ade994dac22312dc149e8232fdfe1c7cb811a7ee2c9
|
7
|
+
data.tar.gz: d3d644694c3e60c26081160167c4698b7bddb3f327b1a439389f60f4195b415588f790484c39cce4b2308c5a9b143aa4bcbfdcfe954a2d4fc448fb05974bab9d
|
@@ -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
|
-
|
7
|
-
page.content = page.content.gsub(
|
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
|
-
|
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
|
@@ -13,7 +13,7 @@ module Jekyll
|
|
13
13
|
@release = release
|
14
14
|
end
|
15
15
|
|
16
|
-
def_delegators :@release, :value, :label, :latest?, :to_s, :to_str, :versions
|
16
|
+
def_delegators :@release, :value, :label, :latest?, :to_s, :to_str, :versions, :tag
|
17
17
|
|
18
18
|
def hash
|
19
19
|
@hash ||= "#{@release.edition}-#{@release.value}".hash
|
@@ -5,69 +5,126 @@ module Jekyll
|
|
5
5
|
module Liquid
|
6
6
|
module Tags
|
7
7
|
class VersionIs < ::Liquid::Block
|
8
|
-
|
9
|
-
@tag = markup
|
8
|
+
attr_reader :blocks
|
10
9
|
|
11
|
-
|
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
|
19
|
-
|
16
|
+
def nodelist
|
17
|
+
@blocks.map(&:attachment)
|
18
|
+
end
|
20
19
|
|
21
|
-
|
20
|
+
def parse(tokens)
|
21
|
+
while parse_body(@blocks.last.attachment, tokens)
|
22
|
+
end
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
if
|
25
|
-
|
26
|
-
|
25
|
+
def unknown_tag(tag, markup, tokens)
|
26
|
+
if 'else'.freeze == tag
|
27
|
+
push_block(tag, markup)
|
28
|
+
else
|
29
|
+
super
|
27
30
|
end
|
31
|
+
end
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
39
|
+
end
|
40
|
+
''.freeze
|
33
41
|
end
|
42
|
+
end
|
34
43
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
39
77
|
end
|
40
78
|
|
41
|
-
|
42
|
-
|
43
|
-
|
79
|
+
def evaluate(context)
|
80
|
+
params = {}
|
81
|
+
@left.scan(TAG_ATTRIBUTES) do |key, value|
|
82
|
+
params[key.to_sym] = value
|
83
|
+
end
|
44
84
|
|
45
|
-
|
46
|
-
# special handline
|
47
|
-
is_table_row = /^\n\s*\|/.match(contents) && /\|\s*\n$/.match(contents)
|
85
|
+
page = context.environments.first['page']
|
48
86
|
|
49
|
-
|
50
|
-
# We can't use .strip as that removes all leading whitespace,
|
51
|
-
# including indentation
|
52
|
-
contents = contents.sub(/^\n/, '')
|
87
|
+
current_version = to_version(page['release'].value)
|
53
88
|
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
57
109
|
|
58
|
-
|
59
|
-
|
110
|
+
true
|
111
|
+
end
|
60
112
|
|
61
|
-
|
113
|
+
def to_version(input)
|
114
|
+
Gem::Version.new(input.to_s.gsub(/\.x$/, '.0'))
|
115
|
+
end
|
62
116
|
end
|
63
117
|
|
64
|
-
|
65
|
-
|
118
|
+
class ParseTreeVisitor < ::Liquid::ParseTreeVisitor
|
119
|
+
def children
|
120
|
+
@node.blocks
|
121
|
+
end
|
66
122
|
end
|
67
123
|
end
|
124
|
+
|
68
125
|
end
|
69
126
|
end
|
70
127
|
end
|
71
128
|
end
|
72
129
|
|
73
|
-
Liquid::Template.register_tag('if_version', Jekyll::GeneratorSingleSource::Liquid::Tags::VersionIs)
|
130
|
+
::Liquid::Template.register_tag('if_version'.freeze, Jekyll::GeneratorSingleSource::Liquid::Tags::VersionIs)
|
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
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabian Rodriguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|