Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Refactor ruby and rake files
Browse files Browse the repository at this point in the history
  • Loading branch information
dshevtsov committed Aug 7, 2019
1 parent db915ce commit 9d800eb
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 10 deletions.
18 changes: 12 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion _checks/html-check-hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions bin/whatsup_github
Original file line number Diff line number Diff line change
@@ -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")
File renamed without changes.
2 changes: 2 additions & 0 deletions rakelib/lib/doc-config.rb → lib/doc_config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Read Docfile file and get configuration data for adding subrepositories
class DocConfig
attr_reader :config
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rakelib/lib/link-checker.rb → lib/link_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 9d800eb

Please sign in to comment.