jekyll-cat 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c009189a0472310e08bd714370497c372fa32c034305911961e4768c5939c31e
4
+ data.tar.gz: 39c45447f6acc6578a9a68e7e350047cf16608c6fbe962d054010cc9076c1f82
5
+ SHA512:
6
+ metadata.gz: e7df718e05c4b7025ed8a40ec42554fdc1e52ffdaf32e83d09af104cbc1767ec102f5c5bac1761e3e993ce59fecaa8aee0ef142c10c1c695734e329c735994ba
7
+ data.tar.gz: 19c662cd239261125358a2ff58639918af5b1487f528c3910e91d857493641e364f5ac32f5dc0468aa87d08ebde1bb726d2eebefcf684bdc6130815f815d456d
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ _site/
2
+ .sass-cache/
3
+ .jekyll-metadata
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Josh Davenport
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Jekyll cat
2
+
3
+ Its name inspired by unix [cat](https://en.wikipedia.org/wiki/Cat_(Unix)), this Jekyll plugin providing a method to output contents of files and URLs. You can access files relatively (e.g. any file in the site, or in directories surrounding it, permissions allowing) as well as absolute paths (if that is any use) and contents return at URLs.
4
+
5
+ ## Install
6
+ Add the following to your Gemfile and then run bundle install.
7
+
8
+ gem 'jekyll-cat'
9
+
10
+ ## Usage
11
+ In liquid, use the `cat` tag to execute your include, passing the tag your path or url.
12
+
13
+ ## Examples
14
+ ### Relative
15
+ ```
16
+ {% cat assets/vector/my-svg-file.svg %}
17
+ ```
18
+
19
+ ### Absolute
20
+ ```
21
+ {% cat /path/to/file %}
22
+ ```
23
+
24
+ ### URL
25
+ ```
26
+ {% cat https://loripsum.net/api/ %}
27
+ ```
28
+
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "jekyll-cat"
3
+ spec.version = '1.0.0'
4
+ spec.authors = ["Josh Davenport"]
5
+ spec.email = ["josh@joshdavenport.co.uk"]
6
+ spec.summary = 'Jekyll plugin providing a method to output contents of files and URLs'
7
+ spec.homepage = 'https://github.com/joshdavenport/jekyll-cat'
8
+ spec.license = "MIT"
9
+ spec.files = `git ls-files -z`.split("\x0")
10
+ spec.require_paths = ['lib']
11
+
12
+ spec.required_ruby_version = '>= 2.1.0'
13
+
14
+ spec.add_development_dependency 'jekyll', '>= 3.1'
15
+ end
16
+
data/lib/jekyll-cat.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'liquid'
2
+ require 'json'
3
+ require 'uri'
4
+ require 'open-uri'
5
+
6
+ module Jekyll
7
+ class Cat < Liquid::Tag
8
+
9
+ def initialize(tag_name, path, tokens)
10
+ super
11
+ @path = path
12
+ end
13
+
14
+ def render(context)
15
+ if @path =~ URI::regexp
16
+ # the requested resource is a URL
17
+ return render_url(context)
18
+ elsif @path[0] == '/'
19
+ # the requested resource is an file, specified with an absolute path
20
+ return render_file_abs(context)
21
+ else
22
+ # the requested resource is an file, specified with a relative path
23
+ return render_file_rel(context)
24
+ end
25
+ end
26
+
27
+ def render_file_abs(context)
28
+ file_path = @path
29
+ content = File.read(file_path.strip!)
30
+ return content
31
+ end
32
+
33
+ def render_file_rel(context)
34
+ site_source = context.registers[:site].config['source']
35
+ file_path = site_source + '/' + @path
36
+ content = File.read(file_path.strip!)
37
+ return content
38
+ end
39
+
40
+ def render_url(context)
41
+ encoded_url = URI.encode(@path)
42
+ return open(encoded_url).read
43
+ end
44
+ end
45
+ end
46
+
47
+ Liquid::Template.register_tag('cat', Jekyll::Cat)
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-cat
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Davenport
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-22 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.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ description:
28
+ email:
29
+ - josh@joshdavenport.co.uk
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - jekyll-cat.gemspec
39
+ - lib/jekyll-cat.rb
40
+ homepage: https://github.com/joshdavenport/jekyll-cat
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.1.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.7.4
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Jekyll plugin providing a method to output contents of files and URLs
64
+ test_files: []