Sha256: 75c3972a8d7552c931256cb32bca1e6cd749dc9a06c3994d36205bd9bc3158ed

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

class ThemeSystem::ThemeController < ActionController::Base

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

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

  def images
    render_theme_item(:images, params[:filename], 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, :disposition => 'inline', :stream => false
  end

  def cache_theme_files
    path = request.request_uri
    begin
      ThemeSystem::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_generator-1.2.2 templates/theme_controller.rb
theme_generator-1.2.1 templates/theme_controller.rb
theme_generator-1.2.0 templates/theme_controller.rb
theme_generator-1.1.1 templates/theme_controller.rb
theme_generator-1.1.0 templates/theme_controller.rb