From 9d800eb24f0bb5f667c5312da47eedd171a52b96 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Wed, 7 Aug 2019 16:44:24 -0500 Subject: [PATCH] Refactor ruby and rake files --- Rakefile | 18 ++++++++---- _checks/html-check-hook.rb | 2 +- .../{ => liquid-tags}/collapsible-content.rb | 0 .../{ => liquid-tags}/glossary-tooltip.rb | 0 _plugins/{ => liquid-tags}/remote_markdown.rb | 0 _plugins/{ => page-params}/github-path.rb | 0 .../{ => page-params}/last-modified-at.rb | 0 .../page-baseurl-generator.rb | 0 .../{ => page-params}/page-canonical-url.rb | 0 .../{ => page-params}/page-versionless.rb | 0 _plugins/{ => page-params}/page-versions.rb | 0 bin/whatsup_github | 29 +++++++++++++++++++ {rakelib/lib => lib}/converter.rb | 0 .../lib/doc-config.rb => lib/doc_config.rb | 2 ++ .../double_slash_check.rb | 7 +++-- .../link-checker.rb => lib/link_checker.rb | 2 +- 16 files changed, 50 insertions(+), 10 deletions(-) rename _plugins/{ => liquid-tags}/collapsible-content.rb (100%) rename _plugins/{ => liquid-tags}/glossary-tooltip.rb (100%) rename _plugins/{ => liquid-tags}/remote_markdown.rb (100%) rename _plugins/{ => page-params}/github-path.rb (100%) rename _plugins/{ => page-params}/last-modified-at.rb (100%) rename _plugins/{ => page-params}/page-baseurl-generator.rb (100%) rename _plugins/{ => page-params}/page-canonical-url.rb (100%) rename _plugins/{ => page-params}/page-versionless.rb (100%) rename _plugins/{ => page-params}/page-versions.rb (100%) create mode 100755 bin/whatsup_github rename {rakelib/lib => lib}/converter.rb (100%) rename rakelib/lib/doc-config.rb => lib/doc_config.rb (89%) rename rakelib/lib/double-slash-check.rb => lib/double_slash_check.rb (63%) rename rakelib/lib/link-checker.rb => lib/link_checker.rb (95%) diff --git a/Rakefile b/Rakefile index 0a7dd65ab3d..148dfd46ff1 100644 --- a/Rakefile +++ b/Rakefile @@ -10,10 +10,9 @@ require 'html-proofer' require 'kramdown' require 'launchy' require 'colorator' -require 'erb' -# Require helper methods from the 'rakelib/lib' directory -Dir.glob('rakelib/lib/**/*.rb') { |file| require_relative(file) } +# Require helper methods from the 'lib' directory +Dir.glob('lib/**/*.rb') { |file| require_relative(file) } desc "Same as 'rake', 'rake preview'" task default: %w[preview] @@ -60,10 +59,17 @@ desc 'Pull docs from external repositories' task init: %w[multirepo:init] desc 'Run checks (image optimization).' -task check: %w[check:image_optim check:mdl] +task check: %w[check:image_optim check:mdl] -desc 'Generate data for the weekly digest.' +desc 'Generate data for a news digest. Default period is a week since today. For other period use "since" argument: since="jul 4"' task :whatsnew do + date = ENV['since'] print 'Generating data for the weekly digest: $ '.magenta - sh 'whatsup_github' + if date.nil? or date.empty? + sh 'bin/whatsup_github' + elsif date.is_a? String + sh 'bin/whatsup_github', 'since', ENV['since'].to_s + else + puts 'The "since" argument must be a string/ Example: "jul 4"' + end end diff --git a/_checks/html-check-hook.rb b/_checks/html-check-hook.rb index f2010fc271b..eee89eacc1c 100644 --- a/_checks/html-check-hook.rb +++ b/_checks/html-check-hook.rb @@ -6,7 +6,7 @@ # require 'html-proofer' require 'yaml' -require_relative '../rakelib/lib/double-slash-check.rb' +require_relative '../lib/double_slash_check.rb' Jekyll::Hooks.register :site, :post_write do |site| # Do nothing unless 'site.check_links' is set diff --git a/_plugins/collapsible-content.rb b/_plugins/liquid-tags/collapsible-content.rb similarity index 100% rename from _plugins/collapsible-content.rb rename to _plugins/liquid-tags/collapsible-content.rb diff --git a/_plugins/glossary-tooltip.rb b/_plugins/liquid-tags/glossary-tooltip.rb similarity index 100% rename from _plugins/glossary-tooltip.rb rename to _plugins/liquid-tags/glossary-tooltip.rb diff --git a/_plugins/remote_markdown.rb b/_plugins/liquid-tags/remote_markdown.rb similarity index 100% rename from _plugins/remote_markdown.rb rename to _plugins/liquid-tags/remote_markdown.rb diff --git a/_plugins/github-path.rb b/_plugins/page-params/github-path.rb similarity index 100% rename from _plugins/github-path.rb rename to _plugins/page-params/github-path.rb diff --git a/_plugins/last-modified-at.rb b/_plugins/page-params/last-modified-at.rb similarity index 100% rename from _plugins/last-modified-at.rb rename to _plugins/page-params/last-modified-at.rb diff --git a/_plugins/page-baseurl-generator.rb b/_plugins/page-params/page-baseurl-generator.rb similarity index 100% rename from _plugins/page-baseurl-generator.rb rename to _plugins/page-params/page-baseurl-generator.rb diff --git a/_plugins/page-canonical-url.rb b/_plugins/page-params/page-canonical-url.rb similarity index 100% rename from _plugins/page-canonical-url.rb rename to _plugins/page-params/page-canonical-url.rb diff --git a/_plugins/page-versionless.rb b/_plugins/page-params/page-versionless.rb similarity index 100% rename from _plugins/page-versionless.rb rename to _plugins/page-params/page-versionless.rb diff --git a/_plugins/page-versions.rb b/_plugins/page-params/page-versions.rb similarity index 100% rename from _plugins/page-versions.rb rename to _plugins/page-params/page-versions.rb diff --git a/bin/whatsup_github b/bin/whatsup_github new file mode 100755 index 00000000000..498f93617a7 --- /dev/null +++ b/bin/whatsup_github @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'whatsup_github' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("whatsup_github", "whatsup_github") diff --git a/rakelib/lib/converter.rb b/lib/converter.rb similarity index 100% rename from rakelib/lib/converter.rb rename to lib/converter.rb diff --git a/rakelib/lib/doc-config.rb b/lib/doc_config.rb similarity index 89% rename from rakelib/lib/doc-config.rb rename to lib/doc_config.rb index 361efe90a92..4ed6c9eefdf 100644 --- a/rakelib/lib/doc-config.rb +++ b/lib/doc_config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Read Docfile file and get configuration data for adding subrepositories class DocConfig attr_reader :config diff --git a/rakelib/lib/double-slash-check.rb b/lib/double_slash_check.rb similarity index 63% rename from rakelib/lib/double-slash-check.rb rename to lib/double_slash_check.rb index beccb0580b7..52628ee9d6b 100644 --- a/rakelib/lib/double-slash-check.rb +++ b/lib/double_slash_check.rb @@ -1,8 +1,11 @@ -# Custom check for html-proofer to find double forward slashes in URLs. +# frozen_string_literal: true + module LinkChecker + # Custom check for html-proofer to find double forward slashes in URLs. class DoubleSlashCheck < ::HTMLProofer::Check def slash? return false if @link.href.nil? + @link.href.match %r{\w//} end @@ -12,7 +15,7 @@ def run line = node.line if slash? - return add_issue("Remove double forward slashes from URLs", line: line) + return add_issue('Remove double forward slashes from URLs', line: line) end end end diff --git a/rakelib/lib/link-checker.rb b/lib/link_checker.rb similarity index 95% rename from rakelib/lib/link-checker.rb rename to lib/link_checker.rb index cd7242ff0d4..3ce1aba21d3 100644 --- a/rakelib/lib/link-checker.rb +++ b/lib/link_checker.rb @@ -4,7 +4,7 @@ module LinkChecker # Run html-proofer to check the generated HTML pages def self.check_site - HTMLProofer.check_directory('_site', options).run + HTMLProofer.check_directory('_ site', options).run end # Read options from the '_config.checks.yml'