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/.rubocop_todo.yml b/.rubocop_todo.yml index ccdfa8a..3db0a29 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,31 +1,21 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-10-26 17:08:37 +0200 using RuboCop version 0.60.0. +# on 2019-07-16 18:09:04 +0200 using RuboCop version 0.71.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # 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: - 'lib/jekyll-gist/gist_tag.rb' # Offense count: 1 -# Configuration parameters: Max. Metrics/AbcSize: - Exclude: - - 'lib/jekyll-gist/gist_tag.rb' + Max: 24 # Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: short, verbose -Style/PreferredHashMethods: - Exclude: - - 'lib/jekyll-gist/gist_tag.rb' +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 21 diff --git a/.travis.yml b/.travis.yml index b4f6166..5918f53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: ruby cache: bundler rvm: - - 2.6 - - 2.4 + - &latest_ruby 2.7 + - 2.5 script : script/cibuild @@ -10,13 +10,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.8.5" + - rvm: *latest_ruby + env: JEKYLL_VERSION="~> 4.0" 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/History.markdown b/History.markdown index b2ee842..a254054 100644 --- a/History.markdown +++ b/History.markdown @@ -1,15 +1,21 @@ -## 1.6.0 / 2019-03-22 +## HEAD ### Development Fixes * Test against Ruby 2.5 (#57) * Rely on rubocop-jekyll (#62) * chore(deps): rubocop-jekyll 0.3 (#64) + * Refactor GistTag (#65) ### Major Enhancements * chore(deps): drop support for Liquid < 4.0 (#66) +### 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 ### Documentation diff --git a/jekyll-gist.gemspec b/jekyll-gist.gemspec index 81f8e22..ba7a55e 100644 --- a/jekyll-gist.gemspec +++ b/jekyll-gist.gemspec @@ -1,9 +1,6 @@ # frozen_string_literal: true -lib = File.expand_path("lib", __dir__) - -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "jekyll-gist/version" +require_relative "lib/jekyll-gist/version" Gem::Specification.new do |spec| spec.name = "jekyll-gist" @@ -14,16 +11,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..ae8ae34 100644 --- a/lib/jekyll-gist/gist_tag.rb +++ b/lib/jekyll-gist/gist_tag.rb @@ -10,22 +10,30 @@ 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 Syntax error in tag 'gist' while parsing the following markup: - #{@markup} - Valid syntax: + + '{% #{raw.strip} %}' + + Valid syntax: {% gist user/1234567 %} {% gist user/1234567 foo.js %} {% gist 28949e1d5ee2273f9fd3 %} @@ -42,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 @@ -60,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("'", "'") "#{code}" else - Jekyll.logger.warn "Warning:", "The tag for your gist #{gist_id} " - Jekyll.logger.warn "", "could not be generated. This will affect users who do " + Jekyll.logger.warn "Warning:", "The tag for your gist #{gist_id}" + Jekyll.logger.warn "", "could not be generated. This will affect users who do" Jekyll.logger.warn "", "not have JavaScript enabled in their browsers." end end @@ -82,6 +79,7 @@ def fetch_raw_code(gist_id, filename = nil) url = "https://gist.githubusercontent.com/#{gist_id}/raw" 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| @@ -95,7 +93,6 @@ def fetch_raw_code(gist_id, filename = nil) 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] @@ -109,10 +106,6 @@ def code_from_api(gist_id, filename = nil) file[:content] if file end - - def self.client - @client ||= Octokit::Client.new :access_token => ENV["JEKYLL_GITHUB_TOKEN"] - end end end end 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 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 pFad - Phonifier reborn Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved. Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages. Alternative Proxies:Alternative ProxypFad ProxypFad v3 ProxypFad v4 Proxy
#{code}
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy