pax_global_header00006660000000000000000000000064136301455050014514gustar00rootroot0000000000000052 comment=96efdd10cb0f629d05717c3fe6ee6dde6ed15aa7 jekyll-mentions-1.6.0/000077500000000000000000000000001363014550500146445ustar00rootroot00000000000000jekyll-mentions-1.6.0/.gitignore000066400000000000000000000001461363014550500166350ustar00rootroot00000000000000.bundle /*.gem /tmp /vendor/gems bin Gemfile.lock pkg/*.gem spec/fixtures/.jekyll-cache vendor/bundle jekyll-mentions-1.6.0/.rspec000066400000000000000000000000551363014550500157610ustar00rootroot00000000000000--color --require spec_helper --order random jekyll-mentions-1.6.0/.rubocop.yml000066400000000000000000000003431363014550500171160ustar00rootroot00000000000000require: rubocop-jekyll inherit_gem: rubocop-jekyll: .rubocop.yml AllCops: TargetRubyVersion: 2.4 Exclude: - vendor/**/* Metrics/BlockLength: Exclude: - spec/**/* Metrics/LineLength: Exclude: - spec/**/* jekyll-mentions-1.6.0/.travis.yml000066400000000000000000000012671363014550500167630ustar00rootroot00000000000000language: ruby cache: bundler rvm: - &latest_ruby 2.6 - 2.4 before_install: - gem update --system - gem install bundler script: script/cibuild env: global: - NOKOGIRI_USE_SYSTEM_LIBRARIES=true matrix: - JEKYLL_VERSION="~> 3.8" matrix: include: # GitHub Pages - rvm: 2.5.3 env: - JEKYLL_VERSION="~> 3.8.5" - GITHUB_PAGES=1 # Only set on one build in matrix - rvm: *latest_ruby env: JEKYLL_VERSION="~> 4.0" notifications: irc: on_success: change on_failure: change channels: - irc.freenode.org#jekyll template: - '%{repository}#%{build_number} (%{branch}) %{message} %{build_url}' email: on_success: never on_failure: never jekyll-mentions-1.6.0/Gemfile000066400000000000000000000002031363014550500161320ustar00rootroot00000000000000# frozen_string_literal: true source "https://rubygems.org" gemspec gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"] jekyll-mentions-1.6.0/History.markdown000066400000000000000000000047711363014550500200620ustar00rootroot00000000000000## 1.6.0 / 2020-03-05 ### Minor Enhancements * Allow configuring base URL in page front matter (#72) * Incorporate document data only if it has override (#73) ### Development Fixes * ci: test against Jekyll 4.0 * style: target Ruby 2.4 * ignore vendor/bundle ### Bug Fixes * Support handling body tag across multiple lines (#70) ## 1.5.1 / 2019-03-23 ### Bug Fixes * Re-introduce Ruby 2.3 support and test with Jekyll 3.7 and beyond (#69) ## 1.5.0 / 2019-03-22 ### Development Fixes * Allow Jekyll v4 (still alpha) * Drop support for Ruby 2.3 * chore(deps): rubocop-jekyll 0.3 (#65) * Reintroduce style checks (#67) ## 1.4.1 / 2018-08-08 ### Bug Fixes * Do not match the body tag eagerly (#64) ## 1.4.0 / 2018-05-02 ### Minor Enhancements * Drop support for Ruby 2.2.x (#61) * Relax version constraint on ActiveSupport (#60) * Bump Rubocop to 0.55 (#61) * Drop dependency on ActiveSupport (#63) * Parse only content necessary to mentionify doc (#59) ## 1.3.0 / 2018-03-14 ### Development Fixes * Add rubocop to script/cibuild (#44) * Rubocop: autocorrect (#49) * Define path with __dir__ (#46) * Test against latest Rubies (#53) * Use a version constant (#54) * Use default Rake tasks and scripts (#55) ### Documentation * Use `plugins` key by default (#50) ### Minor Enhancements * Allow underscores in usernames (#57) * Mentionify only relevant docs or pages (#56) ## 1.2.0 / 2016-08-29 ### Development Fixes * Inherit Jekyll's rubocop config for consistency (#38) ### Minor Enhancements * Add support for building the base URL from ENV on Enterprise (#40) ## 1.1.3 / 2016-06-28 * Allow uppercase chars in username (#33) ## 1.1.2 / 2016-03-19 * Don't strip html, body, and head tags (#29) ## 1.1.1 / 2016-03-09 * Handle subclassing of Jekyll::Page (#28) ## 1.1.0 / 2016-03-08 * jekyll-mentions as a hook: better guarding against accidents (#27) ## 1.0.1 / 2016-02-16 * Don't double-mention in Jekyll > 3.0.0 (#25) ## 1.0.0 / 2015-10-30 * Jekyll 3.x support (#22) * HTML Pipeline 2.2 (#22) ## 0.2.1 / 2014-12-18 * Fix for undefined variable error (#20) ## 0.2.0 / 2014-12-01 * Mentionify collection documents. (#19) ## 0.1.3 / 2014-07-30 * Allow mention from a different base url than https://github.com (#14) ## 0.1.2 / 2014-07-10 * URLs ending in '/' also indicate and HTML page. (#13) ## 0.1.1 / 2014-06-23 * Only mentionify the page if it's an HTML page (#11) ## 0.1.0 / 2014-05-06 * Support for Jekyll 2.0 (#8) jekyll-mentions-1.6.0/LICENSE000066400000000000000000000021441363014550500156520ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-present GitHub, Inc. and the jekyll-mentions contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jekyll-mentions-1.6.0/README.md000066400000000000000000000046111363014550500161250ustar00rootroot00000000000000# Jekyll Mentions @mentionable support for your Jekyll site [![Gem Version](https://badge.fury.io/rb/jekyll-mentions.svg)](http://badge.fury.io/rb/jekyll-mentions) [![Build Status](https://travis-ci.org/jekyll/jekyll-mentions.svg?branch=master)](https://travis-ci.org/jekyll/jekyll-mentions) ## Usage Add the following to your site's `Gemfile` ``` gem 'jekyll-mentions' ``` And add the following to your site's `_config.yml` ```yml plugins: - jekyll-mentions ``` Note: if `jekyll --version` is less than `3.5` use: ```yml gems: - jekyll-mentions ``` In any page or post, use @mentions as you would normally, e.g. ```markdown Hey @benbalter, what do you think of this? ``` **Note**: Jekyll Mentions simply turns the @mentions into links, it does not notify the mentioned user. ## Configuration ### Within the `_config.yml` Have your own social network? No problem. We allow you to configure the base URL of all the mentions. To change it, add the following to your Jekyll configuration: ```yaml jekyll-mentions: base_url: https://twitter.com ``` If you're lazy like me, you can use this shorthand: ```yaml jekyll-mentions: https://twitter.com ``` An example of Twitter mentions using jekyll-mentions: ```yaml plugins: - jekyll-mentions jekyll-mentions: base_url: https://twitter.com ``` Et voilĂ ! Your mentions will now use that base URL instead of the default of `https://github.com`. ### Within a page's front matter Now do you want to override the base URL for just a single page/post? No problem. Just set the base URL for that specific page in the front matter: ```yaml jekyll-mentions: base_url: https://facebook.com ``` You also can use this shorthand: ```yaml jekyll-mentions: https://facebook.com ``` Now, every single mentions in the site will use the base URL defined in the `_config.yml`, _except_ in the file where you set the base URL to be something different. If you wish to change the base URL for a single mention, but not every mentions in that file, then you'll have to link to the URL the old-fashioned way: ```markdown [@benbalter](https://instagram.com/benbalter) ``` Now, let's say you have a single file where you _don't_ want your mentions to become mentionable, AKA you want that to stay plain text. You can do that by specifying `false` in the front matter of that file: ```yaml jekyll-mentions: false ``` Now that page/post's mentions will not link to the profiles. jekyll-mentions-1.6.0/Rakefile000066400000000000000000000002241363014550500163070ustar00rootroot00000000000000# frozen_string_literal: true require "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) task :default => :spec jekyll-mentions-1.6.0/jekyll-mentions.gemspec000066400000000000000000000014741363014550500213430ustar00rootroot00000000000000# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path("lib", __dir__) require("jekyll-mentions/version") Gem::Specification.new do |s| s.name = "jekyll-mentions" s.summary = "@mention support for your Jekyll site" s.version = JekyllMentions::VERSION s.authors = ["GitHub, Inc."] s.email = "support@github.com" s.homepage = "https://github.com/jekyll/jekyll-mentions" s.licenses = ["MIT"] s.files = ["lib/jekyll-mentions.rb"] s.required_ruby_version = ">= 2.4.0" s.add_dependency "html-pipeline", "~> 2.3" s.add_dependency "jekyll", ">= 3.7", "< 5.0" s.add_development_dependency "bundler" s.add_development_dependency "rake", "~> 12.0" s.add_development_dependency "rspec", "~> 3.0" s.add_development_dependency "rubocop-jekyll", "~> 0.4" end jekyll-mentions-1.6.0/lib/000077500000000000000000000000001363014550500154125ustar00rootroot00000000000000jekyll-mentions-1.6.0/lib/jekyll-mentions.rb000066400000000000000000000100501363014550500210570ustar00rootroot00000000000000# frozen_string_literal: true require "jekyll" require "html/pipeline" module Jekyll class Mentions GITHUB_DOT_COM = "https://github.com" BODY_START_TAG = "\s*!m.freeze InvalidJekyllMentionConfig = Class.new(Jekyll::Errors::FatalException) class << self # rubocop:disable Metrics/AbcSize def mentionify(doc) content = doc.output return unless content.include?("@") config = doc.site.config config = config.merge(doc.data) if doc.data.key?("jekyll-mentions") src = mention_base(config) if content.include? BODY_START_TAG head, opener, tail = content.partition(OPENING_BODY_TAG_REGEX) body_content, *rest = tail.partition("") return unless body_content&.match?(filter_regex) processed_markup = filter_with_mention(src).call(body_content)[:output].to_s doc.output = String.new(head) << opener << processed_markup << rest.join else return unless content&.match?(filter_regex) doc.output = filter_with_mention(src).call(content)[:output].to_s end end # rubocop:enable Metrics/AbcSize # Public: Create or fetch the filter for the given {{src}} base URL. # # src - the base URL (e.g. https://github.com) # # Returns an HTML::Pipeline instance for the given base URL. def filter_with_mention(src) filters[src] ||= HTML::Pipeline.new([ HTML::Pipeline::MentionFilter, ], :base_url => src, :username_pattern => mention_username_pattern) end def mention_username_pattern @mention_username_pattern ||= %r![\w][\w-]*! end # Public: Filters hash where the key is the mention base URL. # Effectively a cache. def filters @filters ||= {} end # Public: Calculate the base URL to use for mentioning. # # The custom base URL can be defined in either the site config or a document's # front matter as `jekyll-mentions.base_url` or `jekyll-mentions`, and must be # a valid URL (i.e. it must include a protocol and valid domain). # It should _not_ have a trailing slash. # # config - The effective configuration that includes configurations for mentions. # # 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"] case mention_config when nil, NilClass default_mention_base when String mention_config.to_s when Hash mention_config.fetch("base_url", default_mention_base) else raise InvalidJekyllMentionConfig, "Your jekyll-mentions config has to either be a string or a hash. " \ "It's a #{mention_config.class} right now." end end # Public: Defines the conditions for a document to be mentionable. # # doc - the Jekyll::Document or Jekyll::Page # # Returns true if the doc is written & is HTML. def mentionable?(doc) (doc.is_a?(Jekyll::Page) || doc.write?) && (doc.output_ext == ".html" || (doc.permalink&.end_with?("/"))) && (doc.data["jekyll-mentions"] != false) end private def filter_regex @filter_regex ||= begin Regexp.new( HTML::Pipeline::MentionFilter::MentionPatterns[mention_username_pattern] ) rescue TypeError %r!@\w+! end end def default_mention_base if !ENV["SSL"].to_s.empty? && !ENV["GITHUB_HOSTNAME"].to_s.empty? scheme = ENV["SSL"] == "true" ? "https://" : "http://" "#{scheme}#{ENV["GITHUB_HOSTNAME"].chomp("/")}" else GITHUB_DOT_COM end end end end end Jekyll::Hooks.register [:pages, :documents], :post_render do |doc| Jekyll::Mentions.mentionify(doc) if Jekyll::Mentions.mentionable?(doc) end jekyll-mentions-1.6.0/lib/jekyll-mentions/000077500000000000000000000000001363014550500205365ustar00rootroot00000000000000jekyll-mentions-1.6.0/lib/jekyll-mentions/version.rb000066400000000000000000000001151363014550500225450ustar00rootroot00000000000000# frozen_string_literal: true module JekyllMentions VERSION = "1.6.0" end jekyll-mentions-1.6.0/script/000077500000000000000000000000001363014550500161505ustar00rootroot00000000000000jekyll-mentions-1.6.0/script/bootstrap000077500000000000000000000000421363014550500201070ustar00rootroot00000000000000#! /bin/sh bundle install -j8 $@ jekyll-mentions-1.6.0/script/cibuild000077500000000000000000000001021363014550500175020ustar00rootroot00000000000000#! /bin/sh set -e script/test script/fmt bundle exec rake build jekyll-mentions-1.6.0/script/fmt000077500000000000000000000003401363014550500166610ustar00rootroot00000000000000#!/bin/bash set -e echo "Rubocop $(bundle exec rubocop --version)" bundle exec rubocop -D -E $@ success=$? if ((success != 0)); then echo -e "\nTry running \`script/fmt -a\` to automatically fix errors" fi exit $success jekyll-mentions-1.6.0/script/release000077500000000000000000000001251363014550500175140ustar00rootroot00000000000000#!/bin/sh # Tag and push a release. set -e script/cibuild bundle exec rake release jekyll-mentions-1.6.0/script/test000077500000000000000000000000541363014550500170540ustar00rootroot00000000000000#!/bin/bash set -ex bundle exec rspec "$@" jekyll-mentions-1.6.0/spec/000077500000000000000000000000001363014550500155765ustar00rootroot00000000000000jekyll-mentions-1.6.0/spec/fixtures/000077500000000000000000000000001363014550500174475ustar00rootroot00000000000000jekyll-mentions-1.6.0/spec/fixtures/_config.yml000066400000000000000000000000461363014550500215760ustar00rootroot00000000000000collections: docs: output: true jekyll-mentions-1.6.0/spec/fixtures/_docs/000077500000000000000000000000001363014550500205365ustar00rootroot00000000000000jekyll-mentions-1.6.0/spec/fixtures/_docs/dont_touch_me.txt000066400000000000000000000000621363014550500241240ustar00rootroot00000000000000--- title: Don't Touch Me --- test @TestUser test jekyll-mentions-1.6.0/spec/fixtures/_docs/file.md000066400000000000000000000000351363014550500217750ustar00rootroot00000000000000--- --- test @TestUser test jekyll-mentions-1.6.0/spec/fixtures/_docs/special_characters.md000066400000000000000000000002301363014550500246720ustar00rootroot00000000000000--- title: Unconventional Names --- Howdy @-pardner! @haTTric- sez you are quite the @task-master.. Checkout @Casino_Royale The Original @_Bat_Cave jekyll-mentions-1.6.0/spec/fixtures/_docs/with_liquid.md000066400000000000000000000001351363014550500234010ustar00rootroot00000000000000--- title: With Liquid --- test @TestUser test {{ page.path }} jekyll-mentions-1.6.0/spec/fixtures/_layouts/000077500000000000000000000000001363014550500213065ustar00rootroot00000000000000jekyll-mentions-1.6.0/spec/fixtures/_layouts/default.html000066400000000000000000000004531363014550500236220ustar00rootroot00000000000000 {{ page.title }} {{ content }} jekyll-mentions-1.6.0/spec/fixtures/_layouts/minified.html000066400000000000000000000004041363014550500237560ustar00rootroot00000000000000{{ page.title }}{{ content }} jekyll-mentions-1.6.0/spec/fixtures/_layouts/multiline_body_tag.html000066400000000000000000000004621363014550500260500ustar00rootroot00000000000000 {{ page.title }} {{ content }} jekyll-mentions-1.6.0/spec/fixtures/_posts/000077500000000000000000000000001363014550500207565ustar00rootroot00000000000000jekyll-mentions-1.6.0/spec/fixtures/_posts/2016-01-01-awesome-post.md000066400000000000000000000000571363014550500247470ustar00rootroot00000000000000--- title: I'm a post --- test @TestUser test jekyll-mentions-1.6.0/spec/fixtures/_posts/2016-03-08-code-block.md000066400000000000000000000001261363014550500243340ustar00rootroot00000000000000--- --- ```ruby def test_output "test @TestUser test" end ``` test @TestUser test jekyll-mentions-1.6.0/spec/fixtures/custom-url-01.md000066400000000000000000000001411363014550500223150ustar00rootroot00000000000000--- title: custom URL 01 jekyll-mentions: https://custom-url.com --- test @TestUser test > test jekyll-mentions-1.6.0/spec/fixtures/custom-url-02.md000066400000000000000000000001551363014550500223230ustar00rootroot00000000000000--- title: custom URL 02 jekyll-mentions: base_url: https://custom-url.com --- test @TestUser test > test jekyll-mentions-1.6.0/spec/fixtures/disabled-mentioning.md000066400000000000000000000001261363014550500237040ustar00rootroot00000000000000--- title: ignore all mentions jekyll-mentions: false --- test @TestUser test > test jekyll-mentions-1.6.0/spec/fixtures/index.md000066400000000000000000000000771363014550500211040ustar00rootroot00000000000000--- layout: default title: I'm a page --- test @TestUser test jekyll-mentions-1.6.0/spec/fixtures/leave-liquid-alone.md000066400000000000000000000001351363014550500234450ustar00rootroot00000000000000--- title: don't mangle that liquid plz --- test @TestUser testtestjekyll-mentions-1.6.0/spec/fixtures/mentioned-markdown.md000066400000000000000000000001171363014550500235720ustar00rootroot00000000000000--- title: mention me but don't eff my markdown --- test @TestUser test > testjekyll-mentions-1.6.0/spec/fixtures/minified.md000066400000000000000000000001031363014550500215470ustar00rootroot00000000000000--- layout: minified title: I'm minified! --- test @TestUser test jekyll-mentions-1.6.0/spec/fixtures/multiline-body-tag.md000066400000000000000000000001231363014550500234730ustar00rootroot00000000000000--- layout: multiline_body_tag title: Multi-line Body Tag --- test @TestUser test jekyll-mentions-1.6.0/spec/fixtures/non-mentioned.md000066400000000000000000000000761363014550500225460ustar00rootroot00000000000000--- title: don't mention me bro --- test TestUser test > testjekyll-mentions-1.6.0/spec/fixtures/parkr.txt000066400000000000000000000001041363014550500213220ustar00rootroot00000000000000--- title: Parker Moore type: author-info --- Parker "@parkr" Moorejekyll-mentions-1.6.0/spec/fixtures/test.json000066400000000000000000000000561363014550500213220ustar00rootroot00000000000000--- title: I'm a page --- test @TestUser testjekyll-mentions-1.6.0/spec/mentions_spec.rb000066400000000000000000000176471363014550500210100ustar00rootroot00000000000000# frozen_string_literal: true 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") ) ) end let(:mentions) { described_class } let(:default_src) { "https://github.com" } let(:site) { Jekyll::Site.new(configs) } let(:unrendered) { "test @TestUser test" } let(:result) { "test @TestUser test" } let(:posts) { site.posts.docs.sort.reverse } let(:basic_post) { find_by_title(posts, "I'm a post") } let(:complex_post) { find_by_title(posts, "Code Block") } let(:basic_doc) { find_by_title(site.collections["docs"].docs, "File") } let(:doc_with_liquid) { find_by_title(site.collections["docs"].docs, "With Liquid") } let(:txt_doc) { find_by_title(site.collections["docs"].docs, "Don't Touch Me") } let(:spl_chars_doc) { find_by_title(site.collections["docs"].docs, "Unconventional Names") } let(:index_page) { find_by_title(site.pages, "I'm a page") } let(:minified_page) { find_by_title(site.pages, "I'm minified!") } let(:disabled_mentioning_page) { find_by_title(site.pages, "ignore all mentions") } let(:custom_url_01) { find_by_title(site.pages, "custom URL 01") } let(:custom_url_02) { find_by_title(site.pages, "custom URL 02") } def para(content) "

