Add a global load_path #131

Closed
petebrowne opened this Issue Jul 7, 2011 · 7 comments

Comments

Projects
None yet
3 participants
Contributor

petebrowne commented Jul 7, 2011

Backstory: I'd like to be able to make gems that contain mixins, like Compass & Bourbon. But after looking through their sources, I feel like adding mixins through a gem is needlessly complex. Bourbon is actually setup as a Rails 3.1 Engine using Sprockets 2! To include Sass mixins!

I think Sass is missing an API here. It should have a simple global array (Sass.load_path or Sass::Engine.load_path) which would be used by every Sass::Engine instance. So for a gem to include mixins, in any Sass environment, all they would have to is:

require "sass"
Sass::Engine.load_path << File.expand_path("../my_mixins_directory", __FILE__)

# or maybe even
Sass::Engine.add_load_path File.expand_path("../my_mixins_directory", __FILE__)

I realize that this functionality is sort of present in Sass::Plugin. But there are many places where you don't want to use the plugin...all you need is Sass::Engine. When using Tilt, for instance.

Think about it. It would be great for the Sass ecosystem if there were many gems containing mixins, a la Rack middleware. I'd be happy to work on a fork if you need help!

Owner

chriseppstein commented Jul 7, 2011

I think we need support for an environment variable based setting like SASSPATH. When an engine has no :load_path specified it would read this variable. I'm worried about a global setting for this at the engine level. It's really something best handled at a higher level.

Contributor

petebrowne commented Jul 7, 2011

I do like the idea of an environment variable, so you could setup non-gem load paths if you wanted to. But how would using the environmental variable work inside a gem? Like this?

ENV["SASS_PATH"] ||= []
ENV["SASS_PATH"] << File.expand_path("../my_mixins_directory", __FILE__)

# or
ENV["SASS_PATH"] = File.expand_path("../my_mixins_directory", __FILE__)

The second option is flawed, because if you required multiple gems with Sass mixins, only one would work. But option 1 feels really clumsy to me. I feel like there should definitely be an API within the Sass gem.

Owner

chriseppstein commented Jul 7, 2011

The convention for PATH variables is a delimited string. On unix platforms the delimiter is : and on windows its ;.

Compass supports simple extensions that have no ruby code whatsoever. All you have to do is drop a folder in the extensions directory that has a folder named "stylesheets" and this directory will be placed onto the load path.

Rubygems have some nice properties like being able to manage dependencies and versioning. But for the simple case, compass already handles this problem. At the end of the day, the framework is the piece that needs to decide how extensions are managed. The Sass::Engine is not the right place for this.

Contributor

petebrowne commented Jul 7, 2011

When you mention the framework, do you mean, for instance, Rails? Because, I don't think it makes any sense for Rails to manage Sass extensions...or Sprockets for that matter. Why does there need to be another layer of complexity for something so simple?

If I were to make a gem with some simple Sass mixins that I would like to use in Sinatra, currently the best option is Compass, like you said. But I don't need any of the functionality of Compass besides how it manages the load path.

So something that could be as simple as (with the change I suggested):

require "sinatra"
require "sass"
require "sass-cssframework" # made to work wherever Sass works
                            # (Rails, Sinatra, Tilt enabled libraries)

get "/stylesheet.css" do
  scss "@import 'cssframework';"
end

Would end up being:

require "sinatra"
require "sass"
require "compass"
require "compass-cssframework" # made specifically to work with Compass

configure do
  Compass.configuration do |config|
    config.project_path = File.dirname(__FILE__)
    config.sass_dir = "views"
  end
  set :scss, Compass.sass_engine_options
end

get "/stylesheet.css" do
  scss "@import 'cssframework';"
end

And I'm not even sure that would work!

Contributor

nex3 commented Dec 16, 2011

I agree with Pete here. Adding a SASS_PATH environment variable is essentially equivalent to having a global load path; it's just using a more obscure API for it. I think there's a need for a lightweight way for plugins to register themselves with Sass.

Owner

chriseppstein commented Dec 16, 2011

@nex3 I'm not convinced. We should chat.

Contributor

nex3 commented Dec 16, 2011

@chriseppstein Sure; ping me.

@nex3 nex3 closed this in 5c93cbf Dec 17, 2011

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