diff --git a/.codeclimate.yml b/.codeclimate.yml index f64d0bfabe0..b86672f4316 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -3,7 +3,7 @@ engines: enabled: false rubocop: enabled: true - channel: rubocop-0-49 + channel: rubocop-0-54 exclude_paths: - .codeclimate.yml @@ -29,6 +29,8 @@ exclude_paths: - test/**/* - vendor/**/* + - lib/jekyll/commands/serve/livereload_assets/livereload.js + ratings: paths: - lib/**/*.rb diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index fdba86159e2..73c8928dbbe 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -48,7 +48,7 @@ ## My Reproduction Steps - -{% endif %} - {% if site.google_analytics_id %} ").strip - end - - context "with pygments enabled" do - setup do - @markdown = Converters::Markdown.new @config.merge( - { "highlighter" => "pygments" } - ) - end - - should "render fenced code blocks with syntax highlighting" do - assert_equal( - %(
puts "Hello world"\n
), - @markdown.convert(@sample).strip - ) - end - end - - context "with rouge enabled" do - setup do - @markdown = Converters::Markdown.new @config.merge({ "highlighter" => "rouge" }) - end - - should "render fenced code blocks with syntax highlighting" do - assert_equal( - %(
puts "Hello world"\n
), - @markdown.convert(@sample).strip - ) - end - end - - context "without any highlighter" do - setup do - @markdown = Converters::Markdown.new @config.merge({ "highlighter" => nil }) - end - - should "render fenced code blocks without syntax highlighting" do - assert_equal( - %(
puts "Hello world"\n
), - @markdown.convert(@sample).strip - ) - end - end - end -end diff --git a/test/test_regenerator.rb b/test/test_regenerator.rb index 3a5d35a8aa8..39b28baa4e7 100644 --- a/test/test_regenerator.rb +++ b/test/test_regenerator.rb @@ -7,14 +7,14 @@ class TestRegenerator < JekyllUnitTest setup do FileUtils.rm_rf(source_dir(".jekyll-metadata")) - @site = fixture_site({ + @site = fixture_site( "collections" => { "methods" => { "output" => true, }, }, - "incremental" => true, - }) + "incremental" => true + ) @site.read @page = @site.pages.first @@ -93,9 +93,9 @@ class TestRegenerator < JekyllUnitTest context "The site regenerator" do setup do FileUtils.rm_rf(source_dir(".jekyll-metadata")) - @site = fixture_site({ - "incremental" => true, - }) + @site = fixture_site( + "incremental" => true + ) @site.read @post = @site.posts.first @@ -128,11 +128,11 @@ class TestRegenerator < JekyllUnitTest setup do FileUtils.rm_rf(source_dir(".jekyll-metadata")) - @site = Site.new(Jekyll.configuration({ - "source" => source_dir, - "destination" => dest_dir, - "incremental" => true, - })) + @site = Site.new(Jekyll.configuration( + "source" => source_dir, + "destination" => dest_dir, + "incremental" => true + )) @site.process @path = @site.in_source_dir(@site.pages.first.path) @@ -153,7 +153,8 @@ class TestRegenerator < JekyllUnitTest assert @regenerator.cache[@path] @regenerator.clear_cache - assert_equal @regenerator.cache, {} + expected = {} + assert_equal expected, @regenerator.cache end should "write to the metadata file" do @@ -183,7 +184,7 @@ class TestRegenerator < JekyllUnitTest should "not crash when reading corrupted marshal file" do metadata_file = source_dir(".jekyll-metadata") File.open(metadata_file, "w") do |file| - file.puts Marshal.dump({ :foo => "bar" })[0, 5] + file.puts Marshal.dump(:foo => "bar")[0, 5] end @regenerator = Regenerator.new(@site) @@ -310,11 +311,11 @@ class TestRegenerator < JekyllUnitTest context "when incremental regeneration is disabled" do setup do FileUtils.rm_rf(source_dir(".jekyll-metadata")) - @site = Site.new(Jekyll.configuration({ - "source" => source_dir, - "destination" => dest_dir, - "incremental" => false, - })) + @site = Site.new(Jekyll.configuration( + "source" => source_dir, + "destination" => dest_dir, + "incremental" => false + )) @site.process @path = @site.in_source_dir(@site.pages.first.path) diff --git a/test/test_related_posts.rb b/test/test_related_posts.rb index d6a8fe6f1f3..7f9a978f1a5 100644 --- a/test/test_related_posts.rb +++ b/test/test_related_posts.rb @@ -29,9 +29,9 @@ class TestRelatedPosts < JekyllUnitTest end allow_any_instance_of(Jekyll::RelatedPosts).to receive(:display) - @site = fixture_site({ - "lsi" => true, - }) + @site = fixture_site( + "lsi" => true + ) @site.reset @site.read diff --git a/test/test_sass.rb b/test/test_sass.rb index 15b04162f01..686631d6020 100644 --- a/test/test_sass.rb +++ b/test/test_sass.rb @@ -5,10 +5,10 @@ class TestSass < JekyllUnitTest context "importing partials" do setup do - @site = Jekyll::Site.new(Jekyll.configuration({ - "source" => source_dir, - "destination" => dest_dir, - })) + @site = Jekyll::Site.new(Jekyll.configuration( + "source" => source_dir, + "destination" => dest_dir + )) @site.process @test_css_file = dest_dir("css/main.css") end diff --git a/test/test_site.rb b/test/test_site.rb index a9ef16e3af2..63fb63fde66 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -15,7 +15,7 @@ def read_posts @site.posts.docs.concat(PostReader.new(@site).read_posts("")) posts = Dir[source_dir("_posts", "**", "*")] posts.delete_if do |post| - File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER) + File.directory?(post) && post !~ Document::DATE_FILENAME_MATCHER end end @@ -31,15 +31,15 @@ def read_posts end should "have an array for plugins if passed as a string" do - site = Site.new(site_configuration({ "plugins_dir" => "/tmp/plugins" })) + site = Site.new(site_configuration("plugins_dir" => "/tmp/plugins")) array = Utils::Platforms.windows? ? ["C:/tmp/plugins"] : ["/tmp/plugins"] assert_equal array, site.plugins end should "have an array for plugins if passed as an array" do - site = Site.new(site_configuration({ - "plugins_dir" => ["/tmp/plugins", "/tmp/otherplugins"], - })) + site = Site.new(site_configuration( + "plugins_dir" => ["/tmp/plugins", "/tmp/otherplugins"] + )) array = if Utils::Platforms.windows? ["C:/tmp/plugins", "C:/tmp/otherplugins"] else @@ -49,34 +49,34 @@ def read_posts end should "have an empty array for plugins if nothing is passed" do - site = Site.new(site_configuration({ "plugins_dir" => [] })) + site = Site.new(site_configuration("plugins_dir" => [])) assert_equal [], site.plugins end should "have the default for plugins if nil is passed" do - site = Site.new(site_configuration({ "plugins_dir" => nil })) + site = Site.new(site_configuration("plugins_dir" => nil)) assert_equal [source_dir("_plugins")], site.plugins end - should "expose default baseurl" do + should "default baseurl to `nil`" do site = Site.new(default_configuration) - assert_equal Jekyll::Configuration::DEFAULTS["baseurl"], site.baseurl + assert_nil site.baseurl end should "expose baseurl passed in from config" do - site = Site.new(site_configuration({ "baseurl" => "/blog" })) + site = Site.new(site_configuration("baseurl" => "/blog")) assert_equal "/blog", site.baseurl end should "only include theme includes_path if the path exists" do - site = fixture_site({ "theme" => "test-theme" }) + site = fixture_site("theme" => "test-theme") assert_equal [source_dir("_includes"), theme_dir("_includes")], - site.includes_load_paths + site.includes_load_paths allow(File).to receive(:directory?).with(theme_dir("_sass")).and_return(true) allow(File).to receive(:directory?).with(theme_dir("_layouts")).and_return(true) allow(File).to receive(:directory?).with(theme_dir("_includes")).and_return(false) - site = fixture_site({ "theme" => "test-theme" }) + site = fixture_site("theme" => "test-theme") assert_equal [source_dir("_includes")], site.includes_load_paths end end @@ -87,9 +87,7 @@ def read_posts end teardown do - if defined?(MyGenerator) - self.class.send(:remove_const, :MyGenerator) - end + self.class.send(:remove_const, :MyGenerator) if defined?(MyGenerator) end should "have an empty tag hash by default" do @@ -279,7 +277,7 @@ def generate(site) posts = Dir[source_dir("**", "_posts", "**", "*")] posts.delete_if do |post| - File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER) + File.directory?(post) && post !~ Document::DATE_FILENAME_MATCHER end categories = %w( 2013 bar baz category foo z_category MixedCase Mixedcase publish_test win @@ -305,9 +303,9 @@ def generate(site) should "raise for bad frontmatter if strict_front_matter is set" do site = Site.new(site_configuration( - "collections" => ["broken"], - "strict_front_matter" => true - )) + "collections" => ["broken"], + "strict_front_matter" => true + )) assert_raises(Psych::SyntaxError) do site.process end @@ -315,9 +313,9 @@ def generate(site) should "not raise for bad frontmatter if strict_front_matter is not set" do site = Site.new(site_configuration( - "collections" => ["broken"], - "strict_front_matter" => false - )) + "collections" => ["broken"], + "strict_front_matter" => false + )) site.process end end @@ -412,9 +410,9 @@ def convert(*_args) bad_processor = "Custom::Markdown" s = Site.new(site_configuration( - "markdown" => bad_processor, - "incremental" => false - )) + "markdown" => bad_processor, + "incremental" => false + )) assert_raises Jekyll::Errors::FatalException do s.process end @@ -433,9 +431,9 @@ def convert(*_args) should "throw FatalException at process time" do bad_processor = "not a processor name" s = Site.new(site_configuration( - "markdown" => bad_processor, - "incremental" => false - )) + "markdown" => bad_processor, + "incremental" => false + )) assert_raises Jekyll::Errors::FatalException do s.process end @@ -489,8 +487,8 @@ def convert(*_args) site.process file_content = SafeYAML.load_file(File.join( - source_dir, "_data", "categories", "dairy.yaml" - )) + source_dir, "_data", "categories", "dairy.yaml" + )) assert_equal site.data["categories"]["dairy"], file_content assert_equal( @@ -504,8 +502,8 @@ def convert(*_args) site.process file_content = SafeYAML.load_file(File.join( - source_dir, "_data", "categories.01", "dairy.yaml" - )) + source_dir, "_data", "categories.01", "dairy.yaml" + )) assert_equal site.data["categories01"]["dairy"], file_content assert_equal( @@ -536,9 +534,9 @@ def convert(*_args) context "manipulating the Jekyll environment" do setup do - @site = Site.new(site_configuration({ - "incremental" => false, - })) + @site = Site.new(site_configuration( + "incremental" => false + )) @site.process @page = @site.pages.find { |p| p.name == "environment.html" } end @@ -550,9 +548,9 @@ def convert(*_args) context "in production" do setup do ENV["JEKYLL_ENV"] = "production" - @site = Site.new(site_configuration({ - "incremental" => false, - })) + @site = Site.new(site_configuration( + "incremental" => false + )) @site.process @page = @site.pages.find { |p| p.name == "environment.html" } end @@ -571,13 +569,13 @@ def convert(*_args) should "set no theme if config is not set" do expect($stderr).not_to receive(:puts) expect($stdout).not_to receive(:puts) - site = fixture_site({ "theme" => nil }) + site = fixture_site("theme" => nil) assert_nil site.theme end should "set no theme if config is a hash" do output = capture_output do - site = fixture_site({ "theme" => {} }) + site = fixture_site("theme" => {}) assert_nil site.theme end expected_msg = "Theme: value of 'theme' in config should be String " \ @@ -589,7 +587,7 @@ def convert(*_args) [:debug, :info, :warn, :error].each do |level| expect(Jekyll.logger.writer).not_to receive(level) end - site = fixture_site({ "theme" => "test-theme" }) + site = fixture_site("theme" => "test-theme") assert_instance_of Jekyll::Theme, site.theme assert_equal "test-theme", site.theme.name end @@ -616,9 +614,9 @@ def convert(*_args) context "incremental build" do setup do - @site = Site.new(site_configuration({ - "incremental" => true, - })) + @site = Site.new(site_configuration( + "incremental" => true + )) @site.read end diff --git a/test/test_site_drop.rb b/test/test_site_drop.rb index 43c52d708a5..01f3bed3ffc 100644 --- a/test/test_site_drop.rb +++ b/test/test_site_drop.rb @@ -5,9 +5,9 @@ class TestSiteDrop < JekyllUnitTest context "a site drop" do setup do - @site = fixture_site({ - "collections" => ["thanksgiving"], - }) + @site = fixture_site( + "collections" => ["thanksgiving"] + ) @site.process @drop = @site.to_liquid.site end diff --git a/test/test_static_file.rb b/test/test_static_file.rb index e306d2a299e..96663bacd69 100644 --- a/test/test_static_file.rb +++ b/test/test_static_file.rb @@ -70,7 +70,7 @@ def setup_static_file_with_defaults(base, dir, name, defaults) "root", "_foo/dir/subdir", "file.html", - { "output" => true } + "output" => true ) assert_equal :foo, static_file.type assert_equal "/foo/dir/subdir/file.html", static_file.url @@ -82,7 +82,7 @@ def setup_static_file_with_defaults(base, dir, name, defaults) "root", "_foo/dir/subdir", "file.html", - { "output" => true, "permalink" => "/:path/" } + "output" => true, "permalink" => "/:path/" ) assert_equal :foo, static_file.type assert_equal "/dir/subdir/file.html", static_file.url @@ -92,7 +92,7 @@ def setup_static_file_with_defaults(base, dir, name, defaults) should "be writable by default" do static_file = setup_static_file("root", "dir/subdir", "file.html") assert(static_file.write?, - "static_file.write? should return true by default") + "static_file.write? should return true by default") end should "use the _config.yml defaults to determine writability" do @@ -107,8 +107,8 @@ def setup_static_file_with_defaults(base, dir, name, defaults) defaults ) assert(!static_file.write?, - "static_file.write? should return false when _config.yml sets " \ - "`published: false`") + "static_file.write? should return false when _config.yml sets " \ + "`published: false`") end should "respect front matter defaults" do diff --git a/test/test_tags.rb b/test/test_tags.rb index 5712a9f090b..4141b13b234 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -26,20 +26,20 @@ def create_post(content, override = {}, converter_class = Jekyll::Converters::Ma # rubocop:enable Metrics/AbcSize def fill_post(code, override = {}) - content = < "pygments" }) + fill_post("test", "highlighter" => "pygments") end should "not cause a markdown error" do @@ -202,7 +202,7 @@ def highlight_block_with_opts(options_string) context "post content has highlight with file reference" do setup do - fill_post("./jekyll.gemspec", { "highlighter" => "pygments" }) + fill_post("./jekyll.gemspec", "highlighter" => "pygments") end should "not embed the file" do @@ -216,7 +216,7 @@ def highlight_block_with_opts(options_string) context "post content has highlight tag with UTF character" do setup do - fill_post("Æ", { "highlighter" => "pygments" }) + fill_post("Æ", "highlighter" => "pygments") end should "render markdown with pygments line handling" do @@ -230,14 +230,14 @@ def highlight_block_with_opts(options_string) context "post content has highlight tag with preceding spaces & lines" do setup do - code = <<-EOS + code = <<~EOS - [,1] [,2] -[1,] FALSE TRUE -[2,] FALSE TRUE -EOS - fill_post(code, { "highlighter" => "pygments" }) + [,1] [,2] + [1,] FALSE TRUE + [2,] FALSE TRUE + EOS + fill_post(code, "highlighter" => "pygments") end should "only strip the preceding newlines" do @@ -252,18 +252,18 @@ def highlight_block_with_opts(options_string) context "post content has highlight tag " \ "with preceding spaces & lines in several places" do setup do - code = <<-EOS + code = <<~EOS - [,1] [,2] + [,1] [,2] -[1,] FALSE TRUE -[2,] FALSE TRUE + [1,] FALSE TRUE + [2,] FALSE TRUE -EOS - fill_post(code, { "highlighter" => "pygments" }) + EOS + fill_post(code, "highlighter" => "pygments") end should "only strip the newlines which precede and succeed the entire block" do @@ -278,7 +278,7 @@ def highlight_block_with_opts(options_string) context "post content has highlight tag with " \ "preceding spaces & Windows-style newlines" do setup do - fill_post "\r\n\r\n\r\n [,1] [,2]", { "highlighter" => "pygments" } + fill_post "\r\n\r\n\r\n [,1] [,2]", "highlighter" => "pygments" end should "only strip the preceding newlines" do @@ -292,12 +292,12 @@ def highlight_block_with_opts(options_string) context "post content has highlight tag with only preceding spaces" do setup do - code = <<-EOS - [,1] [,2] -[1,] FALSE TRUE -[2,] FALSE TRUE -EOS - fill_post(code, { "highlighter" => "pygments" }) + code = <<~EOS + [,1] [,2] + [1,] FALSE TRUE + [2,] FALSE TRUE + EOS + fill_post(code, "highlighter" => "pygments") end should "only strip the preceding newlines" do @@ -323,8 +323,7 @@ def highlight_block_with_opts(options_string) ) end - should "render markdown with rouge 2 with line numbers" do - skip "Skipped because using an older version of Rouge" if Utils::Rouge.old_api? + should "render markdown with rouge with line numbers" do assert_match( %() + %(
) + @@ -334,48 +333,25 @@ def highlight_block_with_opts(options_string) @result ) end - - should "render markdown with rouge 1 with line numbers" do - skip "Skipped because using a newer version of Rouge" unless Utils::Rouge.old_api? - assert_match( - %() + - %() + - %() + - %(
) + - %(
1
test\n
), - @result - ) - end end context "post content has raw tag" do setup do - content = <<-CONTENT ---- -title: This is a test ---- - -```liquid -{% raw %} -{{ site.baseurl }}{% link _collection/name-of-document.md %} -{% endraw %} -``` -CONTENT + content = <<~CONTENT + --- + title: This is a test + --- + + ```liquid + {% raw %} + {{ site.baseurl }}{% link _collection/name-of-document.md %} + {% endraw %} + ``` + CONTENT create_post(content) end - should "render markdown with rouge 1" do - skip "Skipped because using a newer version of Rouge" unless Utils::Rouge.old_api? - - assert_match( - %(
),
-          @result
-        )
-      end
-
-      should "render markdown with rouge 2" do
-        skip "Skipped because using an older version of Rouge" if Utils::Rouge.old_api?
-
+      should "render markdown with rouge" do
         assert_match(
           %(
) + %(
),
@@ -413,13 +389,13 @@ def highlight_block_with_opts(options_string)
 
     context "post content has highlight tag with preceding spaces & lines" do
       setup do
-        fill_post <<-EOS
+        fill_post <<~EOS
 
 
-     [,1] [,2]
-[1,] FALSE TRUE
-[2,] FALSE TRUE
-EOS
+               [,1] [,2]
+          [1,] FALSE TRUE
+          [2,] FALSE TRUE
+        EOS
       end
 
       should "only strip the preceding newlines" do
@@ -433,17 +409,17 @@ def highlight_block_with_opts(options_string)
     context "post content has highlight tag with " \
             "preceding spaces & lines in several places" do
       setup do
-        fill_post <<-EOS
+        fill_post <<~EOS
 
 
-     [,1] [,2]
+               [,1] [,2]
 
 
-[1,] FALSE TRUE
-[2,] FALSE TRUE
+          [1,] FALSE TRUE
+          [2,] FALSE TRUE
 
 
-EOS
+        EOS
       end
 
       should "only strip the newlines which precede and succeed the entire block" do
@@ -457,39 +433,27 @@ def highlight_block_with_opts(options_string)
 
     context "post content has highlight tag with linenumbers" do
       setup do
-        create_post <<-EOS
----
-title: This is a test
----
-
-This is not yet highlighted
-{% highlight php linenos %}
-test
-{% endhighlight %}
-
-This should not be highlighted, right?
-EOS
-      end
-
-      should "should stop highlighting at boundary with rouge 2" do
-        skip "Skipped because using an older version of Rouge" if Utils::Rouge.old_api?
-        expected = <<-EOS
-

This is not yet highlighted

\n -
1
-
test
\n -

This should not be highlighted, right?

-EOS - assert_match(expected, @result) - end - - should "should stop highlighting at boundary with rouge 1" do - skip "Skipped because using a newer version of Rouge" unless Utils::Rouge.old_api? - expected = <<-EOS -

This is not yet highlighted

\n -
1
test
-
\n -

This should not be highlighted, right?

-EOS + create_post <<~EOS + --- + title: This is a test + --- + + This is not yet highlighted + {% highlight php linenos %} + test + {% endhighlight %} + + This should not be highlighted, right? + EOS + end + + should "should stop highlighting at boundary with rouge" do + expected = <<~EOS +

This is not yet highlighted

\n +
1
+          
test
\n +

This should not be highlighted, right?

+ EOS assert_match(expected, @result) end end @@ -510,11 +474,11 @@ def highlight_block_with_opts(options_string) context "post content has highlight tag with only preceding spaces" do setup do - fill_post <<-EOS - [,1] [,2] -[1,] FALSE TRUE -[2,] FALSE TRUE -EOS + fill_post <<~EOS + [,1] [,2] + [1,] FALSE TRUE + [2,] FALSE TRUE + EOS end should "only strip the preceding newlines" do @@ -528,38 +492,19 @@ def highlight_block_with_opts(options_string) context "simple post with markdown and pre tags" do setup do - @content = < "rdiscount", - }) - end + {% highlight ruby %} + puts "3..2..1.." + {% endhighlight %} - should "parse correctly" do - assert_match %r{FIGHT!}, @result - assert_match %r!FINISH HIM!, @result - end + *FINISH HIM* + CONTENT end context "using Kramdown" do @@ -572,42 +517,22 @@ def highlight_block_with_opts(options_string) assert_match %r!FINISH HIM!, @result end end - - context "using Redcarpet" do - setup do - if jruby? - skip( - "JRuby does not perform well with CExt, test disabled." - ) - end - - create_post(@content, { - "markdown" => "redcarpet", - }) - end - - should "parse correctly" do - assert_match %r{FIGHT!}, @result - assert_match %r!FINISH HIM!, @result - end - end end context "simple page with post linking" do setup do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + {% post_url 2008-11-21-complex %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end should "not cause an error" do @@ -621,19 +546,18 @@ def highlight_block_with_opts(options_string) context "simple page with post linking containing special characters" do setup do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + {% post_url 2016-11-26-special-chars-(+) %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end should "not cause an error" do @@ -647,22 +571,21 @@ def highlight_block_with_opts(options_string) context "simple page with nested post linking" do setup do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + content = <<~CONTENT + --- + title: Post linking + --- + + - 1 {% post_url 2008-11-21-complex %} + - 2 {% post_url /2008-11-21-complex %} + - 3 {% post_url es/2008-11-21-nested %} + - 4 {% post_url /es/2008-11-21-nested %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end should "not cause an error" do @@ -682,19 +605,18 @@ def highlight_block_with_opts(options_string) context "simple page with nested post linking and path not used in `post_url`" do setup do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + - 1 {% post_url 2008-11-21-nested %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end should "not cause an error" do @@ -716,60 +638,95 @@ def highlight_block_with_opts(options_string) context "simple page with invalid post name linking" do should "cause an error" do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end end should "cause an error with a bad date" do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end end end context "simple page with linking to a page" do setup do - content = < source_dir, - "destination" => dest_dir, - "read_all" => true, - }) + content = <<~CONTENT + --- + title: linking + --- + + {% link contacts.html %} + {% link info.md %} + {% link /css/screen.css %} + CONTENT + create_post(content, + "source" => source_dir, + "destination" => dest_dir, + "read_all" => true) + end + + should "not cause an error" do + refute_match(%r!markdown\-html\-error!, @result) + end + + should "have the URL to the 'contacts' item" do + assert_match(%r!/contacts\.html!, @result) + end + + should "have the URL to the 'info' item" do + assert_match(%r!/info\.html!, @result) + end + + should "have the URL to the 'screen.css' item" do + assert_match(%r!/css/screen\.css!, @result) + end + end + + context "simple page with dynamic linking to a page" do + setup do + content = <<~CONTENT + --- + title: linking + --- + + {% assign contacts_filename = 'contacts' %} + {% assign contacts_ext = 'html' %} + {% link {{contacts_filename}}.{{contacts_ext}} %} + {% assign info_path = 'info.md' %} + {% link {{\ info_path\ }} %} + {% assign screen_css_path = '/css' %} + {% link {{ screen_css_path }}/screen.css %} + CONTENT + create_post(content, + "source" => source_dir, + "destination" => dest_dir, + "read_all" => true) end should "not cause an error" do @@ -791,19 +748,44 @@ def highlight_block_with_opts(options_string) context "simple page with linking" do setup do - content = < source_dir, + "destination" => dest_dir, + "collections" => { "methods" => { "output" => true } }, + "read_collections" => true) + end + + should "not cause an error" do + refute_match(%r!markdown\-html\-error!, @result) + end + + should "have the URL to the 'yaml_with_dots' item" do + assert_match(%r!/methods/yaml_with_dots\.html!, @result) + end + end + + context "simple page with dynamic linking" do + setup do + content = <<~CONTENT + --- + title: linking + --- -{% link _methods/yaml_with_dots.md %} -CONTENT - create_post(content, { - "source" => source_dir, - "destination" => dest_dir, - "collections" => { "methods" => { "output" => true } }, - "read_collections" => true, - }) + {% assign yaml_with_dots_path = '_methods/yaml_with_dots.md' %} + {% link {{yaml_with_dots_path}} %} + CONTENT + create_post(content, + "source" => source_dir, + "destination" => dest_dir, + "collections" => { "methods" => { "output" => true } }, + "read_collections" => true) end should "not cause an error" do @@ -817,20 +799,19 @@ def highlight_block_with_opts(options_string) context "simple page with nested linking" do setup do - content = < source_dir, - "destination" => dest_dir, - "collections" => { "methods" => { "output" => true } }, - "read_collections" => true, - }) + content = <<~CONTENT + --- + title: linking + --- + + - 1 {% link _methods/sanitized_path.md %} + - 2 {% link _methods/site/generate.md %} + CONTENT + create_post(content, + "source" => source_dir, + "destination" => dest_dir, + "collections" => { "methods" => { "output" => true } }, + "read_collections" => true) end should "not cause an error" do @@ -848,21 +829,41 @@ def highlight_block_with_opts(options_string) context "simple page with invalid linking" do should "cause an error" do - content = < source_dir, + "destination" => dest_dir, + "collections" => { "methods" => { "output" => true } }, + "read_collections" => true) + end + end + end + + context "simple page with invalid dynamic linking" do + should "cause an error" do + content = <<~CONTENT + --- + title: Invalid linking + --- -{% link non-existent-collection-item %} -CONTENT + {% assign non_existent_path = 'non-existent-collection-item' %} + {% link {{\ non_existent_path\ }} %} + CONTENT assert_raises ArgumentError do - create_post(content, { - "source" => source_dir, - "destination" => dest_dir, - "collections" => { "methods" => { "output" => true } }, - "read_collections" => true, - }) + create_post(content, + "source" => source_dir, + "destination" => dest_dir, + "collections" => { "methods" => { "output" => true } }, + "read_collections" => true) end end end @@ -872,21 +873,20 @@ def highlight_block_with_opts(options_string) should "not allow symlink includes" do File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") } assert_raises IOError do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - "safe" => true, - }) + content = <<~CONTENT + --- + title: Include symlink + --- + + {% include tmp/pages-test %} + + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true, + "safe" => true) end @result ||= "" refute_match(%r!SYMLINK TEST!, @result) @@ -894,21 +894,20 @@ def highlight_block_with_opts(options_string) should "not expose the existence of symlinked files" do ex = assert_raises IOError do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - "safe" => true, - }) + content = <<~CONTENT + --- + title: Include symlink + --- + + {% include tmp/pages-test-does-not-exist %} + + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true, + "safe" => true) end assert_match( "Could not locate the included file 'tmp/pages-test-does-not-exist' " \ @@ -922,21 +921,76 @@ def highlight_block_with_opts(options_string) context "with one parameter" do setup do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + {% include params.html param="value" %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) + end + + should "correctly output include variable" do + assert_match "value", @result.strip + end + + should "ignore parameters if unused" do + assert_match "
\n

