7

I'm a front-end developer transitioning from CSS to SASS. I've got Ruby and Compass installed on my local machine, and Compass "watch" is working beautifully.

However, I still end up with local CSS files which I have to manually FTP over to the server after every tiny change, to see what the change made. I would like to automate this.

I did find this thread which suggested using rsync, but I use Windows and I feel setting up rsync would be really difficult.

Is there some way to automate this using Ruby? The workflow I'm trying to get:

  1. I save the SCSS file in VIM.
  2. Compass Watch detects the change and compiles a new CSS file
  3. Some magical tool detects the change to the CSS file, uploads to my server
  4. I switch over to Chrome, hit F5, and see the change

I can do everything, except for step 3. Any ideas? (That don't involve Linux or Mac-only software?)

Community
  • 1
  • 1
ezuk
  • 3,096
  • 3
  • 30
  • 41

6 Answers6

11

I disagree with Roy and Adam, When working with Wordpress themes, I develop on a remote dev server. I have a team of people adding content and other edits which update the database, it would be difficult for me as the developer to work locally 100% of the time. Their sql file getting updated with content wouldn't mesh super well after the fact with my sql file (you know theme option settings and what not).

I have avoided using SASS for this reason until now.

My optimal workflow would be to edit my scss file -> auto compile to css -> auto upload to the search (like a upload on save would) -> livereload takes place and I see edits (I can live without this last step).

I haven't attempted this yet but I found this link which seems to be the closest answer thus far.Using SASS with Remote Setup

Side note: Working locally is not always an optimal set up. It isn't an answer and this is about the 8th time I have seen this question with similar answers.

UPDATE: Just tried it without Codekit just sass --watch and it worked great!

ANOTHER UPDATE: I have further modified the way I handle sass and remote development. I know use Sublime, Open my .scss and .css file at the same time. I then use SFTP (a package for sublime) to "Monitor File" which will look for changes to the file outside of directly editing it, I then open up terminal and sass my scss file, now every time I save it complies locally and then the compiled css file auto uploads to my server! Hope that makes sense, maybe I will make a video showing.

philhoyt
  • 133
  • 2
  • 11
  • Sorry for the post resurrection but Nice solution. Been using sublime for quite some time and never saw the "monitor file" in sftp. Im using compass in terminal to watch the scss file which works great… effectively the same I believe. – visyoual Jun 03 '15 at 15:58
  • I was mentally stepping through this, and then googled the issue i was having to be sure... and this post gave me the "right-o, this should work" to get it working, and surely it did. thanks :D – danjah Aug 22 '17 at 09:57
2

Since the question was asked in 2011 Compass has evolved and now provides callback functions to do exactly what was asked in the question:

For Step 3 you can use on_stylesheet_saved and on_sourcemap_saved callback functions to upload your *.css and *.css.map files to the production server.

Sample code how to do this can be found in this StackOverflow answer

Community
  • 1
  • 1
Jürgen Hörmann
  • 462
  • 4
  • 17
1

I am in a similar position developing in sass (scss) and previewing on a remote dev site. When developing on Windows I use Sublime Text 2 to edit with the FTP-Sync plugin to automatically upload on save.

This plugin has a convenient option to flag folders watched for for file saves that trigger it to check a different path for further file changes to upload. So you can flag your scss folder, make changes to an scss file and save, which alerts ST2 to watch the css folder (you can build in a delay to allow enough time to compile) and upload any changed files.

After setup of the software and setup of FTP Sync for the given project, your actions amount to 1) edit and save, 2) wait a couple of seconds, 3) refresh browser to view changes. (If the site looks broken at this point you may need to increase the delay setting by a second and save the file again to trigger the process another time.)

I'm not sure how to accomplish this on other platforms for a remote site, though I wonder if Coda 2 has some options that might work for Mac OS users.

Skrivener
  • 1,003
  • 6
  • 11
1

In my experience the best way is to work this way:

1. you have a site somewhere - and it doesn't really matters where and how complex this site is;
2. you have local SASS files and CSS generated from these SASS files;
3. install Fiddler2 (web proxy)
4. configure it to catch a request for CSS file and replace the response with your local CSS file.

So, as you can see, you can use local CSS file instead of remote one. So there is no need to upload CSS every time you're building the SASS.

Community
  • 1
  • 1
Valentine
  • 11
  • 3
1

Automatically Upload CSS After Sass is Compiled.

  1. Install: gem install net-ssh gem install net-sftp

  2. Add to config.rb:

`

require 'net/ssh'
require 'net/sftp'

http_path = "/"
css_dir = "/"
sass_dir = "/sass"
images_dir = "images"
javascripts_dir = "js"

output_style = :expanded
environment = :development

remote_theme_dir_absolute = '/path/to/where/you/want/to/save/the/file/on/remote/server'

sftp_host = 'your-host.com' # Can be an IP
sftp_user = 'your-user.com' # SFTP Username
sftp_pass = 'xxxxxxxxxxx' # SFTP Password

on_stylesheet_saved do |filename|

  Net::SFTP.start( sftp_host, sftp_user , :password => sftp_pass) do |sftp|
    puts sftp.upload! '/path/to/local/style.css', remote_theme_dir_absolute + '/' + 'style.css'
    end
  puts ">>>> Compass is polling for changes. Press Ctrl-C to Stop"
end

`

For ftp only:

require 'net/ftp'


http_path = "/"
css_dir = ".."
sass_dir = ".."
images_dir = "images"
javascripts_dir = "js"

project_type = :stand_alone
output_style = :compressed
line_comments = false
environment = :development

ftp_host = 'your-host.com' # Can be an IP
ftp_user = 'your-user' # FTP Username
ftp_pass = 'xxxxxxxxx' # FTP Password

TXT_FILE_OBJECT = File.new('/path/to/local/style.css')

on_stylesheet_saved do |filename|
  Net::FTP.open( ftp_host, ftp_user , ftp_pass) do |ftp|
    ftp.putbinaryfile(TXT_FILE_OBJECT, "/path/on/remote/server/#{File.basename(TXT_FILE_OBJECT)}")
    end
  puts ">>>> Compass is polling for changes. Press Ctrl-C to Stop"
end

Change dirs and file paths to yours...

Nikit
  • 5,128
  • 19
  • 31
0

The simplest solution would be to develop locally (as is a best practice). Run a web server on your computer (try XAMP for Windows) and all changes will be instantly visible, without having to upload. Only upload when you're done.

Roy
  • 117
  • 5
  • 2
    That sounds lovely in theory, but I'm working on an existing website which is very large, database-backed, and dynamically generated. Mirroring it locally is simply not an option for my scenario... – ezuk Sep 21 '11 at 11:37
  • I actually gave this some more thought, and decided I will use a version of this solution. Rather than run a webserver, I'll just save the generated webpage off the site as an HTML, and develop locally against that. Accepting your answer, thank you! – ezuk Sep 22 '11 at 09:09
  • I know it can be a pain to get a large project up and running locally, but more often than not you'll be happy you did it in the end. Your solution looks like a fine one when it's just styling. Good luck! – Roy Sep 22 '11 at 14:34
  • 1
    What if you need to ftp to a cloud cms like squarespace, or shopify where you don't have access to the source locally? – Paul Mason May 28 '13 at 23:39
  • Unfortunately it is not always as simple as described in this answer. What if you work in a team? Two developers work on the SASS files and need to compile and upload the CSS to a staging server of the client. Here you will need a slightly more complex setup. – Jürgen Hörmann May 10 '16 at 08:28