2019-03-26 15:32:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-29 22:19:10 +00:00
|
|
|
# Forma de ingreso a Sutty
|
2018-01-02 17:19:25 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
|
|
|
protect_from_forgery with: :exception
|
2018-02-26 22:08:21 +00:00
|
|
|
before_action :set_locale
|
2018-01-29 18:09:30 +00:00
|
|
|
|
2018-01-29 22:19:10 +00:00
|
|
|
# No tenemos índice de sutty, vamos directamente a ver el listado de
|
|
|
|
# sitios
|
2018-01-29 18:09:30 +00:00
|
|
|
def index
|
|
|
|
redirect_to sites_path
|
|
|
|
end
|
2018-01-29 22:19:10 +00:00
|
|
|
|
2019-03-26 15:32:20 +00:00
|
|
|
def markdown; end
|
2018-02-25 01:10:37 +00:00
|
|
|
|
2018-01-29 22:19:10 +00:00
|
|
|
private
|
|
|
|
|
2019-07-03 23:25:23 +00:00
|
|
|
# Encontrar un sitio por su nombre
|
2018-01-29 22:19:10 +00:00
|
|
|
def find_site
|
|
|
|
id = params[:site_id] || params[:id]
|
|
|
|
|
2019-07-04 00:47:59 +00:00
|
|
|
# TODO: encontrar una forma mejor de buscar en todos los sitios en
|
|
|
|
# lugar de desperdiciar una consulta
|
|
|
|
current_usuarie.sites.find_by_name(id) ||
|
|
|
|
current_usuarie.sites_as_invitade.find_by_name(id)
|
2018-01-29 22:19:10 +00:00
|
|
|
end
|
2018-01-30 15:20:19 +00:00
|
|
|
|
|
|
|
def find_post(site)
|
|
|
|
id = params[:post_id] || params[:id]
|
2018-05-08 21:14:00 +00:00
|
|
|
lang = find_lang(site)
|
2018-02-22 19:01:11 +00:00
|
|
|
posts = site.posts_for(lang)
|
2018-01-30 15:20:19 +00:00
|
|
|
|
2018-02-22 19:01:11 +00:00
|
|
|
posts.find do |p|
|
2018-01-30 15:20:19 +00:00
|
|
|
p.id == id
|
|
|
|
end
|
|
|
|
end
|
2018-02-23 19:20:51 +00:00
|
|
|
|
2018-05-08 21:14:00 +00:00
|
|
|
def find_lang(site)
|
|
|
|
params.fetch(:lang, site.default_lang)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_template(site)
|
2018-05-17 19:06:08 +00:00
|
|
|
id = params[:template_id] || params[:template] || params.dig(:post, :layout)
|
2018-05-08 21:14:00 +00:00
|
|
|
site.templates.find do |t|
|
|
|
|
t.id == id
|
|
|
|
end
|
2018-02-23 19:20:51 +00:00
|
|
|
end
|
2018-02-26 22:08:21 +00:00
|
|
|
|
|
|
|
def set_locale
|
|
|
|
I18n.locale = session[:lang] if session[:lang].present?
|
|
|
|
end
|
2018-01-02 17:19:25 +00:00
|
|
|
end
|