nanoc-conref-fs 0.6.9 → 0.6.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nanoc-conref-fs/conref-fs.rb +40 -7
- data/lib/nanoc-conref-fs/datafiles.rb +1 -1
- data/lib/nanoc-conref-fs/variables.rb +6 -2
- data/nanoc-conref-fs.gemspec +1 -1
- data/test/datafiles_test.rb +13 -2
- data/test/fixtures/data_custom/categories/custom.yml +4 -0
- data/test/fixtures/nanoc.custom_data_dir.yaml +87 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af97546774d5b23e33b691e8d3aab9e115061fcd
|
4
|
+
data.tar.gz: 97ce0cf24a1b572201b2f2322d216774ae2039ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fa4d77ccfaf3cbdfdc68e930c98f860b30288b24519e1cfc1f11b8546843572ec71831104058759c0fe598c5b64d3bec919f1ae889da533ed795f5e3a65a065
|
7
|
+
data.tar.gz: b67e5b5ff20ea6754c65a81421d21f02608397c664bc953a061ede33de5eedb9a4c4ae145de0d8983094b9bbb800f38a68164b688e475859b1a12e5007174887
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative 'conrefifier'
|
2
|
+
require 'active_support/core_ext/hash'
|
2
3
|
require 'active_support/core_ext/string'
|
3
4
|
|
4
5
|
class ConrefFS < Nanoc::DataSources::Filesystem
|
6
|
+
DEFAULT_DATA_DIR = "data".freeze
|
7
|
+
|
5
8
|
include NanocConrefFS::Variables
|
6
9
|
include NanocConrefFS::Ancestry
|
7
10
|
|
@@ -10,22 +13,18 @@ class ConrefFS < Nanoc::DataSources::Filesystem
|
|
10
13
|
# Before iterating over the file objects, this method loads the data folder
|
11
14
|
# and applies it to an ivar for later usage.
|
12
15
|
def up
|
13
|
-
data_files = NanocConrefFS::Datafiles.collect_data(data_dir_name)
|
16
|
+
data_files = NanocConrefFS::Datafiles.collect_data(ConrefFS.data_dir_name(config))
|
14
17
|
NanocConrefFS::Variables.data_files = data_files
|
15
18
|
NanocConrefFS::Variables.variables = {}
|
16
19
|
reps = @config[:reps] || [:default]
|
17
20
|
reps.each { |rep| ConrefFS.load_data_folder(@site_config, rep) }
|
18
21
|
end
|
19
22
|
|
20
|
-
def data_dir_name
|
21
|
-
config.fetch(:data_dir) { |_| 'data' }
|
22
|
-
end
|
23
|
-
|
24
23
|
def self.load_data_folder(config, rep)
|
25
24
|
return unless NanocConrefFS::Variables.variables[rep].nil?
|
26
25
|
data_files = NanocConrefFS::Variables.data_files
|
27
26
|
data = NanocConrefFS::Datafiles.process(data_files, config, rep)
|
28
|
-
NanocConrefFS::Variables.variables[rep] = { 'site' => { 'config' => config,
|
27
|
+
NanocConrefFS::Variables.variables[rep] = { 'site' => { 'config' => config, data_dir_name => data } }
|
29
28
|
end
|
30
29
|
|
31
30
|
def self.apply_attributes(config, item, rep)
|
@@ -102,12 +101,46 @@ class ConrefFS < Nanoc::DataSources::Filesystem
|
|
102
101
|
ParseResult.new(content: content, attributes: meta, attributes_data: pieces[2])
|
103
102
|
end
|
104
103
|
|
104
|
+
# Some of the static class methods below (and elsewhere in the Gem) require
|
105
|
+
# access to the `data_dir` value from the config. This need comes about
|
106
|
+
# *before* Nanoc has a chance to properly load up the configuration file,
|
107
|
+
# so we're doing a bare-bones load here to gain access to that configuration
|
108
|
+
# item.
|
109
|
+
#
|
110
|
+
# Parameters:
|
111
|
+
# - An optional already-loaded config, so that this can be used later in the
|
112
|
+
# Nanoc pipeline.
|
113
|
+
#
|
114
|
+
# Returns:
|
115
|
+
# - Custom `data_dir` attribute from the 'conref-fs' data_source
|
116
|
+
# - Default `data_dir` of 'data' if none is configured in `nanoc.yaml`
|
117
|
+
def self.data_dir_name(config=nil)
|
118
|
+
config ||= YAML.load_file('nanoc.yaml')
|
119
|
+
config = config.to_h.with_indifferent_access()
|
120
|
+
|
121
|
+
# In certain parts of the nanoc pipeline the config is rooted at the
|
122
|
+
# data-source already.
|
123
|
+
data_dir = config.fetch("data_dir") { nil }
|
124
|
+
return data_dir if data_dir
|
125
|
+
|
126
|
+
data_sources = config.fetch("data_sources") { nil }
|
127
|
+
return DEFAULT_DATA_DIR unless data_sources
|
128
|
+
|
129
|
+
data_source = data_sources.find { |ds| ds["type"] == "conref-fs" }
|
130
|
+
|
131
|
+
data_dir = data_source.fetch("data_dir") { nil }
|
132
|
+
return DEFAULT_DATA_DIR unless data_dir
|
133
|
+
return data_dir
|
134
|
+
end
|
135
|
+
|
105
136
|
def self.create_ignore_rules(rep, file)
|
106
137
|
current_articles = NanocConrefFS::Variables.fetch_data_file(file, rep)
|
107
138
|
current_articles = flatten_list(current_articles).flatten
|
108
139
|
current_articles = fix_nested_content(current_articles)
|
109
140
|
|
110
|
-
|
141
|
+
basic_yaml_path = "#{data_dir_name}/#{file.tr!('.', '/')}.yml"
|
142
|
+
basic_yaml = NanocConrefFS::Variables.data_files[basic_yaml_path]
|
143
|
+
raise "Could not locate #{basic_yaml_path} in the data files." unless basic_yaml
|
111
144
|
basic_yaml.gsub!(/\{%.+/, '')
|
112
145
|
full_file = YAML.load(basic_yaml)
|
113
146
|
|
@@ -20,9 +20,13 @@ module NanocConrefFS
|
|
20
20
|
def self.fetch_data_file(association, rep)
|
21
21
|
return nil unless association
|
22
22
|
reference = association.split('.')
|
23
|
-
data = @variables[rep]['site'][
|
23
|
+
data = @variables[rep]['site'][ConrefFS.data_dir_name]
|
24
24
|
while key = reference.shift
|
25
|
-
|
25
|
+
begin
|
26
|
+
data = data[key]
|
27
|
+
rescue Exception => ex
|
28
|
+
raise "Unable to locate #{key} in #{@variables[rep]['site'].inspect}"
|
29
|
+
end
|
26
30
|
end
|
27
31
|
data
|
28
32
|
end
|
data/nanoc-conref-fs.gemspec
CHANGED
@@ -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.6.
|
6
|
+
spec.version = '0.6.10'
|
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.'
|
data/test/datafiles_test.rb
CHANGED
@@ -22,8 +22,11 @@ class DatafilesTest < MiniTest::Test
|
|
22
22
|
result = NanocConrefFS::Datafiles.apply_conditionals(CONFIG, path: file, content: content, rep: :default)
|
23
23
|
assert_includes result.to_s, 'No caveats!'
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# Don't modify the global constant, you break other tests.
|
26
|
+
config = YAML.load_file(File.join(FIXTURES_DIR, 'nanoc.yaml')).deep_symbolize_keys
|
27
|
+
config[:data_variables][0][:values][:version] = 'foof'
|
28
|
+
|
29
|
+
result = NanocConrefFS::Datafiles.apply_conditionals(config, path: file, content: content, rep: :default)
|
27
30
|
assert_includes result.to_s, 'Well.....there is one.'
|
28
31
|
end
|
29
32
|
|
@@ -42,4 +45,12 @@ class DatafilesTest < MiniTest::Test
|
|
42
45
|
assert_includes result.to_s, 'About gists'
|
43
46
|
refute_includes result.to_s, 'Deleting an anonymous gist'
|
44
47
|
end
|
48
|
+
|
49
|
+
def test_it_can_use_a_custom_datafile
|
50
|
+
file = File.join(FIXTURES_DIR, 'data_custom', 'categories', 'custom.yml')
|
51
|
+
content = File.read(file)
|
52
|
+
config = YAML.load_file(File.join(FIXTURES_DIR, 'nanoc.custom_data_dir.yaml')).deep_symbolize_keys
|
53
|
+
result = NanocConrefFS::Datafiles.apply_conditionals(config, path: file, content: content, rep: :default)
|
54
|
+
assert_includes result.to_s, 'How to Use a Custom Data Directory'
|
55
|
+
end
|
45
56
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
data_variables:
|
2
|
+
-
|
3
|
+
scope:
|
4
|
+
path: ""
|
5
|
+
values:
|
6
|
+
version: "dotcom"
|
7
|
+
-
|
8
|
+
scope:
|
9
|
+
path: ""
|
10
|
+
reps:
|
11
|
+
- :X
|
12
|
+
values:
|
13
|
+
version: "X"
|
14
|
+
|
15
|
+
page_variables:
|
16
|
+
-
|
17
|
+
scope:
|
18
|
+
path: ""
|
19
|
+
values:
|
20
|
+
version: "dotcom"
|
21
|
+
data_association: "categories.category"
|
22
|
+
just_a_key: wow!
|
23
|
+
-
|
24
|
+
scope:
|
25
|
+
path: "array_parents"
|
26
|
+
values:
|
27
|
+
version: "dotcom"
|
28
|
+
data_association: "categories.simple"
|
29
|
+
-
|
30
|
+
scope:
|
31
|
+
path: "array_children"
|
32
|
+
values:
|
33
|
+
version: "dotcom"
|
34
|
+
data_association: "categories.simple"
|
35
|
+
-
|
36
|
+
scope:
|
37
|
+
path: "different"
|
38
|
+
values:
|
39
|
+
version: "2.0"
|
40
|
+
-
|
41
|
+
scope:
|
42
|
+
path: "empty-categories"
|
43
|
+
values:
|
44
|
+
version: "dotcom"
|
45
|
+
data_association: "categories.empty_category"
|
46
|
+
just_a_key: wow!
|
47
|
+
-
|
48
|
+
scope:
|
49
|
+
path: "multiple_versions"
|
50
|
+
values:
|
51
|
+
version: 2.2
|
52
|
+
|
53
|
+
string_pattern_type: glob
|
54
|
+
|
55
|
+
text_extensions: [ 'coffee', 'css', 'erb', 'haml', 'handlebars', 'hb', 'htm', 'html', 'js', 'less', 'markdown', 'md', 'ms', 'mustache', 'php', 'rb', 'rdoc', 'sass', 'scss', 'slim', 'txt', 'xhtml', 'xml' ]
|
56
|
+
|
57
|
+
output_dir: output
|
58
|
+
|
59
|
+
index_filenames: [ 'index.html' ]
|
60
|
+
|
61
|
+
enable_output_diff: false
|
62
|
+
|
63
|
+
prune:
|
64
|
+
auto_prune: true
|
65
|
+
|
66
|
+
exclude: [ '.git', '.hg', '.svn', 'CVS' ]
|
67
|
+
|
68
|
+
data_sources:
|
69
|
+
-
|
70
|
+
# The type is the identifier of the data source.
|
71
|
+
type: conref-fs
|
72
|
+
|
73
|
+
data_dir: 'data_custom/'
|
74
|
+
|
75
|
+
items_root: /
|
76
|
+
layouts_root: /
|
77
|
+
|
78
|
+
encoding: utf-8
|
79
|
+
|
80
|
+
identifier_type: full
|
81
|
+
reps:
|
82
|
+
- :default
|
83
|
+
- :X
|
84
|
+
|
85
|
+
checks:
|
86
|
+
internal_links:
|
87
|
+
exclude: []
|
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.6.
|
4
|
+
version: 0.6.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nanoc
|
@@ -175,10 +175,12 @@ files:
|
|
175
175
|
- test/fixtures/data/variables/asterisks.yml
|
176
176
|
- test/fixtures/data/variables/empty.yml
|
177
177
|
- test/fixtures/data/variables/product.yml
|
178
|
+
- test/fixtures/data_custom/categories/custom.yml
|
178
179
|
- test/fixtures/layouts/asterisk.html
|
179
180
|
- test/fixtures/layouts/children.html
|
180
181
|
- test/fixtures/layouts/default.html
|
181
182
|
- test/fixtures/layouts/retrieve.html
|
183
|
+
- test/fixtures/nanoc.custom_data_dir.yaml
|
182
184
|
- test/fixtures/nanoc.yaml
|
183
185
|
- test/test_helper.rb
|
184
186
|
- test/variable_mixin_test.rb
|
@@ -266,10 +268,12 @@ test_files:
|
|
266
268
|
- test/fixtures/data/variables/asterisks.yml
|
267
269
|
- test/fixtures/data/variables/empty.yml
|
268
270
|
- test/fixtures/data/variables/product.yml
|
271
|
+
- test/fixtures/data_custom/categories/custom.yml
|
269
272
|
- test/fixtures/layouts/asterisk.html
|
270
273
|
- test/fixtures/layouts/children.html
|
271
274
|
- test/fixtures/layouts/default.html
|
272
275
|
- test/fixtures/layouts/retrieve.html
|
276
|
+
- test/fixtures/nanoc.custom_data_dir.yaml
|
273
277
|
- test/fixtures/nanoc.yaml
|
274
278
|
- test/test_helper.rb
|
275
279
|
- test/variable_mixin_test.rb
|