Module: Koi::Form::Builder
- Extended by:
- ActiveSupport::Concern
- Included in:
- Koi::FormBuilder
- Defined in:
- lib/koi/form/builder.rb
Instance Method Summary collapse
-
#admin_archive(text = "Archive") ⇒ Object
Generates an archive link formatted as a button that will perform a turbo delete with a confirmation.
-
#admin_delete(text = "Delete", url: nil, confirm: "Are you sure?", data: {}) ⇒ Object
Generates a delete link formatted as a button that will perform a turbo delete with a confirmation.
-
#admin_discard(text = "Discard", url: :back) ⇒ Object
Generates a discard changes link formatted as a text button that navigates the user back to the previous page.
-
#admin_save(text = "Save", name: :commit, value: :save, class: "button button--primary") ⇒ Object
Generates a submit button for saving admin resources.
- #govuk_document_field(attribute_name, hint: {}) ⇒ Object
- #govuk_image_field(attribute_name, hint: {}) ⇒ Object
-
#govuk_rich_text_area(attribute_name, data: {}) ⇒ Object
Use content editor trix setup by default.
Instance Method Details
#admin_archive(text = "Archive") ⇒ Object
Generates an archive link formatted as a button that will perform a turbo delete with a confirmation.
30 31 32 |
# File 'lib/koi/form/builder.rb', line 30 def admin_archive(text = "Archive", **) admin_delete(text, **) end |
#admin_delete(text = "Delete", url: nil, confirm: "Are you sure?", data: {}) ⇒ Object
Generates a delete link formatted as a button that will perform a turbo delete with a confirmation.
19 20 21 22 23 24 25 26 |
# File 'lib/koi/form/builder.rb', line 19 def admin_delete(text = "Delete", url: nil, confirm: "Are you sure?", data: {}, **) return unless object.persisted? link_to(text, url || url_for(action: :destroy), class: "button button--secondary", data: data.reverse_merge(turbo_method: :delete, turbo_confirm: confirm), **) end |
#admin_discard(text = "Discard", url: :back) ⇒ Object
Generates a discard changes link formatted as a text button that navigates the user back to the previous page.
36 37 38 |
# File 'lib/koi/form/builder.rb', line 36 def admin_discard(text = "Discard", url: :back, **) link_to(text, url, class: "button button--text", **) end |
#admin_save(text = "Save", name: :commit, value: :save, class: "button button--primary") ⇒ Object
Generates a submit button for saving admin resources.
13 14 15 |
# File 'lib/koi/form/builder.rb', line 13 def admin_save(text = "Save", name: :commit, value: :save, class: "button button--primary", **) (text, name:, value:, class:, **) end |
#govuk_document_field(attribute_name, hint: {}) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/koi/form/builder.rb', line 42 def govuk_document_field(attribute_name, hint: {}, **, &) if hint.is_a?(Hash) max_size = hint.fetch(:max_size, Koi.config.document_size_limit) hint[:text] ||= t("helpers.hint.default.document", max_size: @template.number_to_human_size(max_size)) end super end |
#govuk_image_field(attribute_name, hint: {}) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/koi/form/builder.rb', line 53 def govuk_image_field(attribute_name, hint: {}, **, &) if hint.is_a?(Hash) max_size = hint.fetch(:max_size, Koi.config.image_size_limit) hint[:text] ||= t("helpers.hint.default.document", max_size: @template.number_to_human_size(max_size)) end super end |
#govuk_rich_text_area(attribute_name, data: {}) ⇒ Object
Use content editor trix setup by default.
66 67 68 69 70 71 72 73 |
# File 'lib/koi/form/builder.rb', line 66 def govuk_rich_text_area(attribute_name, data: {}, **, &) data = data.reverse_merge( direct_upload_url: @template.katalyst_content.direct_uploads_url, controller: "content--editor--trix", action: "trix-initialize->content--editor--trix#trixInitialize", ) super end |