5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-10-05 12:26:58 +00:00

Merge branch 'breadcrumbs' into 'rails'

Breadcrumbs

See merge request sutty/sutty!26
This commit is contained in:
fauno 2021-05-10 17:06:15 +00:00
commit 1e2b2d9de3
30 changed files with 125 additions and 161 deletions

View file

@ -48,6 +48,7 @@ gem 'jekyll-commonmark'
gem 'jekyll-images'
gem 'jekyll-include-cache'
gem 'sutty-liquid'
gem 'loaf'
gem 'lockbox'
gem 'mini_magick'
gem 'mobility'

View file

@ -338,6 +338,8 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loaf (0.10.0)
railties (>= 3.2)
lockbox (0.6.4)
lograge (0.11.2)
actionpack (>= 4)
@ -691,6 +693,7 @@ DEPENDENCIES
jekyll-include-cache
letter_opener
listen (>= 3.0.5, < 3.2)
loaf
lockbox
lograge
memory_profiler

View file

@ -355,6 +355,13 @@ $bezier: cubic-bezier(0.75, 0, 0.25, 1);
.text-column-#{$size} {
column-count: $size;
}
.line-clamp-#{$size} {
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: $size;
-webkit-box-orient: vertical;
}
}
/*

View file

@ -7,6 +7,11 @@ class PostsController < ApplicationController
before_action :authenticate_usuarie!
# TODO: Traer los comunes desde ApplicationController
breadcrumb -> { current_usuarie.email }, :edit_usuarie_registration_path
breadcrumb 'sites.index', :sites_path, match: :exact
breadcrumb -> { site.title }, -> { site_posts_path(site, locale: locale) }, match: :exact
# Las URLs siempre llevan el idioma actual o el de le usuarie
def default_url_options
{ locale: params[:locale] || current_usuarie&.lang || I18n.locale }
@ -43,44 +48,34 @@ class PostsController < ApplicationController
end
def show
@site = find_site
@post = @site.posts(lang: locale).find params[:id]
authorize @post
@locale = locale
fresh_when @post
authorize post
breadcrumb post.title.value, ''
fresh_when post
end
# Genera una previsualización del artículo.
#
# TODO: No todos los artículos tienen previsualización!
def preview
@site = find_site
@post = @site.posts(lang: locale).find params[:post_id]
authorize post
authorize @post
render html: @post.render
render html: post.render
end
def new
authorize Post
@site = find_site
@post = @site.posts.build(lang: locale, layout: params[:layout])
@locale = locale
@post = site.posts.build(lang: locale, layout: params[:layout])
breadcrumb I18n.t('loaf.breadcrumbs.posts.new', layout: @post.layout.humanized_name.downcase), ''
end
def create
authorize Post
@site = find_site
service = PostService.new(site: @site,
service = PostService.new(site: site,
usuarie: current_usuarie,
params: params)
@post = service.create
if @post.persisted?
@site.touch
site.touch
forget_content
redirect_to site_post_path(@site, @post)
@ -90,30 +85,24 @@ class PostsController < ApplicationController
end
def edit
@site = find_site
@post = @site.posts(lang: locale).find params[:id]
authorize @post
@locale = locale
authorize post
breadcrumb post.title.value, site_post_path(site, post, locale: locale), match: :exact
breadcrumb 'posts.edit', ''
end
def update
@site = find_site
@post = @site.posts(lang: locale).find params[:id]
authorize post
authorize @post
service = PostService.new(site: @site,
post: @post,
service = PostService.new(site: site,
post: post,
usuarie: current_usuarie,
params: params)
if service.update.persisted?
@site.touch
site.touch
forget_content
redirect_to site_post_path(@site, @post)
redirect_to site_post_path(site, post)
else
render 'posts/edit'
end
@ -121,34 +110,30 @@ class PostsController < ApplicationController
# Eliminar artículos
def destroy
@site = find_site
@post = @site.posts(lang: locale).find params[:id]
authorize post
authorize @post
service = PostService.new(site: @site,
post: @post,
service = PostService.new(site: site,
post: post,
usuarie: current_usuarie,
params: params)
# TODO: Notificar si se pudo o no
service.destroy
@site.touch
redirect_to site_posts_path(@site)
site.touch
redirect_to site_posts_path(site)
end
# Reordenar los artículos
def reorder
@site = find_site
authorize @site
authorize site
service = PostService.new(site: @site,
service = PostService.new(site: site,
usuarie: current_usuarie,
params: params)
service.reorder
@site.touch
redirect_to site_posts_path(@site)
site.touch
redirect_to site_posts_path(site)
end
# Devuelve el idioma solicitado a través de un parámetro, validando
@ -159,7 +144,7 @@ class PostsController < ApplicationController
# solicite a le usuarie crear el nuevo idioma y que esto lo agregue al
# _config.yml del sitio en lugar de mezclar idiomas.
def locale
@site&.locales&.find(-> { I18n.locale }) do |l|
@locale ||= site&.locales&.find(-> { I18n.locale }) do |l|
l.to_s == params[:locale]
end
end
@ -169,4 +154,14 @@ class PostsController < ApplicationController
def forget_content
flash[:js] = { target: 'editor', action: 'forget-content', keys: (params[:storage_keys] || []).to_json }
end
private
def site
@site ||= find_site
end
def post
@post ||= site.posts(lang: locale).find(params[:post_id] || params[:id])
end
end

View file

@ -7,6 +7,9 @@ class SitesController < ApplicationController
before_action :authenticate_usuarie!
breadcrumb -> { current_usuarie.email }, :edit_usuarie_registration_path
breadcrumb 'sites.index', :sites_path, match: :exact
# Ver un listado de sitios
def index
authorize Site
@ -24,6 +27,8 @@ class SitesController < ApplicationController
end
def new
breadcrumb 'sites.new', :new_site_path
@site = Site.new
authorize @site
@ -43,6 +48,10 @@ class SitesController < ApplicationController
def edit
authorize site
breadcrumb site.title, site_posts_path(site), match: :exact
breadcrumb 'sites.edit', site_path(site)
SiteService.new(site: site).build_deploys
end

View file

@ -7,12 +7,18 @@ class UsuariesController < ApplicationController
include Pundit
before_action :authenticate_usuarie!
# TODO: Traer los comunes desde ApplicationController
breadcrumb -> { current_usuarie.email }, :edit_usuarie_registration_path
breadcrumb 'sites.index', :sites_path, match: :exact
breadcrumb -> { site.title }, -> { site_posts_path(site, locale: locale) }, match: :exact
# Mostrar todes les usuaries e invitades de un sitio
def index
@site = find_site
site_usuarie = SiteUsuarie.new(@site, current_usuarie)
site_usuarie = SiteUsuarie.new(site, current_usuarie)
authorize site_usuarie
breadcrumb 'usuaries.index', ''
@policy = policy(site_usuarie)
end
@ -156,4 +162,8 @@ class UsuariesController < ApplicationController
'invitade'
end
end
def site
@site ||= find_site
end
end

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: nil
= content_for :body do
- 'black-bg'

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: nil
= content_for :body do
- 'black-bg'

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: nil
= content_for :body do
- 'black-bg'

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: nil
= content_for :body do
- 'black-bg'

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: nil
= content_for :body do
- 'black-bg'

View file

@ -1,5 +1,4 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('.index'), sites_path), t('.title')]
- breadcrumb 'sites.index', sites_path
= content_for :body do
- 'black-bg'

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: nil
= content_for :body do
- 'black-bg'

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: nil
= content_for :body do
- 'black-bg'

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: nil
= content_for :body do
- 'black-bg'

View file

@ -1,7 +0,0 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path),
link_to(@site.name, site_path(@site)),
t('i18n.index'),
t('i18n.edit')]
= render 'i18n/form'

View file

@ -3,21 +3,14 @@
= inline_svg_tag 'sutty.svg', class: 'black', aria: true,
title: t('svg.sutty.title'), desc: t('svg.sutty.desc')
- if crumbs
%nav{ aria: { label: t('.title') }, role: 'navigation' }
%ol.breadcrumb
%li.breadcrumb-item
= link_to edit_usuarie_registration_path,
data: { toggle: 'tooltip' },
title: t('help.usuarie.edit') do
= current_usuarie.email
- crumbs.compact.each do |crumb|
- if crumb == crumbs.last
%li.breadcrumb-item.active{ aria: { current: 'page' } }
= crumb
%nav{ aria: { label: t('.title') } }
%ol.breadcrumb.m-0.flex-wrap
- breadcrumb_trail do |crumb|
%li.breadcrumb-item{ class: crumb.current? ? 'active' : '' }
- if crumb.current?
%span.line-clamp-1{ aria: { current: 'page' } }= crumb.name
- else
%li.breadcrumb-item= crumb
%span.line-clamp-1= link_to crumb.name, crumb.url
- if current_usuarie
%ul.navbar-nav

View file

@ -20,6 +20,7 @@
%body{ class: yield(:body) }
.container-fluid#sutty
= render 'layouts/breadcrumb'
= yield
- if flash[:js]
.js-flash.d-none{ data: flash[:js] }

View file

@ -1,10 +1,3 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path),
link_to(@site.name, site_posts_path(@site)),
link_to(t('posts.index'), site_posts_path(@site)),
link_to(@post.title.value, site_post_path(@site, @post.id)),
t('posts.edit')]
.row.justify-content-center
.col-md-8
= render 'posts/form', site: @site, post: @post

View file

@ -1,10 +1,3 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path),
@site.name,
link_to(t('posts.index'),
site_posts_path(@site)),
@category_name]
%main.row
%aside.menu.col-md-3
%h1= link_to @site.title, @site.url

View file

@ -1,9 +1,3 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path),
@site.name,
link_to(t('posts.index'),
site_posts_path(@site)), t('posts.new')]
.row.justify-content-center
.col-md-8
= render 'posts/form', site: @site, post: @post

View file

@ -1,9 +1,3 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path),
@site.name,
link_to(t('posts.index'), site_posts_path(@site)),
@post.title.value]
- dir = t("locales.#{@locale}.dir")
.row.justify-content-center
.col-md-8

View file

@ -1,6 +1,3 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path),
t('.title', site: @site.name)]
.row.justify-content-center
.col-md-8
%h1= t('.title', site: @site.name)

View file

@ -1,6 +1,3 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path), t('.title')]
.row.justify-content-center
.col-md-8#pull
%h1= t('.title')

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: [t('sites.index.title')]
%main.row
%aside.col-md-3
%h1= t('.title')

View file

@ -1,6 +1,3 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path), t('.title')]
.row.justify-content-center
.col-md-8
%h1= t('.title')

View file

@ -1,18 +1,10 @@
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path),
link_to(@site.name, @site),
t('.title')]
.row
.col
.row.justify-content-center
.col.col-md-8
%h1= t('.title')
.row
.col
-# Una tabla de usuaries y otra de invitades, con acciones
- %i[usuaries invitades].each do |u|
%h2
= t(".#{u}")
%h2.mt-5= t(".#{u}")
.btn-group{ role: 'group', 'aria-label': t('.actions') }
- if @policy.invite?
= link_to t('.invite'),
@ -26,7 +18,7 @@
class: 'btn',
data: { toggle: 'tooltip' },
title: t('.help.public_invite')
%p= t(".help.#{u}")
%p.lead= t(".help.#{u}")
%table.table.table-condensed
%tbody
- @site.send(u).each do |cuenta|

View file

@ -1,17 +1,9 @@
- invite_as = t("usuaries.invite_as.#{params[:invite_as]}")
= render 'layouts/breadcrumb',
crumbs: [link_to(t('sites.index.title'), sites_path),
@site.name,
link_to(t('posts.index'), site_usuaries_path(@site)),
t('.title', invite_as: invite_as)]
.row
.col
.row.justify-content-center
.col.col-md-8
%h1= t('.title', invite_as: invite_as)
.row
.col
= form_with url: site_usuaries_invite_path(@site), local: true do |f|
= f.hidden_field :invited_as, value: params[:invite_as].singularize
.form-group

View file

@ -579,3 +579,14 @@ en:
local_invalid: "format is incorrect"
not_allowed: "that email provider is not welcome here"
server_not_available: "remote email server not available"
loaf:
breadcrumbs:
sites:
index: 'My sites'
new: 'Create'
edit: 'Configure'
posts:
new: 'New %{layout}'
edit: 'Editing'
usuaries:
index: 'Users'

View file

@ -608,3 +608,14 @@ es:
local_invalid: "el formato es incorrecto"
not_allowed: "no es bienvenida"
server_not_available: "el proveedor no está disponible"
loaf:
breadcrumbs:
sites:
index: 'Mis sitios'
new: 'Crear'
edit: 'Configurar'
posts:
new: 'Nuevo %{layout}'
edit: 'Editando'
usuaries:
index: 'Usuaries'