I have a SCSS project that builds on top of Foundation via Compass. It defines a set of sass variables, then defines a bunch of rules in terms of those variables: (my project has many more variable settings and import statements; this is simplified.)
vars.scss:
$foo = #fafafa
$bar = 14px;
// rules using $foo and $bar
#import '_rules';
I then use compass to compile vars.scss, and everything is great for that set of sass variables. However, I also want the ability to theme my app differently, and generate a different theme by defining a new set of variables which can override the original variables:
vars.scss:
$foo = #fafafa
$bar = 14px;
#import 'otherVars';
#import '_rules';
I can't edit the file manually when I have 70+ themes. (Having that many themes is necessary for the purposes of my app.) What I really want is to be able to do something like the following:
vars.scss:
$foo = #fafafa
$bar = 14px;
#import '{{otherVars}}';
#import '_rules';
And then I could call something like:
compass --otherVars themes/theme2
It would then be easy to whip out all the themes, because I could call compass once for each theme.
Does SCSS let you do this? I looked into it, and it doesn't look like it.
My current workaround is to split the original vars.scss into a prefix and suffix:
_app_prefix.scss:
$foo = #fafafa
$bar = 14px;
_app_suffix.scss:
#import '_rules';
app.scss:
#import '_app_prefix';
// no overrides by default
#import '_app_suffix';
And to override it for a specific theme, you'd make a file that looks like:
theme2.scss:
#import '_app_prefix';
// only override $foo - let the original value of $bar stand
$foo = #ebebeb;
#import '_app_suffix';
This works, but is sorta painful and introduces additional boilerplate.
My next problem is wanting to have additional #import 'rules_foo' statements, which also need to be constructed dynamically. So my overall fantasy would look like:
vars.scss:
$foo = #fafafa
$bar = 14px;
#import '{{otherVars}}';
#import '_rules';
{{ #import 'additional_rules' for additional_rules in rules }}
And I could call:
compass --otherVars themes/theme2 --rules "rules_1" "rules_2" "rules_3"
(Obviously this is somewhat handwavy but hopefully you get the idea.)
Is there a way to do this? Or am I going to have to resort to handlebars or some other templating language?
For people who are using Grunt to compile their SCSS/SASS files, the solution was to add an extra parameter loadPath to "sass" task configuration as follows:
sass: {
options: {
loadPath: ['../src/css/themes/myTheme/'],
style: 'nested',
precision: 2
},
And then in the /src/css/import.scss you can include those files from the theme as if they were in current directory:
#import "config";
The file was included from /src/css/themes/myTheme/config.scss.
NOTE: You can of course add a parameter to your Grunt task and have that theme name dynamic!
You could always generate a temporary file that you send to compass. With python code:
import sys
with open('tmp.scss', 'w') as out:
out.write(("""
$foo = #fafafa
$bar = 14px;
#import '%(pre-rules)s';
#import '_rules';
%(post-rules)s
""" % {'pre-rules': sys.argv[1], 'post-rules': '\n'.join(["#import '%s';" % x for x in sys.argv[2:]])}).strip())
You'd call it like:
python stackoverflow.py themes/theme2 rules_1 rules_2 rules_3
And it creates/overwrites tmp.scss with the output you want.
Related
I do not manage to force sphinx to apply first line indentation to paragraphs with the ReadTheDoc theme. I tried
texinfo_elements = {'paragraphindent': 2}
but it does not seem to work. Is there another thing to do?
You can use a custom style with text-indent.
You can add this style to a custom.css file and include it in your conf.py as a configuration option html_css_files.
custom.css
p {
text-indent: 1em;
}
conf.py
html_css_files = ['custom.css']
I am using the Material Design Components for Web library. I have a tab component that I'd like to change the underline-color of.
The instructions say
To customize the tab indicator, use the following mixins.
Then it gives a table. For underline color, it says
underline-color($color) Customizes the color of the underline.
So, I try in my scss file, the following:
.mdc-tab-indicator {
underline-color(red);
}
I compile my sass (using dart-sass) and get the following error
Error: expected "{".
It says this is a "Sass Mixin." So, I look at the SASS documentation on mixins. I see nothing that follows the syntax mixin-name($variable). Everything in there looks like
#mixin reset-list {
margin: 0;
}
with curly braces, not parentheses. But, the error said it was expecting a curly brace, and also apparently the # symbol is required. So, I try:
.mdc-tab-indicator {
#underline-color(red);
}
This doesn't throw an error, but doesn't cause the underline color to change. I try to follow the syntax of the sass docs:
.mdc-tab-indicator {
#underline-color(red){};
}
No error, but no color change. I try to match the syntax better:
.mdc-tab-indicator {
#mixin underline-color(red){};
}
This throws
Error: expected ")".
I try
.mdc-tab-indicator {
#mixin underline-color(red);
}
Same error.
I don't understand what the material components documentation is instructing. What does it mean when it says "To customize the tab indicator, use the following mixins." ? How can I change the underline color of the Material Design Component tab indicator?
Mixins are defined using the #mixin at-rule, which is written #mixin { ... } or #mixin name() { ... }. A mixin’s name can be any Sass identifier, and it can contain any statement other than top-level statements. They can be used to encapsulate styles that can be dropped into a single style rule; they can contain style rules of their own that can be nested in other rules or included at the top level of the stylesheet; or they can just serve to modify variables.
Mixins are included into the current context using the #include at-rule, which is written #include or #include (), with the name of the mixin being included.
So, to include your specific mixin use:
.mdc-tab-indicator {
#include underline-color(red);
}
See more at https://sass-lang.com/documentation/at-rules/mixin
I have a similar question to this, except for Sphinx and RST. Namely, I would like to prevent text from being hyphenated at the end of the line.
For example I want this:
This is my long sent-
ence.
To be:
This is my long
sentence.
How do I do this?
Hyphenation is implemented by the stylesheet basic.css in the Sphinx theme "basic".
div.body p, div.body dd, div.body li, div.body blockquote {
-moz-hyphens: auto;
-ms-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
You can override these styles with your own. See my answer to How do I customize Sphinx RtD Theme default search settings?
Your theme may have JavaScript or other styles that implement hyphenation.
For PDF output, see https://tex.stackexchange.com/a/5039
After reading pointers from #steve-piercy, I managed to find a solution for the problem. I need to customize conf.py in my project. My conf.py has the following settings:
# ...
# ...
# -- Options for LaTeX output ------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
'papersize': 'a4paper',
# The font size ('10pt', '11pt' or '12pt').
#
'pointsize': '12pt',
# Additional stuff for the LaTeX preamble.
#
'preamble': r'''
\usepackage[none]{hyphenat}
'''
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# ...
# ...
I am using Sphinx 1.8.2, MikTex 2.9 and Strawberry Perl 5.28.1. This new change in conf.py will download new perl package(s).
I'm using Bourbon and SASS-flavour Bootstrap. Here's my base SCSS file:
#import '../../bower_components/bourbon/dist/_bourbon.scss';
#import 'app/swatches.scss';
#import '../../bower_components/bootstrap-sass/lib/bootstrap.scss';
#import 'app/theme.scss';
The idea is that I pull in Bourbon first because I intend to use it all over the place, call in swatches.scss to set app-wide variables, call in Bootstrap (which uses some of the swatches), and then go about customising my application on top of Bootstrap. swatches.scss looks like this:
// The brand
$blue : #0078ae;
$grey-light : #58595b;
$grey-dark : #59595e;
$gradient-blue : linear-gradient( #0089ca, #006cb9 );
$gradient-grey : linear-gradient( #e1e2e2 0, #d8d9da 33%, #cecece 33.001%, #b8b8b8 100% );
// Set Bootstrap's variables (map back to our own vars if need be)
$brand-primary : $blue;
$btn-default-color : #fff;
$panel-primary-heading-bg : $gradient-blue;
$panel-default-heading-bg : $gradient-grey;
%gradient-blue {
#include background-image( $gradient-blue );
}
Somehow, Bootstrap doesn't receive the compiled output of $gradient-blue — it receives the uncompiled string linear-gradient( #0089ca, #006cb9 ). Code in theme.scss has no problem invoking $gradient-blue (or the extension %gradient-blue).
I would have expected $gradient-blue to compile once and be done. How is this not happening?
I think you should use linear-gradient in syntax:
$gradient-blue : #include linear-gradient( #0089ca, #006cb9 );
$gradient-grey : #include linear-gradient( #e1e2e2 0, #d8d9da 33%, #cecece 33.001%, #b8b8b8 100% );
because it's a mixin. Look at documentation: http://bourbon.io/docs/#linear-gradient
This question already has answers here:
False positive "undefined variable" error when compiling SCSS
(4 answers)
Closed 7 years ago.
In my app.scss I import compass like this:
#import "compass/css3";
and I can use all the mixins in app.scss
But when I import a partial:
#import "structure";
and I want to use a mixins inside stucture.scss (e.g. #include border-radius(4px);)
I get the following error:
error structure.scss (Line 544: Undefined mixin 'border-radius'.)
EDIT:
app.scss contents:
#import "compass/css3";
#import "structure";
// other scss code
.promo-front img {
#include border-radius(4px);
}
structure.scss contents:
// other scss code
// this generates error structure.scss (Line 544: Undefined mixin 'border-radius'.)
.main-container {
#include border-radius(4px);
}
What do I do wrong?
thanks in adavance!
ok, I needed to rename structure.scss to _structure.scss to be properly recognized as a partial.