jekyll-cat 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +15 -3
- data/README.md +6 -0
- data/jekyll-cat.gemspec +1 -1
- data/lib/jekyll-cat.rb +21 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e89900ae7cbf069394368c7e2f6ef493ba7fa670310fcc848bd256e821437b22
|
4
|
+
data.tar.gz: ebcc200009af876490c6dd451d082b22c3e2ec752958ad7bca3df2952928f4d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6332d4708c553758f2bacbba923b3487978a969d44420922fd7b04bf8544b622fc901ebda453979775cad06705ab039df6d5c3d5c5e53d478fc5140a0d0875a
|
7
|
+
data.tar.gz: d821edadb0689201d8273cdacfd096535fc0d5fba7ec24485ebfd07e66a01f2549c40e731f4f69f3401db4b05078ad08b72d7c35b05830e6ba4da438a54e6af0
|
data/.gitignore
CHANGED
data/README.md
CHANGED
data/jekyll-cat.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "jekyll-cat"
|
3
|
-
spec.version = '1.
|
3
|
+
spec.version = '1.1.0'
|
4
4
|
spec.authors = ["Josh Davenport"]
|
5
5
|
spec.email = ["josh@joshdavenport.co.uk"]
|
6
6
|
spec.summary = 'Jekyll plugin providing a method to output contents of files and URLs'
|
data/lib/jekyll-cat.rb
CHANGED
@@ -5,40 +5,46 @@ require 'open-uri'
|
|
5
5
|
|
6
6
|
module Jekyll
|
7
7
|
class Cat < Liquid::Tag
|
8
|
-
|
9
8
|
def initialize(tag_name, path, tokens)
|
10
9
|
super
|
11
10
|
@path = path
|
12
11
|
end
|
13
12
|
|
14
13
|
def render(context)
|
15
|
-
|
14
|
+
# parse what was passed to the tag, in case it was a variable
|
15
|
+
if "#{context[@path]}" != ""
|
16
|
+
path = "#{context[@path]}"
|
17
|
+
else
|
18
|
+
path = @path
|
19
|
+
end
|
20
|
+
|
21
|
+
# deal with the path, returning the content
|
22
|
+
if path =~ URI::regexp
|
16
23
|
# the requested resource is a URL
|
17
|
-
return render_url(context)
|
18
|
-
elsif
|
24
|
+
return render_url(context, path)
|
25
|
+
elsif path[0] == '/'
|
19
26
|
# the requested resource is an file, specified with an absolute path
|
20
|
-
return render_file_abs(context)
|
27
|
+
return render_file_abs(context, path)
|
21
28
|
else
|
22
29
|
# the requested resource is an file, specified with a relative path
|
23
|
-
return render_file_rel(context)
|
24
|
-
end
|
30
|
+
return render_file_rel(context, path)
|
31
|
+
end
|
25
32
|
end
|
26
33
|
|
27
|
-
def render_file_abs(context)
|
28
|
-
|
29
|
-
content = File.read(file_path.strip!)
|
34
|
+
def render_file_abs(context, path)
|
35
|
+
content = File.read(path.strip)
|
30
36
|
return content
|
31
37
|
end
|
32
38
|
|
33
|
-
def render_file_rel(context)
|
39
|
+
def render_file_rel(context, path)
|
34
40
|
site_source = context.registers[:site].config['source']
|
35
|
-
file_path = site_source + '/' +
|
36
|
-
content = File.read(file_path.strip
|
41
|
+
file_path = site_source + '/' + path
|
42
|
+
content = File.read(file_path.strip)
|
37
43
|
return content
|
38
44
|
end
|
39
45
|
|
40
|
-
def render_url(context)
|
41
|
-
encoded_url = URI.encode(
|
46
|
+
def render_url(context, path)
|
47
|
+
encoded_url = URI.encode(path)
|
42
48
|
return open(encoded_url).read
|
43
49
|
end
|
44
50
|
end
|