Favor Ruby 2.3 squiggly-heredoc operator (#7584)

Merge pull request 7584
This commit is contained in:
Ashwin Maroli 2019-03-22 21:48:58 +05:30 committed by jekyllbot
parent dea6bdbfaf
commit 2090989fb3
4 changed files with 13 additions and 21 deletions

View File

@ -34,7 +34,7 @@ end
#
Given(%r!^I have an? "(.*)" page(?: with (.*) "(.*)")? that contains "(.*)"$!) do |file, key, value, text|
File.write(file, Jekyll::Utils.strip_heredoc(<<-DATA))
File.write(file, <<~DATA)
---
#{key || "layout"}: #{value || "none"}
---

View File

@ -98,17 +98,16 @@ module Jekyll
# Complicated JavaScript to ensure that livereload.js is loaded from the
# same origin as the page. Mostly useful for dealing with the browser's
# distinction between 'localhost' and 127.0.0.1
template = <<-TEMPLATE
<script>
document.write(
'<script src="http://' +
(location.host || 'localhost').split(':')[0] +
':<%=@options["livereload_port"] %>/livereload.js?snipver=1<%= livereload_args %>"' +
'></' +
'script>');
</script>
@template ||= ERB.new(<<~TEMPLATE)
<script>
document.write(
'<script src="http://' +
(location.host || 'localhost').split(':')[0] +
':<%=@options["livereload_port"] %>/livereload.js?snipver=1<%= livereload_args %>"' +
'></' +
'script>');
</script>
TEMPLATE
ERB.new(Jekyll::Utils.strip_heredoc(template))
end
def livereload_args

View File

@ -17,14 +17,7 @@ module Jekyll
SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
SLUGIFY_ASCII_REGEXP = Regexp.new("[^[A-Za-z0-9]]+").freeze
# Takes an indented string and removes the preceding spaces on each line
def strip_heredoc(str)
str.gsub(%r!^[ \t]{#{(str.scan(%r!^[ \t]*(?=\S)!).min || "").size}}!, "")
end
# Takes a slug and turns it into a simple title.
def titleize_slug(slug)
slug.split("-").map!(&:capitalize).join(" ")
end

View File

@ -88,7 +88,7 @@ class TestKramdown < JekyllUnitTest
end
should "render fenced code blocks with syntax highlighting" do
result = nokogiri_fragment(@markdown.convert(Utils.strip_heredoc(<<-MARKDOWN)))
result = nokogiri_fragment(@markdown.convert(<<~MARKDOWN))
~~~ruby
puts "Hello World"
~~~
@ -109,7 +109,7 @@ class TestKramdown < JekyllUnitTest
}
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
result = nokogiri_fragment(markdown.convert(Utils.strip_heredoc(<<-MARKDOWN)))
result = nokogiri_fragment(markdown.convert(<<~MARKDOWN))
~~~ruby
puts "Hello World"
~~~
@ -130,7 +130,7 @@ class TestKramdown < JekyllUnitTest
@config.delete("highlighter")
@config["kramdown"].delete("syntax_highlighter")
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
result = nokogiri_fragment(markdown.convert(Utils.strip_heredoc(<<-MARKDOWN)))
result = nokogiri_fragment(markdown.convert(<<~MARKDOWN))
~~~ruby
puts "Hello World"
~~~