nanoc-conref-fs 0.4.1 → 0.4.2

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: 8084c53b24aef8bc7312834d613080e4db9a113a
4
- data.tar.gz: 8694bb5fd7471cf585bf315a32939ee5ea5edc52
3
+ metadata.gz: 9a5408983216ce1f6c5960cb218a8730f98830e6
4
+ data.tar.gz: d5042c05beeb62145d09bce9fb749f7e8d125b7c
5
5
  SHA512:
6
- metadata.gz: 4463e0a3e0ad4072eaaf62f2839a36646fb52273f52b2b15ac8f7d7d9790cfd57cdf75b415987f1ae8f471673944222031b8cdbca3248fabf7ba15b3248b9f2d
7
- data.tar.gz: 3fbd9bd87eb03c25a6426bf069e5ebe495cfbe63db828ab2e3e6a47cbad4ba383e671c0d5297bf74ac4fcc08de6e64f01a61a05aae93cfd9dbd0f24c3a61706e
6
+ metadata.gz: 5e23cd9f8d20ea64d178dc3e18aced5590db96e85a29d8fa209e471d31363bbf81c5eecf9e4d4dd3612bb886410e3fd595859676461df65dc2aa84dff89b07ef
7
+ data.tar.gz: 4ca2e1fc67fdb45ef2a0e171c3b20f1373d084026dfd6de796e1919a82ea6e15f1b16e9b1a0e76fd712c5d9ddbaafb8433918e016be5182b792536062f86be63
@@ -31,8 +31,8 @@ class ConrefFS < Nanoc::DataSource
31
31
  # and applies to to an ivar for later usage.
32
32
  def load_objects(dir_name, kind, klass)
33
33
  if klass == Nanoc::Int::Item && @variables.nil?
34
- config = @site_config.to_h.stringify_keys
35
- data = Datafiles.process(config)
34
+ data = Datafiles.process(@site_config)
35
+ config = @site_config.to_h
36
36
  @variables = { 'site' => { 'config' => config, 'data' => data } }
37
37
  VariableMixin.variables = @variables
38
38
  end
@@ -43,18 +43,18 @@ class ConrefFS < Nanoc::DataSource
43
43
  def parse(content_filename, meta_filename, _kind)
44
44
  meta, content = super
45
45
  page_vars = Conrefifier.file_variables(@site_config[:page_variables], content_filename)
46
- unless page_vars['data_association'].nil?
47
- association = page_vars['data_association']
46
+ unless page_vars[:data_association].nil?
47
+ association = page_vars[:data_association]
48
48
  toc = VariableMixin.fetch_data_file(association)
49
49
  meta[:parents] = if toc.is_a?(Array)
50
50
  find_array_parents(toc, meta['title'])
51
- else
51
+ elsif toc.is_a?(Hash)
52
52
  find_hash_parents(toc, meta['title'])
53
53
  end
54
54
 
55
55
  meta[:children] = if toc.is_a?(Array)
56
56
  find_array_children(toc, meta['title'])
57
- else
57
+ elsif toc.is_a?(Hash)
58
58
  find_hash_children(toc, meta['title'])
59
59
  end
60
60
  end
@@ -142,38 +142,36 @@ class ConrefFS < Nanoc::DataSource
142
142
  # (demarcated by Liquid's {{ }} tags) using both the data/ folder and any variables defined
143
143
  # within the nanoc.yaml config file
144
144
  def read(filename)
145
- data = ''
145
+ content = ''
146
146
  begin
147
147
  page_vars = Conrefifier.file_variables(@site_config[:page_variables], filename)
148
- page_vars = { 'page' => page_vars }.merge(@variables)
148
+ page_vars = { :page => page_vars }.merge(@variables)
149
149
 
150
- data = File.read(filename)
151
- return data unless filename.start_with?('content', 'layouts')
150
+ content = File.read(filename)
151
+ return content unless filename.start_with?('content', 'layouts')
152
152
 
153
153
  # we must obfuscate essential ExtendedMarkdownFilter content
154
- data = data.gsub(/\{\{\s*#(\S+)\s*\}\}/, '[[#\1]]')
155
- data = data.gsub(/\{\{\s*\/(\S+)\s*\}\}/, '[[/\1]]')
156
- data = data.gsub(/\{\{\s*(octicon-\S+\s*[^\}]+)\s*\}\}/, '[[\1]]')
154
+ content = content.gsub(/\{\{\s*#(\S+)\s*\}\}/, '[[#\1]]')
155
+ content = content.gsub(/\{\{\s*\/(\S+)\s*\}\}/, '[[/\1]]')
156
+ content = content.gsub(/\{\{\s*(octicon-\S+\s*[^\}]+)\s*\}\}/, '[[\1]]')
157
157
  rescue => e
158
158
  raise "Could not read #{filename}: #{e.inspect}"
159
159
  end
160
160
 
161
- result = data
162
-
163
161
  begin
164
- # This first pass converts the frontmatter variables,
165
- # and inserts data variables into the body
166
- result = Conrefifier.apply_liquid(data, page_vars)
167
- # This second application renders the previously inserted
168
- # data conditionals within the body
169
- result = Conrefifier.apply_liquid(result, page_vars)
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)
169
+ end
170
170
  rescue Liquid::SyntaxError
171
171
  # unrecognized Liquid, so just return the content
172
172
  rescue => e
173
173
  raise "#{e.message}: #{e.inspect}"
174
174
  end
175
-
176
- result
177
175
  end
178
176
 
179
177
  # This method is extracted from the Nanoc default FS
@@ -7,12 +7,13 @@ module Conrefifier
7
7
  data_vars = {}
8
8
  scopes = variables.select { |v| v[:scope][:path].empty? || Regexp.new(v[:scope][:path]) =~ path }
9
9
  scopes.each do |scope|
10
- data_vars = data_vars.merge(scope[:values].stringify_keys)
10
+ data_vars = data_vars.merge(scope[:values])
11
11
  end
12
12
  data_vars
13
13
  end
14
14
 
15
15
  def self.apply_liquid(content, data_vars)
16
+ data_vars['page'] = data_vars[:page].stringify_keys
16
17
  ::Liquid::Template.parse(content).render(data_vars)
17
18
  end
18
19
  end
@@ -7,7 +7,8 @@ module Datafiles
7
7
 
8
8
  def self.apply_conditionals(config, path, content)
9
9
  data_vars = Conrefifier.file_variables(config[:data_variables], path)
10
- data_vars = { 'page' => data_vars, 'site' => { 'config' => config } }
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
13
  # We must obfuscate Liquid variables while replacing conditionals
13
14
  match = match.gsub(/{{/, '~~#~~')
@@ -1,3 +1,3 @@
1
1
  module Conrefifier
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-conref-fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-09 00:00:00.000000000 Z
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nanoc