Home

Awesome

Guard-Slim

Build Status Code Climate

Watches slim files, compiles them to HTML on change.

Installation

Add the gem to your Gemfile

gem "guard-slim", :git => "https://github.com/indrekj/guard-slim.git"

Add guard definition to your Guardfile by running this command:

~ guard init slim

Options

The following options can be passed to guard-slim:

  :input => "templates"    # Relative path to the input directory
                           # Default: templates

  :output => "public"      # Relative path to the output directory
                           # Default: public

  :all_on_start => false   # Compiles all slim files on start
                           # Default: false

  :context => ContextClass # Render the template in the given context with
                           # the locals specified as methods. Look below for
                           # an example.
                           # Default: nil

  :slim_options => {}      # Options for slim engine. e.g {:pretty => true}
                           # Default: {}

Sample Guardfile

guard "slim", :all_on_start => true do
  watch(%r{^templates/.+(\.slim)$})
end

Context

Context classes provide helpers for slim templates. Lets say you want to generate translations relative to your template path.

class SlimContext
  def initialize(template)
    @scope = extract_scope(template.path)
  end

  def t(key)
    I18n.t(key, :scope => @scope)
  end
end

guard "slim", :context => SlimContext do
  watch(%r{^templates/.+(\.slim)$})
end

Now you can use t in your slim templates:

h1 = t(:title)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request