jekyll_github_content 0.0.3
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 +7 -0
- data/README.md +40 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/jekyll_github_content.rb +95 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ddc3f0b418374cc40bb6a884a7e83b3446bcdf6
|
4
|
+
data.tar.gz: ec421a5b60fb89056d179c78ea5d7edd74e2767c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6967e667c1a878d016242a6c06f4dbf3e6bd3b66ecb89c5ae392ad53a52ef410c43dc233ff8492ee574295ccfe09f61843c707e9e4eaec132f2622f3ba85705a
|
7
|
+
data.tar.gz: a84420ad01bf82fd62c99b48eaf32bdfdadf7828cf3905ceeb08975ab4ea54e178c891908cbedc0ccdc43088e6c6a3fc605d04120085698d32d4aa563d69276f
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# JekyllGithubContent
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jekyll/github/inserts`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'jekyll-github-content'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install jekyll-github-content
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll-github-content.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
40
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jekyll_github_content"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# 3rd party libs
|
2
|
+
require 'open-uri'
|
3
|
+
require 'active_support'
|
4
|
+
require 'liquid'
|
5
|
+
|
6
|
+
module JekyllGithubContent
|
7
|
+
|
8
|
+
class GithubUriParser
|
9
|
+
|
10
|
+
GITHUB_URI_ROOT = 'https://github.com/'
|
11
|
+
GITHUB_RAW_URI_ROOT = 'https://raw.githubusercontent.com'
|
12
|
+
|
13
|
+
attr_reader :user, :repo, :file
|
14
|
+
|
15
|
+
def initialize(path)
|
16
|
+
relative_path = path.sub(/^https?\:\/\//, '').sub(/^github.com/, '')
|
17
|
+
url_chunks = relative_path.split('/').delete_if { |e| e.empty? }
|
18
|
+
|
19
|
+
@user, @repo, blob, @branch = url_chunks[0..3]
|
20
|
+
@file = File.join(url_chunks[4..-1])
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_raw_file_uri
|
24
|
+
File.join(GITHUB_RAW_URI_ROOT, @user, @repo, @branch, @file)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_user_uri
|
28
|
+
File.join(GITHUB_URI_ROOT, @user)
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_repo_uri
|
32
|
+
File.join(GITHUB_URI_ROOT, @user, @repo)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class GithubContentRenderer < ::Liquid::Tag
|
38
|
+
|
39
|
+
def initialize(tag_name, params, tokens)
|
40
|
+
path, @initial_line, @end_line = params.split
|
41
|
+
@github_file = GithubUriParser.new(path)
|
42
|
+
@initial_line, @end_line = parse_line_boundaries(@initial_line, @end_line)
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def render(context)
|
47
|
+
file_lines = cache.fetch(@github_file.get_raw_file_uri) do
|
48
|
+
open(@github_file.get_raw_file_uri).readlines
|
49
|
+
end
|
50
|
+
lines_to_print = file_lines[@initial_line..@end_line]
|
51
|
+
lines_to_print.join
|
52
|
+
end
|
53
|
+
|
54
|
+
private # --------------------------------------------------------------------------------------------------------
|
55
|
+
|
56
|
+
def cache
|
57
|
+
@@cache ||= ActiveSupport::Cache::MemoryStore.new
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_line_boundaries(first_line, last_line)
|
61
|
+
if first_line.nil? && last_line.nil?
|
62
|
+
first_line = 0
|
63
|
+
last_line = -1
|
64
|
+
elsif last_line.nil?
|
65
|
+
last_line = first_line
|
66
|
+
end
|
67
|
+
|
68
|
+
[first_line.to_i, last_line.to_i]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class GithubMetaContentRenderer < GithubContentRenderer
|
73
|
+
|
74
|
+
def render(context)
|
75
|
+
<<DELIMITER.strip
|
76
|
+
<div class="github-file">
|
77
|
+
<div class="meta-info">
|
78
|
+
Github file by <a href="#{@github_file.get_user_uri}">#{@github_file.user}</a>
|
79
|
+
<br>
|
80
|
+
Repo: <a href="#{@github_file.get_repo_uri}">#{@github_file.repo}</a>
|
81
|
+
<br>
|
82
|
+
File: #{@github_file.file} <a href="#{@github_file.get_raw_file_uri}">Raw view</a>
|
83
|
+
</div>
|
84
|
+
</div>
|
85
|
+
DELIMITER
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
# Register the tag names in Liquid to allow code & medadata insertion in Jekill markdown files
|
92
|
+
# e.g. {% github_file <my_file_url_in_github> [start_line] [end_line] %}
|
93
|
+
# e.g. {% github_fileref <my_file_url_in_github> %}
|
94
|
+
Liquid::Template.register_tag('github_file', JekyllGithubContent::GithubContentRenderer)
|
95
|
+
Liquid::Template.register_tag('github_fileref', JekyllGithubContent::GithubMetaContentRenderer)
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_github_content
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francisco Perez-Sorrosal
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jekyll
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.13.a
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.13.a
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Allows to insert github files in jekyll markdown files
|
70
|
+
email:
|
71
|
+
- fperezsorrosal@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- README.md
|
77
|
+
- bin/console
|
78
|
+
- bin/setup
|
79
|
+
- lib/jekyll_github_content.rb
|
80
|
+
homepage: https://github.com/francisco-perez-sorrosal/jekyll-github-content
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata:
|
84
|
+
allowed_push_host: https://rubygems.org
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.5.1
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Insert github files with jekyll
|
105
|
+
test_files: []
|