diff --git a/features/support/helpers.rb b/features/support/helpers.rb index 36a726b4..db36141d 100644 --- a/features/support/helpers.rb +++ b/features/support/helpers.rb @@ -1,12 +1,10 @@ # frozen_string_literal: true -require "fileutils" require "jekyll" -require "time" -require "safe_yaml/load" class Paths SOURCE_DIR = Pathname.new(File.expand_path("../..", __dir__)) + def self.test_dir; source_dir.join("tmp", "jekyll"); end def self.theme_gem_dir; source_dir.join("tmp", "jekyll", "my-cool-theme"); end @@ -24,24 +22,19 @@ end def file_content_from_hash(input_hash) matter_hash = input_hash.reject { |k, _v| k == "content" } - matter = matter_hash.map do |k, v| - "#{k}: #{v}\n" - end + matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join + matter.chomp! + content = if input_hash["input"] && input_hash["filter"] + "{{ #{input_hash["input"]} | #{input_hash["filter"]} }}" + else + input_hash["content"] + end - matter = matter.join.chomp - content = \ - if !input_hash["input"] || !input_hash["filter"] - then input_hash["content"] - else "{{ #{input_hash["input"]} | " \ - "#{input_hash["filter"]} }}" - end + <<~EOF + --- + #{matter} + --- - Jekyll::Utils.strip_heredoc(<<-EOF) - --- - #{matter.gsub( - %r!\n!, "\n " - )} - --- #{content} EOF end @@ -49,7 +42,7 @@ end # def source_dir(*files) - return Paths.test_dir(*files) + Paths.test_dir(*files) end # @@ -70,17 +63,13 @@ end # def jekyll_run_output - if Paths.output_file.file? - then return Paths.output_file.read - end + Paths.output_file.read if Paths.output_file.file? end # def jekyll_run_status - if Paths.status_file.file? - then return Paths.status_file.read - end + Paths.status_file.read if Paths.status_file.file? end # @@ -104,6 +93,7 @@ def run_jekyll(args) end # + def run_in_shell(*args) p, output = Jekyll::Utils::Exec.run(*args) @@ -121,9 +111,10 @@ end # def slug(title = nil) - if !title - then Time.now.strftime("%s%9N") # nanoseconds since the Epoch - else title.downcase.gsub(%r![^\w]!, " ").strip.gsub(%r!\s+!, "-") + if title + title.downcase.gsub(%r![^\w]!, " ").strip.gsub(%r!\s+!, "-") + else + Time.now.strftime("%s%9N") # nanoseconds since the Epoch end end @@ -142,7 +133,7 @@ end # def file_contents(path) - return Pathname.new(path).read + Pathname.new(path).read end # @@ -155,8 +146,7 @@ def seconds_agnostic_datetime(datetime = Time.now) Regexp.escape(date), "#{time}:\\d{2}", Regexp.escape(zone), - ] \ - .join("\\ ") + ].join("\\ ") end #