jekyll-data-revised 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +123 -0
- data/lib/jekyll-data.rb +44 -0
- data/lib/jekyll-data/reader.rb +224 -0
- data/lib/jekyll-data/theme_configuration.rb +64 -0
- data/lib/jekyll-data/theme_data_reader.rb +39 -0
- data/lib/jekyll-data/themed_site_drop.rb +14 -0
- data/lib/jekyll-data/version.rb +5 -0
- data/lib/jekyll/build_options.rb +19 -0
- data/lib/jekyll/data_path.rb +9 -0
- data/lib/jekyll/theme_drop.rb +19 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e564d57f1221d0dc6a960069f91669fba9febf32945eb74420defd09ffe5955e
|
4
|
+
data.tar.gz: 9b4cbd5d076f6b713cf3343ae54cb0d130b3bc481fb96e79f7d48da9b47e24d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2bfff099d709386204254508622bb5cc49046ad622882e588408192e931012eef956abb55d1e1c741595d385429246130f0ae9682d021bde9351340c1b97993a
|
7
|
+
data.tar.gz: cc426bbdd5db09e73cc1b258475c9bbe96416a40d70b603653525872261fa85f4c4fff908ce81cb03c93b6e6d9a98f53cbbbb4acd5e44b6fde112068ae381603
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016-2017 Ashwin Maroli & Contributors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# JekyllData
|
2
|
+
|
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
|
7
|
+
|
8
|
+
Introducing a plugin that reads data files within **jekyll theme-gems** and adds the resulting hash to the site's internal data hash. If a **`_config.yml`** is present at the root of the theme-gem, it will be evaluated and the extracted hash data will be incorporated into the site's existing config hash.
|
9
|
+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Simply add the plugin to your site's Gemfile and config file like every other jekyll plugin gem:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# Gemfile
|
17
|
+
|
18
|
+
group :jekyll_plugins do
|
19
|
+
gem "jekyll-data"
|
20
|
+
end
|
21
|
+
```
|
22
|
+
..and run
|
23
|
+
|
24
|
+
bundle install
|
25
|
+
|
26
|
+
|
27
|
+
> **Note: If the plugin has been marked as a `runtime_dependency` by the theme-gem's author it will be installed automatically with the theme-gem. Yet, it is recommended that the plugin be added to `:jekyll_plugins` group in the Gemfile rather than the `gems:` array in the config file while building or serving the site to avoid 'overriding' the `gems:` array data that may have been read-in from the theme-gem.**
|
28
|
+
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
As long as the plugin-gem has been installed properly, and is included in the Gemfile's `:jekyll_plugins` group, data files supported by Jekyll and present in the `_data` directory at the root of your theme-gem will be read. Their contents will be added to the site's internal data hash, provided, an identical data hash doesn't already exist at the site-source.
|
33
|
+
|
34
|
+
If the theme-gem also includes a `_config.yml` at its root, then it will be read as well. The resulting config hash will be mixed into the site's existing config hash, filling in where the *keys* are not already defined. In other words, the config file at `source` will override corresponding identical keys in a `_config.yml` within the theme-gem which would in turn override corresponding `DEFAULTS` from Jekyll:
|
35
|
+
|
36
|
+
**DEFAULTS** < **_config.yml in theme-gem** < **_config.yml at source** < **Override configs via command-line**.
|
37
|
+
|
38
|
+
|
39
|
+
### Theme Configuration
|
40
|
+
|
41
|
+
Jekyll themes (built prior to `Jekyll 3.2`) usually ship with configuration settings defined in the config file, which are then used within the theme's template files directly under the `site` namespace (e.g. `{{ site.myvariable }}`). This is not possible with theme-gems as a config file and data files within gems are not natively read (as of Jekyll 3.3), and hence require end-users to inspect a *demo* or *example* directory to source those files.
|
42
|
+
|
43
|
+
This plugin provides a solution to that hurdle:
|
44
|
+
|
45
|
+
JekyllData now reads the config file (at present only `_config.yml`) present within the theme-gem and uses the data to modify the site's config hash. This allows the theme-gem to continue using `{{ site.myvariable }}` within its templates and work out-of-the-box as intended, with minimal user intervention.
|
46
|
+
|
47
|
+
**Note: the plugins required by the theme may be listed under the `gems:` array and will be automatically `required` by Jekyll while building/serving, provided that the user doesn't have a different `gems:` array in the config file at source. Hence it is recommended to add all other plugins ( including `jekyll-data` ) via the Gemfile's `:jekyll_plugins` group.**
|
48
|
+
|
49
|
+
#### The `theme` namespace
|
50
|
+
|
51
|
+
From `v1.0`, JekyllData no longer supports reading theme configuration provided as a `[theme-name].***` file within the `_data` directory and instead the `theme` namespace points to a certain key in the bundled `_config.yml`.
|
52
|
+
|
53
|
+
For `{{ theme.variable }}` to work, the config file should nest all such key-value pairs under the `[theme-name]` key, as outlined in the example below for a theme-gem called `solitude`:
|
54
|
+
|
55
|
+
```yaml
|
56
|
+
# <solitude-0.1.0>/_config.yml
|
57
|
+
|
58
|
+
# the settings below have been used in this theme's templates via the `theme`
|
59
|
+
# namespace. e.g. `{{ theme.recent_posts.style }}` instead of using the more
|
60
|
+
# verbose `{{ site.solitude.recent_posts.style }}` though both are functionally
|
61
|
+
# the same.
|
62
|
+
#
|
63
|
+
solitude:
|
64
|
+
sidebar : true # enter 'false' to enable horizontal navbar instead.
|
65
|
+
theme_variant : Charcoal # choose from 'Ocean', 'Grass', 'Charcoal'
|
66
|
+
recent_posts :
|
67
|
+
style : list # choose from 'list' and 'grid'.
|
68
|
+
quantity : '4' # either '4' or '6'
|
69
|
+
|
70
|
+
```
|
71
|
+
|
72
|
+
|
73
|
+
### Data files
|
74
|
+
|
75
|
+
Data files may be used to supplement theme templates (e.g. locales and translated UI text) and can be named as desired.
|
76
|
+
- Organize related small data files in sub-directories. (or)
|
77
|
+
- Declare all related data as mapped data blocks within a single file.
|
78
|
+
|
79
|
+
To illustrate with an example, consider a `locales.yml` that has mappings for `en:`, `fr:`, `it:`.
|
80
|
+
|
81
|
+
```yaml
|
82
|
+
# <theme-gem>/_data/locales.yml
|
83
|
+
|
84
|
+
en:
|
85
|
+
previous : previous
|
86
|
+
next : next
|
87
|
+
|
88
|
+
fr:
|
89
|
+
previous : précédent
|
90
|
+
next : prochain
|
91
|
+
|
92
|
+
it:
|
93
|
+
previous : precedente
|
94
|
+
next : seguente
|
95
|
+
```
|
96
|
+
|
97
|
+
the Hash from above would be identical to one had the gem been shipped with a `_data/locales` directory containing individual files for each language data.
|
98
|
+
|
99
|
+
|
100
|
+
### Overriding Data Files
|
101
|
+
|
102
|
+
To override data shipped with a theme-gem, simply have an identical hash at the site-source.
|
103
|
+
|
104
|
+
Irrespective of whether the theme-gem ships with consolidated data files of related entities, or sub-directories containing individual files, the data can be overridden with a single file or with multiple files.
|
105
|
+
|
106
|
+
For example, if a theme-gem contains the above sample `locales.yml`, then to override the `fr:` key-data simply have either of the following:
|
107
|
+
- a **`_data/locales/fr.yml`** with identical subkey(s).
|
108
|
+
- a **`_data/locales.yml`** with **`fr:`** with identical subkey(s).
|
109
|
+
|
110
|
+
--
|
111
|
+
> **Note**
|
112
|
+
- having an **empty** `_data/locales.yml` at `source` directory will override the **entire `["data"]["locales"]` payload** from the theme-gem as **`false`**.
|
113
|
+
- having an **empty** `_data/locales/fr.yml` at `source` directory will override the **enire `["data"]["locales"]["fr"]` payload** from the theme-gem as **`false`**
|
114
|
+
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
Bug reports and pull requests are welcome at the [GitHub Repo](https://github.com/ashmaroli/jekyll-data). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
119
|
+
|
120
|
+
|
121
|
+
## License
|
122
|
+
|
123
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/jekyll-data.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
require "jekyll-data/version"
|
5
|
+
|
6
|
+
module JekyllData
|
7
|
+
autoload :Reader, "jekyll-data/reader"
|
8
|
+
autoload :ThemedSiteDrop, "jekyll-data/themed_site_drop"
|
9
|
+
autoload :ThemeDataReader, "jekyll-data/theme_data_reader"
|
10
|
+
autoload :ThemeConfiguration, "jekyll-data/theme_configuration"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Monkey-patches
|
14
|
+
require_relative "jekyll/build_options"
|
15
|
+
require_relative "jekyll/data_path"
|
16
|
+
require_relative "jekyll/theme_drop"
|
17
|
+
|
18
|
+
# ----------------------------------------------------------------------------
|
19
|
+
# Modify the current site instance only if it uses a gem-based theme.
|
20
|
+
#
|
21
|
+
# if a '_config.yml' is present at the root of theme-gem, it is evaluated and
|
22
|
+
# the extracted hash data is incorprated into the site's config hash.
|
23
|
+
# ----------------------------------------------------------------------------
|
24
|
+
Jekyll::Hooks.register :site, :after_reset do |site|
|
25
|
+
if site.theme
|
26
|
+
file = site.in_theme_dir("_config.yml")
|
27
|
+
JekyllData::ThemeConfiguration.reconfigure(site) if File.exist?(file)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# ---------------------------------------------------------------------------
|
32
|
+
# Replace Jekyll::Reader with a subclass JekyllData::Reader only if the
|
33
|
+
# site uses a gem-based theme.
|
34
|
+
#
|
35
|
+
# If a _config.yml exists at the root of the theme-gem, output its path.
|
36
|
+
# Placed here inorder to avoid outputting the path after every regeneration.
|
37
|
+
# ---------------------------------------------------------------------------
|
38
|
+
Jekyll::Hooks.register :site, :after_init do |site|
|
39
|
+
if site.theme
|
40
|
+
file = site.in_theme_dir("_config.yml")
|
41
|
+
Jekyll.logger.debug "Theme Config file:", file if File.exist?(file)
|
42
|
+
site.reader = JekyllData::Reader.new(site)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "csv"
|
4
|
+
|
5
|
+
module JekyllData
|
6
|
+
class Reader < Jekyll::Reader
|
7
|
+
def initialize(site)
|
8
|
+
@site = site
|
9
|
+
@theme = site.theme
|
10
|
+
@theme_data_files = Dir[File.join(site.theme.root,
|
11
|
+
site.config["data_dir"], "**", "*.{yaml,yml,json,csv}")]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Read data files within theme-gem.
|
15
|
+
#
|
16
|
+
# Returns nothing.
|
17
|
+
def read
|
18
|
+
super
|
19
|
+
read_theme_data
|
20
|
+
end
|
21
|
+
|
22
|
+
# Read data files within a theme gem and add them to internal data
|
23
|
+
#
|
24
|
+
# Returns a hash appended with new data
|
25
|
+
def read_theme_data
|
26
|
+
if @theme.data_path
|
27
|
+
#
|
28
|
+
# show contents of "<theme>/_data/" dir being read while degugging.
|
29
|
+
inspect_theme_data
|
30
|
+
theme_data = ThemeDataReader.new(site).read(site.config["data_dir"])
|
31
|
+
@site.data = Jekyll::Utils.deep_merge_hashes(theme_data, @site.data)
|
32
|
+
#
|
33
|
+
# show contents of merged site.data hash while debugging with
|
34
|
+
# additional --show-data switch.
|
35
|
+
inspect_merged_hash if site.config["show-data"] && site.config["verbose"]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Private:
|
42
|
+
# (only while debugging)
|
43
|
+
#
|
44
|
+
# Print a list of data file(s) within the theme-gem
|
45
|
+
def inspect_theme_data
|
46
|
+
print_clear_line
|
47
|
+
Jekyll.logger.debug "Reading:", "Theme Data Files..."
|
48
|
+
@theme_data_files.each { |file| Jekyll.logger.debug "", file }
|
49
|
+
print_clear_line
|
50
|
+
Jekyll.logger.debug "Merging:", "Theme Data Hash..."
|
51
|
+
|
52
|
+
unless site.config["show-data"] && site.config["verbose"]
|
53
|
+
Jekyll.logger.debug "", "use --show-data with --verbose to output " \
|
54
|
+
"merged Data Hash.".cyan
|
55
|
+
print_clear_line
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Private:
|
60
|
+
# (only while debugging)
|
61
|
+
#
|
62
|
+
# Print contents of the merged data hash
|
63
|
+
def inspect_merged_hash
|
64
|
+
Jekyll.logger.debug "Inspecting:", "Site Data >>"
|
65
|
+
|
66
|
+
# the width of generated logger[message]
|
67
|
+
@width = 50
|
68
|
+
@dashes = "-" * @width
|
69
|
+
|
70
|
+
inspect_hash @site.data
|
71
|
+
print_clear_line
|
72
|
+
end
|
73
|
+
|
74
|
+
# --------------------------------------------------------------------
|
75
|
+
# Private helper methods to inspect data hash and output contents
|
76
|
+
# to logger at level debugging.
|
77
|
+
# --------------------------------------------------------------------
|
78
|
+
|
79
|
+
# Dissect the (merged) site.data hash and print its contents
|
80
|
+
#
|
81
|
+
# - Print the key string(s)
|
82
|
+
# - Individually analyse the hash[key] values and extract contents
|
83
|
+
# to output.
|
84
|
+
def inspect_hash(hash)
|
85
|
+
hash.each do |key, value|
|
86
|
+
print_key key
|
87
|
+
if value.is_a? Hash
|
88
|
+
inspect_inner_hash value
|
89
|
+
elsif value.is_a? Array
|
90
|
+
extract_hashes_and_print value
|
91
|
+
else
|
92
|
+
print_string value.to_s
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Analyse deeper hashes and extract contents to output
|
98
|
+
def inspect_inner_hash(hash)
|
99
|
+
hash.each do |key, value|
|
100
|
+
if value.is_a? Array
|
101
|
+
print_label key
|
102
|
+
extract_hashes_and_print value
|
103
|
+
elsif value.is_a? Hash
|
104
|
+
print_subkey_and_value key, value
|
105
|
+
else
|
106
|
+
print_hash key, value
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# If an array of strings, print. Otherwise assume as an
|
112
|
+
# array of hashes (sequences) that needs further analysis.
|
113
|
+
def extract_hashes_and_print(array)
|
114
|
+
array.each do |entry|
|
115
|
+
if entry.is_a? String
|
116
|
+
print_list entry
|
117
|
+
else
|
118
|
+
inspect_inner_hash entry
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
|
125
|
+
# --------------------------------------------------------------------
|
126
|
+
# Private methods for formatting log messages while debugging
|
127
|
+
# --------------------------------------------------------------------
|
128
|
+
|
129
|
+
# Splits a string longer than the value of '@width' into smaller
|
130
|
+
# strings and prints each line as a logger[message]
|
131
|
+
#
|
132
|
+
# string - the long string
|
133
|
+
#
|
134
|
+
# label - optional text to designate the printed lines.
|
135
|
+
def print_long_string(string, label = "")
|
136
|
+
strings = string.scan(%r!(.{1,#{@width}})(\s+|\W|\Z)!).map { |s| s.join.strip }
|
137
|
+
first_line = strings.first.cyan
|
138
|
+
|
139
|
+
label.empty? ? print_value(first_line) : print(label, first_line)
|
140
|
+
strings[1..-1].each { |s| print_value s.cyan }
|
141
|
+
end
|
142
|
+
|
143
|
+
# Prints key as logger[topic] and value as [message]
|
144
|
+
def print_hash(key, value)
|
145
|
+
if value.length > @width
|
146
|
+
print_long_string value, "#{key}:"
|
147
|
+
else
|
148
|
+
print "#{key}:", value.cyan
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def print_list(item)
|
153
|
+
if item.length > @width
|
154
|
+
print_long_string item, "-"
|
155
|
+
else
|
156
|
+
print "-", item.cyan
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def print_string(str)
|
161
|
+
if str.length > @width
|
162
|
+
print_long_string str
|
163
|
+
else
|
164
|
+
print_value str.inspect
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# Prints the site.data[key] in color
|
169
|
+
def print_key(key)
|
170
|
+
print_clear_line
|
171
|
+
print "Data Key:", " #{key} ".center(@width, "=")
|
172
|
+
print_clear_line
|
173
|
+
end
|
174
|
+
|
175
|
+
# Prints label, keys and values of mappings
|
176
|
+
def print_subkey_and_value(key, value)
|
177
|
+
print_label key
|
178
|
+
value.each do |subkey, val|
|
179
|
+
if val.is_a? Hash
|
180
|
+
print_inner_subkey subkey
|
181
|
+
inspect_inner_hash val
|
182
|
+
elsif val.is_a? Array
|
183
|
+
print_inner_subkey subkey
|
184
|
+
extract_hashes_and_print val
|
185
|
+
elsif val.is_a? String
|
186
|
+
print_hash subkey, val
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Print only logger[message], [topic] = nil
|
192
|
+
def print_value(value)
|
193
|
+
if value.is_a? Array
|
194
|
+
extract_hashes_and_print value
|
195
|
+
else
|
196
|
+
print "", value
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# Print only logger[topic] appended with a colon
|
201
|
+
def print_label(key)
|
202
|
+
print_value " #{key} ".center(@width, "-")
|
203
|
+
end
|
204
|
+
|
205
|
+
def print_inner_subkey(key)
|
206
|
+
print "#{key}:", @dashes
|
207
|
+
end
|
208
|
+
|
209
|
+
def print_dashes
|
210
|
+
print "", @dashes
|
211
|
+
end
|
212
|
+
|
213
|
+
def print_clear_line
|
214
|
+
print ""
|
215
|
+
end
|
216
|
+
|
217
|
+
# Redefine Jekyll Loggers to have the [topic] indented by 30.
|
218
|
+
# (rjust by just 29 to accomodate the additional whitespace added
|
219
|
+
# by Jekyll)
|
220
|
+
def print(topic, message = "")
|
221
|
+
Jekyll.logger.debug topic.rjust(29), message
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JekyllData
|
4
|
+
class ThemeConfiguration < Jekyll::Configuration
|
5
|
+
class << self
|
6
|
+
# Public: Establish a new site.config hash by reading an optional config
|
7
|
+
# file within the theme-gem and appending the resulting hash to
|
8
|
+
# existing site.config filling in keys not already defined.
|
9
|
+
#
|
10
|
+
# site: current Jekyll::Site instance.
|
11
|
+
#
|
12
|
+
# Returns a config Hash to be used by an 'after_reset' hook.
|
13
|
+
def reconfigure(site)
|
14
|
+
default_hash = Jekyll::Configuration::DEFAULTS
|
15
|
+
theme_config = ThemeConfiguration.new(site).read_theme_config
|
16
|
+
|
17
|
+
# Merge with existing site.config and strip any remaining defaults
|
18
|
+
config = Jekyll::Utils.deep_merge_hashes(
|
19
|
+
theme_config, site.config
|
20
|
+
).reject { |key, value| value == default_hash[key] }
|
21
|
+
|
22
|
+
# Merge DEFAULTS < _config.yml in theme-gem < config file(s) from source
|
23
|
+
# and redefine site.config
|
24
|
+
site.config = Jekyll::Configuration.from(
|
25
|
+
Jekyll::Utils.deep_merge_hashes(theme_config, config)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
|
32
|
+
def initialize(site)
|
33
|
+
@site = site
|
34
|
+
end
|
35
|
+
|
36
|
+
# Public: Read the '_config.yml' file within the theme-gem.
|
37
|
+
# Additionally validates that the extracted config data and the
|
38
|
+
# the 'value' of '<site.theme.name> key', when present, is a Hash.
|
39
|
+
#
|
40
|
+
# Returns a Configuration Hash
|
41
|
+
def read_theme_config
|
42
|
+
file = @site.in_theme_dir("_config.yml")
|
43
|
+
theme_name = @site.theme.name
|
44
|
+
|
45
|
+
config = safe_load_file(file)
|
46
|
+
|
47
|
+
check_config_is_hash!(config, file)
|
48
|
+
validate_config_hash config[theme_name] unless config[theme_name].nil?
|
49
|
+
|
50
|
+
config
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# Validate the <site.theme.name> key's value to be accessed via the `theme`
|
56
|
+
# namespace.
|
57
|
+
def validate_config_hash(value)
|
58
|
+
unless value.is_a? Hash
|
59
|
+
Jekyll.logger.abort_with "JekyllData:", "Theme Configuration should be a " \
|
60
|
+
"Hash of key:value pairs or mappings. But got #{value.class} instead."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JekyllData
|
4
|
+
class ThemeDataReader < Jekyll::DataReader
|
5
|
+
attr_reader :site, :content
|
6
|
+
def initialize(site)
|
7
|
+
@site = site
|
8
|
+
@content = {}
|
9
|
+
@entry_filter = Jekyll::EntryFilter.new(site)
|
10
|
+
end
|
11
|
+
|
12
|
+
def read(dir)
|
13
|
+
return unless site.theme && site.theme.data_path
|
14
|
+
base = site.in_theme_dir(dir)
|
15
|
+
read_data_to(base, @content)
|
16
|
+
@content
|
17
|
+
end
|
18
|
+
|
19
|
+
def read_data_to(dir, data)
|
20
|
+
return unless File.directory?(dir) && !@entry_filter.symlink?(dir)
|
21
|
+
|
22
|
+
entries = Dir.chdir(dir) do
|
23
|
+
Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) }
|
24
|
+
end
|
25
|
+
|
26
|
+
entries.each do |entry|
|
27
|
+
path = @site.in_theme_dir(dir, entry)
|
28
|
+
next if @entry_filter.symlink?(path)
|
29
|
+
|
30
|
+
if File.directory?(path)
|
31
|
+
read_data_to(path, data[sanitize_filename(entry)] = {})
|
32
|
+
else
|
33
|
+
key = sanitize_filename(File.basename(entry, ".*"))
|
34
|
+
data[key] = read_data_file(path)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JekyllData
|
4
|
+
class ThemedSiteDrop < Jekyll::Drops::SiteDrop
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
mutable false
|
8
|
+
|
9
|
+
def_delegator :@obj, :site_data, :data
|
10
|
+
def_delegators :@obj, :theme
|
11
|
+
|
12
|
+
private def_delegator :@obj, :config, :fallback_data
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Command
|
5
|
+
class << self
|
6
|
+
#
|
7
|
+
# patch original method to inject a '--show-data' switch to display
|
8
|
+
# merged data hash
|
9
|
+
#
|
10
|
+
alias_method :original_build_options, :add_build_options
|
11
|
+
|
12
|
+
def add_build_options(c)
|
13
|
+
original_build_options(c)
|
14
|
+
c.option "show-data", "--show-data",
|
15
|
+
"Print merged site-data hash when used with --verbose."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Drops
|
5
|
+
class UnifiedPayloadDrop < Drop
|
6
|
+
# Register a namespace to easily call subkeys under <theme-name> key
|
7
|
+
# in the _config.yml within a theme-gem via its bundled templates.
|
8
|
+
# e.g. with this drop, theme-specific variables usually called like
|
9
|
+
# {{ site.minima.date_format }} can be shortened to simply
|
10
|
+
# {{ theme.date_format }}.
|
11
|
+
def theme
|
12
|
+
@theme_drop ||= begin
|
13
|
+
config = site.send(:fallback_data)
|
14
|
+
config[config["theme"]]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-data-revised
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ashwin Maroli
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.7.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.7.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.14.3
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.14'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.14.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: cucumber
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.1'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.1'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: minitest
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '5.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '10.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '10.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.51.0
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.51.0
|
103
|
+
description:
|
104
|
+
email:
|
105
|
+
- ashmaroli@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- lib/jekyll-data.rb
|
113
|
+
- lib/jekyll-data/reader.rb
|
114
|
+
- lib/jekyll-data/theme_configuration.rb
|
115
|
+
- lib/jekyll-data/theme_data_reader.rb
|
116
|
+
- lib/jekyll-data/themed_site_drop.rb
|
117
|
+
- lib/jekyll-data/version.rb
|
118
|
+
- lib/jekyll/build_options.rb
|
119
|
+
- lib/jekyll/data_path.rb
|
120
|
+
- lib/jekyll/theme_drop.rb
|
121
|
+
homepage: https://github.com/ashmaroli/jekyll-data
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata:
|
125
|
+
allowed_push_host: https://rubygems.org
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.7.7
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: A plugin to read '_config.yml' and data files within Jekyll theme-gems
|
146
|
+
test_files: []
|