Sha256: aa6ac8051a7055a39eb63e3588f1a2d8423e57151646b80f341bfff67994c863

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

# The controller for serving/cacheing theme content...
#
class ThemeController < ActionController::Base

  after_filter :cache_theme_files
  
  def stylesheets
    render_theme_item(:stylesheets, params[:filename].join('/'), params[:theme])
  end

  def javascript
    render_theme_item(:javascripts, params[:filename].join('/'), params[:theme], 'text/javascript')
  end

  def images
    render_theme_item(:images, params[:filename].to_s, params[:theme])
  end

  def error
    render :nothing => true, :status => 404
  end
  
  private
  
  def render_theme_item(type, file, theme, mime = mime_for(file))
    render :text => "Not Found", :status => 404 and return if file.split(%r{[\\/]}).include?("..")
    send_file "#{Theme.path_to_theme(theme)}/#{type}/#{file}", :type => mime, :content_type => mime, :disposition => 'inline'
  end

  def cache_theme_files
    path = request.fullpath
    begin
      ThemeController.cache_page( response.body, path )
    rescue
      STERR.puts "Cache Exception: #{$!}"
    end
  end
    
  def mime_for(filename)
    case filename.downcase
    when /\.js$/
      'text/javascript'
    when /\.css$/
      'text/css'
    when /\.gif$/
      'image/gif'
    when /(\.jpg|\.jpeg)$/
      'image/jpeg'
    when /\.png$/
      'image/png'
    when /\.swf$/
      'application/x-shockwave-flash'
    else
      'application/binary'
    end
  end
end


Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
theme_support-3.0.4 lib/theme_support/theme_controller.rb
theme_support-3.0.3 lib/theme_support/theme_controller.rb
theme_support-3.0.2 lib/theme_support/theme_controller.rb
theme_support-3.0.1 lib/theme_support/theme_controller.rb
theme_support-3.0.0 lib/theme_support/theme_controller.rb