diff --git a/.rspec b/.rspec index 5f164763..2559e39f 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,3 @@ --color --format progress +--require spec_helper diff --git a/Gemfile b/Gemfile index be173b20..db52f9e9 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,6 @@ source "https://rubygems.org" gemspec + +# Whitelisted plugins not included in runtime dependencies. +gem "jekyll-octicons" diff --git a/lib/github-pages/configuration.rb b/lib/github-pages/configuration.rb index 563411db..f6db2afa 100644 --- a/lib/github-pages/configuration.rb +++ b/lib/github-pages/configuration.rb @@ -137,19 +137,7 @@ def debug_print_versions # Set the site's configuration with all the proper defaults and overrides. # Should be called by #set to protect against multiple processings. def set!(site) - config = effective_config(site.config) - - # Assign everything to the site - site.instance_variable_set :@config, config - - # Ensure all - CONFIGS_WITH_METHODS.each do |opt| - site.public_send("#{opt}=", site.config[opt]) - end - - # While Configuration renamed the gems key to plugins, Site retained - # backwards compatability and must be set manually - site.gems = site.config["plugins"] + site.config = effective_config(site.config) end end end diff --git a/lib/github-pages/dependencies.rb b/lib/github-pages/dependencies.rb index fc9091bc..948df71a 100644 --- a/lib/github-pages/dependencies.rb +++ b/lib/github-pages/dependencies.rb @@ -7,11 +7,11 @@ module GitHubPages class Dependencies VERSIONS = { # Jekyll - "jekyll" => "3.5.2", + "jekyll" => "3.6.0", "jekyll-sass-converter" => "1.5.0", # Converters - "kramdown" => "1.13.2", + "kramdown" => "1.14.0", "redcarpet" => "3.3.4", # Misc @@ -21,19 +21,19 @@ class Dependencies # Plugins "jekyll-redirect-from" => "0.12.1", - "jekyll-sitemap" => "1.0.0", + "jekyll-sitemap" => "1.1.1", "jekyll-feed" => "0.9.2", "jekyll-gist" => "1.4.1", "jekyll-paginate" => "1.1.0", - "jekyll-coffeescript" => "1.0.1", + "jekyll-coffeescript" => "1.0.2", "jekyll-seo-tag" => "2.3.0", - "jekyll-github-metadata" => "2.9.1", - "jekyll-avatar" => "0.4.2", + "jekyll-github-metadata" => "2.9.3", + "jekyll-avatar" => "0.5.0", # Plugins to match GitHub.com Markdown - "jemoji" => "0.8.0", + "jemoji" => "0.8.1", "jekyll-mentions" => "1.2.0", - "jekyll-relative-links" => "0.4.1", + "jekyll-relative-links" => "0.5.0", "jekyll-optional-front-matter" => "0.2.0", "jekyll-readme-index" => "0.1.0", "jekyll-default-layout" => "0.1.4", @@ -44,7 +44,7 @@ class Dependencies "listen" => "3.0.6", # Pin activesupport because 5.0 is broken on 2.1 - "activesupport" => "4.2.8", + "activesupport" => "4.2.9", }.freeze # Jekyll and related dependency versions as used by GitHub Pages. diff --git a/lib/github-pages/plugins.rb b/lib/github-pages/plugins.rb index d3cd82d2..369b25ea 100644 --- a/lib/github-pages/plugins.rb +++ b/lib/github-pages/plugins.rb @@ -35,6 +35,7 @@ class Plugins jekyll-default-layout jekyll-titles-from-headings jekyll-include-cache + jekyll-octicons ).freeze # Plugins only allowed locally diff --git a/lib/github-pages/version.rb b/lib/github-pages/version.rb index 6dc1d332..ae6f5012 100644 --- a/lib/github-pages/version.rb +++ b/lib/github-pages/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module GitHubPages - VERSION = 157 + VERSION = 164 .to_s + '-siteleaf'.freeze end diff --git a/spec/fixtures/Gemfile b/spec/fixtures/Gemfile new file mode 100644 index 00000000..b7a0058e --- /dev/null +++ b/spec/fixtures/Gemfile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "github-pages", :group => :jekyll_plugins, :path => "../../" +gem "jekyll_test_plugin_malicious" + +# Whitelisted plugins not included in runtime dependencies. +gem "jekyll-octicons", :group => :jekyll_plugins diff --git a/spec/fixtures/_config.yml b/spec/fixtures/_config.yml index f72783a5..9e3ba69b 100644 --- a/spec/fixtures/_config.yml +++ b/spec/fixtures/_config.yml @@ -2,5 +2,17 @@ some_key: some_value safe: false gems: - jekyll-sitemap + - jekyll-redirect-from + - jekyll-feed + - jekyll-octicons + - jekyll-paginate + - jekyll-seo-tag + - jekyll-avatar + - jemoji + - jekyll-mentions - jekyll_test_plugin_malicious quiet: false +paginate: 5 +github: + source: + branch: gh-pages diff --git a/spec/fixtures/_layouts/page.md b/spec/fixtures/_layouts/page.md new file mode 100644 index 00000000..801832c7 --- /dev/null +++ b/spec/fixtures/_layouts/page.md @@ -0,0 +1,4 @@ +--- +--- + +{{ content }} diff --git a/spec/fixtures/_posts/2017-01-10-test.md b/spec/fixtures/_posts/2017-01-10-test.md new file mode 100644 index 00000000..27701318 --- /dev/null +++ b/spec/fixtures/_posts/2017-01-10-test.md @@ -0,0 +1,4 @@ +--- +--- + +# test diff --git a/spec/fixtures/index.html b/spec/fixtures/index.html new file mode 100644 index 00000000..74a4fbed --- /dev/null +++ b/spec/fixtures/index.html @@ -0,0 +1,6 @@ +--- +--- + +Page: {{ paginator.page }} + +Total Pages: {{ paginator.total_pages }} diff --git a/spec/fixtures/jekyll-avatar.html b/spec/fixtures/jekyll-avatar.html new file mode 100644 index 00000000..d3100991 --- /dev/null +++ b/spec/fixtures/jekyll-avatar.html @@ -0,0 +1,4 @@ +--- +--- + +{% avatar hubot %} diff --git a/spec/fixtures/jekyll-coffeescript.coffee b/spec/fixtures/jekyll-coffeescript.coffee new file mode 100644 index 00000000..40459fa7 --- /dev/null +++ b/spec/fixtures/jekyll-coffeescript.coffee @@ -0,0 +1,4 @@ +--- +--- + +console.log "hello world" diff --git a/spec/fixtures/jekyll-default-layout.md b/spec/fixtures/jekyll-default-layout.md new file mode 100644 index 00000000..76eca68a --- /dev/null +++ b/spec/fixtures/jekyll-default-layout.md @@ -0,0 +1,4 @@ +--- +--- + +This page's layout is "{{ page.layout }}" diff --git a/spec/fixtures/jekyll-gist.md b/spec/fixtures/jekyll-gist.md new file mode 100644 index 00000000..03e2ee5c --- /dev/null +++ b/spec/fixtures/jekyll-gist.md @@ -0,0 +1,4 @@ +--- +--- + +{% gist parkr/c08ee0f2726fd0e3909d %} diff --git a/spec/fixtures/jekyll-github-metadata.html b/spec/fixtures/jekyll-github-metadata.html new file mode 100644 index 00000000..b323c391 --- /dev/null +++ b/spec/fixtures/jekyll-github-metadata.html @@ -0,0 +1,4 @@ +--- +--- + +Branch: {{ site.github.source.branch }} diff --git a/spec/fixtures/jekyll-mentions.md b/spec/fixtures/jekyll-mentions.md new file mode 100644 index 00000000..26a8061e --- /dev/null +++ b/spec/fixtures/jekyll-mentions.md @@ -0,0 +1,4 @@ +--- +--- + +@jekyll diff --git a/spec/fixtures/jekyll-octicons.md b/spec/fixtures/jekyll-octicons.md new file mode 100644 index 00000000..06cd7a98 --- /dev/null +++ b/spec/fixtures/jekyll-octicons.md @@ -0,0 +1,4 @@ +--- +--- + +{% octicon alert height:32 class:"right left" aria-label:hi %} diff --git a/spec/fixtures/jekyll-optional-front-matter.md b/spec/fixtures/jekyll-optional-front-matter.md new file mode 100644 index 00000000..e30c8c03 --- /dev/null +++ b/spec/fixtures/jekyll-optional-front-matter.md @@ -0,0 +1 @@ +# File without front matter diff --git a/spec/fixtures/jekyll-readme-index/README.md b/spec/fixtures/jekyll-readme-index/README.md new file mode 100644 index 00000000..7e596007 --- /dev/null +++ b/spec/fixtures/jekyll-readme-index/README.md @@ -0,0 +1 @@ +# README diff --git a/spec/fixtures/jekyll-relative-links.md b/spec/fixtures/jekyll-relative-links.md new file mode 100644 index 00000000..889348d1 --- /dev/null +++ b/spec/fixtures/jekyll-relative-links.md @@ -0,0 +1,5 @@ +--- +--- + + +[Jekyll](jekyll.md) diff --git a/spec/fixtures/jekyll-sass-converter.scss b/spec/fixtures/jekyll-sass-converter.scss new file mode 100644 index 00000000..c770df66 --- /dev/null +++ b/spec/fixtures/jekyll-sass-converter.scss @@ -0,0 +1,8 @@ +--- +--- + +$color: #333; + +body { + color: $color; +} diff --git a/spec/fixtures/jekyll-seo-tag.html b/spec/fixtures/jekyll-seo-tag.html new file mode 100644 index 00000000..1e026768 --- /dev/null +++ b/spec/fixtures/jekyll-seo-tag.html @@ -0,0 +1,5 @@ +--- +title: Jekyll SEO Tag +--- + +{% seo %} diff --git a/spec/fixtures/jekyll-theme-primer.md b/spec/fixtures/jekyll-theme-primer.md new file mode 100644 index 00000000..70122eab --- /dev/null +++ b/spec/fixtures/jekyll-theme-primer.md @@ -0,0 +1,5 @@ +--- +layout: default +--- + +Theme: {{ site.theme }} diff --git a/spec/fixtures/jekyll-titles-from-headings.md b/spec/fixtures/jekyll-titles-from-headings.md new file mode 100644 index 00000000..be0e527f --- /dev/null +++ b/spec/fixtures/jekyll-titles-from-headings.md @@ -0,0 +1,6 @@ +--- +--- + +# First heading + +The page title is "{{ page.title }}" diff --git a/spec/fixtures/jekyll.md b/spec/fixtures/jekyll.md new file mode 100644 index 00000000..fd01db30 --- /dev/null +++ b/spec/fixtures/jekyll.md @@ -0,0 +1,4 @@ +--- +--- + +# Jekyll diff --git a/spec/fixtures/jemoji.md b/spec/fixtures/jemoji.md new file mode 100644 index 00000000..fea9ca7c --- /dev/null +++ b/spec/fixtures/jemoji.md @@ -0,0 +1,4 @@ +--- +--- + +:tada: diff --git a/spec/fixtures/kramdown.md b/spec/fixtures/kramdown.md new file mode 100644 index 00000000..ef355dc0 --- /dev/null +++ b/spec/fixtures/kramdown.md @@ -0,0 +1,4 @@ +--- +--- + +# Test diff --git a/spec/fixtures/liquid.html b/spec/fixtures/liquid.html new file mode 100644 index 00000000..1b70d69b --- /dev/null +++ b/spec/fixtures/liquid.html @@ -0,0 +1,5 @@ +--- +foo: bar +--- + +Value of foo: {{ page.foo }} diff --git a/spec/fixtures/redirect_from.html b/spec/fixtures/redirect_from.html new file mode 100644 index 00000000..1af61da6 --- /dev/null +++ b/spec/fixtures/redirect_from.html @@ -0,0 +1,3 @@ +--- +redirect_from: /redirect/ +--- diff --git a/spec/fixtures/redirect_to.html b/spec/fixtures/redirect_to.html new file mode 100644 index 00000000..8c88da70 --- /dev/null +++ b/spec/fixtures/redirect_to.html @@ -0,0 +1,3 @@ +--- +redirect_to: /someplace-else/ +--- diff --git a/spec/fixtures/rouge.md b/spec/fixtures/rouge.md new file mode 100644 index 00000000..ed8569fd --- /dev/null +++ b/spec/fixtures/rouge.md @@ -0,0 +1,6 @@ +--- +--- + +```ruby +puts "hello world" +``` diff --git a/spec/github-pages/configuration_spec.rb b/spec/github-pages/configuration_spec.rb index 659cedef..6d449c62 100644 --- a/spec/github-pages/configuration_spec.rb +++ b/spec/github-pages/configuration_spec.rb @@ -58,6 +58,29 @@ expect(effective_config["testing"]).to eql("123") end + context "themes" do + context "with no theme set" do + it "sets the theme" do + expect(site.theme).to_not be_nil + expect(site.theme).to be_a(Jekyll::Theme) + expect(site.theme.name).to eql("jekyll-theme-primer") + end + end + + context "with a user-specified theme" do + let(:site) do + config = configuration.merge("theme" => "jekyll-theme-merlot") + Jekyll::Site.new(config) + end + + it "respects the theme" do + expect(site.theme).to_not be_nil + expect(site.theme).to be_a(Jekyll::Theme) + expect(site.theme.name).to eql("jekyll-theme-merlot") + end + end + end + context "in development" do before { ENV["JEKYLL_ENV"] = "development" } diff --git a/spec/github-pages/integration_spec.rb b/spec/github-pages/integration_spec.rb new file mode 100644 index 00000000..158f13f0 --- /dev/null +++ b/spec/github-pages/integration_spec.rb @@ -0,0 +1,234 @@ +# frozen_string_literal: true + +RSpec.describe "Pages Gem Integration spec" do + def destination_file(file) + File.join tmp_dir, file + end + + def source + @source ||= fixture_dir + end + + def destination + @destination ||= tmp_dir + end + + def env + { + "BUNDLE_GEMFILE" => "#{source}/Gemfile", + "JEKYLL_ENV" => "development", + "DISABLE_WHITELIST" => "", # Do not disable the whitelist. + } + end + + let(:file) { "#{self.class.description}.html" } + let(:path) { destination_file file } + let(:contents) { File.read path } + + before(:all) do + FileUtils.rm_rf(destination) + Dir.chdir(source) do + bundle_output, status = Open3.capture2e env, %w(bundle install) + raise StandardError, bundle_output if status.exitstatus != 0 + cmd = %w(bundle exec jekyll build --verbose --trace) + cmd = cmd.concat ["--source", source, "--destination", destination] + build_output, status = Open3.capture2e env, *cmd + raise StandardError, bundle_output + build_output if status.exitstatus != 0 + end + end + after(:all) { FileUtils.rm_rf(destination) } + + it "tests all dependencies" do + contents = File.read(__FILE__) + contexts = contents.scan(/context \"(.*?)\"/) + missing = GitHubPages::Dependencies::VERSIONS.keys - contexts.flatten + missing -= %w(listen activesupport github-pages-health-check) + msg = "The following dependencies are missing integration tests: #{missing.join(", ")}" + expect(missing).to be_empty, msg + end + + context "jekyll" do + it "builds" do + expect(path).to be_an_existing_file + end + end + + context "jekyll-sass-converter" do + let(:file) { "jekyll-sass-converter.css" } + + it "Renders SCSS" do + expect(path).to be_an_existing_file + expect(contents).to match("body { color: #333; }") + end + end + + context "kramdown" do + it "converts markdown to HTML" do + expect(contents).to match('
'
+ expected << 'puts "hello world"'
+ expect(contents).to match(expected)
+ end
+ end
+
+ context "jekyll-redirect-from" do
+ context "redirect_from" do
+ let(:file) { "redirect/index.html" }
+
+ it "redirects from" do
+ expect(path).to be_an_existing_file
+ expected = ''
+ expect(contents).to match(expected)
+ end
+ end
+
+ context "redirect_to" do
+ it "redirects to" do
+ expect(path).to be_an_existing_file
+ expected = ''
+ expect(contents).to match(expected)
+ end
+ end
+ end
+
+ context "jekyll-sitemap" do
+ let(:file) { "sitemap.xml" }
+
+ it "builds the sitemap" do
+ expect(path).to be_an_existing_file
+ expect(contents).to match("/jekyll.html ")
+ end
+ end
+
+ context "jekyll-feed" do
+ let(:file) { "feed.xml" }
+
+ it "builds the feed" do
+ expect(path).to be_an_existing_file
+ expected = 'Test Jekyll SEO Tag")
+ end
+ end
+
+ context "jekyll-github-metadata" do
+ it "builds the site.github namespace" do
+ expect(contents).to match("Branch: gh-pages")
+ end
+ end
+
+ context "jekyll-avatar" do
+ it "renders the avatar" do
+ expected = %r{https://avatars\d\.githubusercontent\.com/hubot\?v=3&s=40}
+ expect(contents).to match(expected)
+ end
+ end
+
+ context "jemoji" do
+ it "renders emoji" do
+ expect(contents).to match('@jekyll')
+ end
+ end
+
+ context "jekyll-relative-links" do
+ it "converts relative links" do
+ expect(contents).to match('Jekyll')
+ end
+ end
+
+ context "jekyll-optional-front-matter" do
+ it "renders pages without front matter" do
+ expect(path).to be_an_existing_file
+ expected = 'File without front matter
'
+ expect(contents).to match(expected)
+ end
+ end
+
+ context "jekyll-titles-from-headings" do
+ it "pulls titles from headings" do
+ expect(contents).to match("The page title is “First heading”")
+ end
+ end
+
+ context "jekyll-default-layout" do
+ it "sets the default layout" do
+ expect(contents).to match("This page’s layout is “page”")
+ end
+ end
+
+ context "jekyll-readme-index" do
+ let(:file) { "jekyll-readme-index/index.html" }
+
+ it "uses the README as the index" do
+ expect(path).to be_an_existing_file
+ expect(contents).to match("README")
+ end
+ end
+
+ context "jekyll-theme-primer" do
+ it "sets the theme" do
+ expect(contents).to match("Theme: jekyll-theme-primer")
+ end
+
+ it "uses the theme" do
+ expect(contents).to match('')
+ end
+ end
+
+ context "jekyll-octicons" do
+ it "plops in the octicon" do
+ expect(contents).to match('