Module: Decidim::Proposals::ProposalWizardHelper
- Defined in:
- app/helpers/decidim/proposals/proposal_wizard_helper.rb
Overview
Simple helpers to handle markup variations for proposal wizard partials
Instance Method Summary collapse
-
#proposal_wizard_current_step_of(step) ⇒ Object
Returns a string with the current step number and the total steps number.
-
#proposal_wizard_step_classes(step, current_step) ⇒ Object
Returns the css classes used for the proposal wizard for the desired step.
-
#proposal_wizard_step_help_text?(step) ⇒ Boolean
Returns a boolean if the step has a help text defined.
-
#proposal_wizard_step_name(step) ⇒ Object
Returns the name of the step, translated.
-
#proposal_wizard_step_number(step) ⇒ Object
Returns the number of the step.
-
#proposal_wizard_step_title(action_name) ⇒ Object
Returns the page title of the given step, translated.
-
#proposal_wizard_stepper(current_step) ⇒ Object
Returns the list with all the steps, in html.
-
#proposal_wizard_stepper_step(step, current_step) ⇒ Object
Returns the list item of the given step, in html.
- #proposal_wizard_steps_title ⇒ Object
Instance Method Details
#proposal_wizard_current_step_of(step) ⇒ Object
Returns a string with the current step number and the total steps number
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 86 def proposal_wizard_current_step_of(step) current_step_num = proposal_wizard_step_number(step) see_steps = content_tag(:span, class: "hide-for-large") do concat " (" concat content_tag :a, t(:"decidim.proposals.proposals.wizard_steps.see_steps"), "data-toggle": "steps" concat ")" end content_tag :span, class: "text-small" do concat t(:"decidim.proposals.proposals.wizard_steps.step_of", current_step_num: current_step_num, total_steps: total_steps) concat see_steps end end |
#proposal_wizard_step_classes(step, current_step) ⇒ Object
Returns the css classes used for the proposal wizard for the desired step
step - A symbol of the target step current_step - A symbol of the current step
Returns a string with the css classes for the desired step
13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 13 def proposal_wizard_step_classes(step, current_step) step_i = step.to_s.split("_").last.to_i if step_i == proposal_wizard_step_number(current_step) %(step--active #{step} #{current_step}) elsif step_i < proposal_wizard_step_number(current_step) %(step--past #{step}) else %() end end |
#proposal_wizard_step_help_text?(step) ⇒ Boolean
Returns a boolean if the step has a help text defined
step - A symbol of the target step
106 107 108 |
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 106 def proposal_wizard_step_help_text?(step) translated_attribute(component_settings.try("proposal_wizard_#{step}_help_text")).present? end |
#proposal_wizard_step_name(step) ⇒ Object
Returns the name of the step, translated
step - A symbol of the target step
34 35 36 |
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 34 def proposal_wizard_step_name(step) t("decidim.proposals.proposals.wizard_steps.#{step}") end |
#proposal_wizard_step_number(step) ⇒ Object
Returns the number of the step
step - A symbol of the target step
27 28 29 |
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 27 def proposal_wizard_step_number(step) step.to_s.split("_").last.to_i end |
#proposal_wizard_step_title(action_name) ⇒ Object
Returns the page title of the given step, translated
action_name - A string of the rendered action
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 41 def proposal_wizard_step_title(action_name) step_title = case action_name when "create" "new" when "update_draft" "edit_draft" else action_name end t("decidim.proposals.proposals.#{step_title}.title") end |
#proposal_wizard_stepper(current_step) ⇒ Object
Returns the list with all the steps, in html
current_step - A symbol of the current step
73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 73 def proposal_wizard_stepper(current_step) content_tag :ol, class: "wizard__steps" do %( #{proposal_wizard_stepper_step(:step_1, current_step)} #{proposal_wizard_stepper_step(:step_2, current_step)} #{proposal_wizard_stepper_step(:step_3, current_step)} #{proposal_wizard_stepper_step(:step_4, current_step)} ).html_safe end end |
#proposal_wizard_stepper_step(step, current_step) ⇒ Object
Returns the list item of the given step, in html
step - A symbol of the target step current_step - A symbol of the current step
58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 58 def proposal_wizard_stepper_step(step, current_step) attributes = { class: proposal_wizard_step_classes(step, current_step).to_s } step_title = proposal_wizard_step_name(step) if step.to_s.split("_").last.to_i == proposal_wizard_step_number(current_step) current_step_title = proposal_wizard_step_name("current_step") step_title = content_tag(:span, "#{current_step_title}: ", class: "show-for-sr") + step_title attributes["aria-current"] = "step" end content_tag(:li, step_title, attributes) end |
#proposal_wizard_steps_title ⇒ Object
99 100 101 |
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 99 def proposal_wizard_steps_title t("title", scope: "decidim.proposals.proposals.wizard_steps") end |