mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 07:51:42 +00:00
actualizar sitios
This commit is contained in:
parent
3a3dd7a2de
commit
6c25e35cd7
8 changed files with 64 additions and 8 deletions
|
@ -38,6 +38,22 @@ class SitesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@site = find_site
|
||||||
|
authorize @site
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@site = find_site
|
||||||
|
authorize @site
|
||||||
|
|
||||||
|
if @site.update(site_params)
|
||||||
|
redirect_to sites_path
|
||||||
|
else
|
||||||
|
render 'edit'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Envía un archivo del directorio público de Jekyll
|
# Envía un archivo del directorio público de Jekyll
|
||||||
def send_public_file
|
def send_public_file
|
||||||
authorize Site
|
authorize Site
|
||||||
|
|
|
@ -23,6 +23,8 @@ class Site < ApplicationRecord
|
||||||
# de crearlo
|
# de crearlo
|
||||||
after_initialize :load_jekyll!
|
after_initialize :load_jekyll!
|
||||||
after_create :load_jekyll!
|
after_create :load_jekyll!
|
||||||
|
# Cambiar el nombre del directorio
|
||||||
|
before_update :update_name!
|
||||||
|
|
||||||
attr_accessor :jekyll, :collections
|
attr_accessor :jekyll, :collections
|
||||||
|
|
||||||
|
@ -38,7 +40,11 @@ class Site < ApplicationRecord
|
||||||
#
|
#
|
||||||
# Equivale a _sites + nombre
|
# Equivale a _sites + nombre
|
||||||
def path
|
def path
|
||||||
@path ||= File.join(Site.site_path, name)
|
File.join(Site.site_path, name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def old_path
|
||||||
|
File.join(Site.site_path, name_was)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Este sitio acepta invitadxs?
|
# Este sitio acepta invitadxs?
|
||||||
|
@ -370,4 +376,10 @@ class Site < ApplicationRecord
|
||||||
def remove_directories!
|
def remove_directories!
|
||||||
FileUtils.rm_rf path
|
FileUtils.rm_rf path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_name!
|
||||||
|
return unless name_changed?
|
||||||
|
|
||||||
|
FileUtils.mv old_path, path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
6
app/views/sites/_form.haml
Normal file
6
app/views/sites/_form.haml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
= form_for @site do |f|
|
||||||
|
.form-group
|
||||||
|
= f.label :name
|
||||||
|
= f.text_field :name, class: 'form-control'
|
||||||
|
.form-group
|
||||||
|
= f.submit submit, class: 'btn btn-success'
|
10
app/views/sites/edit.haml
Normal file
10
app/views/sites/edit.haml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
.row
|
||||||
|
.col
|
||||||
|
= render 'layouts/breadcrumb',
|
||||||
|
crumbs: [link_to(t('sites.index'), sites_path),
|
||||||
|
t('.title', site: @site.name)]
|
||||||
|
.row
|
||||||
|
.col
|
||||||
|
%h1= t('.title', site: @site.name)
|
||||||
|
|
||||||
|
= render 'form', submit: t('.submit')
|
|
@ -1,14 +1,9 @@
|
||||||
.row
|
.row
|
||||||
.col
|
.col
|
||||||
= render 'layouts/breadcrumb',
|
= render 'layouts/breadcrumb',
|
||||||
crumbs: [ link_to(t('sites.index'), sites_path), t('.title') ]
|
crumbs: [link_to(t('sites.index'), sites_path), t('.title')]
|
||||||
.row
|
.row
|
||||||
.col
|
.col
|
||||||
%h1= t('.title')
|
%h1= t('.title')
|
||||||
|
|
||||||
= form_for @site do |f|
|
= render 'form', submit: t('.submit')
|
||||||
.form-group
|
|
||||||
= f.label :name
|
|
||||||
= f.text_field :name, class: 'form-control'
|
|
||||||
.form-group
|
|
||||||
= f.submit t('.submit'), class: 'btn btn-success'
|
|
||||||
|
|
|
@ -155,6 +155,9 @@ en:
|
||||||
new:
|
new:
|
||||||
title: 'Create site'
|
title: 'Create site'
|
||||||
submit: 'Create site'
|
submit: 'Create site'
|
||||||
|
edit:
|
||||||
|
title: 'Edit %{site}'
|
||||||
|
submit: 'Save changes'
|
||||||
footer:
|
footer:
|
||||||
powered_by: 'is developed by'
|
powered_by: 'is developed by'
|
||||||
templates:
|
templates:
|
||||||
|
|
|
@ -160,6 +160,9 @@ es:
|
||||||
new:
|
new:
|
||||||
title: 'Crear un sitio'
|
title: 'Crear un sitio'
|
||||||
submit: 'Crear sitio'
|
submit: 'Crear sitio'
|
||||||
|
edit:
|
||||||
|
title: 'Editar %{site}'
|
||||||
|
submit: 'Guardar cambios'
|
||||||
footer:
|
footer:
|
||||||
powered_by: 'es desarrollada por'
|
powered_by: 'es desarrollada por'
|
||||||
i18n:
|
i18n:
|
||||||
|
|
|
@ -61,4 +61,15 @@ class SiteTest < ActiveSupport::TestCase
|
||||||
assert site.valid?
|
assert site.valid?
|
||||||
assert !site.posts.empty?
|
assert !site.posts.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'se pueden renombrar' do
|
||||||
|
@site = create :site
|
||||||
|
path = @site.path
|
||||||
|
|
||||||
|
@site.update_attribute :name, SecureRandom.hex
|
||||||
|
|
||||||
|
assert_not_equal path, @site.path
|
||||||
|
assert File.directory?(@site.path)
|
||||||
|
assert_not File.directory?(path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue