engine/app/controllers/locomotive/theme_assets_controller.rb

56 lines
1.5 KiB
Ruby
Raw Normal View History

module Locomotive
2010-05-11 21:38:52 +00:00
class ThemeAssetsController < BaseController
include ActionView::Helpers::SanitizeHelper
extend ActionView::Helpers::SanitizeHelper::ClassMethods
include ActionView::Helpers::TextHelper
include ActionView::Helpers::NumberHelper
2010-05-11 21:38:52 +00:00
sections 'settings', 'theme_assets'
respond_to :json, :only => [:create, :update]
before_filter :sanitize_params, :only => [:create, :update]
2010-05-11 21:38:52 +00:00
def index
@assets = ThemeAsset.all_grouped_by_folder(current_site)
@js_and_css_assets = (@assets[:javascripts] || []) + (@assets[:stylesheets] || [])
2010-06-02 00:39:05 +00:00
if request.xhr?
@images = @assets[:images] || []
render :action => 'images', :layout => false and return
else
@snippets = current_site.snippets.order_by([[:name, :asc]]).all.to_a
2010-06-02 00:39:05 +00:00
end
2010-05-11 21:38:52 +00:00
end
def edit
resource.performing_plain_text = true if resource.stylesheet_or_javascript?
edit!
end
2010-05-11 21:38:52 +00:00
def create
create! do |success, failure|
success.json do
render :json => {
:status => 'success',
:url => @theme_asset.source.url,
:local_path => @theme_asset.local_path(true),
:size => number_to_human_size(@theme_asset.size),
:date => l(@theme_asset.updated_at, :format => :short)
}
end
failure.json { render :json => { :status => 'error' } }
2010-05-11 21:38:52 +00:00
end
end
protected
def sanitize_params
params[:theme_asset] = { :source => params[:file] } if params[:file]
end
2010-05-11 21:38:52 +00:00
end
end