jekyll-gist 1.2.1 → 1.3.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: 242bfcd82535771e780626e0048175703253a275
4
- data.tar.gz: 18c154d812f86fce780416c6cc95f99f54dffee9
3
+ metadata.gz: a99d6197be7bf77cd1ce83e1df647719fe1e280c
4
+ data.tar.gz: 3efd76801e613587054fab6aea4733e8db3f68fd
5
5
  SHA512:
6
- metadata.gz: 99699f569f1419c98cb332f286f90a4b5453b30c07d6446bafaa26e5fe58c6c9bc1bac16c852e9d36bb7190935bc6a4794e5cab495533f6fdfd36202a4ec5075
7
- data.tar.gz: ec10b6433bd686c79ccba4f98f231449cfdcac9bc3c92b2a8686df793ad05e7adc12fc09045619896ef8d9fe9d1d63b2b78008a7bef31192c1b23d843e0c843d
6
+ metadata.gz: 54b90840b261aae9fd31927bd9d6731caf5485079d478950b8cece2c18667116edc7a959527d6e80086a303db17524f2ba73700b32d61a725e56a355aba29f41
7
+ data.tar.gz: fe8c68f496c3228083ef3d513e36b813831725493031abd325688df8103df7dcb3f0c0f26bdb027049eae0e86dc1c1ea7b2e16a278cc0d72746bfb3240b5aa27
data/History.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ ## HEAD
2
+
3
+ * Added an `noscript` fallback for browsers without JavaScript enabled. (#7)
4
+
1
5
  ## 1.2.1 / 2015-03-22
2
6
 
3
7
  * Use `has_key?` (#6)
data/jekyll-gist.gemspec CHANGED
@@ -20,5 +20,6 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency "bundler", "~> 1.6"
21
21
  spec.add_development_dependency "rake"
22
22
  spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "webmock"
23
24
  spec.add_development_dependency "jekyll", "~> 2.0"
24
25
  end
@@ -1,3 +1,6 @@
1
+ require 'cgi'
2
+ require 'open-uri'
3
+
1
4
  module Jekyll
2
5
  module Gist
3
6
  class GistTag < Liquid::Tag
@@ -11,7 +14,9 @@ module Jekyll
11
14
  if context.has_key?(filename)
12
15
  filename = context[filename]
13
16
  end
14
- gist_script_tag(gist_id, filename)
17
+ noscript_tag = gist_noscript_tag(gist_id, filename)
18
+ script_tag = gist_script_tag(gist_id, filename)
19
+ "#{noscript_tag}#{script_tag}"
15
20
  else
16
21
  raise ArgumentError.new <<-eos
17
22
  Syntax error in tag 'gist' while parsing the following markup:
@@ -35,13 +40,33 @@ module Jekyll
35
40
  end
36
41
 
37
42
  def gist_script_tag(gist_id, filename = nil)
38
- if filename.empty?
39
- "<script src=\"https://gist.github.com/#{gist_id}.js\"> </script>"
43
+ url = "https://gist.github.com/#{gist_id}.js"
44
+ url = "#{url}?file=#{filename}" unless filename.empty?
45
+ "<script src=\"#{url}\"> </script>"
46
+ end
47
+
48
+ def gist_noscript_tag(gist_id, filename = nil)
49
+ code = fetch_raw_code(gist_id, filename)
50
+ if !code.nil?
51
+ "<noscript><pre>#{CGI.escapeHTML(code)}</pre></noscript>"
40
52
  else
41
- "<script src=\"https://gist.github.com/#{gist_id}.js?file=#{filename}\"> </script>"
53
+ Jekyll.logger.warn "Warning:", "The <noscript> tag for your gist #{gist_id} could not"
54
+ Jekyll.logger.warn "", "be generated. This will affect users who do not have"
55
+ Jekyll.logger.warn "", "JavaScript available or enabled in their browsers."
42
56
  end
43
57
  end
44
58
 
59
+ def fetch_raw_code(gist_id, filename = nil)
60
+ begin
61
+ url = "https://gist.githubusercontent.com/#{gist_id}/raw"
62
+ url = "#{url}/#{filename}" unless filename.empty?
63
+ open(url).read.chomp
64
+ rescue SocketError
65
+ nil
66
+ rescue OpenURI::HTTPError
67
+ nil
68
+ end
69
+ end
45
70
  end
46
71
  end
47
72
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Gist
3
- VERSION = "1.2.1"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe(Jekyll::Gist::GistTag) do
4
+ let(:http_output) { "<test>true</test>" }
4
5
  let(:doc) { doc_with_content(content) }
5
6
  let(:content) { "{% gist #{gist} %}" }
6
7
  let(:output) do
@@ -11,30 +12,43 @@ describe(Jekyll::Gist::GistTag) do
11
12
 
12
13
  context "valid gist" do
13
14
  context "with user prefix" do
15
+ before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) }
14
16
  let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
