From 1079262b6ebf063f3874addbd700109d90095b52 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" <13498015+amyspark@users.noreply.github.com> Date: Tue, 2 Apr 2019 11:57:15 +0000 Subject: [PATCH 01/13] bump dependencies and Jekyll version --- .gitignore | 3 ++- jekyll-target-blank.gemspec | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 90ff2ed..5b244c8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /*.gem Gemfile.lock dev_notes.md -.vscode \ No newline at end of file +.vscode +spec/fixtures/unit/.jekyll-cache \ No newline at end of file diff --git a/jekyll-target-blank.gemspec b/jekyll-target-blank.gemspec index 9eead9c..33fd243 100644 --- a/jekyll-target-blank.gemspec +++ b/jekyll-target-blank.gemspec @@ -17,8 +17,8 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.required_ruby_version = ">= 2.3.0" - spec.add_dependency "jekyll", "~> 3.0" - spec.add_dependency "nokogiri", "~> 1.8.2" + spec.add_dependency "jekyll", ">= 3.0", "<5.0" + spec.add_dependency "nokogiri", "~> 1.10" spec.add_development_dependency "bundler", "~> 1.6" spec.add_development_dependency "rake", "~> 12.0" From 24431b40c72da33a9f3f5dadf5874f1fe3a0d931 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" <13498015+amyspark@users.noreply.github.com> Date: Wed, 3 Apr 2019 16:14:56 +0000 Subject: [PATCH 02/13] Bump Bundler version --- jekyll-target-blank.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll-target-blank.gemspec b/jekyll-target-blank.gemspec index 33fd243..ad561cd 100644 --- a/jekyll-target-blank.gemspec +++ b/jekyll-target-blank.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |spec| spec.add_dependency "jekyll", ">= 3.0", "<5.0" spec.add_dependency "nokogiri", "~> 1.10" - spec.add_development_dependency "bundler", "~> 1.6" + spec.add_development_dependency "bundler", "~> 2.0" spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rubocop", "0.55" From 4e3c14d276d01c6caec6e3b77669722dc3aeb7d5 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" <13498015+amyspark@users.noreply.github.com> Date: Thu, 4 Apr 2019 16:33:26 +0000 Subject: [PATCH 03/13] Updated the version number --- lib/jekyll-target-blank/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll-target-blank/version.rb b/lib/jekyll-target-blank/version.rb index 3665b54..8dc1dfc 100644 --- a/lib/jekyll-target-blank/version.rb +++ b/lib/jekyll-target-blank/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module JekyllTargetBlank - VERSION = "1.1.1" + VERSION = "1.1.2" end From 996f6d3282643baf0d23519dcea96e5a3b4baf64 Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 11:55:17 +0545 Subject: [PATCH 04/13] GH-44 Ruby version requirement. --- jekyll-target-blank.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll-target-blank.gemspec b/jekyll-target-blank.gemspec index 728f131..83446d8 100644 --- a/jekyll-target-blank.gemspec +++ b/jekyll-target-blank.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |spec| spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0") spec.require_paths = ["lib"] - spec.required_ruby_version = ">= 2.3.0" + spec.required_ruby_version = ">= 2.4.0" spec.add_dependency "jekyll", ">= 3.0", "<5.0" spec.add_dependency "nokogiri", "~> 1.10" spec.add_development_dependency "bundler", "~> 2.0.0" From 49a7e9ac9df993510055ad8277f4f0e54a9de3a1 Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 12:03:24 +0545 Subject: [PATCH 05/13] GH-44 Travis config --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 45dd139..c80428c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: ruby rvm: -- 2.5 -- 2.4 -- 2.3 +- 2.5.0 +- 2.4.0 before_install: - gem update --system - gem install bundler From 1e882fa9bf964ed53b95aca4ee4392b9ade6c8e9 Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 12:10:42 +0545 Subject: [PATCH 06/13] GH-44 Travis config --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c80428c..1678168 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: ruby rvm: -- 2.5.0 -- 2.4.0 +- 2.6 +- 2.5 +- 2.4 before_install: - gem update --system - gem install bundler From 06be5fb4b30fa83beffba7433726162fa558a032 Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 12:13:47 +0545 Subject: [PATCH 07/13] GH-44 Travis config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 1678168..8a7ead8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ rvm: before_install: - gem update --system - gem install bundler +- bundle install script: scripts/cibuild sudo: false cache: bundler From 79df2b5ce1a2e46e37254341d6e795a0a88f673e Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 12:25:10 +0545 Subject: [PATCH 08/13] GH-35 deps issues in gemspec --- .travis.yml | 3 +-- jekyll-target-blank.gemspec | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a7ead8..45dd139 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,11 @@ language: ruby rvm: -- 2.6 - 2.5 - 2.4 +- 2.3 before_install: - gem update --system - gem install bundler -- bundle install script: scripts/cibuild sudo: false cache: bundler diff --git a/jekyll-target-blank.gemspec b/jekyll-target-blank.gemspec index 83446d8..df45856 100644 --- a/jekyll-target-blank.gemspec +++ b/jekyll-target-blank.gemspec @@ -15,10 +15,10 @@ Gem::Specification.new do |spec| spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0") spec.require_paths = ["lib"] - spec.required_ruby_version = ">= 2.4.0" + spec.required_ruby_version = ">= 2.3.0" spec.add_dependency "jekyll", ">= 3.0", "<5.0" spec.add_dependency "nokogiri", "~> 1.10" - spec.add_development_dependency "bundler", "~> 2.0.0" + spec.add_development_dependency "bundler", "~> 2.0" spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rubocop", "0.55" From e7f85e356e1f1b9adaec64dd04b6b1440bd30b6e Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 12:44:37 +0545 Subject: [PATCH 09/13] GH-35 deps issues in gemspec --- .gitignore | 3 ++- scripts/cibuild | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5b244c8..05f4181 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ Gemfile.lock dev_notes.md .vscode -spec/fixtures/unit/.jekyll-cache \ No newline at end of file +spec/fixtures/unit/.jekyll-cache +pkg \ No newline at end of file diff --git a/scripts/cibuild b/scripts/cibuild index e83caff..7567ebe 100755 --- a/scripts/cibuild +++ b/scripts/cibuild @@ -3,5 +3,4 @@ set -e scripts/test -scripts/quality bundle exec rake build From 406cfd5f63649b6f4c9c5a32deb6bea9edced651 Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 12:57:33 +0545 Subject: [PATCH 10/13] GH-44 Travis config --- .rubocop.yml | 3 --- jekyll-target-blank.gemspec | 2 +- scripts/cibuild | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6190cf1..1468bd6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,3 @@ -inherit_gem: - jekyll: .rubocop.yml - AllCops: TargetRubyVersion: 2.3 Exclude: diff --git a/jekyll-target-blank.gemspec b/jekyll-target-blank.gemspec index df45856..f3297b4 100644 --- a/jekyll-target-blank.gemspec +++ b/jekyll-target-blank.gemspec @@ -21,5 +21,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 2.0" spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "rubocop", "0.55" + spec.add_development_dependency "rubocop", "~> 0.75.0" end diff --git a/scripts/cibuild b/scripts/cibuild index 7567ebe..e83caff 100755 --- a/scripts/cibuild +++ b/scripts/cibuild @@ -3,4 +3,5 @@ set -e scripts/test +scripts/quality bundle exec rake build From 8d6d1323c2ba847de2273051c4ac7c3dbae81c58 Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 13:27:00 +0545 Subject: [PATCH 11/13] GH-44 coding standards --- .rubocop.yml | 3 + Gemfile | 2 +- Rakefile | 4 +- jekyll-target-blank.gemspec | 36 +-- lib/jekyll-target-blank.rb | 43 ++-- lib/jekyll-target-blank/version.rb | 2 - spec/jekyll-target_spec.rb | 340 ++++++++++++++--------------- spec/spec_helper.rb | 8 +- 8 files changed, 218 insertions(+), 220 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1468bd6..6190cf1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +inherit_gem: + jekyll: .rubocop.yml + AllCops: TargetRubyVersion: 2.3 Exclude: diff --git a/Gemfile b/Gemfile index be173b2..7f4f5e9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile index 92557b5..2e9b334 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/gem_tasks" -require "rspec/core/rake_task" +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) diff --git a/jekyll-target-blank.gemspec b/jekyll-target-blank.gemspec index f3297b4..03d3ed4 100644 --- a/jekyll-target-blank.gemspec +++ b/jekyll-target-blank.gemspec @@ -1,25 +1,27 @@ # frozen_string_literal: true -lib = File.expand_path("lib", __dir__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "jekyll-target-blank/version" +require 'jekyll-target-blank/version' Gem::Specification.new do |spec| - spec.name = "jekyll-target-blank" + spec.name = 'jekyll-target-blank' spec.version = JekyllTargetBlank::VERSION - spec.authors = ["Keith Mifsud"] - spec.email = ["mifsud.k@gmail.com"] - spec.summary = "Target Blank automatically changes the external links to open in a new browser." - spec.description = "Target Blank automatically changes the external links to open in a new browser for Jekyll sites." - spec.homepage = "https://github.com/keithmifsud/jekyll-target-blank" - spec.license = "MIT" + spec.authors = ['Keith Mifsud'] + spec.email = ['mifsud.k@gmail.com'] + spec.summary = 'Target Blank automatically changes the external links to open in a new browser.' + spec.description = 'Target Blank automatically changes the external links to open in a new browser for Jekyll sites.' + spec.homepage = 'https://github.com/keithmifsud/jekyll-target-blank' + spec.license = 'MIT' spec.files = `git ls-files -z`.split("\x0") - spec.require_paths = ["lib"] - spec.required_ruby_version = ">= 2.3.0" - spec.add_dependency "jekyll", ">= 3.0", "<5.0" - spec.add_dependency "nokogiri", "~> 1.10" - spec.add_development_dependency "bundler", "~> 2.0" - spec.add_development_dependency "rake", "~> 12.0" - spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "rubocop", "~> 0.75.0" + spec.require_paths = ['lib'] + spec.required_ruby_version = '>= 2.3.0' + spec.add_dependency 'jekyll', '>= 3.0', '<5.0' + spec.add_dependency 'nokogiri', '~> 1.10' + spec.add_development_dependency 'bundler', '~> 2.0' + spec.add_development_dependency 'rake', '~> 12.0' + spec.add_development_dependency 'rspec', '~> 3.0' + spec.add_development_dependency 'rubocop', '>= 0.68.0', '<= 0.72.0' + spec.add_development_dependency "rubocop-jekyll", "~> 0.10.0" + end diff --git a/lib/jekyll-target-blank.rb b/lib/jekyll-target-blank.rb index 75a68be..62f6a69 100644 --- a/lib/jekyll-target-blank.rb +++ b/lib/jekyll-target-blank.rb @@ -7,7 +7,7 @@ module Jekyll class TargetBlank BODY_START_TAG = "]*)>\s*! + OPENING_BODY_TAG_REGEX = %r!]*)>\s*!.freeze class << self # Public: Processes the content and updated the external links @@ -117,13 +117,9 @@ def configure_adding_additional_css_classes # Private: Handles the default rel attribute values def add_default_rel_attributes? - if should_not_include_noopener? - @should_add_noopener = false - end + @should_add_noopener = false if should_not_include_noopener? - if should_not_include_noreferrer? - @should_add_noreferrrer = false - end + @should_add_noreferrrer = false if should_not_include_noreferrer? end # Private: Sets any extra rel attribute values @@ -142,7 +138,7 @@ def add_css_classes_if_required(link) if @should_add_css_classes existing_classes = get_existing_css_classes(link) existing_classes = " " + existing_classes unless existing_classes.to_s.empty? - link["class"] = @css_classes_to_add + existing_classes + link["class"] = @css_classes_to_add + existing_classes end end @@ -158,27 +154,30 @@ def add_target_blank_attribute(link) # link = Nokogiri node. def add_rel_attributes(link) rel = "" - if @should_add_noopener - rel = "noopener" - end + rel = add_noopener_to_rel(rel) if @should_add_noreferrrer - unless rel.empty? - rel += " " - end + rel += " " unless rel.empty? rel += "noreferrer" end if @should_add_extra_rel_attribute_values - unless rel.empty? - rel += " " - end + rel += " " unless rel.empty? rel += @extra_rel_attribute_values end - unless rel.empty? - link["rel"] = rel + link["rel"] = rel unless rel.empty? + end + + # Private: Adds noopener attribute. + # + # rel = string + def add_noopener_to_rel(rel) + if @should_add_noopener + rel += " " unless rel.empty? + rel += "noopener" end + rel end # Private: Checks if the link is a mailto url. @@ -193,9 +192,7 @@ def not_mailto_link?(link) # # link - a url. def external?(link) - if link =~ URI.regexp(%w(http https)) - URI.parse(link).host != URI.parse(@site_url).host - end + URI.parse(link).host != URI.parse(@site_url).host if link =~ URI.regexp(%w(http https)) end # Private: Checks if a css class name is specified in config @@ -332,6 +329,6 @@ def class_config end # Hooks into Jekyll's post_render event. -Jekyll::Hooks.register %i[pages documents], :post_render do |doc| +Jekyll::Hooks.register [:pages, :documents], :post_render do |doc| Jekyll::TargetBlank.process(doc) if Jekyll::TargetBlank.document_processable?(doc) end diff --git a/lib/jekyll-target-blank/version.rb b/lib/jekyll-target-blank/version.rb index 09062c4..f137b4a 100644 --- a/lib/jekyll-target-blank/version.rb +++ b/lib/jekyll-target-blank/version.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true module JekyllTargetBlank - VERSION = "2.0.0" - end diff --git a/spec/jekyll-target_spec.rb b/spec/jekyll-target_spec.rb index 30906f8..06987e0 100644 --- a/spec/jekyll-target_spec.rb +++ b/spec/jekyll-target_spec.rb @@ -6,53 +6,51 @@ let(:config_overrides) { {} } let(:config_overrides) do { - "url" => "https://keith-mifsud.me", - "collections" => { "docs" => { "output" => "true" } }, + 'url' => 'https://keith-mifsud.me', + 'collections' => { 'docs' => { 'output' => 'true' } } } end let(:configs) do Jekyll.configuration(config_overrides.merge( - { - "skip_config_files" => false, - "collections" => { "docs" => { "output" => true } }, - "source" => unit_fixtures_dir, - "destination" => unit_fixtures_dir("_site"), - } - )) + 'skip_config_files' => false, + 'collections' => { 'docs' => { 'output' => true } }, + 'source' => unit_fixtures_dir, + 'destination' => unit_fixtures_dir('_site') + )) end let(:target_blank) { described_class } let(:site) { Jekyll::Site.new(configs) } let(:posts) { site.posts.docs.sort.reverse } # get some fixtures - let(:post_with_external_markdown_link) { find_by_title(posts, "Post with external markdown link") } + let(:post_with_external_markdown_link) { find_by_title(posts, 'Post with external markdown link') } - let(:post_with_multiple_external_markdown_links) { find_by_title(posts, "Post with multiple external markdown links") } + let(:post_with_multiple_external_markdown_links) { find_by_title(posts, 'Post with multiple external markdown links') } - let(:post_with_relative_markdown_link) { find_by_title(posts, "Post with relative markdown link") } + let(:post_with_relative_markdown_link) { find_by_title(posts, 'Post with relative markdown link') } - let(:post_with_absolute_internal_markdown_link) { find_by_title(posts, "Post with absolute internal markdown link") } + let(:post_with_absolute_internal_markdown_link) { find_by_title(posts, 'Post with absolute internal markdown link') } - let(:post_with_html_anchor_tag) { find_by_title(posts, "Post with html anchor tag") } + let(:post_with_html_anchor_tag) { find_by_title(posts, 'Post with html anchor tag') } - let(:post_with_plain_text_link) { find_by_title(posts, "Post with plain text link") } + let(:post_with_plain_text_link) { find_by_title(posts, 'Post with plain text link') } - let(:document_with_a_processable_link) { find_by_title(site.collections["docs"].docs, "Document with a processable link") } + let(:document_with_a_processable_link) { find_by_title(site.collections['docs'].docs, 'Document with a processable link') } - let(:text_file) { find_by_title(site.collections["docs"].docs, "Text file") } + let(:text_file) { find_by_title(site.collections['docs'].docs, 'Text file') } - let(:post_with_code_block) { find_by_title(posts, "Post with code block") } - let(:document_with_liquid_tag) { find_by_title(site.collections["docs"].docs, "Document with liquid tag") } + let(:post_with_code_block) { find_by_title(posts, 'Post with code block') } + let(:document_with_liquid_tag) { find_by_title(site.collections['docs'].docs, 'Document with liquid tag') } - let(:document_with_include) { find_by_title(site.collections["docs"].docs, "Document with include") } + let(:document_with_include) { find_by_title(site.collections['docs'].docs, 'Document with include') } - let(:post_with_mailto_link) { find_by_title(posts, "Post with mailto link") } + let(:post_with_mailto_link) { find_by_title(posts, 'Post with mailto link') } - let(:post_with_external_html_link_and_random_css_classes) { find_by_title(posts, "Post with external html link and random css classes") } + let(:post_with_external_html_link_and_random_css_classes) { find_by_title(posts, 'Post with external html link and random css classes') } - let(:post_with_html_link_containing_the_specified_css_class) { find_by_title(posts, "Post with html link containing the specified css class") } + let(:post_with_html_link_containing_the_specified_css_class) { find_by_title(posts, 'Post with html link containing the specified css class') } - let(:post_with_external_link_containing_the_specified_css_class_and_other_css_classes) { find_by_title(posts, "Post with external link containing the specified css class and other css classes") } + let(:post_with_external_link_containing_the_specified_css_class_and_other_css_classes) { find_by_title(posts, 'Post with external link containing the specified css class and other css classes') } # define common wrappers. def para(content) @@ -66,50 +64,50 @@ def para(content) site.render end - context "Without entries in config file" do + context 'Without entries in config file' do let(:config_overrides) do - { "target-blank" => { "add_css_classes" => false } } + { 'target-blank' => { 'add_css_classes' => false } } end - it "should add target attribute to external markdown link" do + it 'should add target attribute to external markdown link' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end - it "should add target attribute to multiple external markdown links" do + it 'should add target attribute to multiple external markdown links' do expect(post_with_multiple_external_markdown_links.output).to include('

