jekyll-file-protocol 0.1.4 → 0.2.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/README.md +19 -4
- data/jekyll-file-protocol.gemspec +2 -1
- data/lib/jekyll-file-protocol/version.rb +1 -1
- data/lib/jekyll/filters/relative_path.rb +35 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b5534faf56a4f91f8e2eba6bef3a17ba14d66bf
|
4
|
+
data.tar.gz: 9dd6d94c0fba94d82c0a26efbc6e3341f1010efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac78f5e3d12df2ff657e724b4edd3b3a0c14dc55bd854306a4b565a79f32910e2373729b0bacf845cd9c4f0de6a875c0902d66e2e4b89dadb8b6e2740a56f5bf
|
7
|
+
data.tar.gz: e22d072ee2a25704743cdec349f031fe1c0b786b382a0c42b7a6121c2256e38cdb720127891de34084d180d9ddaae0c68286df1bb0172e4a6b9a3a2166c58a1a
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ This gem is born to help me creating relative paths for filters of the gem [jeky
|
|
10
10
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
|
-
gem 'jekyll-file-protocol', '~> 0.
|
13
|
+
gem 'jekyll-file-protocol', '~> 0.2.0'
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
The gem actually provides
|
25
|
+
The gem actually provides some helpers (filters) that are quite straightforward to use.
|
26
26
|
The example will use the asset_path filter provided by jekyll-assets gem.
|
27
27
|
|
28
28
|
So imagine we have these files:
|
@@ -33,7 +33,7 @@ So imagine we have these files:
|
|
33
33
|
<html>
|
34
34
|
<body>
|
35
35
|
<img src="{{ 'living.png' | asset_path | relative_path }}" />
|
36
|
-
|
36
|
+
</body>
|
37
37
|
</html>
|
38
38
|
```
|
39
39
|
|
@@ -49,10 +49,25 @@ The resulting html will be:
|
|
49
49
|
<html>
|
50
50
|
<body>
|
51
51
|
<img src="../../assets/living.png" />
|
52
|
-
|
52
|
+
</body>
|
53
53
|
</html>
|
54
54
|
```
|
55
55
|
|
56
|
+
The other filter is `relative_tag` which can be used with `stylesheet`,
|
57
|
+
`javascript` and `image`.
|
58
|
+
|
59
|
+
```
|
60
|
+
# /_site/house/rooms/living.html
|
61
|
+
|
62
|
+
<html>
|
63
|
+
<body>
|
64
|
+
{{ 'living.png' | image | relative_tag }}
|
65
|
+
</body>
|
66
|
+
</html>
|
67
|
+
```
|
68
|
+
|
69
|
+
And the output is the same as before.
|
70
|
+
|
56
71
|
## TODO
|
57
72
|
|
58
73
|
- Write some tests
|
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "jekyll",
|
21
|
+
spec.add_dependency "jekyll", "~> 1.2.1"
|
22
|
+
spec.add_dependency "nokogiri", "~> 1.6.0"
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
spec.add_development_dependency "pry"
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'nokogiri'
|
1
2
|
require 'jekyll-file-protocol/relative_path_renderer'
|
2
3
|
|
3
4
|
module JekyllFileProtocol
|
@@ -8,9 +9,43 @@ module JekyllFileProtocol
|
|
8
9
|
|
9
10
|
def relative_path(input)
|
10
11
|
return input if input.nil?
|
12
|
+
|
11
13
|
::JekyllFileProtocol::RelativePathRenderer.new(@context, input).render
|
12
14
|
end
|
13
15
|
|
16
|
+
def relative_tag(input)
|
17
|
+
return input if input.nil?
|
18
|
+
|
19
|
+
node = Nokogiri::HTML.parse(input)
|
20
|
+
tags = nil
|
21
|
+
|
22
|
+
# Stylesheet
|
23
|
+
if tags = node.css('link').to_a
|
24
|
+
return tags.map do |tag|
|
25
|
+
tag['href'] = ::JekyllFileProtocol::RelativePathRenderer.new(@context, tag['href']).render
|
26
|
+
tag
|
27
|
+
end.map(&:to_html)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Javascript
|
31
|
+
if tags = node.css('script').to_a
|
32
|
+
return tags.map do |tag|
|
33
|
+
tag['src'] = ::JekyllFileProtocol::RelativePathRenderer.new(@context, tag['src']).render
|
34
|
+
tag
|
35
|
+
end.map(&:to_html)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Image
|
39
|
+
if tags = node.css('img').to_a
|
40
|
+
return tags.map do |tag|
|
41
|
+
tag['src'] = ::JekyllFileProtocol::RelativePathRenderer.new(@context, tag['src']).render
|
42
|
+
tag
|
43
|
+
end.map(&:to_html)
|
44
|
+
end
|
45
|
+
|
46
|
+
input
|
47
|
+
end
|
48
|
+
|
14
49
|
end
|
15
50
|
end
|
16
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-file-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fire-Dragon-DoL
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|