jekyll-data 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/jekyll-data/version.rb +1 -1
- data/lib/jekyll/theme_reader.rb +68 -25
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fe7b8c111ab83b204be84b5f21de872ffd037ab
|
4
|
+
data.tar.gz: 5e954926b328bf2f1ba45dd0e48e154162786e1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0a9382fb9a07bd5fb47278432fdc4e5bfe270a97b12d4af2b1e4191db93267c7766d1c82ad7bdf88270aea28e84ba6e0301416a74347c0fdca44fe8064815cc
|
7
|
+
data.tar.gz: 105d0a80ceb935055a7e15c7d282615e9eaa8dbc03c1fe186e1b0516bea82d29e896a3235f1a74e44ce67abc54654d7008bfade78bedab806e6cad8a8b048e28
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# JekyllData
|
2
2
|
|
3
3
|
[![Gem Version](https://img.shields.io/gem/v/jekyll-data.svg)](https://rubygems.org/gems/jekyll-data)
|
4
|
+
[![Build Status](https://img.shields.io/travis/ashmaroli/jekyll-data/master.svg?label=Build%20Status)][travis]
|
5
|
+
|
6
|
+
[travis]: https://travis-ci.org/ashmaroli/jekyll-data
|
4
7
|
|
5
8
|
Introducing a plugin that reads data files within **jekyll theme gems** and adds the resulting hash to the site's internal data hash.
|
6
9
|
|
data/lib/jekyll-data/version.rb
CHANGED
data/lib/jekyll/theme_reader.rb
CHANGED
@@ -28,43 +28,68 @@ module Jekyll
|
|
28
28
|
def read_theme_data
|
29
29
|
if site.theme && site.theme.data_path
|
30
30
|
#
|
31
|
-
# show contents of "<theme>/_data/" dir being read
|
32
|
-
|
31
|
+
# show contents of "<theme>/_data/" dir being read while degugging.
|
32
|
+
# Additionally validate if a data file with the same name as the
|
33
|
+
# theme (= theme config or theme config-override) is a Hash.
|
34
|
+
inspect_theme_data
|
33
35
|
theme_data = ThemeDataReader.new(site).read(site.config["data_dir"])
|
34
36
|
@site.data = Utils.deep_merge_hashes(theme_data, @site.data)
|
35
37
|
#
|
36
|
-
#
|
37
|
-
|
38
|
+
# check if the merged hash is suitable for generating the site.
|
39
|
+
# Also show contents of merged site.data hash while debugging.
|
40
|
+
inspect_merged_hash
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
44
|
private
|
42
45
|
|
43
|
-
|
46
|
+
# Private:
|
47
|
+
# Print messages only while debugging.
|
48
|
+
#
|
49
|
+
# Inspect the theme configuration file (data-file with the same name
|
50
|
+
# as the theme) and print a success message, if valid.
|
51
|
+
def inspect_theme_data
|
44
52
|
print_clear_line
|
45
53
|
print "Reading:", "Theme Data Files..."
|
46
54
|
@theme_data_files.each do |file|
|
47
|
-
|
55
|
+
if File.basename(file, ".*") == @site.theme.name
|
56
|
+
inspect_theme_config file
|
57
|
+
print_value file.green
|
58
|
+
else
|
59
|
+
print_value file
|
60
|
+
end
|
48
61
|
end
|
49
62
|
print_clear_line
|
50
63
|
print "Merging:", "Theme Data Hash..."
|
51
64
|
end
|
52
65
|
|
53
|
-
|
66
|
+
# Private:
|
67
|
+
# Print contents of the merged data hash while debugging
|
68
|
+
def inspect_merged_hash
|
54
69
|
print "Inspecting:", "Site Data >>"
|
55
70
|
inspect_hash @site.data
|
56
71
|
print_clear_line
|
57
72
|
end
|
58
73
|
|
74
|
+
# Private helper methods to inspect data hash and output contents
|
75
|
+
# to logger at level debugging.
|
76
|
+
|
77
|
+
# Dissect the (merged) site.data hash and print its contents
|
78
|
+
#
|
79
|
+
# - Print the key string(s) and if matches theme name, validate its
|
80
|
+
# value as well.
|
81
|
+
# - Individually analyse the hash[key] values and extract contents
|
82
|
+
# to output.
|
59
83
|
def inspect_hash(hash)
|
60
84
|
hash.each do |key, value|
|
61
85
|
print_key key
|
62
86
|
if key == @site.theme.name
|
63
|
-
|
87
|
+
validate_config_hash value
|
64
88
|
end
|
65
|
-
|
89
|
+
|
90
|
+
if value.is_a? Hash
|
66
91
|
inspect_inner_hash value
|
67
|
-
elsif value.
|
92
|
+
elsif value.is_a? Array
|
68
93
|
print_label key
|
69
94
|
extract_hashes_and_print value
|
70
95
|
else
|
@@ -73,24 +98,14 @@ module Jekyll
|
|
73
98
|
end
|
74
99
|
end
|
75
100
|
|
76
|
-
|
77
|
-
if value == false
|
78
|
-
abort_with_msg "Cannot define or override Theme Configuration " \
|
79
|
-
"with an empty file!"
|
80
|
-
end
|
81
|
-
unless value.class == Hash
|
82
|
-
abort_with_msg "Theme Config or its override should be a Hash of " \
|
83
|
-
"key:value pairs or mappings. But got #{value.class} instead."
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
101
|
+
# Analyse deeper hashes and extract contents to output
|
87
102
|
def inspect_inner_hash(hash)
|
88
103
|
hash.each do |key, value|
|
89
|
-
if value.
|
104
|
+
if value.is_a? Array
|
90
105
|
print_label key
|
91
106
|
extract_hashes_and_print value
|
92
107
|
print_clear_line
|
93
|
-
elsif value.
|
108
|
+
elsif value.is_a? Hash
|
94
109
|
print_subkey_and_value key, value
|
95
110
|
else
|
96
111
|
print_hash key, value
|
@@ -98,9 +113,11 @@ module Jekyll
|
|
98
113
|
end
|
99
114
|
end
|
100
115
|
|
116
|
+
# If an array of strings, print. Otherwise assume as an
|
117
|
+
# array of hashes (sequences) that needs further analysis.
|
101
118
|
def extract_hashes_and_print(array)
|
102
119
|
array.each do |entry|
|
103
|
-
if entry.
|
120
|
+
if entry.is_a? String
|
104
121
|
print "-", entry
|
105
122
|
else
|
106
123
|
inspect_inner_hash entry
|
@@ -108,10 +125,32 @@ module Jekyll
|
|
108
125
|
end
|
109
126
|
end
|
110
127
|
|
128
|
+
# analyse the theme config file and validate it as Hash
|
129
|
+
def inspect_theme_config(path)
|
130
|
+
config = ThemeDataReader.new(site).read_data_file(path)
|
131
|
+
validate_config_hash config
|
132
|
+
end
|
133
|
+
|
134
|
+
def validate_config_hash(value)
|
135
|
+
if value == false
|
136
|
+
abort_with_msg "Cannot define or override Theme Configuration " \
|
137
|
+
"with an empty file!"
|
138
|
+
end
|
139
|
+
unless value.is_a? Hash
|
140
|
+
abort_with_msg "Theme Config or its override should be a Hash of " \
|
141
|
+
"key:value pairs or mappings. But got #{value.class} instead."
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Private methods for formatting log messages while debugging and a
|
146
|
+
# method to issue conflict alert and abort site.process
|
147
|
+
|
148
|
+
# Prints key as logger[topic] and value as [message]
|
111
149
|
def print_hash(key, value)
|
112
150
|
print "#{key}:", value
|
113
151
|
end
|
114
152
|
|
153
|
+
# Prints the site.data[key] in color
|
115
154
|
def print_key(key)
|
116
155
|
@dashes = "------------------------"
|
117
156
|
print_value @dashes.to_s.cyan
|
@@ -119,6 +158,7 @@ module Jekyll
|
|
119
158
|
print_value @dashes.to_s.cyan
|
120
159
|
end
|
121
160
|
|
161
|
+
# Prints label, keys and values of mappings
|
122
162
|
def print_subkey_and_value(key, value)
|
123
163
|
print_label key
|
124
164
|
value.each do |subkey, val|
|
@@ -127,14 +167,16 @@ module Jekyll
|
|
127
167
|
print_dashes
|
128
168
|
end
|
129
169
|
|
170
|
+
# Print only logger[message], [topic] = nil
|
130
171
|
def print_value(value)
|
131
|
-
if value.
|
172
|
+
if value.is_a? Array
|
132
173
|
extract_hashes_and_print value
|
133
174
|
else
|
134
175
|
print "", value
|
135
176
|
end
|
136
177
|
end
|
137
178
|
|
179
|
+
# Print only logger[topic] appended with a colon
|
138
180
|
def print_label(key)
|
139
181
|
print "#{key}:"
|
140
182
|
end
|
@@ -147,6 +189,7 @@ module Jekyll
|
|
147
189
|
print ""
|
148
190
|
end
|
149
191
|
|
192
|
+
# Redefine Jekyll Loggers
|
150
193
|
def print(arg1, arg2 = "")
|
151
194
|
Jekyll.logger.debug arg1, arg2
|
152
195
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashwin Maroli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.6.
|
106
|
+
rubygems_version: 2.6.8
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: A plugin to read data files in Jekyll Theme Gems
|