nanoc-conref-fs 0.4.2 → 0.4.3

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: 9a5408983216ce1f6c5960cb218a8730f98830e6
4
- data.tar.gz: d5042c05beeb62145d09bce9fb749f7e8d125b7c
3
+ metadata.gz: 80883b64d0bb6285ba2dd26c11d991310170d5d3
4
+ data.tar.gz: b961ceb417cd9538101760a2c871e32e3bf86b2a
5
5
  SHA512:
6
- metadata.gz: 5e23cd9f8d20ea64d178dc3e18aced5590db96e85a29d8fa209e471d31363bbf81c5eecf9e4d4dd3612bb886410e3fd595859676461df65dc2aa84dff89b07ef
7
- data.tar.gz: 4ca2e1fc67fdb45ef2a0e171c3b20f1373d084026dfd6de796e1919a82ea6e15f1b16e9b1a0e76fd712c5d9ddbaafb8433918e016be5182b792536062f86be63
6
+ metadata.gz: 71dcfcc7919e46fe2bc62bf351149eb8af6ede84036e6236807508d72aab159aa05a40eb016d25b03bf40db42fb07a9ba737bc9133d51e12c29676fb3057a083
7
+ data.tar.gz: 3d73990232db307ab431627c5cd40dcbc286bf22dd35864bcbaa37f322c6b8ab7da31456a7b64a74f91e695c09a5858a6d814e80516938e9d92c2f148ee2c61b
@@ -159,16 +159,37 @@ class ConrefFS < Nanoc::DataSource
159
159
  end
160
160
 
161
161
  begin
162
- content.gsub(/(\s\{\{[^\}]+\}\})/m) do |match|
163
- # This first pass converts the frontmatter variables,
164
- # and inserts data variables into the body
165
- result = Conrefifier.apply_liquid(match, page_vars)
166
- # This second application renders the previously inserted
167
- # data conditionals within the body
168
- Conrefifier.apply_liquid(result, page_vars)
162
+ result = ''
163
+ # This pass replaces any conditionals
164
+ result = if content =~ Conrefifier::BLOCK_SUB
165
+ Conrefifier.apply_liquid(content, page_vars)
166
+ else
167
+ content
168
+ end
169
+
170
+ # This pass converts the frontmatter variables,
171
+ # and inserts data variables into the body
172
+ result = if result =~ Conrefifier::SINGLE_SUB
173
+ result.gsub(Conrefifier::SINGLE_SUB) do |match|
174
+ Conrefifier.apply_liquid(match, page_vars)
175
+ end
176
+ else
177
+ result
178
+ end
179
+
180
+ # This second pass renders any previously inserted
181
+ # data conditionals within the body
182
+ if result =~ Conrefifier::SINGLE_SUB
183
+ result = result.gsub(Conrefifier::SINGLE_SUB) do |match|
184
+ Conrefifier.apply_liquid(match, page_vars)
185
+ end
169
186
  end
170
- rescue Liquid::SyntaxError
187
+
188
+ result
189
+ rescue Liquid::SyntaxError => e
171
190
  # unrecognized Liquid, so just return the content
191
+ # STDERR.puts "Could not convert #{filename}: #{e.message}"
192
+ result
172
193
  rescue => e
173
194
  raise "#{e.message}: #{e.inspect}"
174
195
  end
@@ -1,6 +1,10 @@
1
1
  require 'liquid'
2
2
 
3
3
  module Conrefifier
4
+
5
+ SINGLE_SUB = /(\{\{[^\}]+\}\})/m
6
+ BLOCK_SUB = /\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\}/m
7
+
4
8
  def self.file_variables(variables, path)
5
9
  return {} if variables.nil?
6
10
 
@@ -9,7 +9,7 @@ module Datafiles
9
9
  data_vars = Conrefifier.file_variables(config[:data_variables], path)
10
10
  data_vars = { :page => data_vars, :site => { :config => config } }
11
11
 
12
- content = content.gsub(/(\s*\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/m) do |match|
12
+ content = content.gsub(Conrefifier::BLOCK_SUB) do |match|
13
13
  # We must obfuscate Liquid variables while replacing conditionals
14
14
  match = match.gsub(/{{/, '~~#~~')
15
15
  match = Conrefifier.apply_liquid(match, data_vars)
@@ -1,3 +1,3 @@
1
1
  module Conrefifier
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-conref-fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian