jekyll-data 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fe7b8c111ab83b204be84b5f21de872ffd037ab
4
- data.tar.gz: 5e954926b328bf2f1ba45dd0e48e154162786e1d
3
+ metadata.gz: fd5090a5a9fecc23edb990f2af43701cdf018fc2
4
+ data.tar.gz: 5d9c0af30ca3738e65114eb9ac29514b8c7c2fc9
5
5
  SHA512:
6
- metadata.gz: c0a9382fb9a07bd5fb47278432fdc4e5bfe270a97b12d4af2b1e4191db93267c7766d1c82ad7bdf88270aea28e84ba6e0301416a74347c0fdca44fe8064815cc
7
- data.tar.gz: 105d0a80ceb935055a7e15c7d282615e9eaa8dbc03c1fe186e1b0516bea82d29e896a3235f1a74e44ce67abc54654d7008bfade78bedab806e6cad8a8b048e28
6
+ metadata.gz: 89371b0891b485f65b138a30b13af973b4397a058eeaf3130eaaf7a75ac4db733864d79bcf12a1637813be2b4872fe6d74395956225f9a2d7e72bd7d80f931e9
7
+ data.tar.gz: 43d1d7e23a4ed9d40d6154f5100bf192865104259ebb52dc33ecd64c46151e83ad974df6837d5fce6066b72dfd252fd7efe2d7b8e2497e9507d37e084731859f
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  [travis]: https://travis-ci.org/ashmaroli/jekyll-data
7
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.
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 read as well.
9
9
 
10
10
  ## Installation
11
11
 
@@ -16,7 +16,7 @@ Simply add the plugin to your site's Gemfile and config file like every other je
16
16
  group :jekyll_plugins do
17
17
  gem "jekyll-data"
18
18
  end
19
- ```
19
+ ```
20
20
  ```yaml
21
21
  # _config.yml
22
22
 
@@ -31,19 +31,32 @@ bundle install
31
31
 
32
32
  ## Usage
33
33
 
34
- As long as the gem has been installed properly, and is included in the Gemfile & the config file, 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.
34
+ **Note:** *This plugin will only run in conjunction with a gem-based Jekyll-theme.*
35
+
36
+ As long as the plugin gem has been installed properly, and is included in both the Gemfile & the config file, 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.
37
+
38
+ 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 site's config hash without this plugin, will override the conflicting config hash generated by this plugin from reading the included `_config.yml`
35
39
 
36
40
  ### Theme Configuration
37
41
 
38
- 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 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.
39
- 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.
42
+ 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.
40
43
 
41
- Theme specific directives *should* be defined in a file named the same as `theme.name`.
42
- 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 }}`)
44
+ This plugin provides a couple of solutions to that hurdle:
45
+
46
+ - settings via `_config.yml`
47
+ ----------------------------
48
+ This plugin reads the config file (at present only `_config.yml`) and uses the data to modify the site's config hash. This allows the gem to continue using `{{ site.myvariable }}` within its templates.
49
+ - settings via `_data/[theme-name].*`
50
+ --------------------------------------
51
+ An alternate route is to have theme-specific settings defined as a hash, in a valid data file named the same as the theme-gem.
52
+ The defined settings will be accessible via `{{ theme.myvariable }}`.
53
+ e.g. if *minima* were to ship a YAML file with *minima*-specific settings (say, `post_excerpt: enabled`), then the gem would've a **_data/minima.yml** and this particular setting can be accessed in its templates via `{{ theme.post_excerpt }}` which is functionally equivalent to `{{ site.data.minima.post_excerpt }}`
54
+ *Note: The `{{ theme.variable }}` is only available if the data-file is named the same as the theme-gem.*
43
55
 
44
56
  ### Regular Data-files
45
57
 
46
- 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.
58
+ Regular data files that may be used to supplement theme templates (e.g. locales and translated UI text) 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.
59
+
47
60
  ```yaml
48
61
  # <theme-gem>/_data/apparel.yml
49
62
 
@@ -124,4 +137,3 @@ Bug reports and pull requests are welcome at the [GitHub Repo](https://github.co
124
137
  ## License
125
138
 
126
139
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
127
-
@@ -10,7 +10,22 @@ require_relative "jekyll/drops/themed_site_drop"
10
10
  require_relative "jekyll/theme"
11
11
  require_relative "jekyll/drops/unified_payload_drop"
12
12
 
13
- # replace Jekyll::Reader with a subclass Jekyll::ThemeReader
13
+ # replace Jekyll::Reader with a subclass Jekyll::ThemeReader only if the site
14
+ # uses a gem-based theme else have this plugin disabled.
15
+ #
16
+ # Additionally, append to site's config hash with optional config hash from the
17
+ # theme gem by filling in keys not already defined.
14
18
  Jekyll::Hooks.register :site, :after_init do |site|
15
- site.reader = Jekyll::ThemeReader.new(site)
19
+ if site.theme
20
+ site.config = Jekyll::Utils.deep_merge_hashes(
21
+ Jekyll::ThemeReader.new(site).read_theme_config, site.config
22
+ )
23
+ site.reader = Jekyll::ThemeReader.new(site)
24
+ else
25
+ Jekyll.logger.abort_with(
26
+ "JekyllData:",
27
+ "Error! This plugin only works with gem-based jekyll-themes. " \
28
+ "Please disable this plugin to proceed."
29
+ )
30
+ end
16
31
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllData
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -9,24 +9,19 @@ module Jekyll
9
9
  site.config["data_dir"], "**", "*.{yaml,yml,json,csv}")]
10
10
  end
11
11
 
12
- # Read Site data from disk and load it into internal data structures.
12
+ # Read data files within theme-gem.
13
13
  #
14
14
  # Returns nothing.
15
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"])
16
+ super
20
17
  read_theme_data
21
- CollectionReader.new(site).read
22
- ThemeAssetsReader.new(site).read
23
18
  end
24
19
 
25
20
  # Read data files within a theme gem and add them to internal data
26
21
  #
27
22
  # Returns a hash appended with new data
28
23
  def read_theme_data
29
- if site.theme && site.theme.data_path
24
+ if site.theme.data_path
30
25
  #
31
26
  # show contents of "<theme>/_data/" dir being read while degugging.
32
27
  # Additionally validate if a data file with the same name as the
@@ -41,12 +36,25 @@ module Jekyll
41
36
  end
42
37
  end
43
38
 
39
+ # Read the '_config.yml' file if present within the theme gem and
40
+ # return a data hash otherwise return a hash of Jekyll Defaults.
41
+ #
42
+ # Returns a hash
43
+ def read_theme_config
44
+ config = @site.in_theme_dir("_config.yml")
45
+ if File.exist?(config)
46
+ Configuration.new.read_config_file(config)
47
+ else
48
+ Configuration::DEFAULTS
49
+ end
50
+ end
51
+
44
52
  private
45
53
 
46
54
  # Private:
47
55
  # Print messages only while debugging.
48
56
  #
49
- # Inspect the theme configuration file (data-file with the same name
57
+ # Inspect the theme configuration file (data file with the same name
50
58
  # as the theme) and print a success message, if valid.
51
59
  def inspect_theme_data
52
60
  print_clear_line
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.3.0
4
+ version: 0.4.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-21 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -106,5 +106,5 @@ rubyforge_project:
106
106
  rubygems_version: 2.6.8
107
107
  signing_key:
108
108
  specification_version: 4
109
- summary: A plugin to read data files in Jekyll Theme Gems
109
+ summary: A plugin to read '_config.yml' and data files in Jekyll Theme Gems
110
110
  test_files: []