compiling with the variables in _vars.scss ruby on rails 2.0 - ruby-on-rails

it's my first time to compiling a ruby on rails 2.0, and I have a problem with the variables in _vars.scss. The scss files are located in vendor/assets/stylesheets/scss (I located them here because was the only way they worked!) and they are calling them up in app/assets/stylesheets/application.css.scss:
#import "scss/bootstrap.scss";
#import "scss/vars.scss";
#import "scss/styles.scss";
#import "scss/fonts.scss";
#import "scss/icons.scss";
#import "scss/helpers.scss";
The problem that showed up is:
rake aborted!
Sass::SyntaxError: Undefined variable: "$screen-sm-max".
(in /var/rails/DeterminaRASIntegracio/releases/20180414113247/vendor/assets/stylesheets/scss/_styles.scss)
Thanks

The error message is pretty clear.
Sass tried to find variable $screen-sm-max on file _styles.scss but failed.
Try to add
$screen-sm-max: 42;
on file _styles.scss.
And see if that solves the problem.

Related

Rails: Font awesome icons not showing using font-awesome-rails gem

I can't seem to find an answer that works for me.
The icon shows up as a box: 
I'm using:
font-awesome-rails (4.6.2.0)
rails (4.2.3)
I imported font-awesome-rails in my application.scss file using:
#import "font-awesome";
and here is what I wrote for the view:
<i class="quote-left fa fa-quote-left"></i>
I've tried including it before and after bootstrap.
I also tried manually adding the font folder to the pipeline in application.rb
config.assets.paths << Rails.root.join("app", "assets", "fonts")
Clearing the tmp folder didn't seem to do anything either.
I spent way too much time on this, please help :(
I had this issue when working with Rails 6 and Bootstrap 4 in Ubuntu 20.04.
I had set up Fontawesome this way:
First I added Font Awesome to my package.json file:
yarn add #fortawesome/fontawesome-free
Next, I imported it into my app/javascript/packs/application.js file:
require("#fortawesome/fontawesome-free")
Next, I imported it into my app/assets/stylesheets/application.scss file:
$fa-font-path: '#fortawesome/fontawesome-free/webfonts';
#import '#fortawesome/fontawesome-free/scss/fontawesome';
#import '#fortawesome/fontawesome-free/scss/brands';
#import '#fortawesome/fontawesome-free/scss/solid';
#import '#fortawesome/fontawesome-free/scss/regular';
#import '#fortawesome/fontawesome-free/scss/v4-shims';
I also added the Font Awesome 5 Rails gem to my Gemfile:
gem 'font_awesome5_rails'
and installed it in my project:
bundle install
And finally I modified where my fontawesome icons were called from this format:
<i class="fas fa-camera-retro"></i>
to this format
fa_icon('camera-retro')
But the issue was that the icons were displaying fine in development but not in production.
Here's how I fixed it:
The issue was that I needed to import the FontAwesome 5 fonts into the app/assets/stylesheets/application.scss file. So I imported this to it:
#import 'font_awesome5_webfont';
So my fontawesome import to the app/assets/stylesheets/application.scss file looked like this finally:
#import 'font_awesome5_webfont';
$fa-font-path: '#fortawesome/fontawesome-free/webfonts';
#import '#fortawesome/fontawesome-free/scss/fontawesome';
#import '#fortawesome/fontawesome-free/scss/brands';
#import '#fortawesome/fontawesome-free/scss/solid';
#import '#fortawesome/fontawesome-free/scss/regular';
#import '#fortawesome/fontawesome-free/scss/v4-shims';
This time the icons displayed properly in development as well as production.
Note: Please ensure to re-compile your assets after making these changes and restart your server.
That's all.
I hope this helps
I moved my import of font-awesome below my font import and it solved it.
from this:
#import "font-awesome";
#import url("https://fonts.googleapis.com/css?family=Playfair+Display:700,900");
to this:
#import url("https://fonts.googleapis.com/css?family=Playfair+Display:700,900");
#import "font-awesome";
Try restarting your webserver, after adding #import 'font-awesome.css' to your application.scss.
Also read these, if you haven't yet,
https://github.com/bokmann/font-awesome-rails/issues/130#issuecomment-95308175
https://github.com/bokmann/font-awesome-rails/issues?q=is%3Aissue+is%3Aclosed
I solved this issue by explicitly declaring a font-family: FontAwesome; rule in my stylesheet because a global * style was overwriting the font-family attribute for the .fa class.

Sass::SyntaxError Undefined Variable

There are already a plethora of questions on how to resolve the above error message.
The one with the best answers seems to be Sass::SyntaxError Undefined Variable, which unfortunately is quite old already.
My current (works on Rails 4.2) solution to the problem is to #include a file called _variables.sass from every other .sass file that needs to make use of the variables such as color values or font-family definitions. It would, however, be much more convenient if the _variables.sass file could be #imported once from within application.sass (before anything else of course).
All of my attempts at accomplishing this, including using only file names starting with an underscore, have failed. My question is thus if anybody knows how to achieve SASS variables in one file being available to multiple other files with central #import statements in application.sass on Rails 4.2?
Here's proof of error message with the above described setup.
Files:
$ ls app/assets/stylesheets/
application.sass _foundation_and_overrides.sass _list_defaults.sass _phrases.sass _translations.sass _users.sass
_bidi.sass _layout.sass _pages.sass _searches.sass _user_sessions.sass _variables.sass
application.sass:
$ cat app/assets/stylesheets/application.sass
// #import 'list_defaults'
// #import 'font-awesome'
#import '_variables'
#import '_foundation_and_overrides'
#import '_bidi'
#import '_layout'
#import '_pages'
#import '_phrases'
// #import 'searches'
// #import 'translations'
// #import 'user_sessions'
// #import 'users'
_variables.sass:
$ cat app/assets/stylesheets/_variables.sass
$white: #ffffff
$dark_white: #eaeaea
$medium_grey: #eeeeee
$very_light_red: #dbaca4
$light_red: #dc7869
$dark_red: #db1f00
$very_light_green: #b2ebd2
$light_green: #83dab3
$dark_green: #008f4e
$very_light_blue: #b1d8d9
$light_blue: #64c1c4
$dark_blue: #00868b
$font_sans: 'Open Sans', sans
$font_serif: 'Vollkorn', sans-serif
$font_arabic: 'Lateef', 'Amiri', 'Times New Roman', sans
_bidi.sass:
$ cat app/assets/stylesheets/_bidi.sass
// #import '_variables'
*[lang=ar],
*[lang=fa],
*[lang=ur],
*[lang=ps]
direction: rtl
unicode-bidi: bidi-override
font-family: $font_arabic
*[lang=de],
*[lang=en],
*[lang=ku]
direction: ltr
unicode-bidi: bidi-override
Rake run:
$ rake assets:precompile 2>&1 | grep -i error
Sass::SyntaxError: Undefined variable: "$font_arabic".

Cannot precompile assets for production environment, Rails 4.2.1, bower components

I am using bower for third parties on front-end.
I have problem with iCheck component which is used in AdminLTE theme.
Here is application.sass file of my Ruby on Rails 4.2.1 server side app:
#import "bootstrap-css-only/css/bootstrap"
#import "css/AdminLTE"
#import "css/skin-purple"
/*theme AdminLTE-2.3.0*/
#import "font-awesome/css/font-awesome"
#import "iCheck/skins/minimal/_all"
#import "iCheck/skins/square/_all"
#import "iCheck/skins/flat/_all"
#import "iCheck/skins/line/_all"
#import "iCheck/skins/polaris/polaris"
#import "iCheck/skins/futurico/futurico"
#import "iCheck/skins/all"
/*javascript notifications*/
#import "pnotify/src/pnotify.core"
#import "pnotify/src/pnotify.buttons"
/* Font awesome import*/
#import "font-awesome/css/font-awesome"
/*angular modules stylesheets*/
#import "core/stylesheets/users"
There is a problem with iCheck component because in file iCheck/skins/all.css there are imports:
#import url("minimal/_all.css");
#import url("square/_all.css");
And when I precompile assets for production environment, those css files do not exist. In development mode, everything works like a charm!
Any suggestion on this?
The problem here is that your compiled css file still has the same import commands, which is referencing the minimal/_all.css and square/_all.css.
There are two solutions for this problem:
You could change the extension of all imported files to scss, and change the import directive from #import url("...") to #import "..."
Or you could copy the files, which are imported with url to your public folder, and your browser will find them (of course, they will not be minified, and i would not suggest you do use this solution)

Manually compiling Sass in Rails 4.2

I'm manually compiling Sass in a Rails 4.2 app, and I'm running into issue with Sass' #import. It's giving me the following error - "File to import not found or unreadable..." Here's a code snippet.
scheme_css_dir = "#{Rails.root}/app/assets/schemes/#{scheme}/css"
template = File.read("#{scheme_css_dir}/styles.css.scss")
engine = Sass::Engine.new(template, {
:syntax => :scss,
:cache => false,
:read_cache => false,
:style => :compressed,
:load_paths => [scheme_css_dir]
})
output = engine.render
styles.css.scss contains several #import statements, and it's failing on the first one. Here's what the first one looks like.
#import "./flexslider";
There is a flexslider.css.scss file in the same directory as style.css.scss. I'm supplying that directory in the :load_paths option. Interestingly enough, if I change the #import line to...
#import "./flexslider.css.scss";
...then it gets to the next #import line in the file - where it throws the same error. This style.css.scss manifest complies successfully during deploy as is (without adding extensions to all the #imports).
What am I missing? Is there additional config that I need in order to use Sass::Engine to compile css manifest just like Rails would during deploy?
FYI - I'm using the latest version of sass-rails (5.0.3).
Any help is much appreciated. Thanks!
UPDATE: Thanks to papirtiger's comment, I was able to resolve the issue with #import by updated the extensions of my files from .css.scss to .scss. However, I'm still running into errors with asset helpers - specifically image-url and font-url. Here's the error I'm seeing...
undefined method `[]' for nil:NilClass
The error occurs in a sprockets_context method in sprockets (3.1.0) lib/sprockets/sass_processor.rb
def sprockets_context
options[:sprockets][:context]
end
Any thoughts on how to get pass this hurdle?

can't add a stylesheet with sass to a rails project

I'm using the bootstrap-sass gem. With these instructions https://github.com/twbs/bootstrap-sass#usage Things work ok except when I want to add a new stylesheet.
application.css.scss
#import "bourbon";
#import "custom";
#import "users";
#import "font-awesome";
#import "comments";
#import "animations";
directory structure
▾ stylesheets/
animations.css
application.css.scss
classifieds.css.scss
comments.css.scss
custom.css.scss
foo.css.scss
news.css.scss
relationships.css.scss
scaffolds.css.scss
users.css.scss
But if I add foo.css.scss to /stylesheets/ and add #import 'foo' to application.css.scss
I get a wrong number of arguments (2 for 1)
(in app/assets/stylesheets/application.css.scss) error
What could I be doing wrong?
it seems sass gem changed number of arguments of Sass::Importers::Base#public_url.
New version of sass-rails-source-maps should resolve this.

Resources