Skip to content

Rely on rubocop-jekyll #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require: rubocop-jekyll
inherit_gem:
jekyll: .rubocop.yml
rubocop-jekyll: .rubocop.yml

AllCops:
TargetRubyVersion: 2.3
Expand Down
2 changes: 1 addition & 1 deletion jekyll-gist.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "jekyll", ">= 3.0"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rubocop", "~> 0.57.2"
spec.add_development_dependency "rubocop-jekyll", "~> 0.1.0"
spec.add_development_dependency "webmock"
end
32 changes: 11 additions & 21 deletions lib/jekyll-gist/gist_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,20 @@ def render(context)
if (tag_contents = determine_arguments(@markup.strip))
gist_id = tag_contents[0]
filename = tag_contents[1]
if context_contains_key?(context, gist_id)
gist_id = context[gist_id]
end
if context_contains_key?(context, filename)
filename = context[filename]
end
gist_id = context[gist_id] if context_contains_key?(context, gist_id)
filename = context[filename] if context_contains_key?(context, filename)
noscript_tag = gist_noscript_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:
{% gist user/1234567 %}
{% gist user/1234567 foo.js %}
{% gist 28949e1d5ee2273f9fd3 %}
{% gist 28949e1d5ee2273f9fd3 best.md %}
Syntax error in tag 'gist' while parsing the following markup:
#{@markup}
Valid syntax:
{% gist user/1234567 %}
{% gist user/1234567 foo.js %}
{% gist 28949e1d5ee2273f9fd3 %}
{% gist 28949e1d5ee2273f9fd3 best.md %}

ERROR
end
Expand All @@ -48,8 +42,6 @@ def determine_arguments(input)
[matched[1].strip, matched[2].strip] if matched && matched.length >= 3
end

private

def context_contains_key?(context, key)
if context.respond_to?(:has_key?)
context.has_key?(key)
Expand Down Expand Up @@ -90,8 +82,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
Expand All @@ -100,8 +92,6 @@ def fetch_raw_code(gist_id, filename = nil)
nil
end

private

def code_from_api(gist_id, filename = nil)
gist = GistTag.client.gist gist_id

Expand Down