Class: Sites::ContentsController

Inherits:
ApplicationAdminController
  • Object
show all
Defined in:
app/controllers/scribo/admin/sites/contents_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



44
45
46
47
48
49
# File 'app/controllers/scribo/admin/sites/contents_controller.rb', line 44

def create
  parent = params[:parent] ? @site.contents.find(params[:parent]) : nil
  @content = @site.contents.create!(path: params[:path], kind: params[:kind], parent: parent)
rescue  
  Signum.error(Current.user, text: t('.create_fail', kind: params[:kind]))
end

#destroyObject



24
25
26
27
# File 'app/controllers/scribo/admin/sites/contents_controller.rb', line 24

def destroy
  @content.destroy
  head 200
end

#editObject



13
# File 'app/controllers/scribo/admin/sites/contents_controller.rb', line 13

def edit; end

#indexObject

Render the IDE



11
# File 'app/controllers/scribo/admin/sites/contents_controller.rb', line 11

def index; end

#moveObject



29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/scribo/admin/sites/contents_controller.rb', line 29

def move
  if params[:to]
    new_parent = @site.contents.find(params[:to])
    @content.update!(parent: new_parent)
  else
    @content.update!(parent_id: nil)
  end
rescue
  Signum.error(Current.user, text: t('.move_fail'))
end

#renameObject



40
41
42
# File 'app/controllers/scribo/admin/sites/contents_controller.rb', line 40

def rename
  @content.update(path: params[:to]) if params[:to]
end

#showObject



20
21
22
# File 'app/controllers/scribo/admin/sites/contents_controller.rb', line 20

def show
  render :edit
end

#updateObject



15
16
17
18
# File 'app/controllers/scribo/admin/sites/contents_controller.rb', line 15

def update
  @content.update(content_params)
  render :edit
end

#uploadObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/scribo/admin/sites/contents_controller.rb', line 51

def upload
  @parent = Scribo::Content.find(params[:content][:parent_id]) if params[:content][:parent_id]

  params[:content][:files]&.each do |file|
    content = @site.contents.create!(kind: Scribo::Utility.kind_for_path(file.original_filename),
                                     path: file.original_filename, data_with_frontmatter: file.read)
    content.update!(parent: @parent)  if @parent
  rescue
    Signum.error(Current.user, text:t('.upload_fail'))
  end

  @contents = @site.contents.roots.reorder(:path) # unless params[:content][:parent_id]
end