Class: Govspeak::AttachmentPresenter
- Inherits:
-
Object
- Object
- Govspeak::AttachmentPresenter
- Includes:
- ActionView::Helpers::NumberHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper
- Defined in:
- lib/govspeak/presenters/attachment_presenter.rb
Constant Summary collapse
- MS_WORD_DOCUMENT_HUMANIZED_CONTENT_TYPE =
"MS Word Document".freeze
- MS_EXCEL_SPREADSHEET_HUMANIZED_CONTENT_TYPE =
"MS Excel Spreadsheet".freeze
- MS_POWERPOINT_PRESENTATION_HUMANIZED_CONTENT_TYPE =
"MS Powerpoint Presentation".freeze
Instance Attribute Summary collapse
-
#attachment ⇒ Object
readonly
Returns the value of attribute attachment.
Instance Method Summary collapse
- #attachment_attributes ⇒ Object
- #file_abbr_tag(abbr, title) ⇒ Object
- #file_extension ⇒ Object
- #humanized_content_type(file_extension) ⇒ Object
- #id ⇒ Object
-
#initialize(attachment) ⇒ AttachmentPresenter
constructor
A new instance of AttachmentPresenter.
- #link(body, url, options = {}) ⇒ Object
- #title ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(attachment) ⇒ AttachmentPresenter
Returns a new instance of AttachmentPresenter.
12 13 14 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 12 def initialize() @attachment = end |
Instance Attribute Details
#attachment ⇒ Object (readonly)
Returns the value of attribute attachment.
6 7 8 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 6 def @attachment end |
Instance Method Details
#attachment_attributes ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 35 def attributes = [] if file_extension == "html" attributes << content_tag(:span, "HTML", class: "type") elsif [:external?] attributes << content_tag(:span, url, class: "url") else attributes << content_tag(:span, humanized_content_type(file_extension), class: "type") if file_extension attributes << content_tag(:span, number_to_human_size([:file_size]), class: "file-size") if [:file_size] attributes << content_tag(:span, pluralize([:number_of_pages], "page"), class: "page-length") if [:number_of_pages] end attributes.join(", ").html_safe end |
#file_abbr_tag(abbr, title) ⇒ Object
53 54 55 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 53 def file_abbr_tag(abbr, title) content_tag(:abbr, abbr, title:) end |
#file_extension ⇒ Object
28 29 30 31 32 33 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 28 def file_extension # NOTE: this is a separate parameter rather than being calculated from the # filename because at the time of writing not all apps were using the effects # of this field. [:file_extension] end |
#humanized_content_type(file_extension) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 57 def humanized_content_type(file_extension) file_extension_vs_humanized_content_type = { "chm" => file_abbr_tag("CHM", "Microsoft Compiled HTML Help"), "csv" => file_abbr_tag("CSV", "Comma-separated Values"), "diff" => file_abbr_tag("DIFF", "Plain text differences"), "doc" => MS_WORD_DOCUMENT_HUMANIZED_CONTENT_TYPE, "docx" => MS_WORD_DOCUMENT_HUMANIZED_CONTENT_TYPE, "dot" => file_abbr_tag("DOT", "MS Word Document Template"), "dxf" => file_abbr_tag("DXF", "AutoCAD Drawing Exchange Format"), "eps" => file_abbr_tag("EPS", "Encapsulated PostScript"), "gif" => file_abbr_tag("GIF", "Graphics Interchange Format"), "gml" => file_abbr_tag("GML", "Geography Markup Language"), "html" => file_abbr_tag("HTML", "Hypertext Markup Language"), "ics" => file_abbr_tag("ICS", "iCalendar file"), "jpg" => "JPEG", "odp" => file_abbr_tag("ODP", "OpenDocument Presentation"), "ods" => file_abbr_tag("ODS", "OpenDocument Spreadsheet"), "odt" => file_abbr_tag("ODT", "OpenDocument Text document"), "pdf" => file_abbr_tag("PDF", "Portable Document Format"), "png" => file_abbr_tag("PNG", "Portable Network Graphic"), "ppt" => MS_POWERPOINT_PRESENTATION_HUMANIZED_CONTENT_TYPE, "pptx" => MS_POWERPOINT_PRESENTATION_HUMANIZED_CONTENT_TYPE, "ps" => file_abbr_tag("PS", "PostScript"), "rdf" => file_abbr_tag("RDF", "Resource Description Framework"), "rtf" => file_abbr_tag("RTF", "Rich Text Format"), "sch" => file_abbr_tag("SCH", "XML based Schematic"), "txt" => "Plain text", "wsdl" => file_abbr_tag("WSDL", "Web Services Description Language"), "xls" => MS_EXCEL_SPREADSHEET_HUMANIZED_CONTENT_TYPE, "xlsm" => file_abbr_tag("XLSM", "MS Excel Macro-Enabled Workbook"), "xlsx" => MS_EXCEL_SPREADSHEET_HUMANIZED_CONTENT_TYPE, "xlt" => file_abbr_tag("XLT", "MS Excel Spreadsheet Template"), "xsd" => file_abbr_tag("XSD", "XML Schema"), "xslt" => file_abbr_tag("XSLT", "Extensible Stylesheet Language Transformation"), "zip" => file_abbr_tag("ZIP", "Zip archive"), } file_extension_vs_humanized_content_type.fetch(file_extension.to_s.downcase, "") end |
#id ⇒ Object
16 17 18 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 16 def id [:id] end |
#link(body, url, options = {}) ⇒ Object
96 97 98 99 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 96 def link(body, url, = {}) = .map { |k, v| %(#{encode(k)}="#{encode(v)}") }.join(" ") %(<a href="#{encode(url)}" #{}>#{body}</a>) end |
#title ⇒ Object
24 25 26 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 24 def title [:title] end |
#url ⇒ Object
20 21 22 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 20 def url [:url] end |