jekyll-data 0.2.1 → 1.1.1
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 +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +84 -85
- data/lib/jekyll-data.rb +44 -8
- data/lib/jekyll-data/reader.rb +226 -0
- data/lib/jekyll-data/theme_configuration.rb +64 -0
- data/lib/{jekyll/readers → jekyll-data}/theme_data_reader.rb +10 -6
- data/lib/jekyll-data/themed_site_drop.rb +14 -0
- data/lib/jekyll-data/version.rb +3 -1
- 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 +60 -24
- data/lib/jekyll/drops/themed_site_drop.rb +0 -17
- data/lib/jekyll/drops/unified_payload_drop.rb +0 -30
- data/lib/jekyll/theme.rb +0 -66
- data/lib/jekyll/theme_reader.rb +0 -158
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bfc00c25a2b9ae9878a4c854955f88698b114a1a0b7ed4733ec56ee691bdf507
|
|
4
|
+
data.tar.gz: 972a9a1d061585cadf5ceb5c10e057967ccfa6abb37b647682f942ef02bb94a2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18c73a13bef6df9cf945301e8cb1ae8ed62882a0b9b39de1da8e4b4d4124b93ccb07f86ee1bafd363c6ad8591ffe891ec8498a9aa01d9949e24a00a9f309181b
|
|
7
|
+
data.tar.gz: b97f8328beb1003c23f4d0f96f05177f762dfceeffcbb7c577c9db1304076235d866da32cda1cfc952e4a59b93fa994572477d1a846cea3a60cf4e48c26088d1
|
data/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2016 Ashwin Maroli
|
|
3
|
+
Copyright (c) 2016-2017 Ashwin Maroli & Contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
|
@@ -1,118 +1,118 @@
|
|
|
1
1
|
# JekyllData
|
|
2
2
|
|
|
3
3
|
[](https://rubygems.org/gems/jekyll-data)
|
|
4
|
+
[][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.
|
|
4
9
|
|
|
5
|
-
Introducing a plugin that reads data files within **jekyll theme gems** and adds the resulting hash to the site's internal data hash.
|
|
6
10
|
|
|
7
11
|
## Installation
|
|
8
12
|
|
|
9
|
-
Simply add the plugin to your site's Gemfile and config file like every other jekyll plugin
|
|
13
|
+
Simply add the plugin to your site's Gemfile and config file like every other jekyll plugin gem:
|
|
14
|
+
|
|
10
15
|
```ruby
|
|
11
16
|
# Gemfile
|
|
12
17
|
|
|
13
18
|
group :jekyll_plugins do
|
|
14
19
|
gem "jekyll-data"
|
|
15
20
|
end
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
# _config.yml
|
|
21
|
+
```
|
|
22
|
+
..and run
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
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.**
|
|
22
28
|
|
|
23
|
-
```
|
|
24
|
-
..and run
|
|
25
|
-
```
|
|
26
|
-
bundle install
|
|
27
|
-
```
|
|
28
29
|
|
|
29
30
|
## Usage
|
|
30
31
|
|
|
31
|
-
As long as the gem has been installed properly, and is included in the Gemfile
|
|
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
|
+
|
|
32
38
|
|
|
33
39
|
### Theme Configuration
|
|
34
40
|
|
|
35
|
-
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
|
|
36
|
-
This plugin provides a way to have the said data-files read and be used by the site. This plugin expects to find all data-files within the `_data` directory at the root of the theme gem.
|
|
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.
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
e.g. if *minima* were to ship a YAML file with such directives, then it would've a **_data/minima.yml** and variables within it would be referenced in the template files using a `theme` namespace like so: `{{ theme.myvariable }}` (which is functionally identical to `{{ site.data.minima.myvariable }}`)
|
|
43
|
+
This plugin provides a solution to that hurdle:
|
|
40
44
|
|
|
41
|
-
|
|
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`:
|
|
42
54
|
|
|
43
|
-
Regular data files that may be used to supplement theme templates (e.g. demo placeholders) can be named as desired. Either use a sub-directory to house related data-files or declare all of them as a mapped data block within a single file.
|
|
44
|
-
```yaml
|
|
45
|
-
# <theme-gem>/_data/apparel.yml
|
|
46
|
-
|
|
47
|
-
shirts:
|
|
48
|
-
- color: white
|
|
49
|
-
size: large
|
|
50
|
-
image: s_w_lg.jpg
|
|
51
|
-
- color: black
|
|
52
|
-
size: large
|
|
53
|
-
image: s_b_lg.jpg
|
|
54
|
-
|
|
55
|
-
jeans:
|
|
56
|
-
- color: khaki
|
|
57
|
-
waist: 34
|
|
58
|
-
image: j_kh_34.jpg
|
|
59
|
-
- color: blue
|
|
60
|
-
waist: 32
|
|
61
|
-
image: j_bu_32.jpg
|
|
62
|
-
```
|
|
63
|
-
is the same as:
|
|
64
|
-
```yaml
|
|
65
|
-
# <theme-gem>/_data/apparel/shirts.yml
|
|
66
|
-
|
|
67
|
-
- color: white
|
|
68
|
-
size: large
|
|
69
|
-
image: s_w_lg.jpg
|
|
70
|
-
- color: black
|
|
71
|
-
size: large
|
|
72
|
-
image: s_b_lg.jpg
|
|
73
|
-
```
|
|
74
55
|
```yaml
|
|
75
|
-
# <
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
|
|
83
70
|
```
|
|
84
71
|
|
|
85
|
-
### User-overrides
|
|
86
72
|
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
|
|
89
81
|
```yaml
|
|
90
|
-
# <
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
```
|
|
104
|
-
would have overridden the following:
|
|
105
|
-
```yaml
|
|
106
|
-
# <theme-gem>/_data/navigation/mainmenu.yml
|
|
107
|
-
|
|
108
|
-
- title: Link Item 1
|
|
109
|
-
url: /link-one/
|
|
110
|
-
- title: Link Item 2
|
|
111
|
-
url: /link-two/
|
|
112
|
-
- title: Link Item 3
|
|
113
|
-
url: /link-three/
|
|
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 : successivo
|
|
114
95
|
```
|
|
115
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
116
|
## Contributing
|
|
117
117
|
|
|
118
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.
|
|
@@ -121,4 +121,3 @@ Bug reports and pull requests are welcome at the [GitHub Repo](https://github.co
|
|
|
121
121
|
## License
|
|
122
122
|
|
|
123
123
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
124
|
-
|
data/lib/jekyll-data.rb
CHANGED
|
@@ -1,16 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "jekyll"
|
|
2
4
|
require "jekyll-data/version"
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
8
12
|
|
|
9
13
|
# Monkey-patches
|
|
10
|
-
require_relative "jekyll/
|
|
11
|
-
require_relative "jekyll/
|
|
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 4.0 has this feature incorporated in its core.*
|
|
25
|
+
# ----------------------------------------------------------------------------
|
|
26
|
+
unless Jekyll::VERSION.start_with?("4")
|
|
27
|
+
Jekyll::Hooks.register :site, :after_reset do |site|
|
|
28
|
+
if site.theme
|
|
29
|
+
file = site.in_theme_dir("_config.yml")
|
|
30
|
+
JekyllData::ThemeConfiguration.reconfigure(site) if File.exist?(file)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
12
34
|
|
|
13
|
-
#
|
|
35
|
+
# ---------------------------------------------------------------------------
|
|
36
|
+
# Replace Jekyll::Reader with a subclass JekyllData::Reader only if the
|
|
37
|
+
# site uses a gem-based theme.
|
|
38
|
+
#
|
|
39
|
+
# If a _config.yml exists at the root of the theme-gem, output its path.
|
|
40
|
+
# Placed here inorder to avoid outputting the path after every regeneration.
|
|
41
|
+
#
|
|
42
|
+
# *Jekyll 4.0 detects a theme-configuration natively.*
|
|
43
|
+
# ---------------------------------------------------------------------------
|
|
14
44
|
Jekyll::Hooks.register :site, :after_init do |site|
|
|
15
|
-
site.
|
|
45
|
+
if site.theme
|
|
46
|
+
unless Jekyll::VERSION.start_with?("4")
|
|
47
|
+
file = site.in_theme_dir("_config.yml")
|
|
48
|
+
Jekyll.logger.info "Theme Config file:", file if File.exist?(file)
|
|
49
|
+
end
|
|
50
|
+
site.reader = JekyllData::Reader.new(site)
|
|
51
|
+
end
|
|
16
52
|
end
|
|
@@ -0,0 +1,226 @@
|
|
|
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
|
+
|
|
11
|
+
if @theme.data_path
|
|
12
|
+
@theme_data_files = Dir[File.join(@theme.data_path, "**", "*.{yaml,yml,json,csv,tsv}")]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Read data files within theme-gem.
|
|
17
|
+
#
|
|
18
|
+
# Returns nothing.
|
|
19
|
+
def read
|
|
20
|
+
super
|
|
21
|
+
read_theme_data
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Read data files within a theme gem and add them to internal data
|
|
25
|
+
#
|
|
26
|
+
# Returns a hash appended with new data
|
|
27
|
+
def read_theme_data
|
|
28
|
+
if @theme.data_path
|
|
29
|
+
#
|
|
30
|
+
# show contents of "<theme>/_data/" dir being read while degugging.
|
|
31
|
+
inspect_theme_data
|
|
32
|
+
theme_data = ThemeDataReader.new(site).read(site.config["data_dir"])
|
|
33
|
+
@site.data = Jekyll::Utils.deep_merge_hashes(theme_data, @site.data)
|
|
34
|
+
#
|
|
35
|
+
# show contents of merged site.data hash while debugging with
|
|
36
|
+
# additional --show-data switch.
|
|
37
|
+
inspect_merged_hash if site.config["show-data"] && site.config["verbose"]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
# Private:
|
|
44
|
+
# (only while debugging)
|
|
45
|
+
#
|
|
46
|
+
# Print a list of data file(s) within the theme-gem
|
|
47
|
+
def inspect_theme_data
|
|
48
|
+
print_clear_line
|
|
49
|
+
Jekyll.logger.debug "Reading:", "Theme Data Files..."
|
|
50
|
+
@theme_data_files.each { |file| Jekyll.logger.debug "", file }
|
|
51
|
+
print_clear_line
|
|
52
|
+
Jekyll.logger.debug "Merging:", "Theme Data Hash..."
|
|
53
|
+
|
|
54
|
+
unless site.config["show-data"] && site.config["verbose"]
|
|
55
|
+
Jekyll.logger.debug "", "use --show-data with --verbose to output " \
|
|
56
|
+
"merged Data Hash.".cyan
|
|
57
|
+
print_clear_line
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Private:
|
|
62
|
+
# (only while debugging)
|
|
63
|
+
#
|
|
64
|
+
# Print contents of the merged data hash
|
|
65
|
+
def inspect_merged_hash
|
|
66
|
+
Jekyll.logger.debug "Inspecting:", "Site Data >>"
|
|
67
|
+
|
|
68
|
+
# the width of generated logger[message]
|
|
69
|
+
@width = 50
|
|
70
|
+
@dashes = "-" * @width
|
|
71
|
+
|
|
72
|
+
inspect_hash @site.data
|
|
73
|
+
print_clear_line
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# --------------------------------------------------------------------
|
|
77
|
+
# Private helper methods to inspect data hash and output contents
|
|
78
|
+
# to logger at level debugging.
|
|
79
|
+
# --------------------------------------------------------------------
|
|
80
|
+
|
|
81
|
+
# Dissect the (merged) site.data hash and print its contents
|
|
82
|
+
#
|
|
83
|
+
# - Print the key string(s)
|
|
84
|
+
# - Individually analyse the hash[key] values and extract contents
|
|
85
|
+
# to output.
|
|
86
|
+
def inspect_hash(hash)
|
|
87
|
+
hash.each do |key, value|
|
|
88
|
+
print_key key
|
|
89
|
+
if value.is_a? Hash
|
|
90
|
+
inspect_inner_hash value
|
|
91
|
+
elsif value.is_a? Array
|
|
92
|
+
extract_hashes_and_print value
|
|
93
|
+
else
|
|
94
|
+
print_string value.to_s
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Analyse deeper hashes and extract contents to output
|
|
100
|
+
def inspect_inner_hash(hash)
|
|
101
|
+
hash.each do |key, value|
|
|
102
|
+
if value.is_a? Array
|
|
103
|
+
print_label key
|
|
104
|
+
extract_hashes_and_print value
|
|
105
|
+
elsif value.is_a? Hash
|
|
106
|
+
print_subkey_and_value key, value
|
|
107
|
+
else
|
|
108
|
+
print_hash key, value
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# If an array of strings, print. Otherwise assume as an
|
|
114
|
+
# array of hashes (sequences) that needs further analysis.
|
|
115
|
+
def extract_hashes_and_print(array)
|
|
116
|
+
array.each do |entry|
|
|
117
|
+
if entry.is_a? String
|
|
118
|
+
print_list entry
|
|
119
|
+
else
|
|
120
|
+
inspect_inner_hash entry
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
#
|
|
126
|
+
|
|
127
|
+
# --------------------------------------------------------------------
|
|
128
|
+
# Private methods for formatting log messages while debugging
|
|
129
|
+
# --------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
# Splits a string longer than the value of '@width' into smaller
|
|
132
|
+
# strings and prints each line as a logger[message]
|
|
133
|
+
#
|
|
134
|
+
# string - the long string
|
|
135
|
+
#
|
|
136
|
+
# label - optional text to designate the printed lines.
|
|
137
|
+
def print_long_string(string, label = "")
|
|
138
|
+
strings = string.scan(%r!(.{1,#{@width}})(\s+|\W|\Z)!).map { |s| s.join.strip }
|
|
139
|
+
first_line = strings.first.cyan
|
|
140
|
+
|
|
141
|
+
label.empty? ? print_value(first_line) : print(label, first_line)
|
|
142
|
+
strings[1..-1].each { |s| print_value s.cyan }
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Prints key as logger[topic] and value as [message]
|
|
146
|
+
def print_hash(key, value)
|
|
147
|
+
if value.length > @width
|
|
148
|
+
print_long_string value, "#{key}:"
|
|
149
|
+
else
|
|
150
|
+
print "#{key}:", value.cyan
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def print_list(item)
|
|
155
|
+
if item.length > @width
|
|
156
|
+
print_long_string item, "-"
|
|
157
|
+
else
|
|
158
|
+
print "-", item.cyan
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def print_string(str)
|
|
163
|
+
if str.length > @width
|
|
164
|
+
print_long_string str
|
|
165
|
+
else
|
|
166
|
+
print_value str.inspect
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Prints the site.data[key] in color
|
|
171
|
+
def print_key(key)
|
|
172
|
+
print_clear_line
|
|
173
|
+
print "Data Key:", " #{key} ".center(@width, "=")
|
|
174
|
+
print_clear_line
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Prints label, keys and values of mappings
|
|
178
|
+
def print_subkey_and_value(key, value)
|
|
179
|
+
print_label key
|
|
180
|
+
value.each do |subkey, val|
|
|
181
|
+
if val.is_a? Hash
|
|
182
|
+
print_inner_subkey subkey
|
|
183
|
+
inspect_inner_hash val
|
|
184
|
+
elsif val.is_a? Array
|
|
185
|
+
print_inner_subkey subkey
|
|
186
|
+
extract_hashes_and_print val
|
|
187
|
+
elsif val.is_a? String
|
|
188
|
+
print_hash subkey, val
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Print only logger[message], [topic] = nil
|
|
194
|
+
def print_value(value)
|
|
195
|
+
if value.is_a? Array
|
|
196
|
+
extract_hashes_and_print value
|
|
197
|
+
else
|
|
198
|
+
print "", value
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Print only logger[topic] appended with a colon
|
|
203
|
+
def print_label(key)
|
|
204
|
+
print_value " #{key} ".center(@width, "-")
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def print_inner_subkey(key)
|
|
208
|
+
print "#{key}:", @dashes
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def print_dashes
|
|
212
|
+
print "", @dashes
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def print_clear_line
|
|
216
|
+
print ""
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# Redefine Jekyll Loggers to have the [topic] indented by 30.
|
|
220
|
+
# (rjust by just 29 to accomodate the additional whitespace added
|
|
221
|
+
# by Jekyll)
|
|
222
|
+
def print(topic, message = "")
|
|
223
|
+
Jekyll.logger.debug topic.rjust(29), message
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
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
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module JekyllData
|
|
4
|
+
class ThemeDataReader < Jekyll::DataReader
|
|
3
5
|
attr_reader :site, :content
|
|
6
|
+
|
|
4
7
|
def initialize(site)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@
|
|
8
|
+
super
|
|
9
|
+
|
|
10
|
+
@source_dir = site.in_theme_dir("/")
|
|
8
11
|
end
|
|
9
12
|
|
|
10
13
|
def read(dir)
|
|
11
14
|
return unless site.theme && site.theme.data_path
|
|
15
|
+
|
|
12
16
|
base = site.in_theme_dir(dir)
|
|
13
17
|
read_data_to(base, @content)
|
|
14
18
|
@content
|
|
@@ -18,7 +22,7 @@ module Jekyll
|
|
|
18
22
|
return unless File.directory?(dir) && !@entry_filter.symlink?(dir)
|
|
19
23
|
|
|
20
24
|
entries = Dir.chdir(dir) do
|
|
21
|
-
Dir["*.{yaml,yml,json,csv}"] + Dir["*"].select { |fn| File.directory?(fn) }
|
|
25
|
+
Dir["*.{yaml,yml,json,csv,tsv}"] + Dir["*"].select { |fn| File.directory?(fn) }
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
entries.each do |entry|
|
|
@@ -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
|
data/lib/jekyll-data/version.rb
CHANGED
|
@@ -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(cmd)
|
|
13
|
+
original_build_options(cmd)
|
|
14
|
+
cmd.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
CHANGED
|
@@ -1,57 +1,63 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jekyll-data
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ashwin Maroli
|
|
8
|
-
autorequire:
|
|
9
|
-
bindir:
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-01-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jekyll
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '3.3'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 5.0.0
|
|
20
23
|
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
24
|
-
- - "
|
|
27
|
+
- - ">="
|
|
25
28
|
- !ruby/object:Gem::Version
|
|
26
29
|
version: '3.3'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 5.0.0
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
34
|
name: bundler
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
30
36
|
requirements:
|
|
31
|
-
- - "
|
|
37
|
+
- - ">="
|
|
32
38
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
39
|
+
version: 1.14.3
|
|
34
40
|
type: :development
|
|
35
41
|
prerelease: false
|
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
43
|
requirements:
|
|
38
|
-
- - "
|
|
44
|
+
- - ">="
|
|
39
45
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
46
|
+
version: 1.14.3
|
|
41
47
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
48
|
+
name: cucumber
|
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
|
44
50
|
requirements:
|
|
45
51
|
- - "~>"
|
|
46
52
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
53
|
+
version: 5.1.0
|
|
48
54
|
type: :development
|
|
49
55
|
prerelease: false
|
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
57
|
requirements:
|
|
52
58
|
- - "~>"
|
|
53
59
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
60
|
+
version: 5.1.0
|
|
55
61
|
- !ruby/object:Gem::Dependency
|
|
56
62
|
name: minitest
|
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,7 +72,35 @@ dependencies:
|
|
|
66
72
|
- - "~>"
|
|
67
73
|
- !ruby/object:Gem::Version
|
|
68
74
|
version: '5.0'
|
|
69
|
-
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: rake
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '13.0'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '13.0'
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: rubocop-jekyll
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: 0.11.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.11.0
|
|
103
|
+
description:
|
|
70
104
|
email:
|
|
71
105
|
- ashmaroli@gmail.com
|
|
72
106
|
executables: []
|
|
@@ -76,18 +110,20 @@ files:
|
|
|
76
110
|
- LICENSE.txt
|
|
77
111
|
- README.md
|
|
78
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
|
|
79
117
|
- lib/jekyll-data/version.rb
|
|
80
|
-
- lib/jekyll/
|
|
81
|
-
- lib/jekyll/
|
|
82
|
-
- lib/jekyll/
|
|
83
|
-
- lib/jekyll/theme.rb
|
|
84
|
-
- lib/jekyll/theme_reader.rb
|
|
118
|
+
- lib/jekyll/build_options.rb
|
|
119
|
+
- lib/jekyll/data_path.rb
|
|
120
|
+
- lib/jekyll/theme_drop.rb
|
|
85
121
|
homepage: https://github.com/ashmaroli/jekyll-data
|
|
86
122
|
licenses:
|
|
87
123
|
- MIT
|
|
88
124
|
metadata:
|
|
89
125
|
allowed_push_host: https://rubygems.org
|
|
90
|
-
post_install_message:
|
|
126
|
+
post_install_message:
|
|
91
127
|
rdoc_options: []
|
|
92
128
|
require_paths:
|
|
93
129
|
- lib
|
|
@@ -102,9 +138,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
102
138
|
- !ruby/object:Gem::Version
|
|
103
139
|
version: '0'
|
|
104
140
|
requirements: []
|
|
105
|
-
rubyforge_project:
|
|
106
|
-
rubygems_version: 2.6.
|
|
107
|
-
signing_key:
|
|
141
|
+
rubyforge_project:
|
|
142
|
+
rubygems_version: 2.7.6.2
|
|
143
|
+
signing_key:
|
|
108
144
|
specification_version: 4
|
|
109
|
-
summary: A plugin to read data files
|
|
145
|
+
summary: A plugin to read '_config.yml' and data files within Jekyll theme-gems
|
|
110
146
|
test_files: []
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
module Jekyll
|
|
4
|
-
module Drops
|
|
5
|
-
class ThemedSiteDrop < SiteDrop
|
|
6
|
-
extend Forwardable
|
|
7
|
-
|
|
8
|
-
mutable false
|
|
9
|
-
|
|
10
|
-
def_delegator :@obj, :site_data, :data
|
|
11
|
-
def_delegators :@obj, :theme
|
|
12
|
-
|
|
13
|
-
private
|
|
14
|
-
def_delegator :@obj, :config, :fallback_data
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
module Jekyll
|
|
4
|
-
module Drops
|
|
5
|
-
class UnifiedPayloadDrop < Drop
|
|
6
|
-
mutable true
|
|
7
|
-
|
|
8
|
-
attr_accessor :page, :layout, :content, :paginator
|
|
9
|
-
attr_accessor :highlighter_prefix, :highlighter_suffix
|
|
10
|
-
|
|
11
|
-
def jekyll
|
|
12
|
-
JekyllDrop.global
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def site
|
|
16
|
-
@site_drop ||= ThemedSiteDrop.new(@obj)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def theme
|
|
20
|
-
theme_name = site.theme.name
|
|
21
|
-
site.data[theme_name]
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
def fallback_data
|
|
26
|
-
@fallback_data ||= {}
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
data/lib/jekyll/theme.rb
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
module Jekyll
|
|
2
|
-
class Theme
|
|
3
|
-
extend Forwardable
|
|
4
|
-
attr_reader :name
|
|
5
|
-
def_delegator :gemspec, :version, :version
|
|
6
|
-
|
|
7
|
-
def initialize(name)
|
|
8
|
-
@name = name.downcase.strip
|
|
9
|
-
configure_sass
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def root
|
|
13
|
-
# Must use File.realpath to resolve symlinks created by rbenv
|
|
14
|
-
# Otherwise, Jekyll.sanitized path with prepend the unresolved root
|
|
15
|
-
@root ||= File.realpath(gemspec.full_gem_path)
|
|
16
|
-
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
|
|
17
|
-
nil
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def includes_path
|
|
21
|
-
path_for "_includes".freeze
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def layouts_path
|
|
25
|
-
path_for "_layouts".freeze
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def sass_path
|
|
29
|
-
path_for "_sass".freeze
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def data_path
|
|
33
|
-
path_for "_data".freeze
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def assets_path
|
|
37
|
-
path_for "assets".freeze
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def configure_sass
|
|
41
|
-
return unless sass_path
|
|
42
|
-
require "sass"
|
|
43
|
-
Sass.load_paths << sass_path
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
|
|
48
|
-
def path_for(folder)
|
|
49
|
-
path = realpath_for(folder)
|
|
50
|
-
path if path && File.directory?(path)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def realpath_for(folder)
|
|
54
|
-
File.realpath(Jekyll.sanitized_path(root, folder.to_s))
|
|
55
|
-
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
|
|
56
|
-
nil
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def gemspec
|
|
60
|
-
@gemspec ||= Gem::Specification.find_by_name(name)
|
|
61
|
-
rescue Gem::LoadError
|
|
62
|
-
raise Jekyll::Errors::MissingDependencyException,
|
|
63
|
-
"The #{name} theme could not be found."
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
data/lib/jekyll/theme_reader.rb
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require "csv"
|
|
3
|
-
|
|
4
|
-
module Jekyll
|
|
5
|
-
class ThemeReader < Reader
|
|
6
|
-
def initialize(site)
|
|
7
|
-
@site = site
|
|
8
|
-
@theme_data_files = Dir[File.join(@site.theme.root,
|
|
9
|
-
site.config["data_dir"], "**", "*.{yaml,yml,json,csv}")]
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Read Site data from disk and load it into internal data structures.
|
|
13
|
-
#
|
|
14
|
-
# Returns nothing.
|
|
15
|
-
def read
|
|
16
|
-
@site.layouts = LayoutReader.new(site).read
|
|
17
|
-
read_directories
|
|
18
|
-
sort_files!
|
|
19
|
-
@site.data = DataReader.new(site).read(site.config["data_dir"])
|
|
20
|
-
read_theme_data
|
|
21
|
-
CollectionReader.new(site).read
|
|
22
|
-
ThemeAssetsReader.new(site).read
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Read data files within a theme gem and add them to internal data
|
|
26
|
-
#
|
|
27
|
-
# Returns a hash appended with new data
|
|
28
|
-
def read_theme_data
|
|
29
|
-
if site.theme && site.theme.data_path
|
|
30
|
-
#
|
|
31
|
-
# show contents of "<theme>/_data/" dir being read
|
|
32
|
-
debug_theme_reader
|
|
33
|
-
theme_data = ThemeDataReader.new(site).read(site.config["data_dir"])
|
|
34
|
-
@site.data = Utils.deep_merge_hashes(theme_data, @site.data)
|
|
35
|
-
#
|
|
36
|
-
# show site.data hash contents
|
|
37
|
-
debug_theme_data_reader
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
def debug_theme_reader
|
|
44
|
-
print_clear_line
|
|
45
|
-
print "Reading:", "Theme Data Files..."
|
|
46
|
-
@theme_data_files.each do |file|
|
|
47
|
-
print_value file
|
|
48
|
-
end
|
|
49
|
-
print_clear_line
|
|
50
|
-
print "Merging:", "Theme Data Hash..."
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def debug_theme_data_reader
|
|
54
|
-
print "Inspecting:", "Site Data >>"
|
|
55
|
-
inspect_hash @site.data
|
|
56
|
-
print_clear_line
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def inspect_hash(hash)
|
|
60
|
-
hash.each do |key, value|
|
|
61
|
-
print_key key
|
|
62
|
-
if key == @site.theme.name
|
|
63
|
-
inspect_theme_override value
|
|
64
|
-
end
|
|
65
|
-
if value.class == Hash
|
|
66
|
-
inspect_inner_hash value
|
|
67
|
-
elsif value.class == Array
|
|
68
|
-
print_label key
|
|
69
|
-
extract_hashes_and_print value
|
|
70
|
-
else
|
|
71
|
-
print_value "'#{value}'"
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def inspect_theme_override(value)
|
|
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
|
-
|
|
87
|
-
def inspect_inner_hash(hash)
|
|
88
|
-
hash.each do |key, value|
|
|
89
|
-
if value.class == Array
|
|
90
|
-
print_label key
|
|
91
|
-
extract_hashes_and_print value
|
|
92
|
-
print_clear_line
|
|
93
|
-
elsif value.class == Hash
|
|
94
|
-
print_subkey_and_value key, value
|
|
95
|
-
else
|
|
96
|
-
print_hash key, value
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def extract_hashes_and_print(array)
|
|
102
|
-
array.each do |entry|
|
|
103
|
-
if entry.class == String
|
|
104
|
-
print "-", entry
|
|
105
|
-
else
|
|
106
|
-
inspect_inner_hash entry
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def print_hash(key, value)
|
|
112
|
-
print "#{key}:", value
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def print_key(key)
|
|
116
|
-
@dashes = "------------------------"
|
|
117
|
-
print_value @dashes.to_s.cyan
|
|
118
|
-
print "Data Key:", key.to_s.cyan
|
|
119
|
-
print_value @dashes.to_s.cyan
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def print_subkey_and_value(key, value)
|
|
123
|
-
print_label key
|
|
124
|
-
value.each do |subkey, val|
|
|
125
|
-
print_hash subkey, val
|
|
126
|
-
end
|
|
127
|
-
print_dashes
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def print_value(value)
|
|
131
|
-
if value.class == Array
|
|
132
|
-
extract_hashes_and_print value
|
|
133
|
-
else
|
|
134
|
-
print "", value
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def print_label(key)
|
|
139
|
-
print "#{key}:"
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def print_dashes
|
|
143
|
-
print "", @dashes
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def print_clear_line
|
|
147
|
-
print ""
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def print(arg1, arg2 = "")
|
|
151
|
-
Jekyll.logger.debug arg1, arg2
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def abort_with_msg(msg)
|
|
155
|
-
Jekyll.logger.abort_with "JekyllData:", msg
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
end
|