Sha256: 40321424dc431b7c4f541ff63c8299f2edf96b6b439c8cc7ce21246605d5864a

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require "action_controller/metal"

module ThemesForRails
  class AssetsController < ActionController::Base
    include ThemesForRails::CommonMethods
    include ThemesForRails::UrlHelpers
    def stylesheets
      filename = File.basename(params[:asset], File.extname(params[:asset]))
      render_asset theme_stylesheet_path_for(params[:theme], filename), 'text/css'
    end
    def javascripts
      filename = File.basename(params[:asset], File.extname(params[:asset]))
      render_asset theme_javascript_path_for(params[:theme], filename), 'text/javascript'
    end
    def images
      extension = File.extname(params[:asset])
      filename = params[:asset].gsub(extension, '')
      render_asset theme_image_path_for(params[:theme], filename, extension), "image/#{extension.gsub('.', '')}"
    end
  private
    def render_asset(asset, mime_type)
      unless File.exists?(asset)
        render :text => 'not found', :status => 404
      else
        send_file asset, :type => mime_type
      end
    end
    # Physical paths
    def theme_stylesheet_path_for(name, asset)
      File.join(theme_path_for(name), 'stylesheets', "#{asset}.css")
    end
    def theme_javascript_path_for(name, asset)
      File.join(theme_path_for(name), 'javascripts', "#{asset}.js")
    end
    def theme_image_path_for(name, asset, extension = ".png")
      File.join(theme_path_for(name), 'images', "#{asset}#{extension}")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
themes_for_rails-0.2.5 lib/themes_for_rails/assets_controller.rb
themes_for_rails-0.2.4 lib/themes_for_rails/assets_controller.rb