Module: Opulent::Logger
- Defined in:
- lib/opulent/logger.rb
Class Method Summary collapse
-
.black(text) ⇒ Object
Colors available in the terminal.
- .blue(text) ⇒ Object
-
.colorize(text, color_code) ⇒ Object
Color the input text with the chosen color.
-
.compile_error(template, error, *data) ⇒ Object
Output an error message based on class context and input data.
- .cyan(text) ⇒ Object
- .default(text) ⇒ Object
-
.error(type, *data) ⇒ Object
Display an error message based on context.
-
.exec_error(error, *data) ⇒ Object
Output an error message based on class context and input data.
- .green(text) ⇒ Object
-
.log(message, *data) ⇒ Object
Output an error message based on class context and input data.
- .magenta(text) ⇒ Object
-
.parse_error(code, line, character, error, *data) ⇒ Object
Output an error message based on class context and input data.
- .red(text) ⇒ Object
-
.require_windows_libs ⇒ Object
Require windows libraries for ANSI Console output.
- .white(text) ⇒ Object
- .yellow(text) ⇒ Object
Class Method Details
.black(text) ⇒ Object
Colors available in the terminal
19 20 21 |
# File 'lib/opulent/logger.rb', line 19 def black(text) colorize(text, "\e[30m") end |
.blue(text) ⇒ Object
35 36 37 |
# File 'lib/opulent/logger.rb', line 35 def blue(text) colorize(text, "\e[34m") end |
.colorize(text, color_code) ⇒ Object
Color the input text with the chosen color
12 13 14 15 |
# File 'lib/opulent/logger.rb', line 12 def colorize(text, color_code) require_windows_libs "#{color_code}#{text}\e[0m" end |
.compile_error(template, error, *data) ⇒ Object
Output an error message based on class context and input data
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/opulent/logger.rb', line 185 def compile_error(template, error, *data) case error when :explicit_end = <<-ERROR Explicit "end" evaluation nodes are not allowed. End expressions are inserted automatically. ERROR end fail <<-OPULENT_ERROR \n [Opulent Compiler] Runtime Error #{} OPULENT_ERROR end |
.cyan(text) ⇒ Object
43 44 45 |
# File 'lib/opulent/logger.rb', line 43 def cyan(text) colorize(text, "\e[36m") end |
.default(text) ⇒ Object
51 52 53 |
# File 'lib/opulent/logger.rb', line 51 def default(text) colorize(text, "\e[38m") end |
.error(type, *data) ⇒ Object
Display an error message based on context
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/opulent/logger.rb', line 121 def error(type, *data) case type when :parse parse_error data[0], data[1], data[2], data[3], data[4..-1] when :compile compile_error data[0], data[1], data[2..-1] when :exec exec_error data[0], data[1..-1] end end |
.exec_error(error, *data) ⇒ Object
Output an error message based on class context and input data
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/opulent/logger.rb', line 138 def exec_error(error, *data) case error when :input = <<-ERROR Given input file #{data[0].inspect} does not exist or an incorrect path has been specified. ERROR when :layout_error = <<-ERROR Missing input or incorrect file extension for layout [-l] argument. Found #{data[0]} instead. ERROR when :locals_file = <<-ERROR Given context file #{data[0].inspect} does not exist or an incorrect path has been specified. ERROR when :locals_file_format = <<-ERROR Unknown file extension #{data[0].inspect} given as locals file. Please use JSON or YAML as input. ERROR when :input_arguments = <<-ERROR Unknown input argument [#{data[0]}] has been encountered. ERROR when :no_input = <<-ERROR You haven't specified an input file. ERROR end fail <<-OPULENT_ERROR \n [Opulent Engine] Runtime Error #{} OPULENT_ERROR end |
.green(text) ⇒ Object
27 28 29 |
# File 'lib/opulent/logger.rb', line 27 def green(text) colorize(text, "\e[32m") end |
.log(message, *data) ⇒ Object
Output an error message based on class context and input data
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/opulent/logger.rb', line 74 def log(, *data) case when :version title = 'Version' = <<-LOG Version #{Opulent::VERSION} is currently installed. LOG when :successful_render title = 'Render Complete' = <<-LOG Successfully rendered #{data[0].inspect} to #{data[1].inspect}. LOG when :successful_render_print title = 'Render Complete' = <<-LOG Successfully rendered #{data[0].inspect}. No output file specified. Writing result to terminal. #{data[1]}" LOG when :help title = 'Help' = <<-LOG You can use the following commands with the Opulent Command Line Interface: opulent input.op output.html Render an input file and write the result to the output file. opulent layout [-l] layout.op Render an input file using given input layout file. opulent help [-h] Show available command line options. opulent version [-v] Show installed version. LOG end puts <<-OPULENT_LOG \n [Opulent Engine] #{title} #{} OPULENT_LOG end |
.magenta(text) ⇒ Object
39 40 41 |
# File 'lib/opulent/logger.rb', line 39 def magenta(text) colorize(text, "\e[35m") end |
.parse_error(code, line, character, error, *data) ⇒ Object
Output an error message based on class context and input data
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/opulent/logger.rb', line 209 def parse_error(code, line, character, error, *data) line += 1 case error when :unknown_node_type = <<-ERROR An unknown node type has been encountered. ERROR when :expected if [:'(', :'{', :'[', :'<'].include? data[0] data[0] = "#{Tokens.bracket data[0]}" end = <<-ERROR Expected to find a :#{data[0]} token on line #{line} of input. ERROR when :root = <<-ERROR Unknown node type encountered on line #{line} of input. ERROR when :assignments_colon = <<-ERROR Unexpected end of element attributes reached on line #{line} of input. ERROR when :assignments_comma = <<-ERROR Unexpected end of element attributes reached on line #{line} of input. Expected to find an attribute value. ERROR when :expression = <<-ERROR Unexpected end of expression reached on line #{line} of input. Expected to find another expression term. ERROR when :control_child = <<-ERROR Unexpected control structure child found on line #{line} of input. Expected to find a parent #{data[0]} structure. ERROR when :whitespace_expression = <<-ERROR Unexpected end of expression reached on line #{line} of input. Please use paranthesis for method parameters ERROR when :definition = <<-ERROR Unexpected start of definition on line #{line} of input. Found a definition inside another definition or element. ERROR when :self_enclosing = <<-ERROR Unexpected content found after self enclosing node on line #{line} of input. ERROR when :self_enclosing_children = <<-ERROR Unexpected child elements found for self enclosing node on line #{data[0] + 1} of input. ERROR when :include = <<-ERROR The included file #{data[0]} does not exist or an incorrect path has been specified. ERROR when :include_dir = <<-ERROR The included file path #{data[0]} is a directory. ERROR when :include_end = <<-ERROR Missing argument for include on line #{line} of input. ERROR else = <<-ERROR Unexpected syntax error on line #{line} of input. ERROR end fail <<-OPULENT_ERROR \n [Opulent Parser] Runtime Error #{} #{code[line - 1].chomp} #{' ' * character}^ OPULENT_ERROR end |
.red(text) ⇒ Object
23 24 25 |
# File 'lib/opulent/logger.rb', line 23 def red(text) colorize(text, "\e[31m") end |
.require_windows_libs ⇒ Object
Require windows libraries for ANSI Console output
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/opulent/logger.rb', line 57 def require_windows_libs return unless RUBY_PLATFORM =~ /win32/ begin require 'Win32/Console/ANSI' rescue LoadError raise 'You must run "gem install win32console" to use Opulent\'s error reporting on Windows.' end end |
.white(text) ⇒ Object
47 48 49 |
# File 'lib/opulent/logger.rb', line 47 def white(text) colorize(text, "\e[37m") end |
.yellow(text) ⇒ Object
31 32 33 |
# File 'lib/opulent/logger.rb', line 31 def yellow(text) colorize(text, "\e[33m") end |