Skip to content

Commit

Permalink
Sass support.
Browse files Browse the repository at this point in the history
Based on code by imanel (http://github.com/imanel/jekyll/commit/ff69a29fc25093f13cc6da4f4f9f962db20c500b), with some modifications mostly for compatibility with latest Jekyll.
  • Loading branch information
henrik committed Apr 12, 2009
1 parent 40697ac commit 56e1707
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ compilation), you must install it (gem install rdiscount) and then you can
have it used instead:

$ jekyll --rdiscount

h3. Sass

To transform all ".sass":http://github.com/nex3/haml/tree/master
files anywhere in your file tree to CSS (e.g. '/css/site.sass' will
generate '/css/site.css'):

$ jekyll --sass

h3. Local Server

Expand Down
4 changes: 4 additions & 0 deletions bin/jekyll
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ opts = OptionParser.new do |opts|
options['permalink_date'] = format unless format.nil?
end

opts.on("--sass", "Use Sass from haml gem for CSS generation") do
options['sass'] = true
end

opts.on("--version", "Display current version") do
puts "Jekyll " + Jekyll.version
exit 0
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Jekyll

'lsi' => false,
'pygments' => false,
'sass' => false,
'markdown' => 'maruku',
'permalink' => 'date',

Expand Down
35 changes: 34 additions & 1 deletion lib/jekyll/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Jekyll

class Site
attr_accessor :config, :layouts, :posts, :categories
attr_accessor :source, :dest, :lsi, :pygments, :permalink_style, :permalink_date
attr_accessor :source, :dest, :lsi, :pygments, :permalink_style, :permalink_date, :sass

# Initialize the site
# +config+ is a Hash containing site configurations details
Expand Down Expand Up @@ -31,6 +31,16 @@ def reset
def setup
# Check to see if LSI is enabled.
require 'classifier' if self.lsi

if self.config['sass']
begin
require 'sass'
self.sass = true
puts 'Using Sass for CSS generation'
rescue LoadError
puts 'You must have the haml gem installed first'
end
end

# Set the Markdown interpreter (and Maruku self.config, if necessary)
case self.config['markdown']
Expand Down Expand Up @@ -92,6 +102,7 @@ def process
self.reset
self.read_layouts
self.transform_pages
self.transform_sass if self.sass
self.write_posts
end

Expand Down Expand Up @@ -195,6 +206,28 @@ def transform_pages(dir = '')
end
end

# Transform all *.sass files from <dest> to css with the same name
# and delete source sass files.
# Returns nothing
def transform_sass(dir = '')
base = File.join(self.source, dir)
entries = Dir.entries(base)
entries = entries.reject { |e| ['.', '_'].include?(e[0..0]) }
directories = entries.select { |e| File.directory?(File.join(base, e)) }
directories.each { |d| transform_sass(File.join(dir, d)) }
files = entries.reject { |e| File.directory?(File.join(base, e)) }
files = files.select { |f| File.extname(File.join(base, f)) == ".sass" }
files.each do |f|
input = File.open(File.join(base, f), "r")
result = Sass::Engine.new(input.read, :style => :compact, :load_paths => base).render
FileUtils.mkdir_p(File.join(self.dest, dir))
output = File.open(File.join(self.dest, dir, f).gsub(/.sass\Z/, ".css"), "w") do |o|
o.write(result)
end
FileUtils.rm(File.join(self.dest, dir, f))
end
end

# Constructs a hash map of Posts indexed by the specified Post attribute
#
# Returns {post_attr => [<Post>]}
Expand Down

0 comments on commit 56e1707

Please sign in to comment.