private function set_theme($value) { if (self::check_type($value, 'string')) { if (!preg_match('/\\.css$/', $value)) { $value .= '.css'; } if (!luminous::theme_exists($value)) { throw new Exception('No such theme: ' . luminous::root() . '/style/' . $value); } else { $this->theme = $value; } } }
function highlight() { $this->parse_args(); // figure out the code // error cases are: // no input file or source code, if ($this->options['code'] === null && $this->options['input-file'] === null) { $this->error('No input file or source code specified'); } elseif ($this->options['code'] !== null && $this->options['input-file'] !== null) { $this->error('Input file (-i) and source code specified. You probably ' . 'didn\'t mean this'); } // is there an input file? use that. if ($this->options['input-file'] !== null) { $c = @file_get_contents($this->options['input-file']); if ($c === false) { $this->error('Could not read from ' . $this->options['input-file']); } else { $this->options['code'] = $c; } } elseif ($this->options['code'] === '-') { $code = ''; while (($line = fgets(STDIN)) !== false) { $code .= $line; } $this->options['code'] = $code; } // set the formatter luminous::set('format', $this->options['format']); // lame check that the formatter is okay try { luminous::formatter(); } catch (Exception $e) { $this->error('Unknown formatter ' . $this->options['format']); } // set the theme $valid_themes = luminous::themes(); $theme = $this->options['theme']; if (!preg_match('/\\.css$/', $theme)) { $theme .= '.css'; } if (!luminous::theme_exists($theme)) { $this->error('No such theme: ' . $theme); } else { luminous::set('theme', $theme); } // set the language if ($this->options['lang'] === null) { // guessing $this->options['lang'] = luminous::guess_language($this->options['code']); } // user provided language $scanners = luminous::scanners(); $valid_scanner = false; foreach ($scanners as $lang => $codes) { if (in_array($this->options['lang'], $codes)) { $valid_scanner = true; break; } } if (!$valid_scanner) { $this->error('No such language: ' . $this->options['lang']); } // other options luminous::set('max-height', $this->options['height']); luminous::set('line-numbers', $this->options['line-numbers']); $h = luminous::highlight($this->options['lang'], $this->options['code']); if ($this->options['output-file'] !== null) { $r = @file_put_contents($this->options['output-file'], $h, LOCK_EX); if ($r === false) { $this->error('Could not write to ' . $this->options['output-file']); } } else { echo $h; } exit(0); }