Sha256: 09712f93284249204d0786b4a2793c9fc4eaeb2a4998078c7e1ca17b900fa6b1

Contents?: true

Size: 945 Bytes

Versions: 4

Compression:

Stored size: 945 Bytes

Contents

# encoding: UTF-8
class AssetsController < ActionController::Base
  caches_action :index, :show, cache_path: Proc.new{ |c| c.params }, if: Proc.new{ |c| request.get? && c.params[:version] != 'direct' }

  def index
    if format_defined?
      render render_assets
    else
      render text: 'Undefined format', status: 500
    end
  end

  private

  def initialize
    # read assets/models to get formats
    @formats = {}
    Dir[File.dirname(__FILE__) << '/../models/asset_format/*.rb', Rails.root.to_s + '/app/assets/asset_format/*.rb'].each do |path|
      @formats[File.basename(path, '.rb')] = path
    end
  end

  def format_defined?
    @formats.has_key?(params[:format])
  end

  def render_assets
    require @formats[params[:format]]
    asset = AssetFormat.const_get(params[:format].capitalize).new("#{params[:file]}.#{params[:format]}")
    { text: asset.text, content_type: asset.content_type, status: asset.status }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zfben_rails_assets-0.0.10 app/controllers/assets_controller.rb
zfben_rails_assets-0.0.9 app/controllers/assets_controller.rb
zfben_rails_assets-0.0.8 app/controllers/assets_controller.rb
zfben_rails_assets-0.0.7 app/controllers/assets_controller.rb