How to compress assets without Rails or Sprockets? - ruby

I'm writing a Sinatra app and I'm quite tired of Sprockets (because it's hard to configure and doesn't support some libs). I'm thinking of moving to Compass for stylesheet management but I haven't found anything similar to it when it comes to scripts. Now I can manually compile coffeescript into Javascript and concatenate the resulting files, but how do I compress them for less size? Thank you very much.

You may take a look at Gulp. Here is the good article about using Gulp with Rails (but it would work for Sinatra too).

Related

Does an entire dev team need to install Ruby in order for Sass to work on their local machines?

The UI developers touch the CSS, but given that Sass's workflow creates CSS, would any machine that displays the app (servers included?) need to have Ruby and Sass installed to view the app properly?
Or is it enough for anyone just working on the UI to have Ruby and Sass installed, in which case updating the CSS is done by a UI guy, and then the rendered file can be committed to be viewed and used by all?
You only need Ruby to compile Sass, the app will use the CSS (in fact, you don't need Sass files on your production app).
So only the people who are susceptible to work on the UI need to have Ruby (ans Sass) installed.
Sidenote:
Some frameworks allow on-the-fly Sass compilation (I'm thinking to Laravel-SASS for example). In this case, everyone need to have both Ruby ans Sass installed.

SASS and Jekyll integration

I'm just wondering if there is a way to integrate SASS into Jekyll. All that I need is an automatic .scss compilation into .css when I launch Jekyll.
I don't see anything wrong with compiling assets when you launch (which I take to mean run) jekyll. The whole point of running jekyll is to pre-compile your site, which is good for performance.
As for asset conversion-- there are many plugins available that focus on this. I like the Jekyll Asset Pipeline gem, which supports any language (e.g. Scss, Less, CoffeeScript, Erb, etc.) and has a bunch of features (e.g. asset tagging, compression, gzipping, etc.) that set it apart. It also seems to be the fastest growing Jekyll-related gem these days, which I take to mean that it is gaining traction in the community.
If you want to keep it as simple as compass watch you can use the Guard gem along with guard-jekyll and guard-compass (and if you like style injection, guard-livereload).
Guard bundles multiple 'watch' actions under a single terminal window, and is much easier to set up than a robust asset pipeline. Install the gems, configure the .guardfile according to the guard-compass and guard-jekyll instructions, cd to your directory and type guard. Any time a relevant file changes your sass files and/or jekyll site will be recompiled.
Native Sass, and CoffeeScript, processing debuted in Jekyll v2.0:
http://jekyllrb.com/docs/assets/#sassscss
Full disclosure: I am the lead dev behind this project.
The easiest way I've seen to setup Sass with Jekyll is with jekyll-compass. This gem will do exactly as you describe: Any time jekyll builds your website (jekyll build, jekyll serve, etc) your Sass will be compiled into the output folder along with the rest of your website. Check out the readme linked above for full usage details.
There's also some work under way currently by the Jekyll guys to get Sass support into the core of Jekyll so that everyone will have at least basic access to Sass and the wonderful feature-set it provides.

How to automatically compile scss into css with assets pipeline in Rails 3.1?

The new rails 3.1 asset pipeline confused me a lot. In rails 3.0.x, with the sass gem, my global css file got updated when I edit .scss files. But in rails 3.1, that doesn't work anymore. It seems like I have to run a rake task to update my css files whenever I modify the .scss files. I feel like I misunderstand something about the new asset pipeline, but I don't know what it is. Can someone provide a solution or explanation to this problem? Thank you.
There are two possible causes of this. I am assuming that you are in development mode, and that all the gems are loaded.
1. Config
In development mode files are compiled on-demand and cached until any changes are made. You have to get the new 3.1 config options set in the right files or this might not work as expected.
Check out the Rails guides section on upgrading.
2. Extensions
The other is getting the extensions in the right order. For scss that would be file.css.scss. This tells Sprockets to parse the files as scss first, and that the have a css extension. If you had .erb on the end - file.css.scss.erb - then erb is processed first, then scss.
Upgrading apps is a bit tricky because so many things have changed. The asset pipeline guide has lots of useful information and advice.
Sass / SCSS has this built in already so you don't have to do ERB pre-processing.
image-url("image.png")
http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
For me this problem resolved very easy.
I simple deleted all precompiled *.css files from assets/stylesheets and remain all *.scss files. Rails worked fine with *.scss directly, withoutn precompile.

Simple Compass+HAML webserver

I love compass (SASS) and HAML. I've been using staticmatic for building static web pages. Staticmatic seams outdated (no updates, bugs). What are the alternatives?
What I would like:
$ preview .
> Server started ad port XXXX
> Now you can use Compass and HAML
:). So... no configuratio, no directory structure, just haml and sass files.
I am currently using Compass/Sass/Haml with middleman. https://github.com/tdreyno/middleman It is very easy to use, and runs a sinatra in the background so you can see your changes live in your web browser.
After you are done editing and previewing your markup it builds static HTML from your stack of Compass/Sass/Haml. See https://github.com/tdreyno/middleman/wiki for usage.
This requires no conf at all except to tell it which templating engines you are using at setup so I think it is exactly what you are looking for.
You can try jekyll. I think it doesn't work with sass and haml out of the box but you can look at plugins
Don't forget Nanoc. While it is a little involved, it has some slightly more powerful features than StaticMatic. It does depend on a directory however. :/
There are just a ton of static generators around, most of them in Ruby. I'm planning to use Frank for the next few static projects.
It uses Tilt to support a ton of template engines
It has a concept of layouts, which go in a separate layouts folder, and templates can have a metadata header, but other than that it's very minimal.

Fastest and most efficient way of converting **haml** and **scss** files? (Ruby on Windows)

I'm a ruby/haml/sass-beginner. I just installed ruby and rails for windows, haml, and sass (stand alone and plugin for rails).
I know how to convert and haml file into a html file (and vice versa):
haml index.haml > output.html
and how to convert a scss fiel into a css file (and vice versa):
sass --watch style.scss:style.css
I save more time converting scss files because every time I save a scss file the corresponding css file is automatically updated (i think that's the suppose of the watch command)
but for the haml files, I'm still doing it manually (haml index.haml > output.html).
I believe there's other ways to save time converting haml and scss files.
Any suggestions?
When you setup Rails to work with Haml, then start your development server, the Haml in your views get converted into HTML for you on-the-fly, so there's no need to watch for changes to your Haml separately.
However, if you're creating prototypes using just Haml and SCSS and not using the Rails stack at this stage, then there are a couple of useful tools you can use that automatically render your Haml and SCSS on page refresh:
Serve
http://github.com/jlong/serve
StaticMatic
http://github.com/staticmatic/staticmatic
Of these two, Serve is easier to use, but is not as powerful as StaticMatic. With Serve, all you need to do is install it (gem install serve) and type serve at the command line in the directory containing your Haml files. Then point your browser at http://localhost:4000. Full details here.
You can also hook-up Serve to make use of Compass the Sass meta-framework (which is awesome). There's a full tutorial here.
Oh, there's also dynamicmatic now too which might be good as well to look into. Basically similar to staticmatic but with some obvious differences that might be useful. I've used SM quite a lot recently and really like it. Very easy to use, very simple to set up and really does most things I need it to.

Resources