Have you had success compiling SASS in multiple directories? Can you set up compass to recursively watch a directory?
I have read the documentation on add_import_path, but I would really appreciate some sample code, as I have (I am fairly certain) never written a line of ruby code.
The reason I ask is that I have several projects that share some standard scss. I would like changes to the shared scss to cascade to all projects.
thanks.
Let's say you have the following directroy structure:
project
|-- config.rb
+-- apps
|-- main.scss
|-- app1
+-- appst1.scss
|-- app2
+-- appst2.scss
+-- app3
+-- appst3.scss
Then adjust your config.rb:
sass_dir = "apps"
add_import_path "apps"
...
and in your main.scss include the other scss files:
#import "app1/appst1";
#import "app2/appst2";
#import "app3/appst3";
Here is my solution that supports batch compass compile/watch of multiple independent SASS projects, based on two Ruby scripts.
Folder structure with the Ruby files:
Root
--compile.rb
--watch.rb
--Module1
----config.rb
----css
----sass
--Module2
----config.rb
----css
----sass
--Module3
----config.rb
----css
----sass
Run compile.rb and watch.rb with several arguments representing the paths to your module folders containing the config.rb files.
I.e. : ruby compile.rb Module1/ Module2/ Module3/
compile.rb
require 'rubygems'
require 'compass'
require 'compass/exec'
ARGV.each do |arg|
Compass::Exec::SubCommandUI.new(["compile", arg, "--force"]).run!
end
I.e. : ruby watch.rb Module1/ Module2/ Module3/
watch.rb
require 'rubygems'
require 'compass'
require 'compass/exec'
threads = []
ARGV.each do |arg|
threads << Thread.new {
Compass::Exec::SubCommandUI.new(["watch", arg, "--force"]).run!
}
sleep(1)
end
threads.each { |thr| thr.join }
Notice that we need to create a separate thread for each compass watch (since they are blocking processes). sleep(1) is necessary because Compass::Exec::SubCommandUI is not actually thread-safe and might run several watches on the same module, instead of one on each. In case that happens, try increasing the sleep value.
Create a similar config.rb file in all modules. You might have to use compass init to get the a first config.rb that compass recognizes.
config.rb
http_path = "/"
css_dir = "css"
sass_dir = "sass"
Related
I'm creating a gem called brval, and my folder structure is:
lib/
brval/ ... brval files
cep/ ...cep files
brval.rb
I can require and use all modules and classes inside brval/ folder, I just need to add
require 'brval/file.rb' inside brval.rb and then use extend or include to add the modules to brval main module.
But for files inside cep/ folder I can't do that, doesn't work.
I tried to require 'cep/cep_file' (is a class) inside brval.rb module
But when I build my gem to test it I always got the same error:
lib/cep/cep_file.rb:1:in '<top (required)>': uninitialized constant Cep(NameError)
My cep_file module and class structure is:
module Cep
class CepFile
methods...
In my gemspec file I also have:
spec.files = Dir['lib/**/*', 'README.md']
spec.require_paths = ['lib']
I have the following directory structure.
Gulpfile.js
--dist
--src
----config.rb
I'm using Gulp from the root project directory to compile my scss, which is what I think is causing issues.
When I compile (creating a sprite sheet, specifically) the URL ends up being /src/other/stuff/here when I need it to just be /other/stuff/here
You can see my config.rb here.
http_path = "/"
css_dir = "src/assets/css"
sass_dir = "src/assets/sass"
images_dir = "src/assets/images"
javascripts_dir = "src/assets/js"
relative_assets = true
output_style = :compressed
line_comments = false
Then in my scss file, I use the following to generate the sheet.
#import "icons/*.png";
#include all-icons-sprites;
It creates it fine, but I just need to remove the src folder. I could do this with a search/replace pipe in Gulp, but I'd rather just have my config file setup properly if that's possible.
What should I look into to make this work how I need it to?
I want to add Compass to my existing project.
I want to maintain my current project structure, which looks like this (simplified):
app/
build/
|-compass/
assets/
|-css/
|-scss
|-js/
|-img/
So I want all my SASS files under \assets\css\scss and I want to output the compiled CSS files to \assets\css.
Running:
compass create --bare --sass-dir "assets\css\scss" --css-dir "assets\css"
creates the Compass config.rb file directly under my root.
However, I want the file to be under \build\compass.
How can I control where Compass creates the config.rb file?
Compass documentation says that declarations in config.rb (e.g. css_dir, sass_dir, etc.) are all relative to the project_path. Where do I define the project_path?
Compass creates the config.rb in the same directory as where you ran the command from. The project path is where the config.rb resides. You're free to place config.rb wherever you like, as long as you adjust the paths for your assets.
This is an example of config.rb:
# Require any additional compass plugins here.
require 'compass/import-once/activate'
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "../../assets/css"
sass_dir = "../../assets/css/scss"
# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed
output_style = :expanded
# To disable debugging comments that display the original location of your selectors. Uncomment:
line_comments = false
# Enable source map
sourcemap = true
And with this config.rb settings, your project folder should be like (as you wrote):
MyFolder
├ app
├ build
│ └ compass
│ └ config.rb
└ assets
├ css/
│ └ scss/
├ js
└ img
If you don't have a config.rb, simply create a new file "config.rb" and copy/paste inside the configuration i wrote.
Open your terminal, enter in MyFolder/build/compass and then start your compass command, like: compass watch
Remember
You have to execute your compass command in the same folder where is the config.rb file. So in this case in MyFolder/build/compass. Otherwise compass doesn't work.
I don't see why you'd structure a project like this...I mean why not put the scss in build and then everything in assets can be deployed for production?
So:
1.
Running (from "app" directory)
compass create build --http-pat="../" --sass-dir="compass/scss" --css-dir="../assets/css" --javascripts-dir="../assets/js" --images-dir="../assets/img"
will create the project folders and files as such:
app
|-- build
| |--config.rb
| |-- compass
| |-- scss
|-- assets
| |-- css
| |-- img
| |-- js
Again, from within app directory, running:
compass config "build/config.rb" --http-pat="../" --sass-dir="compass/scss" --css-dir="../assets/css" --javascripts-dir="../assets/js" --images-dir="../assets/img"
will simply create the build directory and place a configuration file with these values in it.
I'm new to writing big Ruby projects (only mods and application scripting till now). I've made a project with some files in the project root and others in subfolders, including a "Test" folder.
So far I've tried:
Adding all folders and subfolders to the load path in RubyMine.
Declaring all the files to be part of the same module.
I've thought of using require_relative for loading all files needed but it seems tiresome and very Java-esque... Is there a better way?
Here is an example of a typical folder structure, its modules and how to include everything into the library. You would then only need to require 'lib' wherever you want to pull in the library for use.
# Root folder structure of project
lib.rb
./lib/a.rb
./lib/b.rb
./lib/b/c.rb
# lib.rb
require 'lib/a'
require 'lib/b'
module Lib
end
# ./lib/a.rb
module Lib
module A
end
end
# ./lib/b.rb
require 'lib/b/c'
module Lib
module B
end
end
# ./lib/b/c.rb
module Lib
module B
module C
end
end
end
So, I am trying to create a gem with a lib folder and a spec folder for rspec tests, like so:
- my_gem
|-- lib
| |-- my_gem
| | |-- foo.rb
| |
| |-- my_gem.rb
|
|-- spec
| |-- lib
| |-- foo_spec.rb
|
|-- my_gem.gemfile
|-- Rakefile
my_gem.rb contains require 'my_gem/foo' which works fine.
But my spec file which tries to require 'lib/my_gem' doesn't work. When I run rspec (or rake spec) without explicitly setting a path with -I ., it fails to load the file:
foo_spec.rb:1 in `require': cannot load such file -- lib/my_gem.rb (LoadError)
I feel like I shouldn't have to require a spec_helper.rb in every spec just to fix this, nor should I have to specify the load path for rspec every time. There has to be a simple convention that I am missing because I am new to gem development (I usually only do rails stuff).
Edit: I should point out that I am well aware that I can require_relative '../../lib/my_gem.rb'. The point is that I want to be able to get the root folder onto my path automatically like I am used to in rails. If this just isn't possible then please let me know.
The spec doesn't know the path to lib/my_gem. Try
require_relative '../../lib/my_gem'