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; }
Related
I'm trying to use jqtouch theming which is based on SASS and COMPASS. I have a file custom.scss with the most simple code, one import and one variable to overwrite:
#import 'jqtouch';
// Override variables
$base-color: #fe892a;/* The default base which is later used for toolbar, list, and button backgrounds.*/
When I now compile the scss file to css, it will basically just generate the jqtouch css with my filename. The color specification is nowhere to be seen, although the variable is definitley correct per documentation (Official Guide) and in the jqtouch.scss file, which I import for costumizing.
I'm running Sass 3.2.9 and Compass 0.12.2 on a Windows machine.
I've tried it with more variables and different file imports, but the result is always, that my override values are not incorporated.
The ruby config file for compass seems to be unsuspicious.
Does anyone have an idea what goes wrong in the process so that my override values are ignored?
You're setting the color after it has already been used. Basically, what you're trying to do is this:
$color: red;
.foo {
background: $color;
}
$color: green;
Depending on how jqtouch is written, you might not be able to modify the colors at all. You need the variables to be set as a default in order to overwrite them ahead of time:
$color: green;
$color: red !default; // red is only used if $color is not already set
.foo {
background: $color; // color is green
}
So your code should be written as such:
// Override variables
$base-color: #fe892a;/* The default base which is later used for toolbar, list, and button backgrounds.*/
#import 'jqtouch';
I just upgraded from Rails 3.0 to Rails 3.1.
I have a foo.css.scss file that references an image (/app/assets/images/foo.png) as follows:
.foo {
background-image: image-url('foo.png');
}
The problem is that my foo.png file is not loaded and I see 404 errors in my logs.
The actual css entry that is generated is:
background-image: url(/images/foo.png);
which is wrong (?) because the image can be found at /assets/foo.png and not at /images/foo.png.
Note that I am still working on development mode.
Another important note. If I rename my foo.css.scss file to foo.css.erb and use:
background-image: url(<%= image_path('foo.png') %>);
it works ok, because it generates /assets/foo.png.
So, the question is why my scss precompiler does not generate the correct css?
Update: my foo.css.scss file resides:
app/assets/stylesheets/sub_dir/foo.css.scss
Does that make any difference?
You may try:
.foo {
background: url("/assets/foo.png")
}
should work fine. Hope it helps :)
try
.classname{
background: url(asset_path('/assets/image.png'))
}
I have tried various solutions. The most elegant one was the following:
.foo {
background-image: url('foo.png')
}
which automatically converted to url('/assets/foo.png') by the SCSS compiler.
.foo {
background-image: asset-url('sub_dir/foo.png', asset);
}
I'm using SASS(.scss) on a rails (3.2.13) project and use variables & mixins for my media queries like so:
$desk-wide-start: 1100px !default;
#mixin media-query($media-query) {
#if $media-query == desk-wide{
#media only screen and (min-width: $desk-wide-start) { #content; }
}
}
// I include the mixin like so
#include media-query (desk-wide) {
margin-top: 0;
}
This site is running and working fine live, but I have been working on it locally (Lets call this code B) and made a few changes and now my media queries (mixins) have stopped working (they appear to NOT be compiling). If I write a #media query, this will work however.
I rewound my changes through Git to the code I last deployed to the live site (lets call this code A), and the mixins worked, I swapped back to my changes (code B) and then back to the working code (code A) and they had stopped working on this as well.
I get no Rails errors, and I have hard refreshed / cleared the cache on both Chrome and Firefox (latest stable).
Any ideas what could be causing the mixins to not compile / work?
So far i've tried rolling back in Git (see above) and updating the sass-rails gem to the latest version, I can't think what else may be causing it.
This may help someone else in the future - I've resolved this by figuring out I had a gem that also had:
#mixin media-query($media-query) {
}
This must have been causing some kind of conflict when compiling, shame Rails didn't flag it up for me.
I simply changed one of the #mixins to #mixin mq($media-query)
I am developing an app with jquery-mobile. (yes, and app, it'll run within cordova(aka phone gap))
On the nexus 7 (the target device for the app), The font displays for many things are way too small. I can barely read it and I'm young. Many of the users of this app will have poor eyesight.
Is there any simple way to change the font-size with jquery-mobile?
When I try to add entries in a custom css file, there are unexpected results (Formatting goes out, etc) I have also tried theme-roller, but that only allows you to change the font-family, not the font-size.
eg:
body p {
font-size: 1.5em;
}
Even just a general explanation about how to write a css file for jquery-mobile would be very helpful.
OK, I've worked it out.
In the jquery-mobile-1.2.0.css file is the styling for query-mobile. You modify this stuff.
There's some cryptic info on the jquery-mobile website that will make sense once you've read this.
So, to change the font-size for within all you go to the jquery-mobile-1.2.0.css file and add:
.ui-li p {
font-size: 1.5em;
}
It seams that most of the jquery-mobile elements have .ui- in from of their normal html tags. They have a special class or something. (If anyone wants to elaborate on this it'd be great.)
Setting global <body>'s font-size should be enough:
body {
font-size: 15px; // You can even use !important
}
In my Ruby (1.9.2) Rails (3.0.x) I would like to render a web page as PDF using wicked_pdf, and I would like to control where the page breaks are. My CSS code to control page breaks is as follows:
<style>
#media print
{
h1 {page-break-before:always}
}
</style>
However, when I render the page with wicked_pdf, it does not separate the document into two pages. Is there something else that I must do to get page breaks with wicked_pdf?
For some reason, the "#media print" didn't quite do it. I just went with
.page-break { display:block; clear:both; page-break-after:always; }
for the CSS rule, and then I stuck the following in my page for a page break:
<div class="page-break"></div>
That just worked.
Tried Jay's solution but could not get it to work (maybe a conflict with other css)
I got it to work with this:
<p style='page-break-after:always;'></p>
I had the same problem and I discovered something that might help. This was my page break CSS code:
.page-break {
display: block;
clear: both;
page-break-after: always;
}
This didn't work because of TWO reasons:
I. In one of the SASS imported file I had this line of code:
html, body
overflow-x: hidden !important
II. The other problem was bootstrap
#import "bootstrap"
It looks like because of the float: left in:
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 {
float: left;
}
the page break is no longer working. So, just add this after you import bootstrap.
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 {
float: initial !important;
}
None of these solutions worked for me. I did find a solution that worked for many people in the gem issues here - https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1524
you want to add CSS on the element that needs the page break. In my case, it was table rows, so I added:
tr {
page-break-inside: avoid;
}
Make sure that the stylesheet link tag includes media='print" or media='all' if you are using an external stylesheet:
<%= stylesheet_link_tag 'retailers_pdf',media: 'all' %>
or
<%= stylesheet_link_tag 'retailers_pdf',media: 'print' %>
otherwise wicked_pdf will not pick it up.
Also note that if you are in the middle of a table or div with a border, that the page-break attributes will not work. In this case, it's time to break out jQuery and start splitting things up. This answer: https://stackoverflow.com/a/13394466/2016616 has a good snippet for position measurement. I am working on clean and repeatable table-splitting code and will post it when I have finished it.
i had the same issue and what ended up working for me was to make sure that my element with
page-break: always;
was on the root of the document, seems when its nested inside of other elements, especially ones with height assigned, the declaration gets ignored.
hope this helps someone.