Lietu's homepage

Lietu's tech blog

Yet another techie blog by Janne Enberg, aka. Lietu

Jekyll

Jekyll is a tool that can be used to build static HTML websites using a HTML template engine etc., however it's not perfect by itself, and the documentation for the plugins is rather crappy at times.

Unfortunately, you will need to install ruby (including -devel packages) and do whatever you need to do to get RubyGems installer.

More about Jekyll: http://jekyllrb.com/

Jekyll Asset Pipeline

Definitely worth installing is jekyll-asset-pipeline, it makes sure your CSS and JS files are combined and compressed, as well as making sure (with a little help) that LESS, SASS, CoffeeScript etc. is converted prior to this.

To get this working, read up on https://github.com/matthodan/jekyll-asset-pipeline/

Jekyll Asset Pipeline and LESS

To get LESS compilation working with Jekyll Asset Pipeline, you need to add some code to the jekyll_asset_pipeline.rb file you already created. I tried to look for a ready solution, but eventually ended up combining two-three solutions into something that works.

It uses the node.js lessc compiler to process the files and is written in a fairly unoptimal way in general, because I haven't got a clue of how to write Ruby and this was the first thing that I got to work.

This is the complete contents of that file for me now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'jekyll_asset_pipeline'

# Additions to jekyll-asset-pipeline
module JekyllAssetPipeline

	# Compile LESS to CSS
	class LESSConverter < JekyllAssetPipeline::Converter

		# Dependencies
		require 'shellwords'

		# What filetypes we're interested in
		def self.filetype
			'.less'
		end

		# Function to convert input at @content to output via return
		def convert

			# Build a shell command to convert via lessc
			# echo "less content" | lessc -
			command = [
				"echo",
				Shellwords.escape(@content),
				"|",
				"lessc",
				"-x",
				"-O2",
				"-"
			].join(" ")

			# Execute the command and return stdout data
			return `#{command}`
		end

	end

	# Compress JavaScript
	class JavaScriptCompressor < JekyllAssetPipeline::Compressor
		require 'closure-compiler'

		def self.filetype
			'.js'
		end

		def compress
			return Closure::Compiler.new.compile(@content)
		end
	end
end

Comments

Copyright © 2012 Janne Enberg. All rights reserved.