This post contains three links. The first link is to Google, the second link is, well, to my website and since GitHub is so awesome, why not link to them too?

') end - it "should not add target attribute to relative markdown link" do + it 'should not add target attribute to relative markdown link' do expect(post_with_relative_markdown_link.output).to include(para('Link to contact page.')) expect(post_with_relative_markdown_link.output).to_not include(para('Link to contact page')) end - it "should not add target attribute to absolute internal link" do + it 'should not add target attribute to absolute internal link' do expect(post_with_absolute_internal_markdown_link.output).to include('

This is an absolute internal link.

') end - it "should correctly handle existing html anchor tag" do + it 'should correctly handle existing html anchor tag' do expect(post_with_html_anchor_tag.output).to include('

This is an anchor tag.

') end - it "should not interfere with plain text link" do - expect(post_with_plain_text_link.output).to include("

This is a plain text link to https://google.com.

") + it 'should not interfere with plain text link' do + expect(post_with_plain_text_link.output).to include('

This is a plain text link to https://google.com.

') end - it "should process external links in collections" do + it 'should process external links in collections' do expect(document_with_a_processable_link.output).to include('

This is a valid link.

') end - it "should process external links in pages" do + it 'should process external links in pages' do expect(site.pages.first.output).to include('

This is a valid link.

