Linux command
slim 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Convert a Slim template
slimrb [input.slim]
Read Slim from stdin
echo "[h1 Hello]" | slimrb -s
Convert Slim to ERB
slimrb -e [input.slim]
Output pretty-printed HTML
slimrb -p [input.slim]
Compile to Ruby code
slimrb -c [input.slim]
Generate Rails-compatible code
slimrb --rails [input.slim]
Pass local variables
slimrb -l "{name: 'World'}" [input.slim]
Load a Ruby library
slimrb -r [library] [input.slim]
说明
slimrb is the command-line tool for the Slim template language. Slim is a lightweight Ruby templating engine that reduces HTML syntax to essential parts while maintaining readability. It uses indentation for nesting, eliminating the need for closing tags. Slim syntax is concise: div.container becomes \<div class="container"\>, and h1= title outputs the value of title in an h1 tag. Attributes use parentheses: a(href=url) Link. The tool can render templates to HTML, convert them to ERB for use in other contexts, or compile them to raw Ruby code for inspection. The --pretty option is useful for debugging, producing formatted HTML output. Slim integrates with Rails, Sinatra, and any Rack-based framework through Tilt. It is one of the fastest Ruby template engines, comparable to Erubis in production mode.
参数
- -s, --stdin
- Read input from standard input instead of a file
- -c, --compile
- Compile template to Ruby code without executing
- -e, --erb
- Convert Slim template to ERB format
- --rails
- Generate Rails-compatible code (implies --compile)
- -p, --pretty
- Output pretty-printed HTML with indentation
- -r, --require _library_
- Load a Ruby library or Slim plugin before processing
- -o, --option _name=code_
- Set Slim engine options
- -l, --locals _Hash|YAML|JSON_
- Pass local variables to the template
- --trace
- Show full traceback on errors
- -v, --version
- Display version information
- -h, --help
- Show help message
FAQ
What is the slim command used for?
slimrb is the command-line tool for the Slim template language. Slim is a lightweight Ruby templating engine that reduces HTML syntax to essential parts while maintaining readability. It uses indentation for nesting, eliminating the need for closing tags. Slim syntax is concise: div.container becomes \<div class="container"\>, and h1= title outputs the value of title in an h1 tag. Attributes use parentheses: a(href=url) Link. The tool can render templates to HTML, convert them to ERB for use in other contexts, or compile them to raw Ruby code for inspection. The --pretty option is useful for debugging, producing formatted HTML output. Slim integrates with Rails, Sinatra, and any Rack-based framework through Tilt. It is one of the fastest Ruby template engines, comparable to Erubis in production mode.
How do I run a basic slim example?
Run `slimrb [input.slim]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -s, --stdin do in slim?
Read input from standard input instead of a file