Sha256: d525a1b4c4f3046ea8f46636d391b80e07e3b1b6d98a200f0e12b15d2c05474f

Contents?: true

Size: 591 Bytes

Versions: 7

Compression:

Stored size: 591 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.render_path(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

7 entries across 7 versions & 1 rubygems

Version Path
barista-0.2.1 app/controllers/barista_controller.rb
barista-0.2.0 app/controllers/barista_controller.rb
barista-0.1.5 app/controllers/barista_controller.rb
barista-0.1.4 app/controllers/barista_controller.rb
barista-0.1.3 app/controllers/barista_controller.rb
barista-0.1.2 app/controllers/barista_controller.rb
barista-0.1.1 app/controllers/barista_controller.rb