I am working on the css and html of a simple web-project.
I would like to use livereload to update what gets rendered in the browser on the fly whenever I make a change to any of the files in my project.
From the description on the livereload website:
What does LiveReload do?
LiveReload monitors changes in the file system. As soon as you save a
file, it is preprocessed as needed, and the browser is refreshed.
Even cooler, when you change a CSS file or an image, the browser is
updated instantly without reloading the page.
Since this is not a rails/sinatra project, but just simple html/css/js, what could I use to get live reloading?
E.g. is there some lightweight server in the gem repos that could solve this for me?
You could use the catapult gem to set up a simple sprockets app, without sinatra or rails. It is just a static site that makes it easy to use a sort of asset pipeline. I have used it a lot and I love it.
Then in your Gemfile you can add gem 'guard-livereload' project here.
Just follow the setup instructions, you may also have to check out guard to get everything working nicely together.
I only am suggesting catapult because it makes setting up a simple static site incredibly easy with the added benefit of sprockets, coffeescript and your flavor of sass.
To do this without catapult, just run bundle init (assuming you have the bundler gem installed) in your root directory which will create a Gemfile. Then all you need to do is add the guard-livereload gem like I wrote above.
enjoy
Related
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.
I installed tinymce-rails gem, and included the coffeescript include so that the wysiwyg editor appears on a particular view. I added it to assets/javascripts/application.js file as shown below;
//= require tinymce-jquery
This works great when running on webrick on local machine. It worked fine in the development environment, and after tweaking a couple of variables in the production.rb file it started working locally as well in production environment.
However once I deploy to my webhost (webbynode) and open the view that the editor is supposed to appear in, the javascript for tinymce does not get included. I played a bit with some of the variables in the environment/production.rb file which seemed to make a difference locally, but it did not make a difference in the hosted environment. Any ideas on this?
I have recently experienced an issue where I must add the following to my gemfile:
gem 'execjs'
gem 'therubyracer'
I must do this to avoid a javascript runtime error that occurs when starting the rails server. I would like to have this modification added to all new gemfiles created with the rails new command.
You're looking for application templates.
Rails documentation on Application Templates
If you want the option to customize each app individually instead of having a rigid template, a really good option is Rails Composer. It prompts you about common gems during setup, and it nails a lot of the more common gems.
Finally, if you like Rails Composer, but want to be able to re-use application templates, check out Rails Apps Composer. I haven't looked into this too much, but it seems to give you a lot of flexibility while doing most of the heavy lifting for you.
I have found jasminerice very helpful for getting all my Jasmine tests to run via Rails 3.1's asset pipeline. The only thing I remain stuck with, is that I cannot get my setup to load any stylesheets (that go with my fixtures) and I need them for a couple of dom / element-style specific tests. Does anybody know how to get the stylesheets to be loaded in this setup?
Support for CSS files has been added recently, the README states:
For including stylesheets in your specs, jasminerice uses a spec.css file. Create such a file next to the spec.js.coffee file:
spec/javascripts/spec.css
and in that file, use sprockets directives to include the right css files, e.g.
/*
*= require application
*/
The change is fairly new so you may want to include the gem directly from the latest github version:
# Gemfile
gem 'jasminerice', git: 'git://github.com/bradphelan/jasminerice.git'
You may also want to be precise with your css markup, so as to not mess up Jasmine's spec runner page as the css files (as the js files) are included directly into it.
I have updated the Jasminerice gem and bradphelan (the Jasminerice author) has pulled that change into the source on Github. So in order to use use stylesheets in your Jasmine tests running through Jasminerice, simply refer to the gem on Github in your Gemfile like so: gem "jasminerice", :git => 'git://github.com/bradphelan/jasminerice.git'. The documentation has also been updated on Github.
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.