Module Pygments::Popen
In: lib/pygments/popen.rb

Methods

alive?   css   filters   formatters   highlight   lexer_name_for   lexers   lexers!   start   stop   styles  

Included Modules

POSIX::Spawn

Public Instance methods

Check for a @pid variable, and then hit `kill -0` with the pid to check if the pid is still in the process table. If this function gives us an ENOENT or ESRCH, we can also safely return false (no process to worry about). Defensively, if EPERM is raised, in a odd/rare dying process situation (e.g., mentos is checking on the pid of a dead process and the pid has already been re-used) we‘ll want to raise that as a more informative Mentos exception.

Returns true if the child is alive.

Public: Return css for highlighted code

Public: Return an array of all available filters

Public: Get an array of available Pygments formatters

Returns an array of formatters.

Public: Highlight code.

Takes a first-position argument of the code to be highlighted, and a second-position hash of various arguments specifiying highlighting properties.

Public: Return the name of a lexer.

Public: Get all lexers from a serialized array. This avoids needing to spawn mentos when it‘s not really needed (e.g,. one-off jobs, loading the Rails env, etc).

Should be preferred to lexers!

Returns an array of lexers

Public: Get back all available lexers from mentos itself

Returns an array of lexers

Get things started by opening a pipe to mentos (the freshmaker), a Python process that talks to the Pygments library. We‘ll talk back and forth across this pipe.

Stop the child process by issuing a kill -9.

We then call waitpid() with the pid, which waits for that particular child and reaps it.

kill() can set errno to ESRCH if, for some reason, the file is gone; regardless the final outcome of this method will be to set our @pid variable to nil.

Technically, kill() can also fail with EPERM or EINVAL (wherein the signal isn‘t sent); but we have permissions, and we‘re not doing anything invalid here.

Public: Return an array of all available styles

[Validate]