From 4994c3fdc6d0422442bc315dfa42d0486cd1fa79 Mon Sep 17 00:00:00 2001 From: Antonio Argote Date: Mon, 14 Aug 2017 22:05:01 +0800 Subject: [PATCH 01/57] 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 02/57] 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 03/57] 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