15
17
 
16
18
  it "produces the correct script tag" do
17
19
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
18
20
  end
21
+ it "produces the correct noscript tag" do
22
+ expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
23
+ end
19
24
  end
20
25
 
21
26
  context "without user prefix" do
27
+ before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) }
22
28
  let(:gist) { "28949e1d5ee2273f9fd3" }
23
29
 
24
30
  it "produces the correct script tag" do
25
31
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
26
32
  end
33
+ it "produces the correct noscript tag" do
34
+ expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
35
+ end
27
36
  end
28
37
 
29
38
  context "classic Gist id style" do
39
+ before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) }
30
40
  let(:gist) { "1234321" }
31
41
 
32
42
  it "produces the correct script tag" do
33
43
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
34
44
  end
45
+ it "produces the correct noscript tag" do
46
+ expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
47
+ end
35
48
  end
36
49
 
37
50
  context "with file specified" do
51
+ before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw/#{filename}").to_return(body: http_output) }
38
52
  let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
39
53
  let(:filename) { "myfile.ext" }
40
54
  let(:content) { "{% gist #{gist} #{filename} %}" }
@@ -42,12 +56,17 @@ describe(Jekyll::Gist::GistTag) do
42
56
  it "produces the correct script tag" do
43
57
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>/)
44
58
  end
59
+ it "produces the correct noscript tag" do
60
+ expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
61
+ end
45
62
  end
46
63
 
47
64
  context "with variable gist id" do
65
+ before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw").to_return(body: http_output) }
66
+ let(:gist_id) { "1342013" }
48
67
  let(:gist) { "page.gist_id" }
49
68
  let(:output) do
50
- doc.data['gist_id'] = "1342013"
69
+ doc.data['gist_id'] = gist_id
51
70
  doc.content = content
52
71
  doc.output = Jekyll::Renderer.new(doc.site, doc).run
53
72
  end
@@ -55,12 +74,18 @@ describe(Jekyll::Gist::GistTag) do
55
74
  it "produces the correct script tag" do
56
75
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js">\s<\/script>/)
57
76
  end
77
+ it "produces the correct noscript tag" do
78
+ expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
79
+ end
58
80
  end
59
81
 
60
82
  context "with variable gist id and filename" do
61
- let(:gist) { "page.gist_id" }
62
- let(:filename) { "page.gist_filename" }
63
- let(:content) { "{% gist #{gist} #{filename} %}" }
83
+ before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(body: http_output) }
84
+ let(:gist_id) { "1342013" }
85
+ let(:gist_filename) { "atom.xml" }
86
+ let(:gist) { "page.gist_id" }
87
+ let(:filename) { "page.gist_filename" }
88
+ let(:content) { "{% gist #{gist} #{filename} %}" }
64
89
  let(:output) do
65
90
  doc.data['gist_id'] = "1342013"
66
91
  doc.data['gist_filename'] = "atom.xml"
@@ -71,7 +96,28 @@ describe(Jekyll::Gist::GistTag) do
71
96
  it "produces the correct script tag" do
72
97
  expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js\?file=#{doc.data['gist_filename']}">\s<\/script>/)
73
98
  end
99
+
100
+ it "produces the correct noscript tag" do
101
+ expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
102
+ end
74
103
  end
104
+
105
+ context "with valid gist id and invalid filename" do
106
+ before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(status: 404) }
107
+ let(:gist_id) { "mattr-/24081a1d93d2898ecf0f" }
108
+ let(:gist_filename) { "myfile.ext" }
109
+ let(:content) { "{% gist #{gist_id} #{gist_filename} %}" }
110
+
111
+ it "produces the correct script tag" do
112
+ expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist_id}.js\?file=#{gist_filename}">\s<\/script>/)
113
+ end
114
+
115
+ it "does not produce the noscript tag" do
116
+ expect(output).to_not match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
117
+ end
118
+
119
+ end
120
+
75
121
  end
76
122
 
77
123
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  TEST_DIR = File.dirname(__FILE__)
2
2
  TMP_DIR = File.expand_path("../tmp", TEST_DIR)
3
3
 
4
+ require 'webmock/rspec'
5
+ require 'cgi'
4
6
  require 'jekyll'
5
7
  require File.expand_path("../lib/jekyll-gist.rb", TEST_DIR)
6
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-gist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.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-03-22 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: jekyll
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
123
  version: '0'
110
124
  requirements: []
111
125
  rubyforge_project:
112
- rubygems_version: 2.2.2
126
+ rubygems_version: 2.2.3
113
127
  signing_key:
114
128
  specification_version: 4
115
129
  summary: Liquid tag for displaying GitHub Gists in Jekyll sites.