mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 14:46:21 +00:00
vincular a versión con www
This commit is contained in:
parent
7a8191b854
commit
0bbedd2e26
10 changed files with 144 additions and 38 deletions
|
@ -23,9 +23,7 @@ class SitesController < ApplicationController
|
|||
def new
|
||||
@site = Site.new
|
||||
authorize @site
|
||||
|
||||
@site.deploys.build type: 'DeployLocal'
|
||||
@site.deploys.build type: 'DeployZip'
|
||||
SiteService.new(site: @site).build_deploys
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -41,14 +39,8 @@ class SitesController < ApplicationController
|
|||
|
||||
def edit
|
||||
@site = find_site
|
||||
|
||||
# TODO: esto está acá para ayudar en la migración de
|
||||
if @site.deploys.empty?
|
||||
@site.deploys.build(type: 'DeployLocal')
|
||||
@site.deploys.build type: 'DeployZip'
|
||||
end
|
||||
|
||||
authorize @site
|
||||
SiteService.new(site: @site).build_deploys
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
35
app/models/deploy_www.rb
Normal file
35
app/models/deploy_www.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Vincula la versión del sitio con www a la versión sin
|
||||
class DeployWww < Deploy
|
||||
store :values, accessors: %i[], coder: JSON
|
||||
|
||||
before_destroy :remove_destination!
|
||||
|
||||
def deploy
|
||||
File.symlink?(destination) ||
|
||||
File.symlink(site.hostname, destination).zero?
|
||||
end
|
||||
|
||||
def limit
|
||||
1
|
||||
end
|
||||
|
||||
def size
|
||||
File.size destination
|
||||
end
|
||||
|
||||
def destination
|
||||
File.join(Rails.root, '_deploy', fqdn)
|
||||
end
|
||||
|
||||
def fqdn
|
||||
"www.#{site.hostname}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_destination!
|
||||
File.rm_f destination
|
||||
end
|
||||
end
|
|
@ -5,6 +5,10 @@
|
|||
class Site < ApplicationRecord
|
||||
include FriendlyId
|
||||
|
||||
# TODO: Hacer que los diferentes tipos de deploy se auto registren
|
||||
# @see app/services/site_service.rb
|
||||
DEPLOYS = %i[local www zip].freeze
|
||||
|
||||
validates :name, uniqueness: true, hostname: true
|
||||
validates :design_id, presence: true
|
||||
validate :deploy_local_presence
|
||||
|
|
|
@ -35,6 +35,15 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
|||
site
|
||||
end
|
||||
|
||||
def build_deploys
|
||||
Site::DEPLOYS.map { |deploy| "Deploy#{deploy.capitalize}" }
|
||||
.each do |deploy|
|
||||
next if site.deploys.find_by type: deploy
|
||||
|
||||
site.deploys.build type: deploy
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Guarda los cambios de la configuración en el repositorio git
|
||||
|
|
17
app/views/deploys/_deploy_www.haml
Normal file
17
app/views/deploys/_deploy_www.haml
Normal file
|
@ -0,0 +1,17 @@
|
|||
-# Formulario para alojar una copia a www
|
||||
|
||||
.row
|
||||
.col
|
||||
= deploy.hidden_field :id
|
||||
= deploy.hidden_field :type
|
||||
%h3
|
||||
-#
|
||||
El checkbox invierte la lógica de destrucción porque queremos
|
||||
crear el deploy si está activado y destruirlo si está
|
||||
desactivado.
|
||||
= deploy.check_box :_destroy,
|
||||
{ checked: deploy.object.persisted? },
|
||||
'0', '1'
|
||||
= deploy.label :_destroy, t('.title')
|
||||
= sanitize_markdown t('.help', fqdn: deploy.object.fqdn),
|
||||
tags: %w[p strong em a]
|
|
@ -51,6 +51,10 @@ en:
|
|||
title: Build the site
|
||||
success: Success!
|
||||
error: Error
|
||||
deploy_www:
|
||||
title: Link to www
|
||||
success: Success!
|
||||
error: Error
|
||||
deploy_zip:
|
||||
title: Build ZIP file
|
||||
success: Available for download
|
||||
|
@ -209,6 +213,16 @@ en:
|
|||
We're working out the details for allowing your own site
|
||||
domains, you can help us!
|
||||
ejemplo: 'example'
|
||||
deploy_www:
|
||||
title: 'Add www to the address'
|
||||
help: |
|
||||
When you enable this option, your site will also be available
|
||||
under <https://%{fqdn}/>.
|
||||
|
||||
The www prefix to web addresses has been a way of refering to
|
||||
computers that are available on the World Wide Web. But since
|
||||
the Web has become the hegemonic way of accessing the Internet,
|
||||
it has become less used. Even so, people still uses them.
|
||||
deploy_zip:
|
||||
title: 'Generate a ZIP file'
|
||||
help: |
|
||||
|
|
|
@ -53,6 +53,10 @@ es:
|
|||
title: Generar el sitio
|
||||
success: ¡Éxito!
|
||||
error: Hubo un error
|
||||
deploy_www:
|
||||
title: Vincular a versión con www
|
||||
success: ¡Éxito!
|
||||
error: Hubo un error
|
||||
deploy_zip:
|
||||
title: Generar archivo ZIP
|
||||
success: Disponible para descargar
|
||||
|
@ -212,6 +216,18 @@ es:
|
|||
Estamos desarrollando la posibilidad de agregar tus propios
|
||||
dominios, ¡ayudanos!
|
||||
ejemplo: 'ejemplo'
|
||||
deploy_www:
|
||||
title: 'Agregar www a la dirección'
|
||||
help: |
|
||||
Cuando habilitas esta opción, tu sitio también estará disponible
|
||||
como <https://%{fqdn}/>.
|
||||
|
||||
El prefijo www para las direcciones web ha sido una forma de
|
||||
referirse a las computadoras que están disponibles en la _World
|
||||
Wide Web_ (WWW, Red de alcance mundial). Pero desde que la Web
|
||||
se ha vuelto la forma hegemónica de acceder a Internet, el
|
||||
prefijo se usa cada vez menos. Aun así, algunas personas lo
|
||||
usan.
|
||||
deploy_zip:
|
||||
title: 'Generar un archivo ZIP'
|
||||
help: |
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class DeployZipTest < ActiveSupport::TestCase
|
||||
class DeployLocalTest < ActiveSupport::TestCase
|
||||
test 'se puede deployear' do
|
||||
deploy_local = create :deploy_local
|
||||
site = create :site
|
||||
local = create :deploy_local, site: site
|
||||
deploy = create :deploy_zip, site: site
|
||||
|
||||
assert deploy_local.deploy
|
||||
assert File.directory?(deploy_local.destination)
|
||||
assert File.exist?(File.join(deploy_local.destination, 'index.html'))
|
||||
assert_equal 3, deploy_local.build_stats.count
|
||||
# Primero tenemos que generar el sitio
|
||||
local.deploy
|
||||
|
||||
assert deploy_local.build_stats.map(&:bytes).compact.inject(:+).positive?
|
||||
assert deploy_local.build_stats.map(&:seconds).compact.inject(:+).positive?
|
||||
escaped_path = Shellwords.escape(deploy.path)
|
||||
|
||||
assert deploy_local.destroy
|
||||
assert_not File.directory?(deploy_local.destination)
|
||||
assert deploy.deploy
|
||||
assert File.file?(deploy.path)
|
||||
assert_equal 'application/zip',
|
||||
`file --mime-type "#{escaped_path}"`.split(' ').last
|
||||
assert_equal 1, deploy.build_stats.count
|
||||
assert deploy.build_stats.map(&:bytes).inject(:+).positive?
|
||||
assert deploy.build_stats.map(&:seconds).inject(:+).positive?
|
||||
|
||||
local.destroy
|
||||
end
|
||||
end
|
||||
|
|
19
test/models/deploy_www_test.rb
Normal file
19
test/models/deploy_www_test.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class DeployWwwTest < ActiveSupport::TestCase
|
||||
test 'se puede deployear' do
|
||||
site = create :site
|
||||
local = create :deploy_local, site: site
|
||||
deploy = create :deploy_www, site: site
|
||||
|
||||
# Primero tenemos que generar el sitio
|
||||
local.deploy
|
||||
|
||||
assert deploy.deploy
|
||||
assert File.symlink?(deploy.destination)
|
||||
|
||||
local.destroy
|
||||
end
|
||||
end
|
|
@ -1,24 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DeployLocalTest < ActiveSupport::TestCase
|
||||
require 'test_helper'
|
||||
|
||||
class DeployZipTest < ActiveSupport::TestCase
|
||||
test 'se puede deployear' do
|
||||
site = create :site
|
||||
local = create :deploy_local, site: site
|
||||
deploy = create :deploy_zip, site: site
|
||||
deploy_local = create :deploy_local
|
||||
|
||||
# Primero tenemos que generar el sitio
|
||||
local.deploy
|
||||
assert deploy_local.deploy
|
||||
assert File.directory?(deploy_local.destination)
|
||||
assert File.exist?(File.join(deploy_local.destination, 'index.html'))
|
||||
assert_equal 3, deploy_local.build_stats.count
|
||||
|
||||
escaped_path = Shellwords.escape(deploy.path)
|
||||
assert deploy_local.build_stats.map(&:bytes).compact.inject(:+).positive?
|
||||
assert deploy_local.build_stats.map(&:seconds).compact.inject(:+).positive?
|
||||
|
||||
assert deploy.deploy
|
||||
assert File.file?(deploy.path)
|
||||
assert_equal 'application/zip',
|
||||
`file --mime-type "#{escaped_path}"`.split(' ').last
|
||||
assert_equal 1, deploy.build_stats.count
|
||||
assert deploy.build_stats.map(&:bytes).inject(:+).positive?
|
||||
assert deploy.build_stats.map(&:seconds).inject(:+).positive?
|
||||
|
||||
local.destroy
|
||||
assert deploy_local.destroy
|
||||
assert_not File.directory?(deploy_local.destination)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue