Class: Scribo::Admin::SitesController

Inherits:
Scribo::ApplicationAdminController show all
Defined in:
app/controllers/scribo/admin/sites_controller.rb

Instance Method Summary collapse

Methods included from MaintenanceStandards

#flash_and_redirect

Instance Method Details

#createObject



27
28
29
30
# File 'app/controllers/scribo/admin/sites_controller.rb', line 27

def create
  flash_and_redirect @site.save, admin_site_contents_path(@site), 'Site created successfully',
                     'There were problems creating the site'
end

#destroyObject



36
37
38
39
# File 'app/controllers/scribo/admin/sites_controller.rb', line 36

def destroy
  flash_and_redirect @site.destroy, admin_sites_url, 'Site deleted successfully',
                     'There were problems deleting the site'
end

#exportObject



48
49
50
51
# File 'app/controllers/scribo/admin/sites_controller.rb', line 48

def export
  name, data = Scribo::SiteExportService.new(@site).call
  send_data data, type: 'application/zip', filename: name
end

#importObject



41
42
43
44
45
46
# File 'app/controllers/scribo/admin/sites_controller.rb', line 41

def import
  @sites = Site.adminable
  params[:files].each do |file|
    Scribo::SiteImportService.new(file.path, scribable: Scribo.config.scribable_for_request(request)).call
  end
end

#indexObject



32
33
34
# File 'app/controllers/scribo/admin/sites_controller.rb', line 32

def index
  @sites = Site.adminable
end

#newObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/scribo/admin/sites_controller.rb', line 10

def new
  if params[:template_id]
    url = Scribo.config.templates.find { |t| t[:id] == params[:template_id] }&.[](:url)
    redirect_to(admin_sites_path) && return unless url

    file = Down.download(url)
    @site = Scribo::SiteImportService.new(file.path, scribable: Scribo.config.scribable_for_request(request)).call
    redirect_to(admin_site_contents_path(@site))
    nil
  else
    @site = Scribo::Site.create!(scribable: Scribo.config.scribable_for_request(request))
    Scribo.config.after_site_create(@site)
    redirect_to(admin_site_contents_path(@site))
    nil
  end
end