Project

General

Profile

Compass » History » Version 3

Benjamin Doherty, 04/15/2013 01:36 PM

1 1 Benjamin Doherty
h1. Compass
2
3
Maintaining projects with compass-based themes requires the ability to edit SCSS files and to recompile them to CSS. Be aware that any changes to CSS files (compiled output) will be lost when the stylesheets are recompiled, so you should always make changes to the SCSS files.
4
5 2 Benjamin Doherty
Compass is a tool for managing Sass stylesheet projects. Sass is a language that compiles to CSS and also the name of the compiler. Compass makes working with Sass outside of a Ruby project much easier, however it is entirely possible to work with a Compass project using just the Sass compiler. But truly it's not worth the trouble! You likely won't encounter a situation where you have sass but not compass and no permission to install compass.
6 1 Benjamin Doherty
7 2 Benjamin Doherty
h1. Installing compass
8
9
<pre>
10
sudo apt-get install rubygems
11
sudo gem install compass --pre
12
</pre>
13
14
This installs all dependencies including Sass.
15
16
Our projects tend to use additional compass plugins, which are installed as Ruby gems. Here are the set I commonly rely on:
17
18
<pre>
19
sudo gem install compass-rgbapng survivalkit foundation
20
</pre>
21
22
If one of these things is missing, you will be told in a very straightforward way when you try to compile a project that something is missing:
23
24
<pre>
25
benjamin@dev1:/var/www/dev/nlg/sites/all/themes/prudence$ /var/lib/gems/1.8/bin/compass compile
26
LoadError on line 31 of /usr/lib/ruby/1.8/rubygems/custom_require.rb: no such file to load -- survivalkit
27
Run with --trace to see the full backtrace
28
</pre>
29
30
The proper response to that is:
31
32
<pre>
33
sudo gem install survivalkit
34
</pre>
35
36
h1. Compass projects
37
38 1 Benjamin Doherty
I'm referring to SCSS which is a syntax of Sass that closely resembles CSS. From "Wikipedia":http://en.wikipedia.org/w/index.php?title=Sass_(stylesheet_language)&oldid=550390589
39
40 2 Benjamin Doherty
> Sass consists of two syntaxes. The original syntax, called "the indented syntax" uses a syntax similar to Haml. It uses indentation to separate code blocks and newline characters to separate rules. The newer syntax, "SCSS" uses block formatting like that of CSS. It uses braces to denote code blocks and semicolons to separate lines within a block. The indented syntax and SCSS files are traditionally given the extensions .sass and .scss respectively.
41 1 Benjamin Doherty
42 2 Benjamin Doherty
None of our projects use the Sass syntax. Both variants are fully supported by Compass and Sass.
43
44 1 Benjamin Doherty
Compass-based themes are compass projects. You can identify them by the "config.rb" file in the theme directory. This config.rb specifies the location of SCSS source files and the destination of compiled output. In almost every case, "css" is the name of the output directory and "sass" is the name of the source directory.
45
46
These directories are relative to the theme directory itself. If there's any confusion, view the config.rb file to find the exact names of the directories.
47
48
<pre>
49
# Location of the theme's resources.
50
css_dir         = "css"
51
sass_dir        = "sass"
52
extensions_dir  = "sass-extensions"
53
images_dir      = "images"
54
javascripts_dir = "js"
55
fonts_dir       = "fonts"
56
</pre>
57
58 2 Benjamin Doherty
In the "sass" directory, you will see the source files that end with "scss." Some of these files are prefixed with "_" which identifies them as "partials." This is a Ruby concept that appears throughout the ruby ecosystem. "For sass, this simply means:":http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html
59
60
> If you have a SCSS or Sass file that you want to import but don’t want to compile to a CSS file, you can add an underscore to the beginning of the filename. This will tell Sass not to compile it to a normal CSS file. You can then import these files without using the underscore.
61
62 3 Benjamin Doherty
h1. Recompiling compass
63
64
From the root of the _compass_ project (the Drupal theme), issue this command:
65
66
<pre>
67
/var/lib/gems/1.8/bin/compass compile
68
</pre>
69
70 1 Benjamin Doherty
h1. Editing SCSS
71
72 3 Benjamin Doherty
The SCSS syntax allows you to use the same CSS rules you would normally use and they will be passed through to the compiled output. The main trouble you will find is finding the place to edit.
73
74
If you cannot find the place to make your correction, it's possible that the CSS you want to change is actually being generated by a mixin or a partial, which means the specific code you want to edit is not going to be in the source file with a similar filename to the compiled output.
75
76
In this case, you will need to enable line comments and debugging in Compass. In the config.rb file look for this statement:
77
78
<pre>
79
line_comments = false
80
</pre>
81
82
And change it to "true."
83
84
Then recompile the output and you will see things like this:
85
86
<pre>
87
/* line 62, ../../../../../../../../lib/gems/1.8/gems/compass-0.13.alpha.4/frameworks/compass/stylesheets/compass/typography/lists/_horizontal-list.scss */
88
#social-media-links .pane-content ul li {
89
  list-style-image: none;
90
  list-style-type: none;
91
  margin-left: 0;
92
  white-space: nowrap;
93
  float: left;
94
  display: inline;
95
  padding-left: 4px;
96
  padding-right: 4px;
97
}
98
</pre>
99
100
This indicates that this CSS block is generated using code from the horizontal list mixin from Compass. That's not something you should necessarily edit, but you can read the documentation on that mixin to understand why it's being used.
101
102
<pre>
103
/* line 86, ../sass/_custom.scss */
104
.section-member #content .burr-flipped-content-inner a {
105
  color: black;
106
}
107
</pre>
108
109
This indicates that the code is being generated based on something in line 86 of _custom.scss, a partial file in this project, which you can edit.
110
111
It is *not* recommended to leave debugging enabled when committing your compiled output! It creates a lot of "diff noise" that doesn't belong in the git repository. When you've debugged your code, disable the line comments and re-compile before committing.
Go to top