diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 633aa3b6..a1a2c8aa 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -69,6 +69,13 @@ body { color: var(--foreground); } +* { + .rtl, + &[dir=rtl] { + text-align: right; + } +} + a { color: var(--color); @@ -123,11 +130,6 @@ ol.breadcrumb { background-color: $magenta; } -.rtl { - direction: rtl; - text-align: right; -} - .btn-text { background-color: transparent; border: none; diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 76c5cb60..ca001c9a 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -33,6 +33,7 @@ class PostsController < ApplicationController @site = find_site @post = @site.posts(lang: locale).find params[:id] authorize @post + @locale = locale fresh_when @post end @@ -41,6 +42,7 @@ class PostsController < ApplicationController authorize Post @site = find_site @post = @site.posts.build(lang: locale, layout: params[:layout]) + @locale = locale end def create @@ -64,6 +66,8 @@ class PostsController < ApplicationController @post = @site.posts(lang: locale).find params[:id] authorize @post + + @locale = locale end def update diff --git a/app/models/metadata_template.rb b/app/models/metadata_template.rb index 56b4d275..d53a0459 100644 --- a/app/models/metadata_template.rb +++ b/app/models/metadata_template.rb @@ -51,6 +51,10 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type, name end + def to_s + value.to_s + end + # Decide si el metadato se coloca en el front_matter o no def front_matter? true diff --git a/app/views/posts/attribute_ro/_array.haml b/app/views/posts/attribute_ro/_array.haml index 10b08508..20a0a545 100644 --- a/app/views/posts/attribute_ro/_array.haml +++ b/app/views/posts/attribute_ro/_array.haml @@ -5,4 +5,4 @@ - metadata.value.each do |v| %span.badge.badge-primary= v - else - %span.badge.badge-primary= metadata.value + %span.badge.badge-primary{ lang: locale, dir: dir }= metadata.value diff --git a/app/views/posts/attribute_ro/_boolean.haml b/app/views/posts/attribute_ro/_boolean.haml index 991e5fa5..9e648d3a 100644 --- a/app/views/posts/attribute_ro/_boolean.haml +++ b/app/views/posts/attribute_ro/_boolean.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= t "_#{post.send(attribute).value}" + %td{ lang: locale, dir: dir }= t "_#{post.send(attribute).value}" diff --git a/app/views/posts/attribute_ro/_color.haml b/app/views/posts/attribute_ro/_color.haml index 787aacd5..d727dcec 100644 --- a/app/views/posts/attribute_ro/_color.haml +++ b/app/views/posts/attribute_ro/_color.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td{ style: "background-color: #{metadata.value}" } = metadata.value + %td{ lang: locale, dir: dir, style: "background-color: #{metadata.value}" } = metadata.value diff --git a/app/views/posts/attribute_ro/_content.haml b/app/views/posts/attribute_ro/_content.haml index 31dd8f0d..e6d9a274 100644 --- a/app/views/posts/attribute_ro/_content.haml +++ b/app/views/posts/attribute_ro/_content.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= metadata.value + %td{ lang: locale, dir: dir }= metadata.value diff --git a/app/views/posts/attribute_ro/_date.haml b/app/views/posts/attribute_ro/_date.haml index dc94def2..cf8ea8ac 100644 --- a/app/views/posts/attribute_ro/_date.haml +++ b/app/views/posts/attribute_ro/_date.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= l metadata.value.to_date + %td{ dir: dir, lang: locale }= l metadata.value.to_date diff --git a/app/views/posts/attribute_ro/_document_date.haml b/app/views/posts/attribute_ro/_document_date.haml index dc94def2..0ae5ea53 100644 --- a/app/views/posts/attribute_ro/_document_date.haml +++ b/app/views/posts/attribute_ro/_document_date.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= l metadata.value.to_date + %td{ lang: locale, dir: dir }= l metadata.value.to_date diff --git a/app/views/posts/attribute_ro/_email.haml b/app/views/posts/attribute_ro/_email.haml index cf15531c..854cb2e6 100644 --- a/app/views/posts/attribute_ro/_email.haml +++ b/app/views/posts/attribute_ro/_email.haml @@ -1,4 +1,4 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td + %td{ dir: dir, lang: locale } %a{ href: "mailto:#{metadata.value}" }= metadata.value diff --git a/app/views/posts/attribute_ro/_file.haml b/app/views/posts/attribute_ro/_file.haml index 7bc7b154..7d51156b 100644 --- a/app/views/posts/attribute_ro/_file.haml +++ b/app/views/posts/attribute_ro/_file.haml @@ -3,4 +3,4 @@ %td - if metadata.value['path'].present? = link_to t('.download'), url_for(metadata.static_file) - %p= metadata.value['description'] + %p{ dir: dir, lang: locale }= metadata.value['description'] diff --git a/app/views/posts/attribute_ro/_image.haml b/app/views/posts/attribute_ro/_image.haml index 3663597f..80bbbdbe 100644 --- a/app/views/posts/attribute_ro/_image.haml +++ b/app/views/posts/attribute_ro/_image.haml @@ -6,4 +6,4 @@ = image_tag url_for(metadata.static_file), alt: metadata.value['description'], class: 'img-fluid' - %figcaption= metadata.value['description'] + %figcaption{ dir: dir, lang: locale }= metadata.value['description'] diff --git a/app/views/posts/attribute_ro/_lang.haml b/app/views/posts/attribute_ro/_lang.haml index a2df03ec..b444a429 100644 --- a/app/views/posts/attribute_ro/_lang.haml +++ b/app/views/posts/attribute_ro/_lang.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= t(metadata.value) + %td{ lang: locale, dir: dir }= t(metadata.value) diff --git a/app/views/posts/attribute_ro/_locales.haml b/app/views/posts/attribute_ro/_locales.haml new file mode 100644 index 00000000..3ac22933 --- /dev/null +++ b/app/views/posts/attribute_ro/_locales.haml @@ -0,0 +1,9 @@ +%tr{ id: attribute } + %th= post_label_t(attribute, post: post) + %td + %ul + - metadata.value.each do |uuid| + - p = site.docs.find(uuid, uuid: true) + %li{ dir: t("locales.#{p.lang.value}.dir"), lang: p.lang.value } + = link_to p.title.value, + site_post_path(site, p.id, locale: p.lang.value) diff --git a/app/views/posts/attribute_ro/_number.haml b/app/views/posts/attribute_ro/_number.haml index 31dd8f0d..67642e2c 100644 --- a/app/views/posts/attribute_ro/_number.haml +++ b/app/views/posts/attribute_ro/_number.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= metadata.value + %td{ dir: dir, lang: locale }= metadata.value diff --git a/app/views/posts/attribute_ro/_order.haml b/app/views/posts/attribute_ro/_order.haml index 31dd8f0d..67642e2c 100644 --- a/app/views/posts/attribute_ro/_order.haml +++ b/app/views/posts/attribute_ro/_order.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= metadata.value + %td{ dir: dir, lang: locale }= metadata.value diff --git a/app/views/posts/attribute_ro/_predefined_array.haml b/app/views/posts/attribute_ro/_predefined_array.haml index d5d13b2c..88a82626 100644 --- a/app/views/posts/attribute_ro/_predefined_array.haml +++ b/app/views/posts/attribute_ro/_predefined_array.haml @@ -2,4 +2,4 @@ %th= post_label_t(attribute, post: post) %td - metadata.value.each do |v| - %span.badge.badge-primary= metadata.values.key v + %span.badge.badge-primary{ dir: dir, lang: locale }= metadata.values.key v diff --git a/app/views/posts/attribute_ro/_related_posts.haml b/app/views/posts/attribute_ro/_related_posts.haml index f8ffb73c..c43b589e 100644 --- a/app/views/posts/attribute_ro/_related_posts.haml +++ b/app/views/posts/attribute_ro/_related_posts.haml @@ -1,7 +1,7 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) %td - %ul + %ul{ dir: dir, lang: locale } - metadata.value.each do |v| - p = site.posts(lang: post.lang.value).find(v, uuid: true) -# diff --git a/app/views/posts/attribute_ro/_string.haml b/app/views/posts/attribute_ro/_string.haml index 31dd8f0d..67642e2c 100644 --- a/app/views/posts/attribute_ro/_string.haml +++ b/app/views/posts/attribute_ro/_string.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= metadata.value + %td{ dir: dir, lang: locale }= metadata.value diff --git a/app/views/posts/attribute_ro/_text.haml b/app/views/posts/attribute_ro/_text.haml index 31dd8f0d..67642e2c 100644 --- a/app/views/posts/attribute_ro/_text.haml +++ b/app/views/posts/attribute_ro/_text.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= metadata.value + %td{ dir: dir, lang: locale }= metadata.value diff --git a/app/views/posts/attribute_ro/_url.haml b/app/views/posts/attribute_ro/_url.haml index 74c240bd..9c33572b 100644 --- a/app/views/posts/attribute_ro/_url.haml +++ b/app/views/posts/attribute_ro/_url.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %th= post_label_t(attribute, post: post) - %td= link_to metadata.value + %td{ dir: dir, lang: locale }= link_to metadata.value diff --git a/app/views/posts/attributes/_locales.haml b/app/views/posts/attributes/_locales.haml index 3e1f056b..b7cc8864 100644 --- a/app/views/posts/attributes/_locales.haml +++ b/app/views/posts/attributes/_locales.haml @@ -8,18 +8,19 @@ - site.locales.each do |locale| -# Ignorar el idioma actual - next if post.lang.value == locale + - locale_t = t("locales.#{locale}.name") - values = metadata.value.select do |x| - metadata.values[locale.to_sym].values.include? x .form-group - = label_tag "post_#{attribute}_#{locale}", t(locale) + = label_tag "post_#{attribute}_#{locale}", locale_t .mapable{ data: { values: values.to_json, 'default-values': metadata.values[locale.to_sym].to_json, name: "post[#{attribute}][]", list: id_for_datalist(attribute, locale), button: t('posts.attributes.add'), - remove: 'false', legend: t(locale), + remove: 'false', legend: locale_t, described: id_for_help(attribute, locale) } } = text_field(*field_name_for('post', attribute, '[]'), diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 7177713c..e888625a 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -38,10 +38,11 @@ idiomas .locales - @site.locales.each do |locale| - = link_to t(locale), site_posts_path(@site, locale: locale), + = link_to t("locales.#{locale}.name"), site_posts_path(@site, locale: locale), class: "mr-2 mt-2 mb-2#{locale == @locale ? 'active font-weight-bold' : ''}" %table.table.table-condensed.table-draggable %tbody + - dir = t("locales.#{@locale}.dir") - @posts.each_with_index do |post, i| -# saltearse el post a menos que esté en la categoría por @@ -63,13 +64,13 @@ -# Orden más alto es mayor prioridad = hidden_field 'post[reorder]', post.uuid.value, value: @posts.length - i, class: 'reorder' - %td + %td{ class: dir } %small = link_to @site.i18n.dig('layouts', post.layout.name.to_s) || post.layout.name.to_s.humanize, site_posts_path(@site, layout: post.layout.name) %br/ - = link_to post.title.value, - site_post_path(@site, post.id) + = link_to site_post_path(@site, post.id) do + %span{ lang: post.lang.value, dir: dir }= post.title.value - if post.attributes.include? :draft - if post.draft.value %span.badge.badge-primary @@ -79,7 +80,8 @@ %br %small - post.categories.value.each do |c| - = link_to c, site_posts_path(@site, category: c) + = link_to site_posts_path(@site, category: c) do + %span{ lang: post.lang.value, dir: dir }= c %td = post.date.value.strftime('%F') diff --git a/app/views/posts/show.haml b/app/views/posts/show.haml index b5baa661..80b12ee0 100644 --- a/app/views/posts/show.haml +++ b/app/views/posts/show.haml @@ -4,6 +4,7 @@ link_to(t('posts.index'), site_posts_path(@site)), @post.title.value] +- dir = t("locales.#{@locale}.dir") .row .col %article.content @@ -27,11 +28,12 @@ post: @post, attribute: attr, metadata: metadata, site: @site, - tags: all_html_tags) + tags: all_html_tags, + dir: dir) -# Mostrar todo lo que no va en el front_matter (el contenido) - @post.attributes.each do |attr| - next if @post.send(attr).front_matter? - %section{ id: attr } - = @post.send(attr).value.html_safe + %section{ id: attr, dir: dir } + = @post.send(attr).to_s.html_safe diff --git a/config/locales/en.yml b/config/locales/en.yml index ae579ada..7441dd39 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,4 +1,15 @@ en: + dir: ltr + locales: + es: + name: Castillian Spanish + dir: ltr + en: + name: English + dir: ltr + ar: + name: Arabic + dir: rtl login: email: E-mail address password: Password @@ -7,7 +18,6 @@ en: sr-help: "After this form you'll find links to recover your account and other actions." _true: Yes _false: No - dir: ltr svg: sutty: title: Sutty @@ -33,9 +43,6 @@ en: layout_missing: 'Needs an instance of Layout' document_missing: 'Needs an instance of Jekyll::Document' no_method: '%{method} not allowed' - es: Castillian Spanish - en: English - ar: Arabic seconds: '%{seconds} seconds' contact_mailer: subject: '[%site] Contact form' diff --git a/config/locales/es.yml b/config/locales/es.yml index b2f1c270..c902f5b8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1,4 +1,15 @@ es: + dir: ltr + locales: + es: + name: Castellano + dir: ltr + en: + name: Inglés + dir: ltr + ar: + name: Árabe + dir: rtl login: email: Correo electrónico password: Contraseña @@ -7,7 +18,6 @@ es: sr-help: 'Después del formulario encontrarás vínculos para recuperar tu cuenta, entre otras acciones.' _true: Sí _false: No - dir: ltr svg: sutty: title: Sutty @@ -35,9 +45,6 @@ es: layout_missing: 'Necesita una instancia de Layout' document_missing: 'Necesita una instancia de Jekyll::Document' no_method: '%{method} no está permitido' - es: Castellano - en: Inglés - ar: Árabe seconds: '%{seconds} segundos' contact_mailer: subject: '[%{site}] Formulario de contacto'