jekyll-include-with-frontmatter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9a5b71118abd595b24591241083380854e1164f3f9f1cf6a0ee74be0c0c3c607
4
+ data.tar.gz: 4fb8b41eb56c7a7884025093309ed023bea65d0cecdd576f6726cdd8c5e1f292
5
+ SHA512:
6
+ metadata.gz: c8529f69054697ce5e515b1233392f625520d2b9b30d6b2e53e1ee8ad328e3b349718ac638c0ba3b30e78e50613de09c4a52a5d140ba3444e1173b04ef4cbb9d
7
+ data.tar.gz: 52fba309410905f1cc734d82dab071e471ba5b56eed5397ebea8b3f2fa94bce7d6c244f41b43fe672d2600ebf730eeae5b8370b5d5da6cff3554ff108a033633
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Metrics/MethodLength:
4
+ Enabled: false
5
+ Metrics/ModuleLength:
6
+ Enbled: false
7
+ Metrics/AbcSize:
8
+ Enabled: false
9
+ Metrics/LineLength:
10
+ Enabled: false
11
+ Metrics/CyclomaticComplexity:
12
+ Enabled: false
13
+ Style/UnneededPercentQ:
14
+ Enabled: false
15
+ Naming/FileName:
16
+ Enabled: false
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in jekyll-include-with-frontmatter.gemspec
8
+ gemspec
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jekyll-include-with-frontmatter (0.1.0)
5
+ jekyll
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ colorator (1.1.0)
13
+ concurrent-ruby (1.1.4)
14
+ em-websocket (0.5.1)
15
+ eventmachine (>= 0.12.9)
16
+ http_parser.rb (~> 0.6.0)
17
+ eventmachine (1.2.7)
18
+ ffi (1.9.25)
19
+ forwardable-extended (2.6.0)
20
+ http_parser.rb (0.6.0)
21
+ i18n (0.9.5)
22
+ concurrent-ruby (~> 1.0)
23
+ jekyll (3.8.5)
24
+ addressable (~> 2.4)
25
+ colorator (~> 1.0)
26
+ em-websocket (~> 0.5)
27
+ i18n (~> 0.7)
28
+ jekyll-sass-converter (~> 1.0)
29
+ jekyll-watch (~> 2.0)
30
+ kramdown (~> 1.14)
31
+ liquid (~> 4.0)
32
+ mercenary (~> 0.3.3)
33
+ pathutil (~> 0.9)
34
+ rouge (>= 1.7, < 4)
35
+ safe_yaml (~> 1.0)
36
+ jekyll-sass-converter (1.5.2)
37
+ sass (~> 3.4)
38
+ jekyll-watch (2.1.2)
39
+ listen (~> 3.0)
40
+ kramdown (1.17.0)
41
+ liquid (4.0.1)
42
+ listen (3.1.5)
43
+ rb-fsevent (~> 0.9, >= 0.9.4)
44
+ rb-inotify (~> 0.9, >= 0.9.7)
45
+ ruby_dep (~> 1.2)
46
+ mercenary (0.3.6)
47
+ minitest (5.11.3)
48
+ pathutil (0.16.2)
49
+ forwardable-extended (~> 2.6)
50
+ public_suffix (3.0.3)
51
+ rake (10.5.0)
52
+ rb-fsevent (0.10.3)
53
+ rb-inotify (0.10.0)
54
+ ffi (~> 1.0)
55
+ rouge (3.3.0)
56
+ ruby_dep (1.5.0)
57
+ safe_yaml (1.0.4)
58
+ sass (3.7.2)
59
+ sass-listen (~> 4.0.0)
60
+ sass-listen (4.0.0)
61
+ rb-fsevent (~> 0.9, >= 0.9.4)
62
+ rb-inotify (~> 0.9, >= 0.9.7)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler (~> 1.17)
69
+ jekyll-include-with-frontmatter!
70
+ minitest (~> 5.0)
71
+ rake (~> 10.0)
72
+
73
+ BUNDLED WITH
74
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Kirk Haines
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.
@@ -0,0 +1,62 @@
1
+ # JekyllIncludeWithFrontmatterTag
2
+
3
+ Jekyll's `include` and `include_relative` tags are straight includes -- they don't deal with files that have frontmatter.
4
+
5
+ When working with a Jekyll site that uses Netlify CMS, though, one may want to be able to edit the includes via Netlify CMS. Netlify writes Markdown with frontmatter, though. The solution is to create a couple new tags, `includefm` and `includefm_relative`, which inherit from the Jekyll include tags, and add handling of frontmatter.
6
+
7
+ Frontmatter gets treated as params passed into the include. If there is an include param with the same key as a frontmatter param, the include param takes precedence. Thus, frontmatter params can be thought of as defaults param values for the include.
8
+
9
+ In all other ways, `includefm` and `includefm_relative` should work the same as `include` and `include_relative`.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'jekyll-include-with-frontmatter'
17
+ ```
18
+
19
+ Also add a corresponding line to your Jekyll `config.yml`:
20
+
21
+ ```yaml
22
+ plugins:
23
+ - jekyll-include-with-frontmatter
24
+
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Files which are to be included can include frontmatter:
30
+
31
+ ```yaml
32
+ ---
33
+ title: Documents
34
+ ---
35
+ <div id="documents-column">
36
+ <div class="bg-blue">{{ include.title }}</div>
37
+ <div class="bg-grey"><a href="/media/pdfs/doc1.pdf" target="_blank">Document 1</a></div>
38
+ <div class="bg-grey"><a href="/media/pdfs/doc2.pdf" target="_blank">Document 2</a></div>
39
+ <div class="bg-grey"><a href="/media/pdfs/doc3.pdf" target="_blank">Document 3</a></div>
40
+ </div>
41
+
42
+ ```
43
+
44
+ In your post, page, or layout, you include with frontmatter like this:
45
+
46
+ ```liquid
47
+ {% includefm documents.html %}
48
+ ```
49
+
50
+ These tags should work just like the standard Jekyll include tags on files that do not include frontmatter, as well.
51
+
52
+ ## TODO
53
+
54
+ There are, effectively, no tests. Tests are needed.
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wyhaines/jekyll-include-with-frontmatter.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path(File.join(__dir__,"lib"))
4
+ puts "LIB IS #{lib}"
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'jekyll-include-with-frontmatter/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'jekyll-include-with-frontmatter'
10
+ spec.version = JekyllIncludeWithFrontmatter::VERSION
11
+ spec.authors = ['Kirk Haines']
12
+ spec.email = ['wyhaines@gmail.com']
13
+
14
+ spec.summary = %q(Jekyll include tags that will handle files with frontmatter.)
15
+ spec.description = %q(The built in include tags don't handle files that have frontmatter. This will, and if the frontmatter is a hash, it will be used to populate params for the include.)
16
+ spec.homepage = 'https://github.com/wyhaines/jekyll-include-with-frontmatter'
17
+ spec.license = 'MIT'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.17'
29
+ spec.add_development_dependency 'minitest', '~> 5.0'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+
32
+ spec.add_dependency 'jekyll'
33
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll-include-with-frontmatter/version'
4
+ require 'jekyll'
5
+ require 'jekyll/tags/include'
6
+ require 'yaml'
7
+
8
+ # Implement includes that can handle frontmatter.
9
+ class JekyllIncludeWithFrontmatter < Jekyll::Tags::IncludeTag
10
+ def render(context)
11
+ site = context.registers[:site]
12
+
13
+ file = render_variable(context) || @file
14
+ validate_file_name(file)
15
+
16
+ path = locate_include_file(context, file, site.safe)
17
+ return unless path
18
+
19
+ add_include_to_dependency(site, path, context)
20
+
21
+ partial, include_params = load_cached_partial(path, context)
22
+
23
+ context.stack do
24
+ parsed_params = @params ? parse_params(context) : nil
25
+
26
+ context['include'] = parsed_params ? include_params.merge(parsed_params) : include_params
27
+ begin
28
+ partial.render!(context)
29
+ rescue Liquid::Error => e
30
+ e.template_name = path
31
+ e.markup_context = 'included ' if e.markup_context.nil?
32
+ raise e
33
+ end
34
+ end
35
+ end
36
+
37
+ def load_cached_partial(path, context)
38
+ context.registers[:cached_partials] ||= {}
39
+ cached_partial = context.registers[:cached_partials]
40
+
41
+ unless cached_partial.key?(path)
42
+ unparsed_file = context.registers[:site]
43
+ .liquid_renderer
44
+ .file(path)
45
+ begin
46
+ file_data = read_file(path, context)
47
+ if (matchdata = file_data.match(/(---\n.*---\n)(.*)/m))
48
+ params = YAML.safe_load(matchdata[1])
49
+ cached_partial[path] = [unparsed_file.parse(matchdata[2]), params]
50
+ else
51
+ cached_partial[path] = [unparsed_file.parse(file_data), {}]
52
+ end
53
+ rescue Liquid::Error => e
54
+ e.template_name = path
55
+ e.markup_context = 'included ' if e.markup_context.nil?
56
+ raise e
57
+ end
58
+ end
59
+
60
+ cached_partial[path]
61
+ end
62
+ end
63
+
64
+ # Include relative to the source file. Blatantly stolen from Jekyll itself.
65
+ class JekyllIncludeRelativeWithFrontmatter < JekyllIncludeWithFrontmatter
66
+ def tag_includes_dirs(context)
67
+ Array(page_path(context)).freeze
68
+ end
69
+
70
+ def page_path(context)
71
+ if context.registers[:page].nil?
72
+ context.registers[:site].source
73
+ else
74
+ site = context.registers[:site]
75
+ page_payload = context.registers[:page]
76
+ resource_path = \
77
+ if page_payload['collection'].nil?
78
+ page_payload['path']
79
+ else
80
+ File.join(site.config['collections_dir'], page_payload['path'])
81
+ end
82
+ site.in_source_dir File.dirname(resource_path)
83
+ end
84
+ end
85
+ end
86
+
87
+ Liquid::Template.register_tag('includefm', JekyllIncludeWithFrontmatter)
88
+ Liquid::Template.register_tag('includefm_relative', JekyllIncludeRelativeWithFrontmatter)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll'
4
+ require 'jekyll/tags/include'
5
+ class JekyllIncludeWithFrontmatter < Jekyll::Tags::IncludeTag
6
+ VERSION = '0.1.0'
7
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-include-with-frontmatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kirk Haines
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jekyll
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: The built in include tags don't handle files that have frontmatter. This
70
+ will, and if the frontmatter is a hash, it will be used to populate params for the
71
+ include.
72
+ email:
73
+ - wyhaines@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rubocop.yml"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - jekyll-include-with-frontmatter.gemspec
87
+ - lib/jekyll-include-with-frontmatter.rb
88
+ - lib/jekyll-include-with-frontmatter/version.rb
89
+ homepage: https://github.com/wyhaines/jekyll-include-with-frontmatter
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.0.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Jekyll include tags that will handle files with frontmatter.
112
+ test_files: []