5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-10-05 14:26:56 +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-images'
gem 'jekyll-include-cache' gem 'jekyll-include-cache'
gem 'sutty-liquid' gem 'sutty-liquid'
gem 'loaf'
gem 'lockbox' gem 'lockbox'
gem 'mini_magick' gem 'mini_magick'
gem 'mobility' gem 'mobility'

View file

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

View file

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

View file

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

View file

@ -7,12 +7,18 @@ class UsuariesController < ApplicationController
include Pundit include Pundit
before_action :authenticate_usuarie! 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 # Mostrar todes les usuaries e invitades de un sitio
def index def index
@site = find_site site_usuarie = SiteUsuarie.new(site, current_usuarie)
site_usuarie = SiteUsuarie.new(@site, current_usuarie)
authorize site_usuarie authorize site_usuarie
breadcrumb 'usuaries.index', ''
@policy = policy(site_usuarie) @policy = policy(site_usuarie)
end end
@ -156,4 +162,8 @@ class UsuariesController < ApplicationController
'invitade' 'invitade'
end end
end end
def site
@site ||= find_site
end
end end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: nil
= content_for :body do = content_for :body do
- 'black-bg' - '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, = inline_svg_tag 'sutty.svg', class: 'black', aria: true,
title: t('svg.sutty.title'), desc: t('svg.sutty.desc') title: t('svg.sutty.title'), desc: t('svg.sutty.desc')
- if crumbs %nav{ aria: { label: t('.title') } }
%nav{ aria: { label: t('.title') }, role: 'navigation' } %ol.breadcrumb.m-0.flex-wrap
%ol.breadcrumb - breadcrumb_trail do |crumb|
%li.breadcrumb-item %li.breadcrumb-item{ class: crumb.current? ? 'active' : '' }
= link_to edit_usuarie_registration_path, - if crumb.current?
data: { toggle: 'tooltip' }, %span.line-clamp-1{ aria: { current: 'page' } }= crumb.name
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
- else - else
%li.breadcrumb-item= crumb %span.line-clamp-1= link_to crumb.name, crumb.url
- if current_usuarie - if current_usuarie
%ul.navbar-nav %ul.navbar-nav

View file

@ -20,6 +20,7 @@
%body{ class: yield(:body) } %body{ class: yield(:body) }
.container-fluid#sutty .container-fluid#sutty
= render 'layouts/breadcrumb'
= yield = yield
- if flash[:js] - if flash[:js]
.js-flash.d-none{ data: 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 .row.justify-content-center
.col-md-8 .col-md-8
= render 'posts/form', site: @site, post: @post = 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 %main.row
%aside.menu.col-md-3 %aside.menu.col-md-3
%h1= link_to @site.title, @site.url %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 .row.justify-content-center
.col-md-8 .col-md-8
= render 'posts/form', site: @site, post: @post = 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") - dir = t("locales.#{@locale}.dir")
.row.justify-content-center .row.justify-content-center
.col-md-8 .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 .row.justify-content-center
.col-md-8 .col-md-8
%h1= t('.title', site: @site.name) %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 .row.justify-content-center
.col-md-8#pull .col-md-8#pull
%h1= t('.title') %h1= t('.title')

View file

@ -1,5 +1,3 @@
= render 'layouts/breadcrumb', crumbs: [t('sites.index.title')]
%main.row %main.row
%aside.col-md-3 %aside.col-md-3
%h1= t('.title') %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 .row.justify-content-center
.col-md-8 .col-md-8
%h1= t('.title') %h1= t('.title')

View file

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

View file

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

View file

@ -579,3 +579,14 @@ en:
local_invalid: "format is incorrect" local_invalid: "format is incorrect"
not_allowed: "that email provider is not welcome here" not_allowed: "that email provider is not welcome here"
server_not_available: "remote email server not available" 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" local_invalid: "el formato es incorrecto"
not_allowed: "no es bienvenida" not_allowed: "no es bienvenida"
server_not_available: "el proveedor no está disponible" 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'