Skip to content

Commit 8d6d132

Browse files
committed
GH-44 coding standards
1 parent 406cfd5 commit 8d6d132

File tree

8 files changed

+218
-220
lines changed

8 files changed

+218
-220
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
inherit_gem:
2+
jekyll: .rubocop.yml
3+
14
AllCops:
25
TargetRubyVersion: 2.3
36
Exclude:

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

3-
source "https://rubygems.org"
3+
source 'https://rubygems.org'
44

55
gemspec

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require "bundler/gem_tasks"
4-
require "rspec/core/rake_task"
3+
require 'bundler/gem_tasks'
4+
require 'rspec/core/rake_task'
55

66
RSpec::Core::RakeTask.new(:spec)

jekyll-target-blank.gemspec

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
# frozen_string_literal: true
22

3-
lib = File.expand_path("lib", __dir__)
3+
lib = File.expand_path('lib', __dir__)
44
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5-
require "jekyll-target-blank/version"
5+
require 'jekyll-target-blank/version'
66

77
Gem::Specification.new do |spec|
8-
spec.name = "jekyll-target-blank"
8+
spec.name = 'jekyll-target-blank'
99
spec.version = JekyllTargetBlank::VERSION
10-
spec.authors = ["Keith Mifsud"]
11-
spec.email = ["[email protected]"]
12-
spec.summary = "Target Blank automatically changes the external links to open in a new browser."
13-
spec.description = "Target Blank automatically changes the external links to open in a new browser for Jekyll sites."
14-
spec.homepage = "https://github.com/keithmifsud/jekyll-target-blank"
15-
spec.license = "MIT"
10+
spec.authors = ['Keith Mifsud']
11+
spec.email = ['[email protected]']
12+
spec.summary = 'Target Blank automatically changes the external links to open in a new browser.'
13+
spec.description = 'Target Blank automatically changes the external links to open in a new browser for Jekyll sites.'
14+
spec.homepage = 'https://github.com/keithmifsud/jekyll-target-blank'
15+
spec.license = 'MIT'
1616
spec.files = `git ls-files -z`.split("\x0")
17-
spec.require_paths = ["lib"]
18-
spec.required_ruby_version = ">= 2.3.0"
19-
spec.add_dependency "jekyll", ">= 3.0", "<5.0"
20-
spec.add_dependency "nokogiri", "~> 1.10"
21-
spec.add_development_dependency "bundler", "~> 2.0"
22-
spec.add_development_dependency "rake", "~> 12.0"
23-
spec.add_development_dependency "rspec", "~> 3.0"
24-
spec.add_development_dependency "rubocop", "~> 0.75.0"
17+
spec.require_paths = ['lib']
18+
spec.required_ruby_version = '>= 2.3.0'
19+
spec.add_dependency 'jekyll', '>= 3.0', '<5.0'
20+
spec.add_dependency 'nokogiri', '~> 1.10'
21+
spec.add_development_dependency 'bundler', '~> 2.0'
22+
spec.add_development_dependency 'rake', '~> 12.0'
23+
spec.add_development_dependency 'rspec', '~> 3.0'
24+
spec.add_development_dependency 'rubocop', '>= 0.68.0', '<= 0.72.0'
25+
spec.add_development_dependency "rubocop-jekyll", "~> 0.10.0"
26+
2527
end

lib/jekyll-target-blank.rb

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
module Jekyll
88
class TargetBlank
99
BODY_START_TAG = "<body"
10-
OPENING_BODY_TAG_REGEX = %r!<body([^<>]*)>\s*!
10+
OPENING_BODY_TAG_REGEX = %r!<body([^<>]*)>\s*!.freeze
1111

1212
class << self
1313
# Public: Processes the content and updated the external links
@@ -117,13 +117,9 @@ def configure_adding_additional_css_classes
117117

118118
# Private: Handles the default rel attribute values
119119
def add_default_rel_attributes?
120-
if should_not_include_noopener?
121-
@should_add_noopener = false
122-
end
120+
@should_add_noopener = false if should_not_include_noopener?
123121

124-
if should_not_include_noreferrer?
125-
@should_add_noreferrrer = false
126-
end
122+
@should_add_noreferrrer = false if should_not_include_noreferrer?
127123
end
128124

129125
# Private: Sets any extra rel attribute values
@@ -142,7 +138,7 @@ def add_css_classes_if_required(link)
142138
if @should_add_css_classes
143139
existing_classes = get_existing_css_classes(link)
144140
existing_classes = " " + existing_classes unless existing_classes.to_s.empty?
145-
link["class"] = @css_classes_to_add + existing_classes
141+
link["class"] = @css_classes_to_add + existing_classes
146142
end
147143
end
148144

@@ -158,27 +154,30 @@ def add_target_blank_attribute(link)
158154
# link = Nokogiri node.
159155
def add_rel_attributes(link)
160156
rel = ""
161-
if @should_add_noopener
162-
rel = "noopener"
163-
end
157+
rel = add_noopener_to_rel(rel)
164158

165159
if @should_add_noreferrrer
166-
unless rel.empty?
167-
rel += " "
168-
end
160+
rel += " " unless rel.empty?
169161
rel += "noreferrer"
170162
end
171163

172164
if @should_add_extra_rel_attribute_values
173-
unless rel.empty?
174-
rel += " "
175-
end
165+
rel += " " unless rel.empty?
176166
rel += @extra_rel_attribute_values
177167
end
178168

179-
unless rel.empty?
180-
link["rel"] = rel
169+
link["rel"] = rel unless rel.empty?
170+
end
171+
172+
# Private: Adds noopener attribute.
173+
#
174+
# rel = string
175+
def add_noopener_to_rel(rel)
176+
if @should_add_noopener
177+
rel += " " unless rel.empty?
178+
rel += "noopener"
181179
end
180+
rel
182181
end
183182

184183
# Private: Checks if the link is a mailto url.
@@ -193,9 +192,7 @@ def not_mailto_link?(link)
193192
#
194193
# link - a url.
195194
def external?(link)
196-
if link =~ URI.regexp(%w(http https))
197-
URI.parse(link).host != URI.parse(@site_url).host
198-
end
195+
URI.parse(link).host != URI.parse(@site_url).host if link =~ URI.regexp(%w(http https))
199196
end
200197

201198
# Private: Checks if a css class name is specified in config
@@ -332,6 +329,6 @@ def class_config
332329
end
333330

334331
# Hooks into Jekyll's post_render event.
335-
Jekyll::Hooks.register %i[pages documents], :post_render do |doc|
332+
Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
336333
Jekyll::TargetBlank.process(doc) if Jekyll::TargetBlank.document_processable?(doc)
337334
end

lib/jekyll-target-blank/version.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

33
module JekyllTargetBlank
4-
54
VERSION = "2.0.0"
6-
75
end

0 commit comments

Comments
 (0)