From a1e78b8e1a8fd16f70c5c44c9d1bbc56a84f25e7 Mon Sep 17 00:00:00 2001 From: Suriyaa Kudo Date: Mon, 8 Feb 2016 08:38:15 +0100 Subject: [PATCH 01/68] Remove a empty line in Rakefile --- Rakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Rakefile b/Rakefile index 809eb56..2995527 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1 @@ require "bundler/gem_tasks" - From 4bce49740a4d286f0e2d1e2b3df9134fc47e5260 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 19 Dec 2016 10:47:51 -0800 Subject: [PATCH 02/68] Don't ask .empty? until it's a String. --- lib/jekyll-gist/gist_tag.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll-gist/gist_tag.rb b/lib/jekyll-gist/gist_tag.rb index 83a1595..acb5f04 100644 --- a/lib/jekyll-gist/gist_tag.rb +++ b/lib/jekyll-gist/gist_tag.rb @@ -47,7 +47,7 @@ def determine_arguments(input) def gist_script_tag(gist_id, filename = nil) url = "https://gist.github.com/#{gist_id}.js" - url = "#{url}?file=#{filename}" unless filename.empty? + url = "#{url}?file=#{filename}" unless filename.to_s.empty? "" end @@ -74,7 +74,7 @@ def fetch_raw_code(gist_id, filename = nil) return code_from_api(gist_id, filename) if ENV["JEKYLL_GITHUB_TOKEN"] url = "https://gist.githubusercontent.com/#{gist_id}/raw" - url = "#{url}/#{filename}" unless filename.empty? + url = "#{url}/#{filename}" unless filename.to_s.empty? uri = URI(url) Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', From 8f2a3e2c02484f7713e40a6db48d0302cb193d3b Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Mon, 19 Dec 2016 12:15:37 -0800 Subject: [PATCH 03/68] Update history to reflect merge of #38 [ci skip] --- History.markdown | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/History.markdown b/History.markdown index 7405d33..72369f3 100644 --- a/History.markdown +++ b/History.markdown @@ -1,3 +1,7 @@ +## HEAD + + * Don't ask .empty? until it's a String. (#38) + ## 1.4.0 / 2015-12-01 * Allow `noscript` fallback to be disabled (#29) @@ -21,7 +25,7 @@ * Re-add support for Ruby 1.9.3. Fixes #11 for 1.9.3 (#14) * Replaced `OpenURI` with `Net::HTTP` and introduced timeout of 3 seconds (#11) -## 1.3.1 / 2015-08-16 (yanked) +## 1.3.1 / 2015-08-16 * Replaced `OpenURI` with `Net::HTTP` and introduced timeout of 3 seconds (#11) From 18efb2aadc59e4768539814d28fe3dbb4e75d6d2 Mon Sep 17 00:00:00 2001 From: Marcelo Canina Date: Wed, 21 Jun 2017 11:49:13 -0300 Subject: [PATCH 04/68] rename Liquid 4 has_key to key to add compatibility for liquid 4 (#41) Merge pull request 41 --- lib/jekyll-gist/gist_tag.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/jekyll-gist/gist_tag.rb b/lib/jekyll-gist/gist_tag.rb index acb5f04..0895c15 100644 --- a/lib/jekyll-gist/gist_tag.rb +++ b/lib/jekyll-gist/gist_tag.rb @@ -14,10 +14,10 @@ def render(context) @settings = context.registers[:site].config['gist'] if tag_contents = determine_arguments(@markup.strip) gist_id, filename = tag_contents[0], tag_contents[1] - if context.has_key?(gist_id) + if context_contains_key?(context, gist_id) gist_id = context[gist_id] end - if context.has_key?(filename) + if context_contains_key?(context, filename) filename = context[filename] end noscript_tag = gist_noscript_tag(gist_id, filename) @@ -45,6 +45,16 @@ def determine_arguments(input) [matched[1].strip, matched[2].strip] if matched && matched.length >= 3 end + private + + def context_contains_key?(context, key) + if context.respond_to?(:has_key?) + context.has_key?(key) + else + context.key?(key) + end + end + def gist_script_tag(gist_id, filename = nil) url = "https://gist.github.com/#{gist_id}.js" url = "#{url}?file=#{filename}" unless filename.to_s.empty? From 30681067eda391ad0136d90f2a53e73ef6a1da43 Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Wed, 21 Jun 2017 10:49:15 -0400 Subject: [PATCH 05/68] Update history to reflect merge of #41 [ci skip] --- History.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/History.markdown b/History.markdown index 72369f3..96d844f 100644 --- a/History.markdown +++ b/History.markdown @@ -1,6 +1,7 @@ ## HEAD * Don't ask .empty? until it's a String. (#38) + * rename Liquid 4 has_key to key to add compatibility for liquid 4 (#41) ## 1.4.0 / 2015-12-01 From cd9b84a93ac9739d9f0d3863d5a0a15beebba3f8 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 21 Jun 2017 10:49:59 -0400 Subject: [PATCH 06/68] Slight update to #41's history item. --- History.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/History.markdown b/History.markdown index 96d844f..e2965cc 100644 --- a/History.markdown +++ b/History.markdown @@ -1,7 +1,7 @@ ## HEAD * Don't ask .empty? until it's a String. (#38) - * rename Liquid 4 has_key to key to add compatibility for liquid 4 (#41) + * rename Liquid 4 `has_key?` to `key?` to add compatibility for liquid 4 (#41) ## 1.4.0 / 2015-12-01 From 7915005debad3a669d54a79a8f890d6b11290fad Mon Sep 17 00:00:00 2001 From: Frank Taillandier Date: Wed, 21 Jun 2017 16:51:12 +0200 Subject: [PATCH 07/68] Test against Ruby 2.1 to 2.4 (#45) Merge pull request 45 --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5aed6ab..324b0c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,10 @@ branches: - master rvm: + - 2.4 + - 2.3 - 2.2 - 2.1 - - 2.0 env: - "" - JEKYLL_VERSION=3.0.0.beta8 @@ -18,7 +19,7 @@ env: matrix: include: - # GitHub Pages - rvm: 2.1.1 + rvm: 2.4.0 env: GH_PAGES=true - # Ruby 1.9 rvm: 1.9 From c299987ea8b0e27206f643c39ad00672a516e8a8 Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Wed, 21 Jun 2017 10:51:13 -0400 Subject: [PATCH 08/68] Update history to reflect merge of #45 [ci skip] --- History.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/History.markdown b/History.markdown index e2965cc..0a2bf38 100644 --- a/History.markdown +++ b/History.markdown @@ -2,6 +2,7 @@ * Don't ask .empty? until it's a String. (#38) * rename Liquid 4 `has_key?` to `key?` to add compatibility for liquid 4 (#41) + * Test against Ruby 2.1 to 2.4 (#45) ## 1.4.0 / 2015-12-01 From d804000bea23d2f28b08f93a460fcf708693b866 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 21 Jun 2017 10:51:50 -0400 Subject: [PATCH 09/68] Test against Jekyll mainline & jekyll 3.4 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 324b0c1..d54444f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,7 @@ rvm: - 2.1 env: - "" - - JEKYLL_VERSION=3.0.0.beta8 - - JEKYLL_VERSION=2.0 + - JEKYLL_VERSION=3.4.4 matrix: include: - # GitHub Pages From 2b4303acfe63eb49b66486af1da150cfa4e3def3 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 21 Jun 2017 10:54:46 -0400 Subject: [PATCH 10/68] Remove Ruby 1.9 from test matrix. For real? --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d54444f..728a700 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,3 @@ matrix: - # GitHub Pages rvm: 2.4.0 env: GH_PAGES=true - - # Ruby 1.9 - rvm: 1.9 - env: JEKYLL_VERSION=2.0 From 82f2a5de0148adc802075840e7d0ce5d99fc457c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 21 Jun 2017 11:01:32 -0400 Subject: [PATCH 11/68] Release :gem: v1.4.1 --- History.markdown | 2 +- lib/jekyll-gist/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/History.markdown b/History.markdown index 0a2bf38..b4cc69d 100644 --- a/History.markdown +++ b/History.markdown @@ -1,4 +1,4 @@ -## HEAD +## 1.4.1 / 2017-06-21 * Don't ask .empty? until it's a String. (#38) * rename Liquid 4 `has_key?` to `key?` to add compatibility for liquid 4 (#41) diff --git a/lib/jekyll-gist/version.rb b/lib/jekyll-gist/version.rb index 15e04c4..d91d41a 100644 --- a/lib/jekyll-gist/version.rb +++ b/lib/jekyll-gist/version.rb @@ -1,5 +1,5 @@ module Jekyll module Gist - VERSION = "1.4.0" + VERSION = "1.4.1" end end From 4994c3fdc6d0422442bc315dfa42d0486cd1fa79 Mon Sep 17 00:00:00 2001 From: Antonio Argote Date: Mon, 14 Aug 2017 22:05:01 +0800 Subject: [PATCH 12/68] replace 'plugins' key in config with 'gems' (#46) Merge pull request 46 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cd39080..5cd2b4f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Or install it yourself as: Finally, add the following to your site's `_config.yml`: ``` -gems: +plugins: - jekyll-gist ``` From 6ab6a20c293e02f0f5cc51a2ba8ed3f933d88c9a Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Mon, 14 Aug 2017 10:05:02 -0400 Subject: [PATCH 13/68] Update history to reflect merge of #46 [ci skip] --- History.markdown | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/History.markdown b/History.markdown index b4cc69d..b7a808d 100644 --- a/History.markdown +++ b/History.markdown @@ -1,3 +1,9 @@ +## HEAD + +### Documentation + + * replace 'plugins' key in config with 'gems' (#46) + ## 1.4.1 / 2017-06-21 * Don't ask .empty? until it's a String. (#38) From 50967942bb50b962494c8424a12ec2618940cf03 Mon Sep 17 00:00:00 2001 From: Frank Taillandier Date: Sat, 21 Oct 2017 20:29:45 +0200 Subject: [PATCH 14/68] Inherit Jekyll's rubocop config for consistency (#48) Merge pull request 48 --- .rubocop.yml | 7 +++ Gemfile | 2 +- jekyll-gist.gemspec | 13 +++--- lib/jekyll-gist/gist_tag.rb | 42 ++++++++--------- lib/jekyll-gist/version.rb | 2 +- spec/gist_tag_spec.rb | 89 +++++++++++++++++-------------------- spec/spec_helper.rb | 24 +++++----- 7 files changed, 91 insertions(+), 88 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..5191c5e --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,7 @@ +inherit_gem: + jekyll: .rubocop.yml + +Metrics/LineLength: + Exclude: + - spec/**/* + - jekyll-gist.gemspec diff --git a/Gemfile b/Gemfile index 4296d7f..6f998d7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec if ENV["GH_PAGES"] diff --git a/jekyll-gist.gemspec b/jekyll-gist.gemspec index 8b62a2a..b87f144 100644 --- a/jekyll-gist.gemspec +++ b/jekyll-gist.gemspec @@ -1,22 +1,23 @@ # coding: utf-8 -lib = File.expand_path('../lib', __FILE__) + +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'jekyll-gist/version' +require "jekyll-gist/version" Gem::Specification.new do |spec| spec.name = "jekyll-gist" spec.version = Jekyll::Gist::VERSION spec.authors = ["Parker Moore"] spec.email = ["parkrmoore@gmail.com"] - spec.summary = %q{Liquid tag for displaying GitHub Gists in Jekyll sites.} + spec.summary = "Liquid tag for displaying GitHub Gists in Jekyll sites." spec.homepage = "https://github.com/jekyll/jekyll-gist" spec.license = "MIT" - spec.required_ruby_version = '>= 1.9.3' + spec.required_ruby_version = ">= 1.9.3" spec.files = `git ls-files -z`.split("\x0") - spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.executables = spec.files.grep(%r!^bin/!) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r!^(test|spec|features)/!) spec.require_paths = ["lib"] spec.add_dependency "octokit", "~> 4.2" diff --git a/lib/jekyll-gist/gist_tag.rb b/lib/jekyll-gist/gist_tag.rb index 0895c15..250fc70 100644 --- a/lib/jekyll-gist/gist_tag.rb +++ b/lib/jekyll-gist/gist_tag.rb @@ -1,6 +1,6 @@ -require 'cgi' -require 'net/http' -require 'octokit' +require "cgi" +require "net/http" +require "octokit" Net::OpenTimeout = Class.new(RuntimeError) unless Net.const_defined?(:OpenTimeout) Net::ReadTimeout = Class.new(RuntimeError) unless Net.const_defined?(:ReadTimeout) @@ -8,12 +8,12 @@ module Jekyll module Gist class GistTag < Liquid::Tag - def render(context) - @encoding = context.registers[:site].config['encoding'] || 'utf-8' - @settings = context.registers[:site].config['gist'] + @encoding = context.registers[:site].config["encoding"] || "utf-8" + @settings = context.registers[:site].config["gist"] if tag_contents = determine_arguments(@markup.strip) - gist_id, filename = tag_contents[0], tag_contents[1] + gist_id = tag_contents[0] + filename = tag_contents[1] if context_contains_key?(context, gist_id) gist_id = context[gist_id] end @@ -24,7 +24,7 @@ def render(context) script_tag = gist_script_tag(gist_id, filename) "#{noscript_tag}#{script_tag}" else - raise ArgumentError.new <<-eos + raise ArgumentError, <<-eos Syntax error in tag 'gist' while parsing the following markup: #{@markup} @@ -41,7 +41,7 @@ def render(context) private def determine_arguments(input) - matched = input.match(/\A([\S]+|.*(?=\/).+)\s?(\S*)\Z/) + matched = input.match(%r!\A([\S]+|.*(?=\/).+)\s?(\S*)\Z!) [matched[1].strip, matched[2].strip] if matched && matched.length >= 3 end @@ -87,8 +87,8 @@ def fetch_raw_code(gist_id, filename = nil) url = "#{url}/#{filename}" unless filename.to_s.empty? uri = URI(url) Net::HTTP.start(uri.host, uri.port, - use_ssl: uri.scheme == 'https', - read_timeout: 3, open_timeout: 3) do |http| + :use_ssl => uri.scheme == "https", + :read_timeout => 3, :open_timeout => 3) do |http| request = Net::HTTP::Get.new uri.to_s response = http.request(request) response.body @@ -103,15 +103,15 @@ def code_from_api(gist_id, filename = nil) gist = GistTag.client.gist gist_id file = if filename.to_s.empty? - # No file specified, return the value of the first key/value pair - gist.files.first[1] - else - # .files is a hash of :"filename.extension" => data pairs - # Rather than using to_sym on arbitrary user input, - # Find our file by calling to_s on the keys - match = gist.files.find { |name, data| name.to_s == filename } - match[1] if match - end + # No file specified, return the value of the first key/value pair + gist.files.first[1] + else + # .files is a hash of :"filename.extension" => data pairs + # Rather than using to_sym on arbitrary user input, + # Find our file by calling to_s on the keys + match = gist.files.find { |name, _data| name.to_s == filename } + match[1] if match + end file[:content] if file end @@ -123,4 +123,4 @@ def self.client end end -Liquid::Template.register_tag('gist', Jekyll::Gist::GistTag) +Liquid::Template.register_tag("gist", Jekyll::Gist::GistTag) diff --git a/lib/jekyll-gist/version.rb b/lib/jekyll-gist/version.rb index d91d41a..fa69c1a 100644 --- a/lib/jekyll-gist/version.rb +++ b/lib/jekyll-gist/version.rb @@ -1,5 +1,5 @@ module Jekyll module Gist - VERSION = "1.4.1" + VERSION = "1.4.1".freeze end end diff --git a/spec/gist_tag_spec.rb b/spec/gist_tag_spec.rb index 15d8602..f04618c 100644 --- a/spec/gist_tag_spec.rb +++ b/spec/gist_tag_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" describe(Jekyll::Gist::GistTag) do let(:http_output) { "true" } let(:doc) { doc_with_content(content) } - let(:content) { "{% gist #{gist} %}" } + let(:content) { "{% gist #{gist} %}" } let(:output) do doc.content = content doc.output = Jekyll::Renderer.new(doc.site, doc).run @@ -13,139 +13,138 @@ context "valid gist" do context "with user prefix" do - before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(body: http_output) } + before { stub_request(:get, "https://gist.githubusercontent.com/#{gist}/raw").to_return(:body => http_output) } let(:gist) { "mattr-/24081a1d93d2898ecf0f" } it "produces the correct script tag" do - expect(output).to match(/" end @@ -62,18 +61,14 @@ def gist_noscript_tag(gist_id, filename = nil) return if @settings && @settings["noscript"] == false code = fetch_raw_code(gist_id, filename) - if !code.nil? + if code code = code.force_encoding(@encoding) - code = CGI.escapeHTML(code) - - # CGI.escapeHTML behavior differs in Ruby < 2.0 - # See https://github.com/jekyll/jekyll-gist/pull/28 - code = code.gsub("'", "'") if RUBY_VERSION < "2.0" + code = CGI.escapeHTML(code).gsub("'", "'") "" else - Jekyll.logger.warn "Warning:", "The