2017-08-13 21:02:48 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-05-27 03:29:47 +08:00
|
|
|
namespace :guides do
|
2012-09-07 12:09:56 +08:00
|
|
|
desc 'Generate guides (for authors), use ONLY=foo to process just "foo.md"'
|
2016-08-07 01:39:28 +08:00
|
|
|
task generate: "generate:html"
|
2012-05-27 03:29:47 +08:00
|
|
|
|
|
|
|
namespace :generate do
|
|
|
|
desc "Generate HTML guides"
|
2018-02-04 21:49:22 +08:00
|
|
|
task :html do
|
2018-02-04 21:37:17 +08:00
|
|
|
ruby "-Eutf-8:utf-8", "rails_guides.rb"
|
2012-05-27 03:29:47 +08:00
|
|
|
end
|
|
|
|
|
2022-07-06 14:59:06 +08:00
|
|
|
desc "Generate .mobi file"
|
2018-02-04 21:49:22 +08:00
|
|
|
task :kindle do
|
2023-02-14 19:55:25 +08:00
|
|
|
warn("DEPRECATION WARNING: The guides:generate:kindle rake task is deprecated and will be removed in 7.2. Run rake guides:generate:epub instead.")
|
2022-07-06 14:59:06 +08:00
|
|
|
Rake::Task["guides:generate:epub"].invoke
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Generate .epub file"
|
|
|
|
task :epub do
|
|
|
|
ENV["EPUB"] = "1"
|
2016-08-07 01:21:59 +08:00
|
|
|
Rake::Task["guides:generate:html"].invoke
|
2012-05-27 03:29:47 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-27 11:14:18 +08:00
|
|
|
desc "Lint guides, using `mdl`"
|
|
|
|
task :lint do
|
|
|
|
require "mdl"
|
|
|
|
all = Dir.glob("#{__dir__}/source/*.md")
|
|
|
|
files = all - Dir.glob("#{__dir__}/**/*_release_notes.md") # Ignore release notes
|
|
|
|
MarkdownLint.run files
|
|
|
|
end
|
|
|
|
|
2012-05-27 03:29:47 +08:00
|
|
|
# Validate guides -------------------------------------------------------------------------
|
|
|
|
desc 'Validate guides, use ONLY=foo to process just "foo.html"'
|
2021-11-10 17:27:45 +08:00
|
|
|
task :validate do
|
2012-05-27 03:29:47 +08:00
|
|
|
ruby "w3c_validator.rb"
|
|
|
|
end
|
2012-03-17 23:32:49 +08:00
|
|
|
|
2023-02-13 13:32:52 +08:00
|
|
|
task :vendor_javascript do
|
|
|
|
module Importmap; end
|
|
|
|
require "importmap/packager"
|
|
|
|
|
|
|
|
packager = Importmap::Packager.new(vendor_path: "assets/javascripts")
|
|
|
|
imports = packager.import("@hotwired/turbo", from: "unpkg")
|
|
|
|
imports.each do |package, url|
|
|
|
|
umd_url = url.gsub("esm.js", "umd.js")
|
|
|
|
puts %(Vendoring "#{package}" to #{packager.vendor_path}/#{package}.js via download from #{umd_url})
|
|
|
|
packager.download(package, umd_url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-27 04:05:52 +08:00
|
|
|
desc "Show help"
|
|
|
|
task :help do
|
2017-02-12 17:21:20 +08:00
|
|
|
puts <<HELP
|
2012-05-27 04:05:52 +08:00
|
|
|
|
2014-11-26 08:54:30 +08:00
|
|
|
Guides are taken from the source directory, and the result goes into the
|
2012-05-27 04:05:52 +08:00
|
|
|
output directory. Assets are stored under files, and copied to output/files as
|
|
|
|
part of the generation process.
|
|
|
|
|
2014-11-26 08:54:30 +08:00
|
|
|
You can generate HTML, Kindle or both formats using the `guides:generate` task.
|
|
|
|
|
2014-12-05 23:32:50 +08:00
|
|
|
All of these processes are handled via rake tasks, here's a full list of them:
|
2012-05-29 05:17:00 +08:00
|
|
|
|
|
|
|
#{%x[rake -T]}
|
2012-05-27 04:05:52 +08:00
|
|
|
Some arguments may be passed via environment variables:
|
|
|
|
|
2017-02-12 17:21:20 +08:00
|
|
|
RAILS_VERSION=tag
|
|
|
|
If guides are being generated for a specific Rails version set the Git tag
|
|
|
|
here, otherwise the current SHA1 is going to be used to generate edge guides.
|
2012-05-27 04:05:52 +08:00
|
|
|
|
|
|
|
ALL=1
|
|
|
|
Force generation of all guides.
|
|
|
|
|
|
|
|
ONLY=name
|
|
|
|
Useful if you want to generate only one or a set of guides.
|
2012-09-01 00:01:06 +08:00
|
|
|
|
2012-05-27 04:05:52 +08:00
|
|
|
Generate only association_basics.html:
|
|
|
|
ONLY=assoc
|
|
|
|
|
|
|
|
Separate many using commas:
|
|
|
|
ONLY=assoc,migrations
|
|
|
|
|
|
|
|
GUIDES_LANGUAGE
|
|
|
|
Use it when you want to generate translated guides in
|
|
|
|
source/<GUIDES_LANGUAGE> folder (such as source/es)
|
|
|
|
|
|
|
|
Examples:
|
2017-02-12 17:21:20 +08:00
|
|
|
$ rake guides:generate ALL=1 RAILS_VERSION=v5.1.0
|
|
|
|
$ rake guides:generate ONLY=migrations
|
2022-07-06 14:59:06 +08:00
|
|
|
$ rake guides:generate:epub
|
2012-05-27 04:05:52 +08:00
|
|
|
$ rake guides:generate GUIDES_LANGUAGE=es
|
2017-02-12 17:21:20 +08:00
|
|
|
HELP
|
2012-05-27 04:05:52 +08:00
|
|
|
end
|
2012-03-17 23:32:49 +08:00
|
|
|
end
|
2012-05-27 04:05:52 +08:00
|
|
|
|
2019-02-05 22:50:06 +08:00
|
|
|
task :test do
|
2022-01-07 05:56:06 +08:00
|
|
|
templates = Dir.glob("bug_report_templates/*.rb")
|
2019-02-05 22:50:06 +08:00
|
|
|
counter = templates.count do |file|
|
|
|
|
puts "--- Running #{file}"
|
2021-06-01 07:29:00 +08:00
|
|
|
Bundler.unbundled_system(Gem.ruby, "-w", file) ||
|
2019-02-05 22:50:06 +08:00
|
|
|
puts("+++ 💥 FAILED (exit #{$?.exitstatus})")
|
|
|
|
end
|
|
|
|
puts "+++ #{counter} / #{templates.size} templates executed successfully"
|
|
|
|
exit 1 if counter < templates.size
|
|
|
|
end
|
|
|
|
|
2016-08-07 01:39:28 +08:00
|
|
|
task default: "guides:help"
|