Compass sprite-map support #8

Closed
ixti opened this Issue Jan 26, 2013 · 6 comments

Comments

3 participants
Contributor

ixti commented Jan 26, 2013

Need to find a way to support sprite-map feature of Compass, see discussion of #4 for details.

MrJoy commented Feb 20, 2013

I actually have this mostly sussed out. There are two parts to it.

  1. You need a dependency on sprockets-sass to bridge the API incompatibilities.

  2. You need to tell Jekyll about the generated spritemaps so it doesn't nuke them. I've got an ugly means of doing this, and I need to submit a slightly cleaner version as a pull request -- I'm monkey-patching things because I'm using Octopress at the moment, but the gist of it is this:

My Jekyll plugin looks like this:

require 'uglifier'
require 'sprockets'
require 'sass'
require 'compass'

compass_config = File.expand_path("../../config.rb", __FILE__)
Compass.add_project_configuration(compass_config)
Compass.discover_extensions!

require 'sprockets-helpers'
require 'sprockets-sass'
require 'jekyll-assets'
module Jekyll
  module AssetsPlugin
    class Environment < Sprockets::Environment
      def self.instance; return @instance; end
      def self.instance=(val); @instance = val; end
      alias_method :original_initialize, :initialize
      def initialize site
        original_initialize(site)
        self.class.instance = self
      end
    end
  end
end
require 'jekyll-assets/compass'

Then, my config.rb for Compass includes this at the bottom:

require 'tempfile'

# TODO: Find a way to finalize these things after a compilation run, or use
# TODO: a cache directory or some such...
sprite_temp_files = []
on_sprite_saved do |filename|
  env = Jekyll::AssetsPlugin::Environment.instance
  if(env)
    env.site.static_files << Jekyll::AssetsPlugin::AssetFile.new(env.site, Sprockets::StaticAsset.new(env, File.basename(filename), sprite_temp_files[-1].path))
  end
end

on_sprite_generated do |sprite_data|
  sprite_temp_files << Tempfile.new("/tmp/sprockets.")
  sprite_temp_files[-1].write(sprite_data)
end

kryptt commented Jul 20, 2013

I have the following jekyll plugin:

require 'uglifier'
require 'sprockets'
require 'sass'
require 'compass'

Compass.add_project_configuration("config.rb")
Compass.discover_extensions!

require "jekyll-assets"

module Jekyll
  module AssetsPlugin
    class Environment < Sprockets::Environment
      def self.instance; return @instance; end
      def self.instance=(val); @instance = val; end
      alias_method :original_initialize, :initialize
      def initialize site
        original_initialize(site)
        self.class.instance = self
      end
    end
  end
end

 require "jekyll-assets/compass"

along with this config.rb:

http_images_path = "assets"
images_dir = ".assets"
sprite_load_path = "_assets/img"

on_sprite_saved do |filename|
  env = Jekyll::AssetsPlugin::Environment.instance
  puts filename
  if(env)
    env.site.static_files << Jekyll::AssetsPlugin::AssetFile.new(env.site, Sprockets::StaticAsset.new(env, File.basename(filename), filename))
  end
end

Now your sprites are written directly to _sites/assets and can be referenced as assets/

Contributor

ixti commented Jul 20, 2013

Hm, I have some ideas how to make it out of the box now. Thanks. @kryptt may I see the sources of a website with this workaround so I could check if my ideas are correct?

kryptt commented Jul 20, 2013

sorry, I only just came across this problem myself, and I tried to clean up the fix from MrJoy

Contributor

ixti commented Jul 21, 2013

Well, I really need something I can play on :D

Contributor

ixti commented Jun 23, 2014

Should be fixed in master.

@ixti ixti closed this Jun 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment