Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

CSS live edit with AJAX and rails !!!

(part of zena)

Using the helper <%= css_edit('style.css') %> shows two buttons to start/stop the css live update

Usage (on your local machine) :
0. open the web page where you inserted <%= css_edit('style.css') %> (replace style.css with your own stylesheets name)
1. click start on the web page
2. open your great editor
3. edit 'style.css'
4. save the file
5 MAGIC ! the web page is updated

# CONTROLLER (version but could be anything else)
  def css_preview
    file = params[:css].gsub('..','')
    path = File.join(RAILS_ROOT, 'public', 'stylesheets', file)
    if File.exists?(path)
      if session[:css] && session[:css] == File.stat(path).mtime
        render :nothing=>true
      else
        session[:css] = File.stat(path).mtime
        @css = File.read(path)
      end
    else
      render :nothing=>true
    end
  end

# HELPER :
  def css_edit(css_file = 'zen.css')
    str = <<ENDTXT
    
ENDTXT end # RJS template 'css_preview.rjs' page.replace_html "css", ""
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed