Add logger

This commit is contained in:
Clément Fournier
2018-08-15 01:52:31 +02:00
parent e888283b39
commit ba19c59bdb
3 changed files with 65 additions and 17 deletions

62
.travis/render_release_notes.rb Executable file
View File

@ -0,0 +1,62 @@
#!/usr/bin/env ruby
# Renders the release notes for Github releases,
# and prints them to standard output
# Doesn't trim the header, which is done in shell
# Args:
# $1 : location of the file to render
require "liquid"
require "yaml"
# include some custom liquid extensions
require_relative "../docs/_plugins/rule_tag"
require_relative "../docs/_plugins/custom_filters"
# this could be somewhere else
module Logger
def Logger.log_error(should_exit = true, message)
log_col(COL_RED, :error, message)
if should_exit
exit 1
end
end
private
def Logger.log_col(col, tag, message)
puts "#{col}[#{tag.to_s.upcase}] In #{$0}: #{message}#{COL_RESET}"
end
COL_GREEN = "\e[32m"
COL_YELLOW = "\e[33;1m"
COL_RED = "\e[31m"
COL_RESET = "\e[0m"
end
# START OF THE SCRIPT
unless ARGV.length == 1
Logger::log_error "No file name provided"
end
unless File.exists?(ARGV[0])
Logger::log_error("The provided file must exist")
end
release_notes_file = ARGV[0]
# wrap the config under a "site." namespace because that's how jekyll does it
liquid_env = {'site' => YAML.load_file("docs/_config.yml")}
to_render = File.read(release_notes_file)
rendered = Liquid::Template.parse(to_render).render(liquid_env)
print(rendered)

View File

@ -1,11 +1,13 @@
# 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
#
# That means rule descriptions can also 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

View File

@ -1,16 +0,0 @@
#!/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))