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(/