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 b8742e8..3655459 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