nanoc-conref-fs 0.1.1 → 0.2.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: d3a726e64721a3b46fba7d2c2127e5a32443e32e
4
- data.tar.gz: 4029668164382b87e6e6214a43a6799ab6bbe9b1
3
+ metadata.gz: 4d7ad8948dbfd2807188dace405629e8556be38b
4
+ data.tar.gz: a2e748402407b1c74347d32c4f3cda89fff7d1cd
5
5
  SHA512:
6
- metadata.gz: 721c545407580610d9e5837274e4255b948e2258b9282ed01e84c2d7a7e59ad8f130d38a1def79cb1f789cdf3eac58f9c1cd3f4f4082790a1729268da35ff5b5
7
- data.tar.gz: 2d02ae7a354ed8660f4a78b43bfc7fa0cb16966fada9c662ab829fe4c557150c1c79d0554ee3c28477d63e8723b710144c89e849b27b10f0167082d221bb838b
6
+ metadata.gz: 331081baa3f15c26b040858f4a24ed03d9d01d6a73448b6da85c19d0908c852f2380eb07c0995cc2cd9d25e0ce454629cad01dae4842167108f049c8a14bcdd8
7
+ data.tar.gz: ef19358bbe4722d0181b6d999a8878aad3960208856978555ab22976ad79b2ebb75783bbf4a1d347c06d6d93984c7574b3e7e953956ea9d920f6509304fdbacd
@@ -1,20 +1,37 @@
1
1
  require_relative 'conrefifier'
2
2
 
3
+ # Unsure why attr_accessor does not work here
4
+ module VariableMixin
5
+ def self.variables
6
+ @variables
7
+ end
8
+
9
+ def self.variables=(variables)
10
+ @variables = variables
11
+ end
12
+ end
13
+
3
14
  class ConrefFS < Nanoc::DataSource
4
15
  include Nanoc::DataSources::Filesystem
16
+ include VariableMixin
5
17
 
6
18
  identifier :conref_fs
7
19
 
8
20
  # Before iterating over the file objects, this method loads the data folder
9
21
  # and applies to to an ivar for later usage.
10
22
  def load_objects(dir_name, kind, klass)
11
- if klass == Nanoc::Int::Item && @vars.nil?
23
+ if klass == Nanoc::Int::Item && @variables.nil?
12
24
  data = Datafiles.process(@site_config)
13
- @vars = { 'site' => { 'config' => @site_config.to_h, 'data' => data } }
25
+ @variables = { 'site' => { 'config' => @site_config.to_h, 'data' => data } }
26
+ VariableMixin.variables = @variables
14
27
  end
15
28
  super
16
29
  end
17
30
 
31
+ def self.fetch_variables
32
+ @variables
33
+ end
34
+
18
35
  # This function calls the parent super, then adds additional metadata to the item.
19
36
  def parse(content_filename, meta_filename, _kind)
20
37
  meta, content = super
@@ -22,7 +39,7 @@ class ConrefFS < Nanoc::DataSource
22
39
  unless page_vars[:data_association].nil?
23
40
  association = page_vars[:data_association]
24
41
  reference = association.split('.')
25
- toc = @vars['site']['data']
42
+ toc = @variables['site']['data']
26
43
  while key = reference.shift
27
44
  toc = toc[key]
28
45
  end
@@ -62,7 +79,7 @@ class ConrefFS < Nanoc::DataSource
62
79
  def read(filename)
63
80
  begin
64
81
  page_vars = Conrefifier.file_variables(@site_config[:page_variables], filename)
65
- page_vars = { :page => page_vars }.merge(@vars)
82
+ page_vars = { :page => page_vars }.merge(@variables)
66
83
 
67
84
  data = File.read(filename)
68
85
  return data unless filename.start_with?('content')
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'nanoc-conref-fs'
6
- spec.version = '0.1.1'
6
+ spec.version = '0.2.0'
7
7
  spec.authors = ['Garen Torikian']
8
8
  spec.email = ['gjtorikian@gmail.com']
9
9
  spec.summary = 'A Nanoc filesystem to permit using conrefs/reusables in your content.'
@@ -113,4 +113,15 @@ class DatafilesTest < MiniTest::Test
113
113
  assert_equal output_file, test_file
114
114
  end
115
115
  end
116
+
117
+ def test_it_fetches_variables
118
+ with_site(name: FIXTURES_DIR) do |site|
119
+
120
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
121
+ site.compile
122
+ output_file = read_output_file('datafiles', 'retrieve')
123
+ test_file = read_test_file('datafiles', 'retrieve')
124
+ assert_equal output_file, test_file
125
+ end
126
+ end
116
127
  end
@@ -5,9 +5,14 @@ compile '/**/*.html' do
5
5
  end
6
6
 
7
7
  compile '/**/*.md' do
8
- layout '/default.*'
8
+ if item[:filename] =~ /retrieve/
9
+ layout '/retrieve.*'
10
+ else
11
+ layout '/default.*'
12
+ end
9
13
  end
10
14
 
15
+
11
16
  route '/**/*.md' do
12
17
  item.identifier.without_ext + '/index.html'
13
18
  end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Fetching data
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+ GitHub Enterprise
12
+
13
+ Fetchy
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Fetching data
3
+ ---
4
+
5
+ Fetchy
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ <%= @item[:title] %>
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+ <%= VariableMixin.variables['site']['data']['variables']['product']['product_name']['2.0'] %>
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
@@ -104,6 +104,8 @@ files:
104
104
  - test/fixtures/Rules
105
105
  - test/fixtures/content/datafiles/deep.html
106
106
  - test/fixtures/content/datafiles/deep.md
107
+ - test/fixtures/content/datafiles/retrieve.html
108
+ - test/fixtures/content/datafiles/retrieve.md
107
109
  - test/fixtures/content/frontmatter/audience.html
108
110
  - test/fixtures/content/frontmatter/audience.md
109
111
  - test/fixtures/content/frontmatter/different.html
@@ -126,6 +128,7 @@ files:
126
128
  - test/fixtures/data/variables/empty.yml
127
129
  - test/fixtures/data/variables/product.yml
128
130
  - test/fixtures/layouts/default.html
131
+ - test/fixtures/layouts/retrieve.html
129
132
  - test/fixtures/nanoc.yaml
130
133
  - test/test_helper.rb
131
134
  homepage: https://github.com/gjtorikian/nanoc-conref-fs
@@ -158,6 +161,8 @@ test_files:
158
161
  - test/fixtures/Rules
159
162
  - test/fixtures/content/datafiles/deep.html
160
163
  - test/fixtures/content/datafiles/deep.md
164
+ - test/fixtures/content/datafiles/retrieve.html
165
+ - test/fixtures/content/datafiles/retrieve.md
161
166
  - test/fixtures/content/frontmatter/audience.html
162
167
  - test/fixtures/content/frontmatter/audience.md
163
168
  - test/fixtures/content/frontmatter/different.html
@@ -180,5 +185,6 @@ test_files:
180
185
  - test/fixtures/data/variables/empty.yml
181
186
  - test/fixtures/data/variables/product.yml
182
187
  - test/fixtures/layouts/default.html
188
+ - test/fixtures/layouts/retrieve.html
183
189
  - test/fixtures/nanoc.yaml
184
190
  - test/test_helper.rb