diff --git a/Gemfile b/Gemfile index 63b921c2..3f100e6b 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 5c1d0627..e80d3ccf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 0a215c48..5886a2a7 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -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; + } } /* diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index a4b47a16..e8ceeebf 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index d7d2f9f6..f3114d9a 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -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 diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index 71deee91..6d02a35a 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -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 diff --git a/app/views/devise/confirmations/new.haml b/app/views/devise/confirmations/new.haml index b1080788..59568cb7 100644 --- a/app/views/devise/confirmations/new.haml +++ b/app/views/devise/confirmations/new.haml @@ -1,5 +1,3 @@ -= render 'layouts/breadcrumb', crumbs: nil - = content_for :body do - 'black-bg' diff --git a/app/views/devise/invitations/edit.haml b/app/views/devise/invitations/edit.haml index b8bb4315..565429a8 100644 --- a/app/views/devise/invitations/edit.haml +++ b/app/views/devise/invitations/edit.haml @@ -1,5 +1,3 @@ -= render 'layouts/breadcrumb', crumbs: nil - = content_for :body do - 'black-bg' diff --git a/app/views/devise/invitations/new.haml b/app/views/devise/invitations/new.haml index 8a0e318e..44ceec2e 100644 --- a/app/views/devise/invitations/new.haml +++ b/app/views/devise/invitations/new.haml @@ -1,5 +1,3 @@ -= render 'layouts/breadcrumb', crumbs: nil - = content_for :body do - 'black-bg' diff --git a/app/views/devise/passwords/edit.haml b/app/views/devise/passwords/edit.haml index d5e0778c..7f7b16fb 100644 --- a/app/views/devise/passwords/edit.haml +++ b/app/views/devise/passwords/edit.haml @@ -1,5 +1,3 @@ -= render 'layouts/breadcrumb', crumbs: nil - = content_for :body do - 'black-bg' diff --git a/app/views/devise/passwords/new.haml b/app/views/devise/passwords/new.haml index 75e22859..3c80b8a0 100644 --- a/app/views/devise/passwords/new.haml +++ b/app/views/devise/passwords/new.haml @@ -1,5 +1,3 @@ -= render 'layouts/breadcrumb', crumbs: nil - = content_for :body do - 'black-bg' diff --git a/app/views/devise/registrations/edit.haml b/app/views/devise/registrations/edit.haml index ece85540..6a25da65 100644 --- a/app/views/devise/registrations/edit.haml +++ b/app/views/devise/registrations/edit.haml @@ -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' diff --git a/app/views/devise/registrations/new.haml b/app/views/devise/registrations/new.haml index 92a44aec..cb6ff0d1 100644 --- a/app/views/devise/registrations/new.haml +++ b/app/views/devise/registrations/new.haml @@ -1,5 +1,3 @@ -= render 'layouts/breadcrumb', crumbs: nil - = content_for :body do - 'black-bg' diff --git a/app/views/devise/sessions/new.haml b/app/views/devise/sessions/new.haml index 2826be44..b5223e5f 100644 --- a/app/views/devise/sessions/new.haml +++ b/app/views/devise/sessions/new.haml @@ -1,5 +1,3 @@ -= render 'layouts/breadcrumb', crumbs: nil - = content_for :body do - 'black-bg' diff --git a/app/views/devise/unlocks/new.haml b/app/views/devise/unlocks/new.haml index af5bf50b..ac511115 100644 --- a/app/views/devise/unlocks/new.haml +++ b/app/views/devise/unlocks/new.haml @@ -1,5 +1,3 @@ -= render 'layouts/breadcrumb', crumbs: nil - = content_for :body do - 'black-bg' diff --git a/app/views/i18n/edit.haml b/app/views/i18n/edit.haml deleted file mode 100644 index 3e44af6f..00000000 --- a/app/views/i18n/edit.haml +++ /dev/null @@ -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' diff --git a/app/views/layouts/_breadcrumb.haml b/app/views/layouts/_breadcrumb.haml index 01765d0d..c4920bc7 100644 --- a/app/views/layouts/_breadcrumb.haml +++ b/app/views/layouts/_breadcrumb.haml @@ -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 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 891d635c..85d5ab22 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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] } diff --git a/app/views/posts/edit.haml b/app/views/posts/edit.haml index 282d9d05..6ec252fe 100644 --- a/app/views/posts/edit.haml +++ b/app/views/posts/edit.haml @@ -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 diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index b2f3f661..291945ae 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -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 diff --git a/app/views/posts/new.haml b/app/views/posts/new.haml index adcc843d..6ec252fe 100644 --- a/app/views/posts/new.haml +++ b/app/views/posts/new.haml @@ -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 diff --git a/app/views/posts/show.haml b/app/views/posts/show.haml index 9dd4faa0..9d6f37cd 100644 --- a/app/views/posts/show.haml +++ b/app/views/posts/show.haml @@ -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 diff --git a/app/views/sites/edit.haml b/app/views/sites/edit.haml index cc5977cf..4ae7308d 100644 --- a/app/views/sites/edit.haml +++ b/app/views/sites/edit.haml @@ -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) diff --git a/app/views/sites/fetch.haml b/app/views/sites/fetch.haml index 6a16e2e0..f5d049c8 100644 --- a/app/views/sites/fetch.haml +++ b/app/views/sites/fetch.haml @@ -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') diff --git a/app/views/sites/index.haml b/app/views/sites/index.haml index 07ea670a..dfcc2203 100644 --- a/app/views/sites/index.haml +++ b/app/views/sites/index.haml @@ -1,5 +1,3 @@ -= render 'layouts/breadcrumb', crumbs: [t('sites.index.title')] - %main.row %aside.col-md-3 %h1= t('.title') diff --git a/app/views/sites/new.haml b/app/views/sites/new.haml index fa724421..68c17882 100644 --- a/app/views/sites/new.haml +++ b/app/views/sites/new.haml @@ -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') diff --git a/app/views/usuaries/index.haml b/app/views/usuaries/index.haml index c3c6c3b4..124fb04b 100644 --- a/app/views/usuaries/index.haml +++ b/app/views/usuaries/index.haml @@ -1,32 +1,24 @@ -= 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}") - .btn-group{ role: 'group', 'aria-label': t('.actions') } - - if @policy.invite? - = link_to t('.invite'), - site_usuaries_invite_path(@site, invite_as: u.to_s), - class: 'btn', - data: { toggle: 'tooltip' }, - title: t('.help.invite', invite_as: u.to_s) - - if policy(Collaboration.new(@site)).collaborate? - = link_to t('.public_invite'), - site_collaborate_path(@site), - class: 'btn', - data: { toggle: 'tooltip' }, - title: t('.help.public_invite') - %p= t(".help.#{u}") + %h2.mt-5= t(".#{u}") + .btn-group{ role: 'group', 'aria-label': t('.actions') } + - if @policy.invite? + = link_to t('.invite'), + site_usuaries_invite_path(@site, invite_as: u.to_s), + class: 'btn', + data: { toggle: 'tooltip' }, + title: t('.help.invite', invite_as: u.to_s) + - if policy(Collaboration.new(@site)).collaborate? + = link_to t('.public_invite'), + site_collaborate_path(@site), + class: 'btn', + data: { toggle: 'tooltip' }, + title: t('.help.public_invite') + %p.lead= t(".help.#{u}") %table.table.table-condensed %tbody - @site.send(u).each do |cuenta| diff --git a/app/views/usuaries/invite.haml b/app/views/usuaries/invite.haml index 62552e70..26eb5039 100644 --- a/app/views/usuaries/invite.haml +++ b/app/views/usuaries/invite.haml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 48bb653d..1ad6cbd3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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' diff --git a/config/locales/es.yml b/config/locales/es.yml index 4cdca67e..c9c42c60 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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'