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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fc934e789af079d163dfb7bf9f994ea16ce5c6d
4
- data.tar.gz: a004f777c732c6513a45ae389bfb1e37f0b5b9d6
3
+ metadata.gz: e2ed660e3593b7948aefd367012dde558e9b55db
4
+ data.tar.gz: 968ce0c43f883868038e4c6515675da48fde8411
5
5
  SHA512:
6
- metadata.gz: 7744291afed0919d295e6cab3b66a320f532a23c672c443b70fb3a47b5e88866105bdaac043b1af1ce952231b9fc11492645c39c2021244c304b30444123f750
7
- data.tar.gz: f16c934cb342edb0e4e0de3821a7b49a1e3c08df6731c3dde518b9809bc98ef146bbcd713506aebb65955560f719f5931816cbefe15168d72733ff3d5fa9d3af
6
+ metadata.gz: 9ebbd3f498ab1ba28ec66d932b8d1ac8da2f46962ff6c4647d12a0ec064f30825331cfd9042dbba467363f7a6f5a5037a8819af43cee4196eee2ce1990b711e2
7
+ data.tar.gz: e4bb16b125a702358237b7f4d00578fa2cbada23e0ca0a79b578086fbf0161b9e334fc1e19665184541b38e8209840cb597d92b0e72d39262e6dcd1df8ae1533
@@ -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
- value = Liquid::Template.parse(value).render({ 'site' => { 'data' => @site.data }.merge(@site.config) })
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.sub('.', '/')
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
@@ -1,3 +1,3 @@
1
1
  module JekyllConrefifier
2
- VERSION = '0.3.4'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  ---
2
- title: Welcome to {{ site.data.conrefs.product_name[site.audience] }}
2
+ title: Welcome to {{ site.data.conrefs.product_name[site.config.audience] }}
3
3
  ---
4
4
 
5
5
  Some other page.
@@ -1,8 +1,8 @@
1
1
  product_name:
2
2
  dotcom: GitHub
3
- '2.0': GitHub Enterprise
4
- '2.1': GitHub Enterprise
5
- 11.10.340: GitHub Enterprise
3
+ '2.0': 'GitHub Enterprise'
4
+ '2.1': 'GitHub Enterprise'
5
+ 11.10.340: 'GitHub Enterprise'
6
6
 
7
7
  product_type: 'Amazing'
8
8
 
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.3.4
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-08 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll