jekyll_github_sample 0.2.0 → 0.3.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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +12 -1
- data/lib/jekyll_github_sample/code_tag.rb +6 -2
- data/lib/jekyll_github_sample/text_utils.rb +19 -0
- data/lib/jekyll_github_sample/version.rb +1 -1
- data/spec/lib/jekyll_github_sample/text_utils_spec.rb +21 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc04ac952632c2231479dc871d6b2abcfebf96ee
|
4
|
+
data.tar.gz: e71916874ca33eea7bc973099ed2eedd4a610e2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f53146882fc4603a272b1b93436dc9cfbadfe3ccad3d134a1c532740852f2b3f7c920b09b4c8bb8de84e2fdd134b9174777f9c1939072b5d16b990c4e842834
|
7
|
+
data.tar.gz: 0c02616d019a1a15c321ce6e1d527a8b3585c2e02a569f46d13be85bca93dbc64d3d8d6b496ff238bfa45876d925c5a8dc73b77e7401fbef1b0b5c0a192e383e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@ Two Jekyll Liquid tags to display a code sample from a file in a public Github r
|
|
5
5
|
|
6
6
|
# Install
|
7
7
|
|
8
|
-
- First add the gem to your `Gemfile`
|
8
|
+
- First add the gem to your `Gemfile`
|
9
9
|
```
|
10
10
|
gem 'jekyll_github_sample'
|
11
11
|
```
|
@@ -30,6 +30,16 @@ A [write up](https://bwillis.github.io/2014/05/28/include-github-repo-code-in-je
|
|
30
30
|
* START_LINE_NUMBER - (optional) number that is the first line to include (0 based)
|
31
31
|
* END_LINE_NUMBER - (optional) number that is the last line to include, if excluded will read to end of file
|
32
32
|
|
33
|
+
One can also specify the lines to include based on markings in the file itself.
|
34
|
+
This is done by invoking
|
35
|
+
|
36
|
+
```
|
37
|
+
{% github_sample URL_WITH_USERNAME_REPO_AND_FILE tag:TAG_NAME %}
|
38
|
+
```
|
39
|
+
|
40
|
+
and placing the strings `[START TAG_NAME]` and `[END TAG_NAME]` anywhere in the lines immediately before and after the content you wish to include.
|
41
|
+
|
42
|
+
|
33
43
|
# github_sample_ref Usage
|
34
44
|
```
|
35
45
|
{% github_sample_ref URL_WITH_USERNAME_REPO_AND_FILE %}
|
@@ -53,6 +63,7 @@ This is how you would display, reference and highlight code in your Jekyll post.
|
|
53
63
|
Thanks to all those who have helped make this really awesome:
|
54
64
|
|
55
65
|
* [heedfull](https://github.com/heedfull)
|
66
|
+
* [robertwb](https://github.com/robertwb)
|
56
67
|
|
57
68
|
# License
|
58
69
|
Jekyll Github Sample is released under the MIT license: www.opensource.org/licenses/MIT
|
@@ -11,7 +11,6 @@ module JekyllGithubSample
|
|
11
11
|
def initialize(tag_name, params, tokens)
|
12
12
|
github_file_path, @line_start, @line_end = params.split
|
13
13
|
@github_file = FileHelper.new(github_file_path)
|
14
|
-
@line_start, @line_end = determine_line_numbers(@line_start, @line_end)
|
15
14
|
super
|
16
15
|
end
|
17
16
|
|
@@ -19,7 +18,12 @@ module JekyllGithubSample
|
|
19
18
|
all_lines = cache.fetch(@github_file.raw_uri) do
|
20
19
|
open(@github_file.raw_uri).readlines
|
21
20
|
end
|
22
|
-
|
21
|
+
if @line_start.respond_to?(:match) and tag_match = @line_start.match(/^tag:(.*)/)
|
22
|
+
lines = extract_tagged_lines(all_lines, tag_match[1])
|
23
|
+
else
|
24
|
+
@line_start, @line_ends = determine_line_numbers(@line_start, @line_end)
|
25
|
+
lines = all_lines[@line_start..@line_end]
|
26
|
+
end
|
23
27
|
lines = remove_common_indentation(lines)
|
24
28
|
lines.join
|
25
29
|
end
|
@@ -18,5 +18,24 @@ module JekyllGithubSample
|
|
18
18
|
line.length == 1 ? line : line[leading_spaces.min..-1]
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
def extract_tagged_lines(lines, tag)
|
23
|
+
start_tag = "[START #{tag}]"
|
24
|
+
end_tag = "[END #{tag}]"
|
25
|
+
tagged_lines = []
|
26
|
+
in_tagged_content = false
|
27
|
+
lines.each do |line|
|
28
|
+
if in_tagged_content
|
29
|
+
if line.include? end_tag
|
30
|
+
in_tagged_content = false
|
31
|
+
else
|
32
|
+
tagged_lines << line
|
33
|
+
end
|
34
|
+
else
|
35
|
+
in_tagged_content = line.include? start_tag
|
36
|
+
end
|
37
|
+
end
|
38
|
+
tagged_lines
|
39
|
+
end
|
21
40
|
end
|
22
41
|
end
|
@@ -33,4 +33,24 @@ describe JekyllGithubSample::TextUtils do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
context '#extract_tagged_lines' do
|
37
|
+
let(:lines) { [
|
38
|
+
'header',
|
39
|
+
'[START tag]',
|
40
|
+
'content 1',
|
41
|
+
'content 2',
|
42
|
+
'[END tag]',
|
43
|
+
'footer 1',
|
44
|
+
'footer 2'
|
45
|
+
] }
|
46
|
+
subject { text_utils.extract_tagged_lines(lines, 'tag') }
|
47
|
+
|
48
|
+
it 'extracts content' do
|
49
|
+
should =~ [
|
50
|
+
'content 1',
|
51
|
+
'content 2'
|
52
|
+
]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_github_sample
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Willis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.5.
|
125
|
+
rubygems_version: 2.5.2
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Include a sample of a Github repo file.
|