jekyll-conrefifier 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7059a7736b67f01af3dfb5000cf2c686e98a5abe
4
- data.tar.gz: 866a2d9c119d548c5028735df74500f8e57ae429
3
+ metadata.gz: efdff59b0efc358924f29d372fdde512b16c1280
4
+ data.tar.gz: 32e3178eb7720e9e7f8371251fc057495584f386
5
5
  SHA512:
6
- metadata.gz: 32748009a5dcbd176b78dab0349ef649040e333a4005da9300db83720f8c87641a110bb672ce5eaa2589539f22693120d38da074741208e0f516137bdaa7ad27
7
- data.tar.gz: 86411b8490361e483925086fccb6be2b49afd579b437890e83af0152d74b612da30f44302971da0194cfa256c8719bfc492b73e3ea5ff0202638f347e04190f8
6
+ metadata.gz: ebf92a86304459d5004088293efdd19e1586a30ccc3c61680eaee9fdfc875895c84cb4d221eeba215391fa51f2b7b4c3ff14ba0235327d66d3df2308148a00e8
7
+ data.tar.gz: 459315d522117b7db0d552cd053727c01f3959da75e7cfc67d792918c682096ff9c36336505c1890ee8e7cedafffd9a3abcecb5442ecdd83acc5df96b2492dc0
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/version_tmp
17
17
  tmp
18
18
  spec/fixtures/_site
19
19
  .jekyll_metadata
20
+ .DS_Store
@@ -116,11 +116,9 @@ module Jekyll
116
116
  ConrefifierUtils.og_paths << path.slice(dir.index(src) + src.length + 1..-1).sub(/\.[^.]+\z/, '')
117
117
  # if we hit upon if/unless conditionals, we'll need to pause and render them
118
118
  contents = File.read(path)
119
- if (matches = contents.scan /(\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/m)
119
+ if (matches = contents.scan /(\s*\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/m)
120
120
  unless ConrefifierUtils.data_file_variables(config, path).nil?
121
- contents = contents.gsub(/\{\{/, '[[')
122
- contents = apply_vars_to_datafile(contents, matches, path)
123
- contents = contents.gsub(/\[\[/, '{{')
121
+ contents = apply_vars_to_datafile(contents, matches, path, { preserve_all: true } )
124
122
  end
125
123
  end
126
124
 
@@ -139,13 +137,14 @@ module Jekyll
139
137
  keys = path.split('/')
140
138
  value = keys.inject(data, :fetch)
141
139
  yaml_dump = YAML::dump value
140
+
142
141
  keys[0...-1].inject(data, :fetch)[keys.last] = SafeYAML.load transform_liquid_variables(yaml_dump, path)
143
142
  end
144
143
  old_read_collections
145
144
  end
146
145
 
147
146
  # apply the custom scope plus the rest of the `site.data` information
148
- def apply_vars_to_datafile(contents, matches, path)
147
+ def apply_vars_to_datafile(contents, matches, path, preserve_all: true, preserve_non_vars: false)
149
148
  return contents if matches.empty?
150
149
 
151
150
  data_vars = path.nil? ? {} : ConrefifierUtils.data_file_variables(config, path)
@@ -155,16 +154,21 @@ module Jekyll
155
154
 
156
155
  matches.each do |match|
157
156
  match = match.is_a?(Array) ? match.first : match
157
+ safe_match = if preserve_all
158
+ match.gsub(/\{\{/, '[[\1')
159
+ elsif preserve_non_vars
160
+ match.gsub(/\{\{(\s*)(?!\s*(site|page))/, '[[\1')
161
+ end
158
162
 
159
163
  parsed_content = begin
160
- Liquid::Template.parse(match).render(config)
161
- rescue
164
+ parsed = Liquid::Template.parse(safe_match).render(config)
165
+ parsed.gsub(/\[\[/, '{{\1') if preserve_all || preserve_non_vars
166
+ rescue Exception => e
167
+ puts "Parse error in #{matches}: #{e}"
162
168
  match
163
169
  end
164
-
165
- unless match =~ /\{\{/ && parsed_content.empty?
166
- contents = contents.sub(match, parsed_content)
167
- end
170
+ next if parsed_content.nil?
171
+ contents = contents.sub(match, parsed_content)
168
172
  end
169
173
  contents
170
174
  end
@@ -174,7 +178,7 @@ module Jekyll
174
178
  # renders as "GitHub Glossary" for dotcom, but "GitHub Enterprise Glossary" for Enterprise
175
179
  def transform_liquid_variables(contents, path = nil)
176
180
  if (matches = contents.scan /(\{\{.+?\}\})/)
177
- contents = apply_vars_to_datafile(contents, matches, path)
181
+ contents = apply_vars_to_datafile(contents, matches, path, preserve_all: false, preserve_non_vars: true)
178
182
  end
179
183
 
180
184
  contents
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JekyllConrefifier
2
- VERSION = '0.4.3'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -64,4 +64,12 @@ describe("Conrefifier") do
64
64
  expect(filtering_layout_contents.scan(/Article v2.0/).count).to eq(1)
65
65
  expect(filtering_layout_contents.scan(/Ignored/).count).to eq(1)
66
66
  end
67
+
68
+ it 'filters items even if they have other curlies' do
69
+ warnings = @dest.join("warnings.html")
70
+ expect(warnings).to exist
71
+ warnings_contents = File.read(warnings)
72
+ expect(warnings_contents.scan(/- A dotcom Article/).count).to eq(1)
73
+ expect(warnings_contents.scan(/Article v2.0/).count).to eq(0)
74
+ end
67
75
  end
@@ -22,6 +22,11 @@ data_file_variables:
22
22
  path: ""
23
23
  values:
24
24
  version: "2.0"
25
+ -
26
+ scope:
27
+ path: "^warn"
28
+ values:
29
+ version: "dotcom"
25
30
  -
26
31
  scope:
27
32
  path: "^categories"
@@ -0,0 +1,6 @@
1
+ article_name: |
2
+ {% if page.version == '2.1' %}
3
+ - Article v2.0
4
+ {% else %}
5
+ - A {{ page.version }} Article
6
+ {% endif %}
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Using warning tags
3
+ ---
4
+
5
+ {{ site.data.warnings.article_name }}
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.3
4
+ version: 0.5.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-08-27 00:00:00.000000000 Z
11
+ date: 2015-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -79,12 +79,14 @@ files:
79
79
  - spec/fixtures/_data/conrefs.yml
80
80
  - spec/fixtures/_data/enterprise_filtered_categories.yml
81
81
  - spec/fixtures/_data/filtered_categories.yml
82
+ - spec/fixtures/_data/warnings.yml
82
83
  - spec/fixtures/_layouts/article.html
83
84
  - spec/fixtures/_layouts/filtering_layout.html
84
85
  - spec/fixtures/enterprise_filtered_index.html
85
86
  - spec/fixtures/filtered_index.html
86
87
  - spec/fixtures/filtering_layout.html
87
88
  - spec/fixtures/index.html
89
+ - spec/fixtures/warnings.html
88
90
  - spec/spec_helper.rb
89
91
  homepage: ''
90
92
  licenses: