How to install and use Slim template engine with Middleman
So here we go... after much reading and searching google for examples I think I figured it out.
To get Slim working with Middleman
- Add
gem "slim"
to your project's gemfile - go to command line, in your project folder and
gem install bundler
- In the config.rb file add
require 'slim'
- Start the middleman server to test it
Include a slim file in another slim file
Looks like it can be done in this way:
Slim::Template.new('template.slim', optional_option_hash).render(scope)
Found in slim readme: https://github.com/slim-template/slim
How to add html-file with JavaScript code in template Slim?
The best way to add some javascript to your slim file is either by including the javascript file using
= javascript_include_tag 'name of the file'
or by directly adding the javascript code to your slim file, using
javascript:
code line 1
code line 2
...
Define custom title for calendar pages in MiddleMan
In the end, here's how I chose to proceed : in my calendar.slim and tag.slim templates, I simply defined a @title
variable that I use in my default layout. In calendar.slim
, I use the built-in variables year
, month
and day
to build a title string, and in tag.slim
, I use the built-in tagname
variable.
[calendar.slim]
- case page_type
- when 'month'
- date = date_to_fr Date.new(year, month, 1).strftime('%B %Y')
- when 'year'
- date = year
- @title = "#{date} - Archives"
(...)
And then in the layout, I then use the following code to display my @title
variable followed by my blog name, unless @title
does not exist (then I just use my blog name as the page title) :
[layout.slim]
title
= "#{@title} | " unless @title.nil?
| Pierre-Adrien Buisson : Le Blog !
Related Topics
Have a Parent Class's Method Access the Subclass's Constants
Implicit Argument Passing of Super from Method Defined by Define_Method() Is Not Supported
Using Negative Conditions Within Regular Expressions
Update Rails to a Specific Version
How to Read Post Data in Rack Request
Ruby Syntactic Sugar: Dealing with Nils
Good Resources to Learn MACruby
Why Does Array#Each Return an Array with The Same Elements
What Exactly Is a Gem Native Extension
"No Available Formula for Gcc46" While Installing Ruby 1.9.3 on Os X with Rvm:
Superclass Mismatch, Struct, Reloading and Spork
Passing Local Variables to a View from Controller
Undefined Method 'Reset' for Rdoc::Toplevel:Class When Installing a New Ruby Gem
What Are Some Examples of Using Nokogiri
Where Is the Best Place to Add Methods to the Integer Class in Rails
Download File from S3 to Rails 4 App
Preventing Delayed_Job Background Jobs from Consuming Too Much CPU on a Single Server