Class: Refinery::Themes::Admin::EditorController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/refinery/themes/admin/editor_controller.rb

Instance Method Summary collapse

Instance Method Details

#addObject



55
56
57
58
# File 'app/controllers/refinery/themes/admin/editor_controller.rb', line 55

def add
  render(:json => FileManager.create_dir(params[:fullpath], params[:title]), :layout => false) if params[:type].eql?('folder')
  render(:json => FileManager.create_file(params[:fullpath], params[:title]), :layout => false) if params[:type].eql?('default')
end

#deleteObject



65
66
67
68
# File 'app/controllers/refinery/themes/admin/editor_controller.rb', line 65

def delete
  render(:json => FileManager.remove_dir(params[:fullpath]), :layout => false) if params[:type].eql?('folder')
  render(:json => FileManager.remove_file(params[:fullpath]), :layout => false) if params[:type].eql?('default')
end

#fileObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/refinery/themes/admin/editor_controller.rb', line 34

def file
  @related_path = params[:fullpath]
  file = File.join(Rails.root, "themes", Refinery::Themes::Theme.current_theme_key, params[:fullpath])
  render :text => 'file not found' and return unless File.exist? file
  @content = File.read(file)
  @content_type = Editable.mime_for file

  if @content_type == 'image'
    render :inline => "<%= image_tag '#{params[:fullpath]}' %>"
  else
    render :layout => false
  end
end

#indexObject



6
# File 'app/controllers/refinery/themes/admin/editor_controller.rb', line 6

def index; end

#listObject



28
29
30
31
32
# File 'app/controllers/refinery/themes/admin/editor_controller.rb', line 28

def list
  @parent = params[:fullpath]
  file_manager = FileManager.new(Rails.root.join("themes/#{Refinery::Themes::Theme.current_theme_key}/#{@parent}"), @parent)
  render :json => file_manager.dirs.concat(file_manager.files), :layout => false
end

#renameObject



60
61
62
63
# File 'app/controllers/refinery/themes/admin/editor_controller.rb', line 60

def rename
  render(:json => FileManager.rename_dir(params[:fullpath], params[:new_name]), :layout => false) if params[:type].eql?('folder')
  render(:json => FileManager.rename_file(params[:fullpath], params[:new_name]), :layout => false) if params[:type].eql?('default')
end

#save_fileObject



48
49
50
51
52
53
# File 'app/controllers/refinery/themes/admin/editor_controller.rb', line 48

def save_file
  @related_path = params[:file_name]
  @content = FileManager.save_file(@related_path, params[:file_content])
  @content_type = Editable.mime_for @related_path
  render :template => 'refinery/themes/admin/editor/file.html.erb', :layout => false
end

#uploadObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/refinery/themes/admin/editor_controller.rb', line 12

def upload
  file = params[:file]

  unless FileManager.allowed_content_type?(File.extname(file.original_filename))
    notice = 'File "%s" could not be uploaded' % File.extname(file.original_filename)
  else
    file_path = "#{params[:path]}/#{file.original_filename}"
    FileManager.save_file(file_path, file.read)
    notice = "A new file was successfully uploaded!"
  end
  @dialog_successful = true
  render :nothing => true, :layout => 'refinery/admin_dialog'
  #render :action => 'index'
  #redirect_to(refinery.root_themes_admin_editor_path, :notice => notice)
end

#upload_fileObject



8
9
10
# File 'app/controllers/refinery/themes/admin/editor_controller.rb', line 8

def upload_file
  @path = params[:path]
end