Module: Alchemy::NameConversions
- Included in:
- Attachment, Page::PageNaming, Picture
- Defined in:
- lib/alchemy/name_conversions.rb
Overview
Provides methods for converting names into urlnames and vice versa.
Instance Method Summary collapse
-
#convert_to_humanized_name(name, suffix) ⇒ Object
Converts a filename and suffix into a human readable name.
-
#convert_to_urlname(name) ⇒ Object
Converts a given name into url save and readable urlanme.
-
#sanitized_filename(file_name) ⇒ Object
Sanitizes a given filename by removing directory traversal attempts and HTML entities.
Instance Method Details
#convert_to_humanized_name(name, suffix) ⇒ Object
Converts a filename and suffix into a human readable name.
22 23 24 |
# File 'lib/alchemy/name_conversions.rb', line 22 def convert_to_humanized_name(name, suffix) name.gsub(/\.#{::Regexp.quote(suffix)}$/i, "").tr("_", " ").strip end |
#convert_to_urlname(name) ⇒ Object
Converts a given name into url save and readable urlanme. Uses rails parameterize, but converts german umlauts before.
11 12 13 14 15 16 17 18 |
# File 'lib/alchemy/name_conversions.rb', line 11 def convert_to_urlname(name) name .gsub(/[äÄ]/, "ae") .gsub(/[üÜ]/, "ue") .gsub(/[öÖ]/, "oe") .gsub(/ß/, "ss") .parameterize end |
#sanitized_filename(file_name) ⇒ Object
Sanitizes a given filename by removing directory traversal attempts and HTML entities.
27 28 29 30 |
# File 'lib/alchemy/name_conversions.rb', line 27 def sanitized_filename(file_name) file_name = File.basename(file_name) CGI.escapeHTML(file_name) end |