I am trying to add a custom compass function using ruby.
Here is my code. But finding hard to pick that function.
My folder structure
resources
-- css
-- extensions
----- extension_name
---------- stylesheets
-------------- _extension_name.scss
---------- templates
---------- compass_init.rb
-- icons
-- images
-- sass
----- something.scss
In compass_init.rb
require 'sass'
module WikiaFunctions
def get_command_line_param(param_name, default_result='')
result = ARGV.find {|arg| arg =~ /^#{param_name}=/} || default_result
Sass::Script::String.new result.split(/=/).last
end
end
module Sass::Script::Functions
include WikiaFunctionss
end
In my own Scss file something.scss
.test {
display: block;
background-color: get_command_line_param("logoColor", "white");
}
But the out put of something.css is
.test {
display: block;
background-color: get_command_line_param("logoColor", "white");
}
What am i doing wrong here?
Please guide me in getting this solved. Basically my compass version is in 0.12.7 and str_index, str_length and str_slice is not supported to make custom str_replace. So I wanted to build my own string functions.
I can't upgrade to compass version 1 or higher as my sencha touch application doesn't support it.
So I am planning to write my own ruby function but failing to do so.
Related
I don't understand what this compile error is describing because I do define the SASS variable:
Dart Sass failed with this error: Undefined variable.
╷
64 │ color: $sc-blue-light;
│ ^^^^^^^^^^^^^^
╵
_partials/navigation/_search.scss 64:12 #use
style.scss 65:1 root stylesheet
_utilities.scss
$sc-blue-light: #5BC2E7;
_search.scss
.search {
color: $sc-blue-light;
}
_style.scss (the main stylesheet)
#use '_partials/base/_utilities';
#use '_partials/navigation/_search';
The utilities are being loaded first, which is what I've read in other answers but it's not applying here. The file paths are correct.
All my other styles compile okay. It's just when I started using variables that this error comes up.
Any thoughts?
TL;DR
Add #use rule at top of the file in _search.scss too.
With namespace
#use '_partials/base/_utilities';
.search {
color: utilities.$sc-blue-light;
}
or without namespace
#use '_partials/base/_utilities' as *;
.search {
color: $sc-blue-light;
}
Quote from official sass
Members (variables, functions, and mixins) loaded with #use are only
visible in the stylesheet that loads them. Other stylesheets will need
to write their own #use rules if they also want to access them.
and
The simplest #use rule is written #use "", which loads the module
at the given URL. Any styles loaded this way will be included exactly
once in the compiled CSS output, no matter how many times those styles
are loaded.
Read about sass #use members
Read about sass #use namespace
I have scss files that use variables for colors. like -
.label-primary, .badge-primary {
background-color: $navy;
color: #FFFFFF;
}
.label-success, .badge-success {
background-color: $blue;
color: #FFFFFF;
}
.label-warning, .badge-warning {
background-color: $yellow;
color: #FFFFFF;
}
These variables are defined in variables.scss file
I have already #imported #import "base/variables"; in application.css.scss file.
// Variables, Mixins
#import "base/variables";
#import "base/mixins";
but still it doesnt loads in other scss files and throws error Sass::SyntaxError: Undefined variable: "$navy". where trying to precompile in production.
I have to explicitely #import "base/variables"; in every scss file on the top. there are 35 files.
How can i define this variable.scss file in just one place so that its loaded in every scss file?
NOTE: I am using rails-api gem and the application is API only. I have tweaked a bit to make some views on this application.
Have you tried sprockets-sass gem ? It works great with Sprockets 2.x and 3.x with both SCSS and SASS files.
And it does exactly what you need :D
This one is not easy!
I'm building a page that switches between two locales AR & EN (RTL & LTR)
page is built using SCSS bootstrap v3.
having this as a fun fact:
http://sass-lang.com/documentation/file.FAQ.html#q-ruby-code
I already have all Boostrap files switch between left & right based on one single SCSS flag (ie. $flag-direction)
My main concern now is what to do with assets pipeline on Production environment ? things seems to work fine when switching between RTL & LTR flag.
But in production it only creates on version and then starts serving that version. Did anyone work around this ?
I always end up finding solutions like these: http://dolinked.com/questions/229493/maintain-rtl-version-of-stylesheets-with-rails-asset-pipeline
which are a little scary since it's too much of a work around. is there anything simpler ?
Thanks !
As I do understand you want compile all code into a single CSS file? Unless you change the Bootstrap code yourself, i expect that you will load many unused CSS code. If your are able to set the text directory of your HTML conditionally, you should also able to load your CSS file(s) dynamically and compile a CSS file for each text direction.
Otherwise you possible can use the nested #import feature of Sass:
With grid.scss:
#at-root body#{&} {
direction: $direction;
}
.row {
float: $float;
}
The following code:
.rtl {
$direction: rtl;
$float: left;
#import "grid.scss";
}
.ltr {
$direction: ltr;
$float: right;
#import "grid.scss";
}
compiles into CSS code as follows:
body.rtl {
direction: rtl; }
.rtl .row {
float: left; }
body.ltr {
direction: ltr; }
.ltr .row {
float: right; }
I'm confused about how works assets pipeline, im using a gem called aloha-rails and it have the next CSS rule:
button.aloha-button {
background: url("../img/base.png") no-repeat scroll 0 0 transparent !important;
}
If I run it on local, that rule is on file:
http://local.dev/assets/aloha/css/aloha.css?body=1
And I CAN see the image, it is loaded from this address:
http://local.dev/assets/aloha/img/base.png
But when I run it on heroku, on when I precompile assets on local the css rule is loaded from applications.css, the rule still with ../img/base.png so the image is trying to be loaded from:
http://server.herokuapp.com/img/base.png
and that DOESNT exist, so I receive a 404 error and dont see the image.
Write as following: Remove the dots(..) before the path.
button.aloha-button {
background: url("/img/base.png") no-repeat scroll 0 0 transparent !important;
}
Please do let me know if not working still.
In order to access your image assets in production, where asset precompilation will stick a hash at the end of each filename, you need to use the img-url helper provided by sass-rails if your css has a .scss or .sass extension, or you can use the asset_path helper if you add .erb to the end of your stylesheet filenames:
button.aloha-button {
background: image-url("/img/base.png") no-repeat scroll 0 0 transparent !important;
}
It seems like the aloha-rails gem doesn't do this. Probably also needs to drop the .. in front of the path.
I would like to stop importing my Sass files with Sprocket and using the #import function of Sass.
It works fine but the files are not imported one by one in developement mode so the debuging is harder.
Is there a way to import all files separately with Sass in developement mode?
You can enable asset debugging in Sprockets by adding the setting to your development.rb:
# Expands the lines which load the assets
config.assets.debug = true
When debug is true, compiled CSS files contain line numbers that tell you where to find the uncompiled CSS:
/* line 5, ../../../app/assets/stylesheets/_colors.scss */
.color-facebook-blue {
color: #3B5998;
}