LinuxCommandLibrary

slimrb

Precompile Slim templates for Ruby

TLDR

Convert a Slim file to HTML

$ slimrb [input.slim] [output.html]
copy

Convert a Slim file and output to prettified HTML
$ slimrb --pretty [input.slim] [output.html]
copy

Convert a Slim file to ERB
$ slimrb --erb [input.slim] [output.erb]
copy

SYNOPSIS

slimrb [options] [file...]

PARAMETERS

-o, --output FILE
    Specifies the path for the output file. By default, output is sent to standard output.

-r, --require LIBRARY
    Requires a Ruby library before processing the Slim template, making its classes and modules available.

-s, --static
    Renders the template as static HTML by disabling the execution of any embedded Ruby code.

-p, --pretty
    Pretty prints the output HTML with proper indentation for improved readability.

-l, --layout FILE
    Specifies a layout file that will wrap the content of the main Slim template.

-f, --format FORMAT
    Sets the output format. Common formats include html, xhtml, and xml.

-e, --exec CODE
    Executes arbitrary Ruby code provided as a string before the template rendering begins.

-c, --compile
    Compiles the Slim template into raw Ruby code rather than rendered HTML or other markup.

-d, --disable-escape
    Disables HTML escaping for interpolated Ruby code, allowing raw output.

-t, --disable-tags
    Disables the output of HTML tags, only rendering the content within them.

--trace
    Shows a full Ruby backtrace when an error occurs during processing.

--erb
    Outputs the template in ERB (Embedded Ruby) syntax instead of HTML.

--rails
    Enables compatibility features specifically designed for Ruby on Rails environments.

--stdin
    Reads the Slim template content from standard input rather than a specified file.

-v, --version
    Displays the installed slimrb version information.

-h, --help
    Displays the command-line help message, detailing available options.

DESCRIPTION

Slim is a fast, lightweight templating language inspired by Haml, offering a concise and elegant syntax for generating HTML, XML, or other markup. slimrb is the command-line interface for the Slim templating engine.

It allows users to compile Slim template files directly from the terminal, rendering them into their desired output format, typically HTML. It supports features like Ruby code embedding, layout files, and various output formatting options, making it a versatile tool for both web development and standalone markup generation.

CAVEATS

Using slimrb requires the Ruby programming language to be installed on your system. Additionally, the slim gem must be installed via RubyGems (e.g., gem install slim) for the command to function correctly.

Errors within embedded Ruby code in Slim templates can halt the rendering process unless explicitly handled within the Ruby code itself.

INPUT AND OUTPUT

slimrb can process one or more Slim files specified as arguments. If no files are given, or if the --stdin option is used, it reads template content from standard input. The processed output is sent to standard output by default, unless the --output option is used to redirect it to a specified file.

RUBY INTEGRATION

Slim templates allow seamless embedding of Ruby code using specific syntax (e.g., = for output, - for execution, & for unescaped output). slimrb executes this embedded Ruby code during the rendering process, enabling the generation of dynamic content based on data or logic.

HISTORY

Slim was created to offer a faster and more streamlined alternative to Haml, focusing on performance and simplicity. It quickly gained popularity within the Ruby community for its clean syntax and speed, becoming a favored choice for web applications, especially those built with frameworks like Ruby on Rails or Sinatra, where efficient template rendering is crucial. Its development continues to evolve with Ruby language features, maintaining its position as a robust templating solution.

SEE ALSO

haml(1), erb(1), ruby(1)

Copied to clipboard