Sha256: 8cec3a78543d2aca7659eceadfe894de83d452ed137322edd6fb50938e702624

Contents?: true

Size: 594 Bytes

Versions: 9

Compression:

Stored size: 594 Bytes

Contents

class BaristaController < ActionController::Base
  
  caches_page :show if Rails.env.production?
  
  # Used for rendering on the fly.
  def show
    headers['Content-Type'] = "application/javascript"
    path = normalize_path(params[:js_path])
    p path
    return head(:forbidden) unless can_render_path?(path)
    compiled = Barista.compile_file!(path)
    compiled.nil? ? head(:not_found) : render(:text => compiled.to_s)
  end
  
  protected
  
  def normalize_path(path)
    File.join(Array.wrap(path).flatten)
  end
  
  def can_render_path?(path)
    !path.include?("..")
  end
  
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
barista-0.6.1 app/controllers/barista_controller.rb
barista-0.6.0 app/controllers/barista_controller.rb
barista-0.5.1 app/controllers/barista_controller.rb
barista-0.5.0 app/controllers/barista_controller.rb
barista-0.4.3 app/controllers/barista_controller.rb
barista-0.4.2 app/controllers/barista_controller.rb
barista-0.4.1 app/controllers/barista_controller.rb
barista-0.4.0 app/controllers/barista_controller.rb
barista-0.3.0 app/controllers/barista_controller.rb