Skip to content
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

Inherit Jekyll's rubocop config for consistency #38

Merged
merged 4 commits into from
Aug 11, 2016
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
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
inherit_gem:
jekyll: .rubocop.yml

Metrics/LineLength:
Exclude:
- spec/**/*
- jekyll-mentions.gemspec
14 changes: 7 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require 'rubygems'
require 'bundler'
require "rubygems"
require "bundler"
begin
Bundler.setup(:default, :development, :test)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'bundler/gem_tasks'
require 'rake'
require 'rake/testtask'
require "bundler/gem_tasks"
require "rake"
require "rake/testtask"

Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.libs << "lib" << "test"
test.pattern = "test/**/test_*.rb"
test.verbose = true
end
11 changes: 6 additions & 5 deletions jekyll-mentions.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Gem::Specification.new do |s|
s.licenses = ["MIT"]
s.files = [ "lib/jekyll-mentions.rb" ]

s.add_dependency "jekyll", '~> 3.0'
s.add_dependency "html-pipeline", '~> 2.3'
s.add_dependency "jekyll", "~> 3.0"
s.add_dependency "html-pipeline", "~> 2.3"
s.add_dependency "activesupport", "~> 4.0"

s.add_development_dependency 'rake'
s.add_development_dependency 'rdoc'
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency "rake"
s.add_development_dependency "rdoc"
s.add_development_dependency "rspec", "~> 3.0"
end
19 changes: 11 additions & 8 deletions lib/jekyll-mentions.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
require 'jekyll'
require 'html/pipeline'
require "jekyll"
require "html/pipeline"

module Jekyll
class Mentions
GITHUB_DOT_COM = "https://github.com".freeze
BODY_START_TAG = "<body".freeze


InvalidJekyllMentionConfig = Class.new(Jekyll::Errors::FatalException)

class << self
# rubocop:disable Metrics/AbcSize
def mentionify(doc)
return unless doc.output.include?("@")
src = mention_base(doc.site.config)
if doc.output.include? BODY_START_TAG
parsed_doc = Nokogiri::HTML::Document.parse(doc.output)
body = parsed_doc.at_css('body')
body = parsed_doc.at_css("body")
body.children = filter_with_mention(src).call(body.inner_html)[:output].to_s
doc.output = parsed_doc.to_html
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get Rubocop to not yell at us about the method, you could move the contents of the first half of the condition to a private parse_as_html or whatever method (or you can ignore it for now).

Expand All @@ -31,11 +31,14 @@ def mentionify(doc)
def filter_with_mention(src)
filters[src] ||= HTML::Pipeline.new([
HTML::Pipeline::MentionFilter
], { :base_url => src , :username_pattern => mention_username_pattern })
], { :base_url => src, :username_pattern => mention_username_pattern })
end

def mention_username_pattern
Regexp.new(HTML::Pipeline::MentionFilter::UsernamePattern.source, Regexp::IGNORECASE)
Regexp.new(
HTML::Pipeline::MentionFilter::UsernamePattern.source,
Regexp::IGNORECASE
)
end

# Public: Filters hash where the key is the mention base URL.
Expand All @@ -55,14 +58,14 @@ def filters
# Returns a URL to use as the base URL for mentions.
# Defaults to the https://github.com.
def mention_base(config = {})
mention_config = config['jekyll-mentions']
mention_config = config["jekyll-mentions"]
case mention_config
when nil, NilClass
GITHUB_DOT_COM
when String
mention_config.to_s
when Hash
mention_config.fetch('base_url', GITHUB_DOT_COM)
mention_config.fetch("base_url", GITHUB_DOT_COM)
else
raise InvalidJekyllMentionConfig,
"Your jekyll-mentions config has to either be a" \
Expand Down
10 changes: 5 additions & 5 deletions spec/mentions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require 'spec_helper'
require "spec_helper"

RSpec.describe(Jekyll::Mentions) do
Jekyll.logger.log_level = :error

let(:config_overrides) { {} }
let(:configs) do
Jekyll.configuration(config_overrides.merge({
'skip_config_files' => false,
'collections' => { 'docs' => { 'output' => true } },
'source' => fixtures_dir,
'destination' => fixtures_dir('_site')
"skip_config_files" => false,
"collections" => { "docs" => { "output" => true } },
"source" => fixtures_dir,
"destination" => fixtures_dir("_site")
}))
end
let(:mentions) { described_class }
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path('../../lib/jekyll-mentions.rb', __FILE__)
require File.expand_path("../../lib/jekyll-mentions.rb", __FILE__)

RSpec.configure do |config|
FIXTURES_DIR = File.expand_path('../fixtures', __FILE__)
FIXTURES_DIR = File.expand_path("../fixtures", __FILE__)
def fixtures_dir(*paths)
File.join(FIXTURES_DIR, *paths)
end
Expand Down