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.
11 12 13 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 11 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
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 34 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
52 53 54 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 52 def file_abbr_tag(abbr, title) content_tag(:abbr, abbr, title: title) end |
#file_extension ⇒ Object
27 28 29 30 31 32 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 27 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
56 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 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 56 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
15 16 17 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 15 def id [:id] end |
#link(body, url, options = {}) ⇒ Object
95 96 97 98 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 95 def link(body, url, = {}) = .map { |k, v| %{#{encode(k)}="#{encode(v)}"} }.join(" ") %{<a href="#{encode(url)}" #{}>#{body}</a>} end |
#title ⇒ Object
23 24 25 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 23 def title [:title] end |
#url ⇒ Object
19 20 21 |
# File 'lib/govspeak/presenters/attachment_presenter.rb', line 19 def url [:url] end |