jekyll-fetch 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 78fbc096ac10a2e0de1821d788ef39d7d3aac90d548f991a86fb2321648b64de
4
+ data.tar.gz: 0c64327b464de1bf621164c567e9aed699397b39efdeb4806f7a1015f81176d4
5
+ SHA512:
6
+ metadata.gz: 693b15d089811dcc193f2857156049ad0a1d53b2df37ebd7f26dce5c4b253f4b4c0bd5c51117a8029677ea288f63c2544dc65b18f2663903b963094bc9f9e478
7
+ data.tar.gz: 968522b19ff9b1e5b804cadbbc6cf8e59986ebc14c62f3da892324456984a02eeb46dd1634cc3a0e7c55fa3137d41031db3cf9691d3a38f41c2d26af02cf19cb
data/.rubocop.yml ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in jekyll_http.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 pcouy
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.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # JekyllHttp
2
+
3
+ This plugin adds a new `fetch` filter that allows you to include content from an HTTP URL.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add jekyll-fetch
10
+
11
+ Add the plugin to your `_config.yml`:
12
+
13
+ ```yaml
14
+ plugins:
15
+ - jekyll-fetch
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ Simply pass the URL you want to fetch the content from to the filter :
21
+
22
+ ```
23
+ {{ "https://raw.githubusercontent.com/pcouy/jekyll-fetch/main/README.md" | fetch }}
24
+ ```
25
+
26
+ The example above will render to the raw markdown of this readme. You can chain it with the `markdownify` filter to render it :
27
+
28
+ ```
29
+ {{ "https://raw.githubusercontent.com/pcouy/jekyll-fetch/main/README.md" | fetch | markdownify }}
30
+ ```
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ You can use your local development version of this plugin by modifying the `Gemfile` of your website to look like the following :
39
+
40
+ ```
41
+ gem "jekyll-fetch", "~> VERSION", :path => "/path/to/your/local/jekyll-fetch"
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pcouy/jekyll-fetch.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllFetch
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jekyll-fetch/version"
4
+ require "liquid"
5
+ require "net/https"
6
+
7
+ module Jekyll
8
+ module JekyllFetch
9
+ class Error < StandardError; end
10
+
11
+ def fetch(uri_str, limit = 10)
12
+ # You should choose better exception.
13
+ raise ArgumentError, 'HTTP redirect too deep' if limit == 0
14
+
15
+ url = URI.parse(uri_str)
16
+ req = Net::HTTP::Get.new(url.path, { 'User-Agent' => 'Mozilla/5.0 (etc...)' })
17
+ response = Net::HTTP.start(url.host, url.port, use_ssl: true) { |http| http.request(req) }
18
+ case response
19
+ when Net::HTTPSuccess then response.body
20
+ when Net::HTTPRedirection then fetch(response['location'], limit - 1)
21
+ else
22
+ response.error!
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ Liquid::Template.register_filter(Jekyll::JekyllFetch)
@@ -0,0 +1,4 @@
1
+ module JekyllHttp
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-fetch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - pcouy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-11 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - couy.pierre@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - lib/jekyll-fetch.rb
40
+ - lib/jekyll-fetch/version.rb
41
+ - sig/jekyll_http.rbs
42
+ homepage: https://github.com/pcouy/jekyll-fetch
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ allowed_push_host: https://rubygems.org
47
+ homepage_uri: https://github.com/pcouy/jekyll-fetch
48
+ source_code_uri: https://github.com/pcouy/jekyll-fetch
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.6.0
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.3.25
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Liquid filter that enables including content from an HTTP URL
68
+ test_files: []