jekyll-gist 1.3.5 → 1.4.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: 07abe6ba906f53a7b31a29a8e0b168288cc52de0
4
- data.tar.gz: 949a7ae1b43609af36a6557d86bb982ea85d07ce
3
+ metadata.gz: 51416e403d33d8cd13aec298cba2647f63ce68b6
4
+ data.tar.gz: 10ae86f8b7a948be0862aa2c3a6b3547d30b0f9e
5
5
  SHA512:
6
- metadata.gz: b98fb0388d6d647036dd3c4a850f0e2bbbf26c5169eb575b1b6173a64bea861f7569c5cbee1877ef775250e5f8f9d587b134425680cabfb5b7109377716c4718
7
- data.tar.gz: 397ebd3045c39691b7edba845e8c03826593ec4e76387e4b52d386ffdb2814f354a836c0a4843ac450ed25ccf9a181ed42bee86ad853b471e7e9e4b55af68e54
6
+ metadata.gz: 7c26bc80c20feaa1066b2366be6add5430fcc7a7c6f0efb48e4d257745a59c67e4d636d6e6b49fbb0ef94a0c9b1c34f99e5832e7f7626ac58b4685eed1138963
7
+ data.tar.gz: b0b37b9fa634058b2af275c683379b97d87ac6fbcda8a3e6ac5273fcb7c6274f0275cf61d93bdf13eaf2fbd8161a61720620fe3902a66a52957c400edcf3db15
@@ -1,3 +1,8 @@
1
+ ## 1.4.0 / 2015-12-01
2
+
3
+ * Allow `noscript` fallback to be disabled (#29)
4
+ * Use Octokit to fetch Gist content when passed `JEKYLL_GITHUB_TOKEN` in env(#28)
5
+
1
6
  ## 1.3.5 / 2015-10-23
2
7
 
3
8
  * Fix encoding error for `noscript` code (#23)
data/README.md CHANGED
@@ -18,6 +18,13 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install jekyll-gist
20
20
 
21
+ Finally, add the following to your site's `_config.yml`:
22
+
23
+ ```
24
+ gems:
25
+ - jekyll-gist
26
+ ```
27
+
21
28
  ## Usage
22
29
 
23
30
  Use the tag as follows in your Jekyll pages, posts and collections:
@@ -40,6 +47,17 @@ You may optionally specify a `filename` after the `gist_id`:
40
47
 
41
48
  This will produce the correct URL to show just the specified file in your post rather than the entire Gist.
42
49
 
50
+ **Pro-tip**: If you provide a personal access token with Gist scope, as the environmental variable `JEKYLL_GITHUB_TOKEN`, Jekyll Gist will use the Gist API to speed up site generation.
51
+
52
+ ## Disabling `noscript` support
53
+
54
+ By default, Jekyll Gist will make an HTTP call per Gist to retrieve the raw content of the Gist. This information is used to propagate `noscript` tags for search engines and browsers without Javascript support. If you'd like to disable this feature, for example, to speed up builds locally, simply add the following to your site's `_config.yml`:
55
+
56
+ ```yml
57
+ gist:
58
+ noscript: false
59
+ ```
60
+
43
61
  ## Contributing
44
62
 
45
63
  1. Fork it ( https://github.com/jekyll/jekyll-gist/fork )
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_dependency "octokit", "~> 4.2"
22
23
  spec.add_development_dependency "bundler", "~> 1.6"
23
24
  spec.add_development_dependency "rake"
24
25
  spec.add_development_dependency "rspec"
@@ -1,5 +1,6 @@
1
1
  require 'cgi'
2
2
  require 'net/http'
3
+ require 'octokit'
3
4
 
4
5
  Net::OpenTimeout = Class.new(RuntimeError) unless Net.const_defined?(:OpenTimeout)
5
6
  Net::ReadTimeout = Class.new(RuntimeError) unless Net.const_defined?(:ReadTimeout)
@@ -10,6 +11,7 @@ module Jekyll
10
11
 
11
12
  def render(context)
12
13
  @encoding = context.registers[:site].config['encoding'] || 'utf-8'
14
+ @settings = context.registers[:site].config['gist']
13
15
  if tag_contents = determine_arguments(@markup.strip)
14
16
  gist_id, filename = tag_contents[0], tag_contents[1]
15
17
  if context.has_key?(gist_id)
@@ -50,10 +52,17 @@ module Jekyll
50
52
  end
51
53
 
52
54
  def gist_noscript_tag(gist_id, filename = nil)
55
+ return if @settings && @settings["noscript"] == false
53
56
  code = fetch_raw_code(gist_id, filename)
54
57
  if !code.nil?
55
58
  code = code.force_encoding(@encoding)
56
- "<noscript><pre>#{CGI.escapeHTML(code)}</pre></noscript>"
59
+ code = CGI.escapeHTML(code)
60
+
61
+ # CGI.escapeHTML behavior differs in Ruby < 2.0
62
+ # See https://github.com/jekyll/jekyll-gist/pull/28
63
+ code = code.gsub("'", "&#39;") if RUBY_VERSION < "2.0"
64
+
65
+ "<noscript><pre>#{code}</pre></noscript>"
57
66
  else
58
67
  Jekyll.logger.warn "Warning:", "The <noscript> tag for your gist #{gist_id} could not"
59
68
  Jekyll.logger.warn "", "be generated. This will affect users who do not have"
@@ -62,20 +71,43 @@ module Jekyll
62
71
  end
63
72
 
64
73
  def fetch_raw_code(gist_id, filename = nil)
74
+ return code_from_api(gist_id, filename) if ENV["JEKYLL_GITHUB_TOKEN"]
75
+
65
76
  url = "https://gist.githubusercontent.com/#{gist_id}/raw"
66
77
  url = "#{url}/#{filename}" unless filename.empty?
67
- begin
68
- uri = URI(url)
69
- Net::HTTP.start(uri.host, uri.port,
70
- use_ssl: uri.scheme == 'https',
71
- read_timeout: 3, open_timeout: 3) do |http|
72
- request = Net::HTTP::Get.new uri.to_s
73
- response = http.request(request)
74
- response.body
75
- end
76
- rescue SocketError, Net::HTTPError, Net::OpenTimeout, Net::ReadTimeout, TimeoutError
77
- nil
78
+ uri = URI(url)
79
+ Net::HTTP.start(uri.host, uri.port,
80
+ use_ssl: uri.scheme == 'https',
81
+ read_timeout: 3, open_timeout: 3) do |http|
82
+ request = Net::HTTP::Get.new uri.to_s
83
+ response = http.request(request)
84
+ response.body
85
+ end
86
+ rescue SocketError, Net::HTTPError, Net::OpenTimeout, Net::ReadTimeout, TimeoutError
87
+ nil
88
+ end
89
+
90
+ private
91
+
92
+ def code_from_api(gist_id, filename = nil)
93
+ gist = GistTag.client.gist gist_id
94
+
95
+ file = if filename.to_s.empty?
96
+ # No file specified, return the value of the first key/value pair
97
+ gist.files.first[1]
98
+ else
99
+ # .files is a hash of :"filename.extension" => data pairs
100
+ # Rather than using to_sym on arbitrary user input,
101
+ # Find our file by calling to_s on the keys
102
+ match = gist.files.find { |name, data| name.to_s == filename }
103
+ match[1] if match
78
104
  end
105
+
106
+ file[:content] if file
107
+ end
108
+
109
+ def self.client
110
+ @client ||= Octokit::Client.new :access_token => ENV["JEKYLL_GITHUB_TOKEN"]
79
111
  end
80
112
  end
81
113
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Gist
3
- VERSION = "1.3.5"
3
+ VERSION = "1.4.0"
4
4
  end
5
5
  end
@@ -0,0 +1,111 @@
1
+ {
2
+ "url": "https://api.github.com/gists/aa5a315d61ae9438b18d",
3
+ "forks_url": "https://api.github.com/gists/aa5a315d61ae9438b18d/forks",
4
+ "commits_url": "https://api.github.com/gists/aa5a315d61ae9438b18d/commits",
5
+ "id": "aa5a315d61ae9438b18d",
6
+ "description": "description of gist",
7
+ "public": true,
8
+ "owner": {
9
+ "login": "octocat",
10
+ "id": 1,
11
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
12
+ "gravatar_id": "",
13
+ "url": "https://api.github.com/users/octocat",
14
+ "html_url": "https://github.com/octocat",
15
+ "followers_url": "https://api.github.com/users/octocat/followers",
16
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
17
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
18
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
19
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
20
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
21
+ "repos_url": "https://api.github.com/users/octocat/repos",
22
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
23
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
24
+ "type": "User",
25
+ "site_admin": false
26
+ },
27
+ "user": null,
28
+ "files": {
29
+ "ring.erl": {
30
+ "size": 932,
31
+ "raw_url": "https://gist.githubusercontent.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
32
+ "type": "text/plain",
33
+ "language": "Erlang",
34
+ "truncated": false,
35
+ "content": "contents of gist"
36
+ },
37
+ "hello-world.rb": {
38
+ "size": 932,
39
+ "raw_url": "https://gist.githubusercontent.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
40
+ "type": "text/plain",
41
+ "language": "Ruby",
42
+ "truncated": false,
43
+ "content": "puts 'hello world'"
44
+ }
45
+ },
46
+ "comments": 0,
47
+ "comments_url": "https://api.github.com/gists/aa5a315d61ae9438b18d/comments/",
48
+ "html_url": "https://gist.github.com/aa5a315d61ae9438b18d",
49
+ "git_pull_url": "https://gist.github.com/aa5a315d61ae9438b18d.git",
50
+ "git_push_url": "https://gist.github.com/aa5a315d61ae9438b18d.git",
51
+ "created_at": "2010-04-14T02:15:15Z",
52
+ "updated_at": "2011-06-20T11:34:15Z",
53
+ "forks": [
54
+ {
55
+ "user": {
56
+ "login": "octocat",
57
+ "id": 1,
58
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
59
+ "gravatar_id": "",
60
+ "url": "https://api.github.com/users/octocat",
61
+ "html_url": "https://github.com/octocat",
62
+ "followers_url": "https://api.github.com/users/octocat/followers",
63
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
64
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
65
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
66
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
67
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
68
+ "repos_url": "https://api.github.com/users/octocat/repos",
69
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
70
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
71
+ "type": "User",
72
+ "site_admin": false
73
+ },
74
+ "url": "https://api.github.com/gists/dee9c42e4998ce2ea439",
75
+ "id": "dee9c42e4998ce2ea439",
76
+ "created_at": "2011-04-14T16:00:49Z",
77
+ "updated_at": "2011-04-14T16:00:49Z"
78
+ }
79
+ ],
80
+ "history": [
81
+ {
82
+ "url": "https://api.github.com/gists/aa5a315d61ae9438b18d/57a7f021a713b1c5a6a199b54cc514735d2d462f",
83
+ "version": "57a7f021a713b1c5a6a199b54cc514735d2d462f",
84
+ "user": {
85
+ "login": "octocat",
86
+ "id": 1,
87
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
88
+ "gravatar_id": "",
89
+ "url": "https://api.github.com/users/octocat",
90
+ "html_url": "https://github.com/octocat",
91
+ "followers_url": "https://api.github.com/users/octocat/followers",
92
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
93
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
94
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
95
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
96
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
97
+ "repos_url": "https://api.github.com/users/octocat/repos",
98
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
99
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
100
+ "type": "User",
101
+ "site_admin": false
102
+ },
103
+ "change_status": {
104
+ "deletions": 0,
105
+ "additions": 180,
106
+ "total": 180
107
+ },
108
+ "committed_at": "2010-04-14T02:15:15Z"
109
+ }
110
+ ]
111
+ }
@@ -0,0 +1,103 @@
1
+ {
2
+ "url": "https://api.github.com/gists/aa5a315d61ae9438b18d",
3
+ "forks_url": "https://api.github.com/gists/aa5a315d61ae9438b18d/forks",
4
+ "commits_url": "https://api.github.com/gists/aa5a315d61ae9438b18d/commits",
5
+ "id": "aa5a315d61ae9438b18d",
6
+ "description": "description of gist",
7
+ "public": true,
8
+ "owner": {
9
+ "login": "octocat",
10
+ "id": 1,
11
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
12
+ "gravatar_id": "",
13
+ "url": "https://api.github.com/users/octocat",
14
+ "html_url": "https://github.com/octocat",
15
+ "followers_url": "https://api.github.com/users/octocat/followers",
16
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
17
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
18
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
19
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
20
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
21
+ "repos_url": "https://api.github.com/users/octocat/repos",
22
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
23
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
24
+ "type": "User",
25
+ "site_admin": false
26
+ },
27
+ "user": null,
28
+ "files": {
29
+ "ring.erl": {
30
+ "size": 932,
31
+ "raw_url": "https://gist.githubusercontent.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl",
32
+ "type": "text/plain",
33
+ "language": "Erlang",
34
+ "truncated": false,
35
+ "content": "contents of gist"
36
+ }
37
+ },
38
+ "comments": 0,
39
+ "comments_url": "https://api.github.com/gists/aa5a315d61ae9438b18d/comments/",
40
+ "html_url": "https://gist.github.com/aa5a315d61ae9438b18d",
41
+ "git_pull_url": "https://gist.github.com/aa5a315d61ae9438b18d.git",
42
+ "git_push_url": "https://gist.github.com/aa5a315d61ae9438b18d.git",
43
+ "created_at": "2010-04-14T02:15:15Z",
44
+ "updated_at": "2011-06-20T11:34:15Z",
45
+ "forks": [
46
+ {
47
+ "user": {
48
+ "login": "octocat",
49
+ "id": 1,
50
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
51
+ "gravatar_id": "",
52
+ "url": "https://api.github.com/users/octocat",
53
+ "html_url": "https://github.com/octocat",
54
+ "followers_url": "https://api.github.com/users/octocat/followers",
55
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
56
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
57
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
58
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
59
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
60
+ "repos_url": "https://api.github.com/users/octocat/repos",
61
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
62
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
63
+ "type": "User",
64
+ "site_admin": false
65
+ },
66
+ "url": "https://api.github.com/gists/dee9c42e4998ce2ea439",
67
+ "id": "dee9c42e4998ce2ea439",
68
+ "created_at": "2011-04-14T16:00:49Z",
69
+ "updated_at": "2011-04-14T16:00:49Z"
70
+ }
71
+ ],
72
+ "history": [
73
+ {
74
+ "url": "https://api.github.com/gists/aa5a315d61ae9438b18d/57a7f021a713b1c5a6a199b54cc514735d2d462f",
75
+ "version": "57a7f021a713b1c5a6a199b54cc514735d2d462f",
76
+ "user": {
77
+ "login": "octocat",
78
+ "id": 1,
79
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
80
+ "gravatar_id": "",
81
+ "url": "https://api.github.com/users/octocat",
82
+ "html_url": "https://github.com/octocat",
83
+ "followers_url": "https://api.github.com/users/octocat/followers",
84
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
85
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
86
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
87
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
88
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
89
+ "repos_url": "https://api.github.com/users/octocat/repos",
90
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
91
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
92
+ "type": "User",
93
+ "site_admin": false
94
+ },
95
+ "change_status": {
96
+ "deletions": 0,
97
+ "additions": 180,
98
+ "total": 180
99
+ },
100
+ "committed_at": "2010-04-14T02:15:15Z"
101
+ }
102
+ ]
103
+ }
@@ -9,6 +9,7 @@ describe(Jekyll::Gist::GistTag) do
9
9
  doc.output = Jekyll::Renderer.new(doc.site, doc).run
10
10
  end
11
11
 
12
+ before(:each) { ENV["JEKYLL_GITHUB_TOKEN"] = nil }
12
13
 
13
14
  context "valid gist" do
14
15
  context "with user prefix" do
@@ -18,7 +19,7 @@ describe(Jekyll::Gist::GistTag) do
18
19
  it "produces the correct script tag" do
19
20
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
20
21
  end
21
- it "produces the correct noscript tag" do
22
+ it "produces the correct noscript tag" do
22
23
  expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
23
24
  end
24
25
  end
@@ -30,7 +31,7 @@ describe(Jekyll::Gist::GistTag) do
30
31
  it "produces the correct script tag" do
31
32
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
32
33
  end
33
- it "produces the correct noscript tag" do
34
+ it "produces the correct noscript tag" do
34
35
  expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
35
36
  end
36
37
  end
@@ -42,7 +43,7 @@ describe(Jekyll::Gist::GistTag) do
42
43
  it "produces the correct script tag" do
43
44
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
44
45
  end
45
- it "produces the correct noscript tag" do
46
+ it "produces the correct noscript tag" do
46
47
  expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
47
48
  end
48
49
  end
@@ -56,7 +57,7 @@ describe(Jekyll::Gist::GistTag) do
56
57
  it "produces the correct script tag" do
57
58
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>/)
58
59
  end
59
- it "produces the correct noscript tag" do
60
+ it "produces the correct noscript tag" do
60
61
  expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
61
62
  end
62
63
  end
@@ -74,7 +75,7 @@ describe(Jekyll::Gist::GistTag) do
74
75
  it "produces the correct script tag" do
75
76
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js">\s<\/script>/)
76
77
  end
77
- it "produces the correct noscript tag" do
78
+ it "produces the correct noscript tag" do
78
79
  expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
79
80
  end
80
81
  end
@@ -97,12 +98,12 @@ describe(Jekyll::Gist::GistTag) do
97
98
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js\?file=#{doc.data['gist_filename']}">\s<\/script>/)
98
99
  end
99
100
 
100
- it "produces the correct noscript tag" do
101
+ it "produces the correct noscript tag" do
101
102
  expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
102
103
  end
103
104
  end
104
105
 
105
- context "with valid gist id and invalid filename" do
106
+ context "with valid gist id and invalid filename" do
106
107
  before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(status: 404) }
107
108
  let(:gist_id) { "mattr-/24081a1d93d2898ecf0f" }
108
109
  let(:gist_filename) { "myfile.ext" }
@@ -112,14 +113,57 @@ describe(Jekyll::Gist::GistTag) do
112
113
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist_id}.js\?file=#{gist_filename}">\s<\/script>/)
113
114
  end
114
115
 
115
- it "does not produce the noscript tag" do
116
+ it "does not produce the noscript tag" do
116
117
  expect(output).to_not match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
117
118
  end
118
119
 
119
120
  end
120
121
 
121
- end
122
+ context "with token" do
123
+ before { ENV["JEKYLL_GITHUB_TOKEN"] = "1234" }
124
+ before {
125
+ stub_request(:get, "https://api.github.com/gists/1342013").
126
+ to_return(:status => 200, :body => fixture("single-file"), :headers => {"Content-Type" => "application/json"})
127
+ }
128
+ let(:gist_id) { "1342013" }
129
+ let(:gist) { "page.gist_id" }
130
+ let(:output) do
131
+ doc.data['gist_id'] = gist_id
132
+ doc.content = content
133
+ doc.output = Jekyll::Renderer.new(doc.site, doc).run
134
+ end
135
+
136
+ it "produces the noscript tag" do
137
+ expect(output).to match(/<noscript><pre>contents of gist<\/pre><\/noscript>/)
138
+ end
139
+
140
+ context "with a filename" do
141
+ before {
142
+ stub_request(:get, "https://api.github.com/gists/1342013").
143
+ to_return(:status => 200, :body => fixture("multiple-files"), :headers => {"Content-Type" => "application/json"})
144
+ }
145
+ let(:content) { "{% gist 1342013 hello-world.rb %}" }
146
+
147
+ it "produces the noscript tag" do
148
+ expect(output).to match(/<noscript><pre>puts &#39;hello world&#39;<\/pre><\/noscript>/)
149
+ end
150
+ end
151
+ end
152
+
153
+ context "with noscript disabled" do
154
+ let(:doc) { doc_with_content(content, { "gist" => { "noscript" => false } }) }
155
+ let(:output) do
156
+ doc.content = content
157
+ doc.output = Jekyll::Renderer.new(doc.site, doc).run
158
+ end
159
+ let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
160
+
161
+ it "does not produce the noscript tag" do
162
+ expect(output).to_not match(/<noscript>/)
163
+ end
164
+ end
122
165
 
166
+ end
123
167
 
124
168
  context "invalid gist" do
125
169
 
@@ -7,7 +7,6 @@ require 'jekyll'
7
7
  require File.expand_path("../lib/jekyll-gist.rb", TEST_DIR)
8
8
 
9
9
  Jekyll.logger.log_level = :error
10
- STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:')
11
10
 
12
11
  RSpec.configure do |config|
13
12
  config.run_all_when_everything_filtered = true
@@ -27,7 +26,7 @@ RSpec.configure do |config|
27
26
  end
28
27
 
29
28
  def doc_with_content(content, opts = {})
30
- my_site = site
29
+ my_site = site(opts)
31
30
  Jekyll::Document.new(source_dir('_test/doc.md'), {site: my_site, collection: collection(my_site)})
32
31
  end
33
32
 
@@ -42,4 +41,9 @@ RSpec.configure do |config|
42
41
  }))
43
42
  Jekyll::Site.new(conf)
44
43
  end
44
+
45
+ def fixture(name)
46
+ path = File.expand_path "./fixtures/#{name}.json", File.dirname(__FILE__)
47
+ File.open(path).read
48
+ end
45
49
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-gist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-24 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +115,8 @@ files:
101
115
  - lib/jekyll-gist/version.rb
102
116
  - script/bootstrap
103
117
  - script/cibuild
118
+ - spec/fixtures/multiple-files.json
119
+ - spec/fixtures/single-file.json
104
120
  - spec/gist_tag_spec.rb
105
121
  - spec/spec_helper.rb
106
122
  homepage: https://github.com/jekyll/jekyll-gist
@@ -123,10 +139,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
139
  version: '0'
124
140
  requirements: []
125
141
  rubyforge_project:
126
- rubygems_version: 2.2.3
142
+ rubygems_version: 2.2.5
127
143
  signing_key:
128
144
  specification_version: 4
129
145
  summary: Liquid tag for displaying GitHub Gists in Jekyll sites.
130
146
  test_files:
147
+ - spec/fixtures/multiple-files.json
148
+ - spec/fixtures/single-file.json
131
149
  - spec/gist_tag_spec.rb
132
150
  - spec/spec_helper.rb