5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-01 22:34:17 +00:00

vincular a versión con www

This commit is contained in:
f 2019-10-01 16:41:33 -03:00
parent 7a8191b854
commit 0bbedd2e26
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
10 changed files with 144 additions and 38 deletions

View file

@ -23,9 +23,7 @@ class SitesController < ApplicationController
def new def new
@site = Site.new @site = Site.new
authorize @site authorize @site
SiteService.new(site: @site).build_deploys
@site.deploys.build type: 'DeployLocal'
@site.deploys.build type: 'DeployZip'
end end
def create def create
@ -41,14 +39,8 @@ class SitesController < ApplicationController
def edit def edit
@site = find_site @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 authorize @site
SiteService.new(site: @site).build_deploys
end end
def update def update

35
app/models/deploy_www.rb Normal file
View 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

View file

@ -5,6 +5,10 @@
class Site < ApplicationRecord class Site < ApplicationRecord
include FriendlyId 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 :name, uniqueness: true, hostname: true
validates :design_id, presence: true validates :design_id, presence: true
validate :deploy_local_presence validate :deploy_local_presence

View file

@ -35,6 +35,15 @@ SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
site site
end 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 private
# Guarda los cambios de la configuración en el repositorio git # Guarda los cambios de la configuración en el repositorio git

View 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]

View file

@ -51,6 +51,10 @@ en:
title: Build the site title: Build the site
success: Success! success: Success!
error: Error error: Error
deploy_www:
title: Link to www
success: Success!
error: Error
deploy_zip: deploy_zip:
title: Build ZIP file title: Build ZIP file
success: Available for download success: Available for download
@ -209,6 +213,16 @@ en:
We're working out the details for allowing your own site We're working out the details for allowing your own site
domains, you can help us! domains, you can help us!
ejemplo: 'example' 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: deploy_zip:
title: 'Generate a ZIP file' title: 'Generate a ZIP file'
help: | help: |

View file

@ -53,6 +53,10 @@ es:
title: Generar el sitio title: Generar el sitio
success: ¡Éxito! success: ¡Éxito!
error: Hubo un error error: Hubo un error
deploy_www:
title: Vincular a versión con www
success: ¡Éxito!
error: Hubo un error
deploy_zip: deploy_zip:
title: Generar archivo ZIP title: Generar archivo ZIP
success: Disponible para descargar success: Disponible para descargar
@ -212,6 +216,18 @@ es:
Estamos desarrollando la posibilidad de agregar tus propios Estamos desarrollando la posibilidad de agregar tus propios
dominios, ¡ayudanos! dominios, ¡ayudanos!
ejemplo: 'ejemplo' 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: deploy_zip:
title: 'Generar un archivo ZIP' title: 'Generar un archivo ZIP'
help: | help: |

View file

@ -1,20 +1,24 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'test_helper' class DeployLocalTest < ActiveSupport::TestCase
class DeployZipTest < ActiveSupport::TestCase
test 'se puede deployear' do 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 # Primero tenemos que generar el sitio
assert File.directory?(deploy_local.destination) local.deploy
assert File.exist?(File.join(deploy_local.destination, 'index.html'))
assert_equal 3, deploy_local.build_stats.count
assert deploy_local.build_stats.map(&:bytes).compact.inject(:+).positive? escaped_path = Shellwords.escape(deploy.path)
assert deploy_local.build_stats.map(&:seconds).compact.inject(:+).positive?
assert deploy_local.destroy assert deploy.deploy
assert_not File.directory?(deploy_local.destination) 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
end end

View 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

View file

@ -1,24 +1,20 @@
# frozen_string_literal: true # frozen_string_literal: true
class DeployLocalTest < ActiveSupport::TestCase require 'test_helper'
class DeployZipTest < ActiveSupport::TestCase
test 'se puede deployear' do test 'se puede deployear' do
site = create :site deploy_local = create :deploy_local
local = create :deploy_local, site: site
deploy = create :deploy_zip, site: site
# Primero tenemos que generar el sitio assert deploy_local.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 deploy_local.destroy
assert File.file?(deploy.path) assert_not File.directory?(deploy_local.destination)
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
end end