') end - it "should not process links in non html files" do - expect(text_file.output).to eq("Valid [link](https://google.com).") + it 'should not process links in non html files' do + expect(text_file.output).to eq('Valid [link](https://google.com).') end - it "should not process link in code block but process link outside of block" do + it 'should not process link in code block but process link outside of block' do expect(post_with_code_block.output).to include('\'https://google.com\'') expect(post_with_code_block.output).not_to include('https://google.com') @@ -117,307 +115,307 @@ def para(content) expect(post_with_code_block.output).to include('

Valid link

') end - it "should not break layouts" do + it 'should not break layouts' do expect(site.pages.first.output).to include('') expect(site.pages.first.output).to include('') end - it "should not interfere with liquid tags" do + it 'should not interfere with liquid tags' do expect(document_with_liquid_tag.output).to include('

This _docs/document-with-liquid-tag.md is a document with a liquid tag.

') end - it "should not interfere with includes" do - expect(document_with_include.output).to include("

This is a document with an include: This is an include.

") + it 'should not interfere with includes' do + expect(document_with_include.output).to include('

This is a document with an include: This is an include.

') end - it "should not break layout content" do - expect(site.pages.first.output).to include("
Layout content started.
") + it 'should not break layout content' do + expect(site.pages.first.output).to include('
Layout content started.
') - expect(site.pages.first.output).to include("
Layout content ended.
") + expect(site.pages.first.output).to include('
Layout content ended.
') end - it "should not duplicate post content" do + it 'should not duplicate post content' do expect(post_with_external_markdown_link.output).to eq(post_with_layout_result) end - it "should ignore mailto links" do + it 'should ignore mailto links' do expect(post_with_mailto_link.output).to include(para('This is a mailto link.')) end end - context "With a specified css class name" do - let(:target_blank_css_class) { "ext-link" } + context 'With a specified css class name' do + let(:target_blank_css_class) { 'ext-link' } let(:config_overrides) do { - "target-blank" => { - "css_class" => target_blank_css_class, - "add_css_classes" => false, - }, + 'target-blank' => { + 'css_class' => target_blank_css_class, + 'add_css_classes' => false + } } end - it "should not add target attribute to external markdown link that does not have the specified css class" do + it 'should not add target attribute to external markdown link that does not have the specified css class' do expect(post_with_external_markdown_link.output).to_not include(para('Link to Google.')) end - it "should not add target attribute to external markdown link that does not have the specified css class even if it does have other css classes" do + it 'should not add target attribute to external markdown link that does not have the specified css class even if it does have other css classes' do expect(post_with_external_html_link_and_random_css_classes.output).to include(para('Link.')) expect(post_with_external_html_link_and_random_css_classes.output).to_not include('target="_blank" rel="noopener noreferrer"') end - it "should add target attribute to an external link containing the specified css class" do + it 'should add target attribute to an external link containing the specified css class' do expect(post_with_html_link_containing_the_specified_css_class.output).to include(para('Link with the css class specified in config.')) end - it "should add target attribute to an external link containing the specified css class even when other css classes are specified" do + it 'should add target attribute to an external link containing the specified css class even when other css classes are specified' do expect(post_with_external_link_containing_the_specified_css_class_and_other_css_classes.output).to include(para('This is a link containing the specified css class and two other random css classes.')) end end - context "Adds a CSS classes to the links" do - let(:target_blank_add_css_class) { "some-class" } + context 'Adds a CSS classes to the links' do + let(:target_blank_add_css_class) { 'some-class' } let(:config_overrides) do - { "target-blank" => { "add_css_classes" => target_blank_add_css_class } } + { 'target-blank' => { 'add_css_classes' => target_blank_add_css_class } } end - it "should add the CSS class specified in config" do + it 'should add the CSS class specified in config' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end - it "should add the CSS class specified in config even when the link already has a CSS class specified" do + it 'should add the CSS class specified in config even when the link already has a CSS class specified' do expect(post_with_html_link_containing_the_specified_css_class.output).to include(para('Link with the css class specified in config.')) end - it "should add the CSS class specified in config even when the link has more than CSS classes already included" do + it 'should add the CSS class specified in config even when the link has more than CSS classes already included' do expect(post_with_external_link_containing_the_specified_css_class_and_other_css_classes.output).to include(para('This is a link containing the specified css class and two other random css classes.')) end end - context "When more than one CSS classes are specified in config" do - it "should add the CSS classes specified in config" do + context 'When more than one CSS classes are specified in config' do + it 'should add the CSS classes specified in config' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end - it "should add the CSS classes specified in config even when the link already has a CSS class included" do + it 'should add the CSS classes specified in config even when the link already has a CSS class included' do expect(post_with_html_link_containing_the_specified_css_class.output).to include(para('Link with the css class specified in config.')) end - it "should add the CSS classes specified in config even when the link already has more than one CSS classes included" do + it 'should add the CSS classes specified in config even when the link already has more than one CSS classes included' do expect(post_with_external_link_containing_the_specified_css_class_and_other_css_classes.output).to include(para('This is a link containing the specified css class and two other random css classes.')) end end - context "When noopener is set to false in config" do + context 'When noopener is set to false in config' do let(:noopener) { false } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "noopener" => noopener, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'noopener' => noopener + } } end - it "should not add noopener value to the rel attribute" do + it 'should not add noopener value to the rel attribute' do expect(post_with_external_markdown_link.output).to_not include(para('Link to Google.')) end - it "should still add noreferrer value to the rel attribute" do + it 'should still add noreferrer value to the rel attribute' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When noreferrer is set to false in config" do + context 'When noreferrer is set to false in config' do let(:noreferrer) { false } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "noreferrer" => noreferrer, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'noreferrer' => noreferrer + } } end - it "should not add noreferrer value to the rel attribute" do + it 'should not add noreferrer value to the rel attribute' do expect(post_with_external_markdown_link.output).to_not include(para('Link to Google.')) end - it "should still add noopener value to the rel attribute" do + it 'should still add noopener value to the rel attribute' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When both noopener and noreferrer values are set to false in config" do + context 'When both noopener and noreferrer values are set to false in config' do let(:noopener) { false } let(:noreferrer) { false } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "noopener" => noopener, - "noreferrer" => noreferrer, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'noopener' => noopener, + 'noreferrer' => noreferrer + } } end - it "should not include the rel attribute values" do + it 'should not include the rel attribute values' do expect(post_with_external_markdown_link.output).to_not include(para('Link to Google.')) end - it "should not include the rel attribute noopener value" do + it 'should not include the rel attribute noopener value' do expect(post_with_external_markdown_link.output).to_not include(para('Link to Google.')) end - it "should not include the rel attribute noreferrer value" do + it 'should not include the rel attribute noreferrer value' do expect(post_with_external_markdown_link.output).to_not include(para('Link to Google.')) end - it "should not include any rel attributes" do + it 'should not include any rel attributes' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When one additional rel attribute is added in config" do - let(:rel_attribute) { "nofollow" } + context 'When one additional rel attribute is added in config' do + let(:rel_attribute) { 'nofollow' } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "rel" => rel_attribute, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'rel' => rel_attribute + } } end - it "should add the extra rel attribute together with the default ones" do + it 'should add the extra rel attribute together with the default ones' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When more than one additional rel attributes are added in config" do - let(:rel_attribute) { "nofollow tag" } + context 'When more than one additional rel attributes are added in config' do + let(:rel_attribute) { 'nofollow tag' } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "rel" => rel_attribute, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'rel' => rel_attribute + } } end - it "should add the extra rel attributes together with the default ones" do + it 'should add the extra rel attributes together with the default ones' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When one extra rel attribute value are set in config and noopener is set to false" do - let(:rel_attribute) { "nofollow" } + context 'When one extra rel attribute value are set in config and noopener is set to false' do + let(:rel_attribute) { 'nofollow' } let(:noopener) { false } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "noopener" => noopener, - "rel" => rel_attribute, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'noopener' => noopener, + 'rel' => rel_attribute + } } end - it "should the extra rel attribute value and not add the default noopener value" do + it 'should the extra rel attribute value and not add the default noopener value' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When more than one extra rel attribute values are set in config and noopener is set to false" do - let(:rel_attribute) { "nofollow tag" } + context 'When more than one extra rel attribute values are set in config and noopener is set to false' do + let(:rel_attribute) { 'nofollow tag' } let(:noopener) { false } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "noopener" => noopener, - "rel" => rel_attribute, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'noopener' => noopener, + 'rel' => rel_attribute + } } end - it "should the extra rel attribute values and not add the default noopener value" do + it 'should the extra rel attribute values and not add the default noopener value' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When one extra rel attributes is set in config and both noopener and noreferer are set to false" do - let(:rel_attribute) { "nofollow" } + context 'When one extra rel attributes is set in config and both noopener and noreferer are set to false' do + let(:rel_attribute) { 'nofollow' } let(:noopener) { false } let(:noreferrer) { false } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "noopener" => noopener, - "noreferrer" => noreferrer, - "rel" => rel_attribute, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'noopener' => noopener, + 'noreferrer' => noreferrer, + 'rel' => rel_attribute + } } end - it "should add the extra rel attribute value and no default ones" do + it 'should add the extra rel attribute value and no default ones' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When more than one extra rel attribute values are set in config and both noopener and noreferer are set to false" do - let(:rel_attribute) { "nofollow tag" } + context 'When more than one extra rel attribute values are set in config and both noopener and noreferer are set to false' do + let(:rel_attribute) { 'nofollow tag' } let(:noopener) { false } let(:noreferrer) { false } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "noopener" => noopener, - "noreferrer" => noreferrer, - "rel" => rel_attribute, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'noopener' => noopener, + 'noreferrer' => noreferrer, + 'rel' => rel_attribute + } } end - it "should add the extra rel attribute values and no default ones" do + it 'should add the extra rel attribute values and no default ones' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When noopener is set to false in config but added to the rel config property" do - let(:rel_attribute) { "noopener" } + context 'When noopener is set to false in config but added to the rel config property' do + let(:rel_attribute) { 'noopener' } let(:noopener) { false } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "noopener" => noopener, - "rel" => rel_attribute, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'noopener' => noopener, + 'rel' => rel_attribute + } } end - it "should still include the noopener rel attribute value" do + it 'should still include the noopener rel attribute value' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end - context "When noopener is set to false in config but added t0 the rel config property alongside one more extra rel attribute value." do - let(:rel_attribute) { "noopener nofollow" } + context 'When noopener is set to false in config but added t0 the rel config property alongside one more extra rel attribute value.' do + let(:rel_attribute) { 'noopener nofollow' } let(:noopener) { false } let(:config_overrides) do { - "target-blank" => { - "add_css_classes" => false, - "noopener" => noopener, - "rel" => rel_attribute, - }, + 'target-blank' => { + 'add_css_classes' => false, + 'noopener' => noopener, + 'rel' => rel_attribute + } } end - it "should still include the noopener rel attribute value along the extra one" do + it 'should still include the noopener rel attribute value along the extra one' do expect(post_with_external_markdown_link.output).to include(para('Link to Google.')) end end @@ -425,22 +423,22 @@ def para(content) private def post_with_layout_result - <<-RESULT - - - - - Post with external markdown link - - - - -
Layout content started.
-

Link to Google.

- -
Layout content ended.
- - + <<~RESULT + + + + + Post with external markdown link + + + + +
Layout content started.
+

Link to Google.

+ +
Layout content ended.
+ + RESULT end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8bb8103..94438e0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require File.expand_path("../lib/jekyll-target-blank.rb", __dir__) +require File.expand_path('../lib/jekyll-target-blank.rb', __dir__) RSpec.configure do |config| - UNIT_FIXTURES_DIR = File.expand_path("fixtures/unit", __dir__) + UNIT_FIXTURES_DIR = File.expand_path('fixtures/unit', __dir__) - INTEGRATION_FIXTURES_DIR = File.expand_path("fixtures/integration", __dir__) + INTEGRATION_FIXTURES_DIR = File.expand_path('fixtures/integration', __dir__) def unit_fixtures_dir(*paths) File.join(UNIT_FIXTURES_DIR, *paths) @@ -16,7 +16,7 @@ def integration_fixtures_dir(*paths) end def find_by_title(docs, title) - docs.find { |d| d.data["title"] == title } + docs.find { |d| d.data['title'] == title } end # rspec-expectations config goes here. You can use an alternate From 6d74c8baedb3ff2232e0c1cc6f8241401d64c3c3 Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 13:43:30 +0545 Subject: [PATCH 12/13] GH-40 CS fixes --- .rubocop.yml | 2 +- lib/jekyll-target-blank.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6190cf1..bd51008 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ inherit_gem: jekyll: .rubocop.yml AllCops: - TargetRubyVersion: 2.3 + TargetRubyVersion: 2.6 Exclude: - vendor/**/* diff --git a/lib/jekyll-target-blank.rb b/lib/jekyll-target-blank.rb index 62f6a69..88ce8d4 100644 --- a/lib/jekyll-target-blank.rb +++ b/lib/jekyll-target-blank.rb @@ -192,7 +192,9 @@ def not_mailto_link?(link) # # link - a url. def external?(link) - URI.parse(link).host != URI.parse(@site_url).host if link =~ URI.regexp(%w(http https)) + if link&.match?(URI.regexp(%w(http https))) + URI.parse(link).host != URI.parse(@site_url).host + end end # Private: Checks if a css class name is specified in config From ed24db2ecd3851c396c9b666cc8be8dc7a66c919 Mon Sep 17 00:00:00 2001 From: Keith Mifsud Date: Mon, 14 Oct 2019 13:44:09 +0545 Subject: [PATCH 13/13] GH-40 Added ruby 2.6 and removed 2.3 from build tests. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 45dd139..ea5038b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: ruby rvm: - 2.5 - 2.4 -- 2.3 +- 2.6 before_install: - gem update --system - gem install bundler