Module: Renalware::LayoutHelper
- Defined in:
- app/helpers/renalware/layout_helper.rb
Instance Method Summary collapse
-
#breadcrumbs_and_title(breadcrumbs: [], title:) ⇒ Object
Example usage for the edit patient (demographics) page breadcrumbs_and_title( breadcrumbs: [ Breadcrumb.new(title: “Demographics”, anchor: link_to(“Demographics”, patient_path) ], title: “Edit” ) Returns Demographics / Edit where Demographics is a link back in the navigation, like a true breadcrumb. :breadcrumbs can be anchors or just a page name, and is single does not need to be an array. :title is normally just a string as it represents the current page, and should not be a link..
- #generate_page_title(local_assigns:, patient: nil, separator: Renalware.config.page_title_spearator) ⇒ Object
-
#with_format(format) ⇒ Object
In order for pdf rendering to easily re-use html partials (despite a mime type of :pdf), pass partial rendering code as a block to ‘with_format`.
-
#within_admin_layout(title: nil, **opts) ⇒ Object
If you don’t want the title argument to be used in the browser bar, pass in page_title: in opts also.
- #within_layout(layout:, title: nil, **opts) ⇒ Object
- #within_patient_layout(title: nil, **opts) ⇒ Object
Instance Method Details
#breadcrumbs_and_title(breadcrumbs: [], title:) ⇒ Object
Example usage for the edit patient (demographics) page breadcrumbs_and_title(
breadcrumbs: [
Breadcrumb.new(title: "Demographics",
anchor: link_to("Demographics", patient_path)
],
title: "Edit"
) Returns
Demographics / Edit
where Demographics is a link back in the navigation, like a true breadcrumb. :breadcrumbs can be anchors or just a page name, and is single does not need to be an array. :title is normally just a string as it represents the current page, and should not be a link.
50 51 52 |
# File 'app/helpers/renalware/layout_helper.rb', line 50 def (breadcrumbs: [], title:) safe_join(Array().map(&:anchor).append(title), " / ") end |
#generate_page_title(local_assigns:, patient: nil, separator: Renalware.config.page_title_spearator) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/renalware/layout_helper.rb', line 25 def generate_page_title(local_assigns:, patient: nil, separator: Renalware.config.page_title_spearator) parts = [] parts << "#{patient} #{patient.age}y #{patient.sex}" if patient.present? parts << Array(local_assigns[:breadcrumbs]).map(&:title) parts << local_assigns[:title] title = parts.flatten.compact.join(separator) content_for(:page_title){ title&.html_safe } title end |
#with_format(format) ⇒ Object
In order for pdf rendering to easily re-use html partials (despite a mime type of :pdf), pass partial rendering code as a block to ‘with_format`.
Example issues and usage trying to render my_partial.html.slim from my_template.pdf.slim:
= render 'my_partial' # cannot resolve the html partial
= render 'my_partial', format: :html # resolves partial but i18n requires an `html:` key
- with_format(:html) do
= render 'my_partial' # resolves the html partial and existing i18n keys are used.
See stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-\ different-format-in-rails/3427634#3427634
68 69 70 71 72 73 74 75 76 |
# File 'app/helpers/renalware/layout_helper.rb', line 68 def with_format(format) old_formats = formats begin self.formats = [format] return yield ensure self.formats = old_formats end end |
#within_admin_layout(title: nil, **opts) ⇒ Object
If you don’t want the title argument to be used in the browser bar, pass in page_title: in opts also.
7 8 9 10 11 |
# File 'app/helpers/renalware/layout_helper.rb', line 7 def within_admin_layout(title: nil, **opts) within_layout(layout: "renalware/layouts/non_patient", title: opts.fetch(:page_title, title), **opts) { yield } end |
#within_layout(layout:, title: nil, **opts) ⇒ Object
19 20 21 22 23 |
# File 'app/helpers/renalware/layout_helper.rb', line 19 def within_layout(layout:, title: nil, **opts) title ||= t?(".page_title") ? t(".page_title") : t(".title", cascade: false) opts[:title] = title render(layout: layout, locals: opts) { yield } end |
#within_patient_layout(title: nil, **opts) ⇒ Object
13 14 15 16 17 |
# File 'app/helpers/renalware/layout_helper.rb', line 13 def within_patient_layout(title: nil, **opts) within_layout(layout: "renalware/layouts/patient", title: title, **opts) { yield } end |