jekyll-plugin-include 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 67a5391d4ca7a662d4dff68b38f89cf2298fdd0b
4
+ data.tar.gz: c93679e4e7c5c20988799f17df0442ac1097e0fe
5
+ SHA512:
6
+ metadata.gz: dd80fb512d2079f508d041c28db5181cacf55dc65c8cbc32431592f5fff22ed352f3b654a87d34b65ae9662ca309486a550ba59384ae7f80af2ff2c53ddd5c01
7
+ data.tar.gz: f53b13e87781963957b397fcbc97744de4f09c71e7c51519d104d088a68dce527fe2048fdfd816debfa733457fb4f0c17440aeb9a834617906e3f3ae40df5150
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,11 @@
1
+ Style/RedundantReturn:
2
+ Enabled: False
3
+ Style/TrailingCommaInArrayLiteral:
4
+ Enabled: False
5
+ Style/TrailingCommaInHashLiteral:
6
+ Enabled: False
7
+
8
+ Metrics/AbcSize:
9
+ Max: 25
10
+ Metrics/MethodLength:
11
+ Max: 20
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Christopher Peterson
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,81 @@
1
+ jekyll-plugin-include
2
+ =====================
3
+
4
+ A Jekyll liquid tag plugin which allows includes directly from plugins' `_include` directories, with optional ability to override with files present in site includes_dir (if they exist).
5
+
6
+ Normally, Jekyll's `include` tag can only search for files in the site's single configured includes directory (and that of the *theme* plugin, if it using one). That means that if a plugin wants to provide you with a template/fragment via includes, the best it can do is ask you to copy it into your own repo manually.
7
+
8
+ This plugin then makes it easy to use includes that ship *with* a plugin directly *from* a plugin. And if a modified version of the file is provided in the site's own includes directory, it can intelligently use that one instead!
9
+
10
+ And for plugin developers, this provides a way to ship and use includes without leaning on the user to manage the unmodified files themselves.
11
+
12
+ # Requirements
13
+
14
+ * Jekyll static site generator
15
+ * A build process that runs somewhere other than Github pages (as this is a custom plugin)
16
+
17
+ # Installation
18
+
19
+ You can add a Rubygems-hosted Jekyll plugin (like this one) to your site by either adding adding it to your `_config` or to your `Gemfile`. you can also use it in your own gem-based plugin by adding it to your gemspec.
20
+
21
+ ## gemfile install (recommended)
22
+
23
+ Add to the `jekyll_plugins` group in your `Gemfile`.
24
+
25
+ ```ruby
26
+ group :jekyll_plugins do
27
+ gem "jekyll-plugin-include"
28
+ end
29
+ ```
30
+
31
+ ## Jekyll `_config` install
32
+
33
+ Add it to the array `plugins` in your `_config.yml`:
34
+ ```yaml
35
+ plugins:
36
+ - jekyll-plugin-include
37
+ ```
38
+
39
+ # For use in your own gem-based plugin (gemspec)
40
+
41
+ Add something like this to your gemspec
42
+ ```ruby
43
+ spec.add_runtime_dependency "jekyll-plugin-include", ">= 0.1.0"
44
+ ```
45
+ # Usage
46
+
47
+ Note: quotes are required for arguments with spaces, and whitespace after the `:` is acceptable
48
+
49
+ This plugin provides a single custom Jekyll Liquid tag which provides enhanced include-like functionality, so it will look a lot like the standard `include`.
50
+
51
+ In this example with the `jekyll-podcast` plugin, this will function much like Jekyll's normal `include` (inserting the rendered contents of `includefile.html`), but will look in the `_includes` directory of the specified plugin if it doesn't find the file in the site's configured includes directory.
52
+
53
+ ```liquid
54
+ {% plugin_include plugin:"jekyll-podcast" file: "podcast_feed_episode_content_encoded.html" %}
55
+ ```
56
+
57
+ It is also possible to *force* this plugin to skip the site's configured includes directory completely and look exclusively in the plugin's `_includes` directory with the `allow_override` parameter:
58
+
59
+ ```liquid
60
+ {% plugin_include plugin:"jekyll-podcast" file: "podcast_feed_misc.xml" allow_override: false %}
61
+ ```
62
+
63
+ ## Include parameters
64
+
65
+ Any parameters passed to the include besides `_plugin` and `_file` will be passed through as-is and will be available as `include.param_name` in the file.
66
+
67
+ # Testing
68
+
69
+ * syntax: a .rubocop.yml is provided. `rubocop lib/jekyll/plugin-include.rb`
70
+
71
+ # Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/decipher-media/jekyll-plugin-include.
74
+
75
+ # License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
78
+
79
+ # Credits
80
+
81
+ By [Christopher Peterson](https://chrispeterson.info) for [Decipher Media](https://github.com/decipher-media/jekyll-plugin-include).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jekyll/plugin/include"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "jekyll_plugin_include/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-plugin-include"
8
+ spec.version = Jekyll::PluginInclude::VERSION
9
+ spec.authors = ["Decipher Media"]
10
+ spec.email = ["deciphermediatv@gmail.com"]
11
+ spec.summary = %q{A Jekyll liquid tag plugin which allows includes directly from plugins' _include directories, with optional ability to override with equivalently-named files present in site includes_dir (if they exist).}
12
+ spec.description = %q{A Jekyll liquid tag plugin which allows includes directly from plugins' `_include` directories, with optional ability to override with files present in site includes_dir (if they exist).
13
+
14
+ Normally, Jekyll's `include` tag can only search for files in the site's single configured includes directory (and that of the *theme* plugin, if it using one). That means that if a plugin wants to provide you with a template/fragment via includes, the best it can do is ask you to copy it into your own repo manually.
15
+
16
+ This plugin then makes it easy to use includes that ship *with* a plugin directly *from* a plugin. And if a modified version of the file is provided in the site's own includes directory, it can intelligently use that one instead!
17
+
18
+ And for plugin developers, this provides a way to ship and use includes without leaning on the user to manage the unmodified files themselves.}
19
+ spec.homepage = "https://github.com/decipher-media/jekyll-plugin-include"
20
+ spec.license = "MIT"
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
+ f.match(%r{^(test|spec|features)/})
24
+ end
25
+ spec.bindir = "bin"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency "jekyll", ['>= 3.8', '< 4.0']
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.16"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "rubocop", "~> 0.59.1"
35
+ end
@@ -0,0 +1,96 @@
1
+ require "jekyll_plugin_include/version"
2
+ # rubocop:disable Metrics/MethodLength
3
+
4
+ module Jekyll
5
+ module PluginInclude
6
+ class Tag < Liquid::Tag
7
+ VARIABLE_SYNTAX = /
8
+ (?<variable>[^{]*(\{\{\s*[\w\-\.]+\s*(\|.*)?\}\}[^\s{}]*)+)
9
+ (?<params>.*)
10
+ /x
11
+
12
+ def initialize(tagname, content, tokens)
13
+ super
14
+
15
+ @attributes = { '_allow_override' => 'true' }
16
+ content.scan(::Liquid::TagAttributes) do |key, value|
17
+ # Strip quotes from around attribute values
18
+ @attributes[key] = value.gsub(/^['"]|['"]$/, '')
19
+ end
20
+
21
+ gem_root = Gem::Specification.find_by_name(@attributes['_plugin']).gem_dir
22
+ @gem_includes = File.join(gem_root, '_includes')
23
+ @site_root = Jekyll.configuration({})['source']
24
+ @site_includes_dir = File.join(
25
+ @site_root,
26
+ Jekyll.configuration({})['includes_dir']
27
+ )
28
+ end
29
+
30
+ def render(context)
31
+ searchpath = if @attributes['_allow_override'] == 'true'
32
+ [
33
+ @site_includes_dir,
34
+ @gem_includes,
35
+ ]
36
+ else
37
+ [
38
+ @gem_includes,
39
+ @site_includes_dir,
40
+ ]
41
+ end
42
+
43
+ file = render_variable(
44
+ context,
45
+ @attributes['_file']
46
+ ) || @attributes['_file']
47
+
48
+ # Pass on the include params minus ours
49
+ pass_params = @attributes
50
+ pass_params.delete('_plugin')
51
+ pass_params.delete('_file')
52
+ pass_params.delete('_allow_override')
53
+ context['include'] = pass_params
54
+
55
+ file = findfile(searchpath, file)
56
+ if file.nil?
57
+ raise 'podcast_include could not find the file '\
58
+ "\"#{@attributes['_file']}\"."
59
+ else
60
+ f = File.read(file, context.registers[:site].file_read_opts)
61
+ partial = Liquid::Template.parse(f)
62
+ partial.render!(context)
63
+ end
64
+ end
65
+
66
+ # Render the variable if required (@see https://goo.gl/N5sMV3)
67
+ def render_variable(context, var)
68
+ return unless var.match(VARIABLE_SYNTAX)
69
+
70
+ partial = context.registers[:site]
71
+ .liquid_renderer
72
+ .file('(variable)')
73
+ .parse(var)
74
+ return partial.render!(context)
75
+ end
76
+
77
+ def findfile(path, filename)
78
+ file = nil
79
+
80
+ path.each do |dir|
81
+ testfile = File.join(dir, filename)
82
+ if File.file?(testfile)
83
+ file = testfile
84
+ break
85
+ end
86
+ end
87
+
88
+ return file
89
+ end
90
+
91
+ Liquid::Template.register_tag 'plugin_include', self
92
+ end
93
+ end
94
+ end
95
+
96
+ # rubocop:enable Metrics/MethodLength
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module PluginInclude
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-plugin-include
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Decipher Media
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-24 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.8'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.8'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.16'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.16'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.59.1
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.59.1
89
+ description: |-
90
+ A Jekyll liquid tag plugin which allows includes directly from plugins' `_include` directories, with optional ability to override with files present in site includes_dir (if they exist).
91
+
92
+ Normally, Jekyll's `include` tag can only search for files in the site's single configured includes directory (and that of the *theme* plugin, if it using one). That means that if a plugin wants to provide you with a template/fragment via includes, the best it can do is ask you to copy it into your own repo manually.
93
+
94
+ This plugin then makes it easy to use includes that ship *with* a plugin directly *from* a plugin. And if a modified version of the file is provided in the site's own includes directory, it can intelligently use that one instead!
95
+
96
+ And for plugin developers, this provides a way to ship and use includes without leaning on the user to manage the unmodified files themselves.
97
+ email:
98
+ - deciphermediatv@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".rspec"
105
+ - ".rubocop.yml"
106
+ - ".travis.yml"
107
+ - LICENSE.md
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - jekyll-plugin-include.gemspec
113
+ - lib/jekyll-plugin-include.rb
114
+ - lib/jekyll_plugin_include/version.rb
115
+ homepage: https://github.com/decipher-media/jekyll-plugin-include
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.5.2.1
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: A Jekyll liquid tag plugin which allows includes directly from plugins' _include
139
+ directories, with optional ability to override with equivalently-named files present
140
+ in site includes_dir (if they exist).
141
+ test_files: []