Make script to render release notes liquid

This commit is contained in:
Clément Fournier
2018-08-14 17:07:53 +02:00
parent 62612dc507
commit e888283b39
4 changed files with 90 additions and 4 deletions

View File

@ -3,6 +3,7 @@ repository: pmd/pmd
pmd:
version: 6.7.0
date: 2018-??-??
release_type: minor
output: web
# this property is useful for conditional filtering of content that is separate from the PDF.

69
docs/_plugins/rule_tag.rb Normal file
View File

@ -0,0 +1,69 @@
# Tag to reference a rule
# Usage:
# {% rule "java/codestyle/LinguisticNaming" %} works from anywhere
# If inside the doc page of a ruleset/category, the language and
# category segment can be dropped, they're taken to be the same.
# That means rule descriptions can reference rules e.g. by simply
# saying {% rule AvoidFinalLocalVars %} if they're in the same category
# This could allow deprecated rule notices to link to the replacement rule
class RuleTag < Liquid::Tag
def initialize(tag_name, rule_ref, tokens)
super
if %r!(?:(?:(\w+)/)?(\w+)/)?(\w+)! =~ rule_ref
@lang_name = $1
@category_name = $2
@rule_name = $3
else
fail "Invalid rule reference format"
end
end
def render(context)
if /pmd_rules_(\w+)_(\w+)\.html/ =~ context["page.permalink"]
# If we're in a page describing a ruleset,
# omitted language or category are taken to be that of this page
@lang_name = @lang_name || $1
@category_name = @category_name || $2
end
unless @category_name
fail "no category for rule reference, and no implicit category name available"
end
unless @lang_name
fail "no language for rule reference, and no implicit language name available"
end
url_prefix = ""
if (version = context["site.pmd.version"])
url_prefix = "https://pmd.github.io/pmd-#{version}/"
end
markup_link(@rule_name, url_prefix + relativelink(@lang_name, @category_name, @rule_name))
end
private
def relativelink(lang, cat, rname)
"pmd_rules_#{lang}_#{cat}.html##{rname.downcase}"
end
def markup_link(rname, link)
"[`#{rname}`](#{link})"
end
end
Liquid::Template.register_tag('rule', RuleTag)

View File

@ -4,11 +4,11 @@ permalink: pmd_release_notes.html
keywords: changelog, release notes
---
## ????? - 6.7.0-SNAPSHOT
## {{ site.pmd.date }} - {{ site.pmd.version }}
The PMD team is pleased to announce PMD 6.7.0.
The PMD team is pleased to announce PMD {{ site.pmd.version }}.
This is a minor release.
This is a {{ site.pmd.release_type }} release.
### Table Of Contents
@ -22,7 +22,7 @@ This is a minor release.
#### New Rules
* The new Java rule [`LinguisticNaming`](pmd_rules_java_codestyle.html#linguisticnaming) (`java-codestyle`)
* The new Java rule {% rule "java/codestyle/LinguisticNaming" %} (`java-codestyle`)
detects cases, when a method name indicates it returns a boolean (such as `isSmall()`) but it doesn't.
Besides method names, the rule also checks field and variable names. It also checks, that getters return
something but setters won't. The rule has several properties with which it can be customized.

16
preprocess_release_notes.rb Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env ruby
require "liquid"
require "yaml"
require_relative "docs/_plugins/rule_tag"
require_relative "docs/_plugins/custom_filters"
release_notes_file = "docs/pages/release_notes.md"
# wrap the config under a "site." namespace because that's how jekyll does it
liquid_env = {'site' => YAML.load_file("docs/_config.yml")}
@template = Liquid::Template.parse(File.read(release_notes_file))
print(@template.render(liquid_env))