module Test

Test jekyll module

Constants

TASKS_OPTIONS

Public Instance Methods

html() click to toggle source
# File lib/jekyll_theme_marketing/test.rb, line 12
def html
  puts '## Skipping rel="canonical" from jekyll-seo-tag gem'
  htmlproofer_ignore_canonical(%r{\/>}, "data-proofer-ignore \/>")

  puts '## Running: bundle exec jekyll build --trace'
  system 'bundle exec jekyll build --trace'

  puts '## Revert jekyll-seo-tag gem to pristine condition'
  system 'gem pristine jekyll-seo-tag'

  HTMLProofer.check_directory('./_site', options).run
end

Private Instance Methods

edit_contents_file(path, search_line, old_str, new_str) click to toggle source
# File lib/jekyll_theme_marketing/test.rb, line 27
def edit_contents_file(path, search_line, old_str, new_str)
  temp_file = Tempfile.new('foo')
  File.open(path, 'r') do |file|
    file.each_line do |l|
      temp_file.puts l.include?(search_line) ? l.gsub(old_str, new_str) : l
    end
  end
  FileUtils.mv(temp_file.path, path)
ensure
  temp_file.close
  temp_file.unlink
end
htmlproofer_ignore_canonical(old_string, new_string) click to toggle source
# File lib/jekyll_theme_marketing/test.rb, line 40
def htmlproofer_ignore_canonical(old_string, new_string)
  gem_path = `bundle show jekyll-seo-tag`.strip
  template_path = "#{gem_path}/lib/template.html"
  template_line = 'rel="canonical"'
  edit_contents_file(template_path, template_line, old_string, new_string)
end
options() click to toggle source
# File lib/jekyll_theme_marketing/test.rb, line 47
def options
  default_options = {
    assume_extension: true,
    error_sort: :desc,
    url_ignore: ['https://mx.linkedin.com/company/grupo-pv-mexico']
  }

  TASKS_OPTIONS.each do |key, value|
    default_options.merge!(value) if key.to_s == ARGV[1]
  end

  default_options
end