parent
f4a632a947
commit
1878749910
3 changed files with 32 additions and 0 deletions
22
app/models/metadata_permalink.rb
Normal file
22
app/models/metadata_permalink.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Este metadato permite generar rutas manuales.
|
||||
class MetadataPermalink < MetadataString
|
||||
# Los permalinks nunca pueden ser privados
|
||||
def private?
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Al hacer limpieza, validamos la ruta. Eliminamos / multiplicadas,
|
||||
# puntos suspensivos, la primera / para que siempre sea relativa y
|
||||
# agregamos una / al final si la ruta no tiene extensión.
|
||||
def sanitize(value)
|
||||
value = value.strip.gsub('..', '/').gsub('./', '').squeeze('/')
|
||||
value = value[1..-1] if value.start_with? '/'
|
||||
value += '/' if File.extname(value).blank?
|
||||
|
||||
value
|
||||
end
|
||||
end
|
3
app/views/posts/attribute_ro/_permalink.haml
Normal file
3
app/views/posts/attribute_ro/_permalink.haml
Normal file
|
@ -0,0 +1,3 @@
|
|||
%tr{ id: attribute }
|
||||
%th= post_label_t(attribute, post: post)
|
||||
%td{ dir: dir, lang: locale }= metadata.value
|
7
app/views/posts/attributes/_permalink.haml
Normal file
7
app/views/posts/attributes/_permalink.haml
Normal file
|
@ -0,0 +1,7 @@
|
|||
.form-group
|
||||
= label_tag "post_#{attribute}", post_label_t(attribute, post: post)
|
||||
= text_field 'post', attribute, value: metadata.value,
|
||||
dir: dir, lang: locale,
|
||||
**field_options(attribute, metadata)
|
||||
= render 'posts/attribute_feedback',
|
||||
post: post, attribute: attribute, metadata: metadata
|
Loading…
Reference in a new issue