#{content}

" end before(:each) do site.reset site.read (site.pages | posts | site.docs_to_write).each { |p| p.content.strip! } site.render end it "creates a filter" do expect(mentions.filters[default_src]).to be_a(HTML::Pipeline) end it "has a default source" do expect(mentions.mention_base).to eql(default_src) end it "correctly replaces the mentions with the img in posts" do expect(basic_post.output).to start_with(para(result)) end it "doesn't replace mentions in a code block" do expect(complex_post.output).to include( "\"test @TestUser test\"" ) expect(complex_post.output).to include(result) end it "correctly replaces the mentions with the link in pages" do expect(index_page.output).to include(para(result)) end it "correctly replaces the mentions with the link in minified pages" do expect(minified_page.output).to include(para(result)) end it "doesn't mangle layouts" do expect(index_page.output).to include("") expect(index_page.output).to include("\n") end it "correctly replaces the mentions with the link in collection documents" do expect(basic_doc.output).to start_with(para(result)) end it "leaves non-HTML files alone" do expect(txt_doc.output).to start_with(unrendered) end it "does not mangle liquid templates" do expect(doc_with_liquid.output).to start_with( para("#{result} _docs/with_liquid.md") ) end it "works with HTML body tag markup across multiple lines" do expect(find_by_title(site.pages, "Multi-line Body Tag").output).to include(para(result)) end context "when jekyll-mentions is set to false" do it "should not replace the @TestUser with the link to @TestUser" do expect(disabled_mentioning_page.output).not_to include(result) end it "should leave other pages in the site alone and mention as normal" do expect(index_page.output).to include(result) end end context "when the jekyll-mentions is overridden on a single file" do let(:custom_url_result) do "@TestUser" end context "when overriden in pattern 'jekyll-mentions: custom_url'" do it "should replace the mentions with the link in that specific file" do expect(custom_url_01.output).to include(custom_url_result) end it "should not include the default URL" do expect(custom_url_01.output).not_to include(result) end it "should leave other pages in the site alone and mention as normal" do expect(index_page.output).to include(result) end end context "when overriden in pattern 'jekyll-mentions.base_url: custom_url'" do it "should replace the mentions with the link in that specific file" do expect(custom_url_02.output).to include(custom_url_result) end it "should not include the default URL" do expect(custom_url_02.output).not_to include(result) end it "should leave other pages in the site alone and mention as normal" do expect(index_page.output).to include(result) end end end context "with non-word characters" do it "does not render when there's a leading hyphen" do expect(spl_chars_doc.output).to start_with(para("Howdy @-pardner!")) end it "renders fine when there's a non-leading hyphen" do expect(spl_chars_doc.output).to include( para( "@haTTric- sez you are quite " \ "the @task-master.." ) ) end it "renders fine when there's an underscore" do expect(spl_chars_doc.output).to include( para( "Checkout @Casino_Royale" ) ) expect(spl_chars_doc.output).to include( para( "The Original @_Bat_Cave" ) ) end end context "with a different base for jmentions" do let(:mentions_src) { "https://twitter.com" } let(:config_overrides) do { "jekyll-mentions" => { "base_url" => mentions_src }, } end it "fetches the custom base from the config" do expect(mentions.mention_base(site.config)).to eql(mentions_src) end it "respects the new base when mentionifying" do expect(basic_post.output).to start_with(para(result.sub(default_src, mentions_src))) end end context "when the different base is defined in the front matter of the doc" do let(:mentions_src) { "https://twitter.com" } let(:doc_overrides) do { "jekyll-mentions" => { "base_url" => mentions_src }, } end let(:config_overrides) do { "jekyll-mentions" => { "base_url" => default_src }, } end it "fetches the custom base from the config" do effective_overrides = site.config.merge(doc_overrides) expect(mentions.mention_base(effective_overrides)).to eql(mentions_src) end end context "with the SSL and GITHUB_HOSTNAME environment variables set" do let(:ssl) { "true" } let(:github_hostname) { "github.vm" } let(:default_mention_base) { "https://github.vm" } before(:each) do ENV["SSL"] = ssl ENV["GITHUB_HOSTNAME"] = github_hostname end after(:each) do ENV.delete("SSL") ENV.delete("GITHUB_HOSTNAME") end it "has a default source based on SSL and GITHUB_HOSTNAME" do expect(mentions.mention_base).to eql(default_mention_base) end it "uses correct mention URLs when SSL and GITHUB_HOSTNAME are set" do # Re-render the site, so that ENV is used site.render expect(basic_post.output).to start_with(para(result.sub(default_src, default_mention_base))) end it "falls back to using the default if SSL is empty" do ENV["SSL"] = "" expect(mentions.mention_base).to eql(default_src) end it "falls back to using the default if GITHUB_HOSTNAME is empty" do ENV["GITHUB_HOSTNAME"] = "" expect(mentions.mention_base).to eql(default_src) end end end jekyll-mentions-1.6.0/spec/spec_helper.rb000066400000000000000000000057161363014550500204250ustar00rootroot00000000000000# frozen_string_literal: true require File.expand_path("../lib/jekyll-mentions.rb", __dir__) RSpec.configure do |config| FIXTURES_DIR = File.expand_path("fixtures", __dir__) def fixtures_dir(*paths) File.join(FIXTURES_DIR, *paths) end def find_by_title(docs, title) docs.find { |d| d.data["title"] == title } end # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. config.expect_with :rspec do |expectations| # This option will default to `true` in RSpec 4. It makes the `description` # and `failure_message` of custom matchers include text for helper methods # defined using `chain`, e.g.: # be_bigger_than(2).and_smaller_than(4).description # # => "be bigger than 2 and smaller than 4" # ...rather than: # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end # rspec-mocks config goes here. You can use an alternate test double # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| # Prevents you from mocking or stubbing a method that does not exist on # a real object. This is generally recommended, and will default to # `true` in RSpec 4. mocks.verify_partial_doubles = true end # These two settings work together to allow you to limit a spec run # to individual examples or groups you care about by tagging them with # `:focus` metadata. When nothing is tagged with `:focus`, all examples # get run. config.filter_run :focus config.run_all_when_everything_filtered = true # Limits the available syntax to the non-monkey patched syntax that is recommended. # For more details, see: # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching config.disable_monkey_patching! # This setting enables warnings. It's recommended, but in some cases may # be too noisy due to issues in dependencies. config.warnings = false # Print the 10 slowest examples and example groups at the # end of the spec run, to help surface which specs are running # particularly slow. # config.profile_examples = 10 # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = :random # Seed global randomization in this process using the `--seed` CLI option. # Setting this allows you to use `--seed` to deterministically reproduce # test failures related to randomization by passing the same `--seed` value # as the one that triggered the failure. Kernel.srand config.seed end