Class: Admin::StylesheetController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/stylesheet_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/admin/stylesheet_controller.rb', line 22

def create
  add_sid(:stylesheet)
  @sheet = Stylesheet.new(params[:stylesheet])
  @sheet.user_id = current_user.id
  @sheet.body = Stylesheet.default_body
  if @sheet.save
    redirect_to "/admin/stylesheets"
  else
    setup_index
    render "index"
  end
end

#destroyObject



63
64
65
66
67
# File 'app/controllers/admin/stylesheet_controller.rb', line 63

def destroy
  Stylesheet.delete_all("id = #{params[:id]} and system_id = #{_sid}")

  redirect_to "/admin/stylesheets"
end

#indexObject

TODO: What happens to stylesheet caching with multi server???



8
9
10
# File 'app/controllers/admin/stylesheet_controller.rb', line 8

def index
  setup_index
end

#serveObject



12
13
14
15
16
17
18
19
20
# File 'app/controllers/admin/stylesheet_controller.rb', line 12

def serve 
  name,fingerprint = params[:path].split('-')
   
  stylesheet = Stylesheet.fetch(_sid, name.downcase)
  response.headers['Content-Type'] = 'text/css'
  response.headers['Cache-Control'] = 'max-age=31536000, public'
  response.headers["Expires"] = CGI.rfc1123_date(Time.now + 360.days)
  render :text=>stylesheet.css, :layout=>false
end

#showObject



35
36
37
# File 'app/controllers/admin/stylesheet_controller.rb', line 35

def show
  @sheet = Stylesheet.find_sys_id(_sid, params[:id])
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/admin/stylesheet_controller.rb', line 39

def update
  @sheet = Stylesheet.find_sys_id(_sid, params[:id])
  add_sid(:stylesheet)
  @sheet.body = params[:stylesheet][:body]
  begin
    @sheet.generate_css
  rescue Sass::SyntaxError => error
    @sheet = Stylesheet.new(params[:stylesheet])
    @sheet.id = params[:id]
    @sheet.system_id = _sid
    flash[:notice] = error.to_s
    render "show"
    return
  end

  if @sheet.update_attributes(params[:stylesheet])
    Rails.cache.delete(Stylesheet.cache_key(@sheet.name.downcase))
    @sheet.generate_css
    redirect_to "/admin/stylesheets"
  else
    render "show"
  end
end