Watches slim files, compiles them to HTML on change.
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
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
:extension => "html" # Output extension
# Default: "html"
: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: {}
guard "slim", :all_on_start => true do
watch(%r{^templates/.+(\.slim)$})
end
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)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request