jekyll-conrefifier 0.3.4 → 0.4.0
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-conrefifier.rb +23 -17
- data/lib/version.rb +1 -1
- data/spec/fixtures/_articles/filtered_frontmatter.md +1 -1
- data/spec/fixtures/_data/conrefs.yml +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2ed660e3593b7948aefd367012dde558e9b55db
|
4
|
+
data.tar.gz: 968ce0c43f883868038e4c6515675da48fde8411
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ebbd3f498ab1ba28ec66d932b8d1ac8da2f46962ff6c4647d12a0ec064f30825331cfd9042dbba467363f7a6f5a5037a8819af43cee4196eee2ce1990b711e2
|
7
|
+
data.tar.gz: e4bb16b125a702358237b7f4d00578fa2cbada23e0ca0a79b578086fbf0161b9e334fc1e19665184541b38e8209840cb597d92b0e72d39262e6dcd1df8ae1533
|
data/lib/jekyll-conrefifier.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
module Jekyll
|
2
|
+
module ConrefifierUtils
|
3
|
+
# fetch the custom scope vars, as defined in _config.yml
|
4
|
+
def self.data_file_variables(config, path)
|
5
|
+
data_vars = {}
|
6
|
+
scopes = config['data_file_variables'].select { |v| v['scope']['path'].empty? || Regexp.new(v['scope']['path']) =~ path }
|
7
|
+
scopes.each do |scope|
|
8
|
+
data_vars = data_vars.merge(scope['values'])
|
9
|
+
end
|
10
|
+
|
11
|
+
data_vars
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
2
15
|
class Document
|
3
16
|
alias_method :old_read, :read
|
4
17
|
|
@@ -8,8 +21,12 @@ module Jekyll
|
|
8
21
|
def read(opts = {})
|
9
22
|
old_read(opts)
|
10
23
|
@data.each_pair do |key, value|
|
11
|
-
if value =~ /\{\{.+?\}\}/
|
12
|
-
|
24
|
+
if value =~ /\{\{.+?\}\}/ || value =~ /(\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/
|
25
|
+
data_vars = path.nil? ? {} : ConrefifierUtils.data_file_variables(@site.config, opts[:actual_path] || path)
|
26
|
+
config = { 'page' => data_vars }
|
27
|
+
config = { 'site' => { 'data' => @site.data, 'config' => @site.config } }.merge(config)
|
28
|
+
|
29
|
+
value = Liquid::Template.parse(value).render(config)
|
13
30
|
@data[key] = Jekyll::Renderer.new(@site, self).convert(value)
|
14
31
|
@data[key] = @data[key].sub(/^<p>/, '').sub(/<\/p>$/, '').strip
|
15
32
|
end
|
@@ -50,7 +67,7 @@ module Jekyll
|
|
50
67
|
# if we hit upon if/unless conditionals, we'll need to pause and render them
|
51
68
|
contents = File.read(path)
|
52
69
|
if (matches = contents.scan /(\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/m)
|
53
|
-
unless data_file_variables(path).nil?
|
70
|
+
unless ConrefifierUtils.data_file_variables(config, path).nil?
|
54
71
|
contents = contents.gsub(/\{\{/, '[[')
|
55
72
|
contents = apply_vars_to_datafile(contents, matches, path)
|
56
73
|
contents = contents.gsub(/\[\[/, '{{')
|
@@ -75,10 +92,10 @@ module Jekyll
|
|
75
92
|
def apply_vars_to_datafile(contents, matches, path)
|
76
93
|
return contents if matches.empty?
|
77
94
|
|
78
|
-
data_vars = path.nil? ? {} : data_file_variables(path)
|
95
|
+
data_vars = path.nil? ? {} : ConrefifierUtils.data_file_variables(config, path)
|
79
96
|
|
80
97
|
config = { 'page' => data_vars }
|
81
|
-
config = { 'site' => { 'data' => self.data } }.merge(config)
|
98
|
+
config = { 'site' => { 'data' => self.data, 'config' => self.config } }.merge(config)
|
82
99
|
|
83
100
|
matches.each do |match|
|
84
101
|
parsed_content = begin
|
@@ -94,17 +111,6 @@ module Jekyll
|
|
94
111
|
contents
|
95
112
|
end
|
96
113
|
|
97
|
-
# fetch the custom scope vars, as defined in _config.yml
|
98
|
-
def data_file_variables(path)
|
99
|
-
data_vars = {}
|
100
|
-
scopes = config['data_file_variables'].select { |v| v['scope']['path'].empty? || Regexp.new(v['scope']['path']) =~ path }
|
101
|
-
scopes.each do |scope|
|
102
|
-
data_vars = data_vars.merge(scope['values'])
|
103
|
-
end
|
104
|
-
|
105
|
-
data_vars
|
106
|
-
end
|
107
|
-
|
108
114
|
# allow us to use any variable within Jekyll data files; for example:
|
109
115
|
# - '{{ site.data.conrefs.product_name[site.audience] }} Glossary'
|
110
116
|
# renders as "GitHub Glossary" for dotcom, but "GitHub Enterprise Glossary" for Enterprise
|
@@ -138,7 +144,7 @@ module Jekyll
|
|
138
144
|
data_file = context.registers[:site].data["data_render_#{@id}"]
|
139
145
|
return data_file unless data_file.nil?
|
140
146
|
|
141
|
-
path = @id.
|
147
|
+
path = @id.gsub('.', '/')
|
142
148
|
data_source = File.join(context.registers[:site].source, context.registers[:site].config['data_source'])
|
143
149
|
data_file = File.read("#{data_source}/#{path}.yml")
|
144
150
|
context.registers[:site].data["data_render_#{@id}"] = data_file
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-conrefifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen J. Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|