From b3942b518fff878ff1bd3ce8412176529d6d0cdc Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sat, 23 Mar 2019 09:29:21 +0530 Subject: [PATCH 01/10] Revert release of v1.6.0 --- 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 b2ee842..a0615f1 100644 --- a/History.markdown +++ b/History.markdown @@ -1,4 +1,4 @@ -## 1.6.0 / 2019-03-22 +## HEAD ### Development Fixes diff --git a/lib/jekyll-gist/version.rb b/lib/jekyll-gist/version.rb index ca4dd69..2bef474 100644 --- a/lib/jekyll-gist/version.rb +++ b/lib/jekyll-gist/version.rb @@ -2,6 +2,6 @@ module Jekyll module Gist - VERSION = "1.6.0" + VERSION = "1.5.0" end end From 1607c3a5fd17590b40ebe7768421235ee9a2197a Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sat, 23 Mar 2019 13:20:51 +0530 Subject: [PATCH 02/10] Re-introduce Ruby 2.3 support and test Jekyll 3.7+ (#72) Merge pull request 72 --- .rubocop.yml | 2 +- .travis.yml | 11 +++++++---- Gemfile | 6 +----- jekyll-gist.gemspec | 12 ++++++------ lib/jekyll-gist/gist_tag.rb | 6 ++++-- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index dc42b75..62ba652 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ inherit_gem: rubocop-jekyll: .rubocop.yml AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.3 Exclude: - vendor/**/* - spec/*.rb diff --git a/.travis.yml b/.travis.yml index b4f6166..1886167 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: ruby cache: bundler rvm: - - 2.6 + - &latest_ruby 2.6 - 2.4 + - 2.3 script : script/cibuild @@ -10,13 +11,15 @@ branches: only: - master env: - - JEKYLL_VERSION=3.7.4 - + matrix: + - JEKYLL_VERSION="~> 3.8" matrix: include: - # GitHub Pages rvm: 2.5.3 - env: GH_PAGES=true + env: JEKYLL_VERSION="~> 3.7.4" + - rvm: *latest_ruby + env: JEKYLL_VERSION=">= 4.0.0.pre.alpha1" notifications: email: false diff --git a/Gemfile b/Gemfile index c24711a..46cdbf0 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,4 @@ source "https://rubygems.org" gemspec -if ENV["GH_PAGES"] - gem "github-pages" -elsif ENV["JEKYLL_VERSION"] - gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}" -end +gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"] diff --git a/jekyll-gist.gemspec b/jekyll-gist.gemspec index 81f8e22..6e1f928 100644 --- a/jekyll-gist.gemspec +++ b/jekyll-gist.gemspec @@ -14,16 +14,16 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/jekyll/jekyll-gist" spec.license = "MIT" - spec.required_ruby_version = ">= 2.4.0" - 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.test_files = spec.files.grep(%r!^spec/!) spec.require_paths = ["lib"] - spec.add_dependency "octokit", "~> 4.2" + spec.required_ruby_version = ">= 2.3.0" + + spec.add_runtime_dependency "jekyll", ">= 3.7", "< 5.0" + spec.add_runtime_dependency "octokit", "~> 4.2" + spec.add_development_dependency "bundler" - spec.add_development_dependency "jekyll", ">= 3.7", "< 5.0" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" spec.add_development_dependency "rubocop-jekyll", "~> 0.4" diff --git a/lib/jekyll-gist/gist_tag.rb b/lib/jekyll-gist/gist_tag.rb index 2633692..b8742e8 100644 --- a/lib/jekyll-gist/gist_tag.rb +++ b/lib/jekyll-gist/gist_tag.rb @@ -24,8 +24,10 @@ def render(context) else raise ArgumentError, <<~ERROR Syntax error in tag 'gist' while parsing the following markup: - #{@markup} - Valid syntax: + + #{@markup} + + Valid syntax: {% gist user/1234567 %} {% gist user/1234567 foo.js %} {% gist 28949e1d5ee2273f9fd3 %} From a2fc4e48cb79c9752b6ee30174bcb4a0bb8fe4ac Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Sat, 23 Mar 2019 03:50:52 -0400 Subject: [PATCH 03/10] Update history to reflect merge of #72 [ci skip] --- History.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/History.markdown b/History.markdown index a0615f1..6976f85 100644 --- a/History.markdown +++ b/History.markdown @@ -10,6 +10,10 @@ * chore(deps): drop support for Liquid < 4.0 (#66) +### Bug Fixes + + * Re-introduce Ruby 2.3 support and test Jekyll 3.7+ (#72) + ## 1.5.0 / 2017-12-03 ### Documentation From 01941ee65def03c796ae4c44a77d99b1af1fb42c Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Tue, 16 Jul 2019 21:17:26 +0530 Subject: [PATCH 04/10] Use Liquid::Tag#raw to clarify error message (#73) Merge pull request 73 --- lib/jekyll-gist/gist_tag.rb | 2 +- spec/gist_tag_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll-gist/gist_tag.rb b/lib/jekyll-gist/gist_tag.rb index b8742e8..2bd2273 100644 --- a/lib/jekyll-gist/gist_tag.rb +++ b/lib/jekyll-gist/gist_tag.rb @@ -25,7 +25,7 @@ def render(context) raise ArgumentError, <<~ERROR Syntax error in tag 'gist' while parsing the following markup: - #{@markup} + '{% #{raw.strip} %}' Valid syntax: {% gist user/1234567 %} diff --git a/spec/gist_tag_spec.rb b/spec/gist_tag_spec.rb index f04618c..b889220 100644 --- a/spec/gist_tag_spec.rb +++ b/spec/gist_tag_spec.rb @@ -168,7 +168,7 @@ let(:gist) { "" } it "raises an error" do - expect(-> { output }).to raise_error + expect(-> { output }).to raise_error(ArgumentError) end end end From ab3e64b649f5701c3e62f352bef88baeaeb1de94 Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Tue, 16 Jul 2019 11:47:28 -0400 Subject: [PATCH 05/10] Update history to reflect merge of #73 [ci skip] --- History.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/History.markdown b/History.markdown index 6976f85..dc534c9 100644 --- a/History.markdown +++ b/History.markdown @@ -13,6 +13,7 @@ ### Bug Fixes * Re-introduce Ruby 2.3 support and test Jekyll 3.7+ (#72) + * Use Liquid::Tag#raw to clarify error message (#73) ## 1.5.0 / 2017-12-03 From bc23c25e0d611e68ab5dee8fdc6cba190ba7d333 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Tue, 16 Jul 2019 21:22:46 +0530 Subject: [PATCH 06/10] Refactor GistTag (#65) Merge pull request 65 --- .rubocop_todo.yml | 13 ------------ lib/jekyll-gist/gist_tag.rb | 41 +++++++++++++++---------------------- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ccdfa8a..71efb07 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,11 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -Lint/IneffectiveAccessModifier: - Exclude: - - 'lib/jekyll-gist/gist_tag.rb' - # Offense count: 1 Lint/ShadowedException: Exclude: @@ -21,11 +16,3 @@ Lint/ShadowedException: Metrics/AbcSize: Exclude: - 'lib/jekyll-gist/gist_tag.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: short, verbose -Style/PreferredHashMethods: - Exclude: - - 'lib/jekyll-gist/gist_tag.rb' diff --git a/lib/jekyll-gist/gist_tag.rb b/lib/jekyll-gist/gist_tag.rb index 2bd2273..ae8ae34 100644 --- a/lib/jekyll-gist/gist_tag.rb +++ b/lib/jekyll-gist/gist_tag.rb @@ -10,16 +10,22 @@ module Jekyll module Gist class GistTag < Liquid::Tag + def self.client + @client ||= Octokit::Client.new :access_token => ENV["JEKYLL_GITHUB_TOKEN"] + end + def render(context) @encoding = context.registers[:site].config["encoding"] || "utf-8" @settings = context.registers[:site].config["gist"] if (tag_contents = determine_arguments(@markup.strip)) - gist_id = tag_contents[0] + gist_id = tag_contents[0] filename = tag_contents[1] - gist_id = context[gist_id] if context_contains_key?(context, gist_id) - filename = context[filename] if context_contains_key?(context, filename) + gist_id = context[gist_id] if context.key?(gist_id) + filename = context[filename] if context.key?(filename) + noscript_tag = gist_noscript_tag(gist_id, filename) - script_tag = gist_script_tag(gist_id, filename) + script_tag = gist_script_tag(gist_id, filename) + "#{noscript_tag}#{script_tag}" else raise ArgumentError, <<~ERROR @@ -44,17 +50,10 @@ def determine_arguments(input) [matched[1].strip, matched[2].strip] if matched && matched.length >= 3 end - 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? + "" 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