matthodan / jekyll-asset-pipeline

Powerful asset pipeline for Jekyll that collects, converts and compresses JavaScript and CSS assets
http://www.matthodan.com/2012/11/22/jekyll-asset-pipeline.html
MIT License
364 stars 31 forks source link

Support For Compass and other extensions #17

Closed micahgodbolt closed 9 years ago

micahgodbolt commented 11 years ago

We use compass and a grid framework based on compass (susy), and are trying to set up a jekyll project with jekyll asset pipeline to work with these frameworks.

Is this possible? It appears the only way we've gotten it to work is to just include the compass and susy files inside of our sass folder, and @include them manually.

Is there any way have jekyll pull them from our gem directory, and to follow the configuration set up in the config.rb?

ggamel commented 11 years ago

:+1: from me as well. Too much good stuff in Compass and Compass extensions, but this Jekyll plugin is great.

Would :heart: this support added!

recurser commented 11 years ago

+1 would be very handy!

darrinholst commented 11 years ago

I hacked something together with

module JekyllAssetPipeline
  class CompassConverter < JekyllAssetPipeline::Converter
    require 'compass'
    require 'tempfile'

    def self.filetype
      '.scss'
    end

    def initialize(asset)
      @asset = asset
      super
    end

    def convert
      output = Tempfile.new('compass_output')
      Compass.add_project_configuration({})
      Compass.configure_sass_plugin!
      Compass.compiler.compile("./_assets/stylesheets/#{@asset.filename}", output.path)
      output.read
    end
  end
end

I didn't look really hard, but compass seems to be file only based in that you can't just pass it a string of sass and it will return you a string of css in the way that the asset pipeline currently works. So that's the reason for the tempfile and the hardcoded file paths. I could be wrong though.

The add_project_configuration would be where you pass a path to config.rb or just a hash of options. (I guess...I'm kind of a compass n00b)

alex88 commented 11 years ago

:+1: for me too! WIthout any tricky thing

lolmaus commented 11 years ago

I'm not sure whether it's relevant to Jekyll Asset Pipeline, but there is a way to compile SASS strings (not files) with support for Compass.

All you need is to do:

  Compass.sass_engine_options[:load_paths].each do |path|
    Sass.load_paths << path
  end

And then you can compile SASS strings like this:

sass a_sting_of_sass, {style: 'compressed', cache: false})

or using Tilt:

Tilt::SassTemplate.new('SASS code', {style: :compressed, cache: false}) { a_sting_of_sass }
jasonrobertfox commented 11 years ago

Awesome! Thanks for that, it was very helpful in integrating zurb foundation with this:

# Encoding: utf-8

require 'jekyll_asset_pipeline'
require 'compass'
require 'zurb-foundation'

module JekyllAssetPipeline

  # process SCSS files
  class SassConverter < JekyllAssetPipeline::Converter

    Compass.sass_engine_options[:load_paths].each do |path|
      Sass.load_paths << path
    end

    def self.filetype
      '.scss'
    end

    def convert
      Sass::Engine.new(@content, syntax: :scss).render
    end
  end
end
brtdv commented 10 years ago

@jasonrobertfox Thanks, that worked for me too!