Tom Preston-Werner\ngithub.com/mojombo

\n", @result + end + end + + context "with simple syntax but multiline markup" do + setup do + content = <<~CONTENT + --- + title: Include tag parameters + --- + + {% include sig.markdown myparam="test" %} + + {% include params.html + param="value" %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) + end + + should "correctly output include variable" do + assert_match "value", @result.strip + end + + should "ignore parameters if unused" do + assert_match "
\n

Tom Preston-Werner\ngithub.com/mojombo

\n", @result + end + end + + context "with variable syntax but multiline markup" do + setup do + content = <<~CONTENT + --- + title: Include tag parameters + --- + + {% include sig.markdown myparam="test" %} + {% assign path = "params" | append: ".html" %} + {% include {{ path }} + param="value" %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end should "correctly output include variable" do @@ -950,57 +1004,54 @@ def highlight_block_with_opts(options_string) context "with invalid parameter syntax" do should "throw a ArgumentError" do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end end end context "with several parameters" do setup do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + {% include params.html param1="new_value" param2="another" %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end should "list all parameters" do @@ -1015,19 +1066,18 @@ def highlight_block_with_opts(options_string) context "without parameters" do setup do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + {% include params.html %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end should "include file with empty parameters" do @@ -1037,20 +1087,19 @@ def highlight_block_with_opts(options_string) context "with custom includes directory" do setup do - content = < "_includes_custom", - "permalink" => "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + content = <<~CONTENT + --- + title: custom includes directory + --- + + {% include custom.html %} + CONTENT + create_post(content, + "includes_dir" => "_includes_custom", + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end should "include file from custom directory" do @@ -1060,19 +1109,18 @@ def highlight_block_with_opts(options_string) context "without parameters within if statement" do setup do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + {% if true %}{% include params.html %}{% endif %} + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end should "include file with empty parameters within if statement" do @@ -1082,23 +1130,22 @@ def highlight_block_with_opts(options_string) context "include missing file" do setup do - @content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + create_post(@content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end assert_match( "Could not locate the included file 'missing.html' in any of " \ @@ -1110,7 +1157,7 @@ def highlight_block_with_opts(options_string) context "include tag with variable and liquid filters" do setup do - site = fixture_site({ "pygments" => true }).tap(&:read).tap(&:render) + site = fixture_site("pygments" => true).tap(&:read).tap(&:render) post = site.posts.docs.find do |p| p.basename.eql? "2013-12-17-include-variable-filters.markdown" end @@ -1142,7 +1189,7 @@ def highlight_block_with_opts(options_string) context "relative include tag with variable and liquid filters" do setup do - site = fixture_site({ "pygments" => true }).tap(&:read).tap(&:render) + site = fixture_site("pygments" => true).tap(&:read).tap(&:render) post = site.posts.docs.find do |p| p.basename.eql? "2014-09-02-relative-includes.markdown" end @@ -1177,23 +1224,22 @@ def highlight_block_with_opts(options_string) context "trying to do bad stuff" do context "include missing file" do setup do - @content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + create_post(@content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end assert_match "Could not locate the included file 'missing.html' in any of " \ "[\"#{source_dir}\"].", exception.message @@ -1202,23 +1248,22 @@ def highlight_block_with_opts(options_string) context "include existing file above you" do setup do - @content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - }) + create_post(@content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true) end assert_equal( "Invalid syntax for include tag. File contains invalid characters or " \ @@ -1234,21 +1279,20 @@ def highlight_block_with_opts(options_string) should "not allow symlink includes" do File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") } assert_raises IOError do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - "safe" => true, - }) + content = <<~CONTENT + --- + title: Include symlink + --- + + {% include_relative tmp/pages-test %} + + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true, + "safe" => true) end @result ||= "" refute_match(%r!SYMLINK TEST!, @result) @@ -1256,21 +1300,20 @@ def highlight_block_with_opts(options_string) should "not expose the existence of symlinked files" do ex = assert_raises IOError do - content = < "pretty", - "source" => source_dir, - "destination" => dest_dir, - "read_posts" => true, - "safe" => true, - }) + content = <<~CONTENT + --- + title: Include symlink + --- + + {% include_relative tmp/pages-test-does-not-exist %} + + CONTENT + create_post(content, + "permalink" => "pretty", + "source" => source_dir, + "destination" => dest_dir, + "read_posts" => true, + "safe" => true) end assert_match( "Ensure it exists in one of those directories and is not a symlink "\ diff --git a/test/test_utils.rb b/test/test_utils.rb index 844ef825d35..509f92e861d 100644 --- a/test/test_utils.rb +++ b/test/test_utils.rb @@ -202,20 +202,20 @@ class TestUtils < JekyllUnitTest should "replace everything else but ASCII characters" do assert_equal "the-config-yml-file", - Utils.slugify("The _config.yml file?", :mode => "ascii") + Utils.slugify("The _config.yml file?", :mode => "ascii") assert_equal "f-rtive-glance", - Utils.slugify("fürtive glance!!!!", :mode => "ascii") + Utils.slugify("fürtive glance!!!!", :mode => "ascii") end should "map accented latin characters to ASCII characters" do assert_equal "the-config-yml-file", - Utils.slugify("The _config.yml file?", :mode => "latin") + Utils.slugify("The _config.yml file?", :mode => "latin") assert_equal "furtive-glance", - Utils.slugify("fürtive glance!!!!", :mode => "latin") + Utils.slugify("fürtive glance!!!!", :mode => "latin") assert_equal "aaceeiioouu", - Utils.slugify("àáçèéíïòóúü", :mode => "latin") + Utils.slugify("àáçèéíïòóúü", :mode => "latin") assert_equal "a-z", - Utils.slugify("Aあわれ鬱господинZ", :mode => "latin") + Utils.slugify("Aあわれ鬱господинZ", :mode => "latin") end should "only replace whitespace if mode is raw" do