zmoazeni/csscss

Implement "--require path/to/file.rb" to allow the user to customize requires/setup

Melindrea opened this issue · 12 comments

Related to #40 (sort of).

Not sure how high priority this should have, but the ability to in the call to the gem give a number of gems that are being used in the file(s), like the following:

csscss --compass --gems [breakpoint, bourbon, sass-getunicode]

This would for instance be useful if one does what I do: compile Sass through Grunt. I don't have a config.rb, all of my options are set in my Gruntfile.js, so the theory is that if there was support for supplying required gems, grunt-csscss could fetch requirements from the file.

I think what I prefer is to have a switch like --require /path/to/file.rb. Then the user can require whatever gems or prepare any configurations they want. I'd rather not call it --config because they're not really configuring csscss or any options for it.

Works for me. I suddenly realised that using gems like breakpoint is not limited to compass, so found the syntax for sass:

sass -r sass-getunicode --watch sass_dir:css_dir

Which means that yeah, there really needs to be something to be able to parse Sass properly, I'd imagine.

Do something with the Gemfile if present, maybe? (inspired by #55)

Nah, I'm not going to directly interface with bundler. What you're describing can be achieved with:

bundle install
bundle exec csscss ...

Not quite, unfortunately. You got my hopes up there a moment! =)

# Gemfile for MarieHogebrandt.se
source "https://rubygems.org"

gem "compass"
gem "breakpoint"
gem "sass-getunicode"
gem "csscss"

Style.scss

@charset "UTF-8";

//Gems from Ruby
@import "compass";
@import "breakpoint";

And when I run bundle exec csscss --compass app/styles/style.scss, I still get the error message:

app/styles/style.scss:8: File to import not found or unreadable: breakpoint. (Sass::SyntaxError)
Load paths:
  /home/marie/.rvm/gems/ruby-1.9.3-p194/gems/compass-0.12.2/frameworks/blueprint/stylesheets
  /home/marie/.rvm/gems/ruby-1.9.3-p194/gems/compass-0.12.2/frameworks/compass/stylesheets
  Compass::SpriteImporter
etc

Yeah, once I implement the --require flag, that will work with:

bundle exec csscss --require myconfig.rb --compass app/styles/style.scss

# in myconfig.rb
require "breakpoint"
require "sass-getunicode"

# Or a shorter version
require 'bundler'
Bundler.setup

bundler doesn't auto require the gems in the Gemfile right away. You have to do it, or it will be done when booting rails.

Can you tell that I only use gems due to Sass/Compass? =)

So, if I understand how you're figuring with --require, it'd be giving it a path to a config where any required files are stated, rather than giving it a list of required gems to load?

So, if I understand how you're figuring with --require, it'd be giving it a path to a config where any required files are stated, rather than giving it a list of required gems to load?

Yeah. There's not a great reason for csscss to manage requiring gems. It can attempt a few things, but beyond that it's better to put it in the user's control. Too many edge cases in that implementation that I would rather avoid.

Works for me. I'll explore a few things on how to use that for Grunt, since that's the case I need.

Awesome tool =)

This will go out in the next release

And this works, assuming I also require compass in my config file, which I can live with. (If I don't, there's some issues with some of the options I'm using)

@Melindrea I think csscss --compass --require ... will work. I'd like to deprecate the --compass flag, but I'm not positive I can yet.