class Rake::ToolkitProgram::HelpStyling
An object that captures styling rules for a CLI program
This class defines several methods that either configure a styling transformation or apply the configured transformation, depending on the argument type. These methods are defined with .define_style for consistency.
Each “style” method (e.g. title) “learns” how to apply its style if passed anything responding to to_proc and applies its current style transformation if passed a string.
Constants
- IDENTITY
Public Class Methods
define_style(*names)
click to toggle source
# File lib/rake/toolkit_program/help_styling.rb, line 52 def self.define_style(*names) names.each do |name| vname = "@#{name}".to_sym define_method(name) do |s| case when String === s then (instance_variable_get(vname) || IDENTITY)[s] when s.respond_to?(:to_proc) then instance_variable_set(vname, s.to_proc) else raise ArgumentError, "\##{name} accepts a String or Proc" end end end end
new()
click to toggle source
Calls superclass method
# File lib/rake/toolkit_program/help_styling.rb, line 38 def initialize super begin require 'colorize' rescue LoadError title ->(s) {"*** #{s} ***"} else title ->(s) {"*** #{s} ***".light_white.bold.on_blue} code ->(s) {s.bold} param ->(s) {s.italic} error_marker ->(s) {s.bold.red.on_black} end end