jekyll-file-protocol 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb0e572a1078b3b5436abd0809aee6e4b62df780
4
- data.tar.gz: d0311c4bdb469ec445a5258409e50c6b60e31bbd
3
+ metadata.gz: 7b5534faf56a4f91f8e2eba6bef3a17ba14d66bf
4
+ data.tar.gz: 9dd6d94c0fba94d82c0a26efbc6e3341f1010efa
5
5
  SHA512:
6
- metadata.gz: a785f5cceef4cda6be7e45bc4887ed0a974cf9f58a7e5a4de758a33111f97b51622c300ccbeb0e579e01b4cdb2825f9d37c5d54fb4ae27b2d99cf4f4ceac8779
7
- data.tar.gz: fefdc757f6f87c76dc2db442b64b4bda034d57cf1b9ce2dfb6a749e95e2087f1480f968ada03b13079f3cfee59a8c42cd62b605ff9773754c0a8434dd2cb6034
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.1.4'
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 a single helper (a filter) that is quite straightforward to use.
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
- </body>
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
- </body>
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", "~> 1.2.1"
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,3 @@
1
1
  module JekyllFileProtocol
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.1.4
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