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

Instance Method Details

#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

Returns:

  • (Boolean)


39
40
41
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 39

def proposal_wizard_step_help_text?(step)
  translated_attribute(component_settings.try("proposal_wizard_#{step}_help_text")).present?
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



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 23

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_stepsObject



43
44
45
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 43

def proposal_wizard_steps
  [ProposalsController::STEP1, ProposalsController::STEP2]
end

#wizard_steps(current_step) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 7

def wizard_steps(current_step)
  scope = "decidim.proposals.proposals.wizard_steps"
  inactive_data = { data: { past: "" } }
  (:ol, id: "wizard-steps", class: "wizard-steps") do
    proposal_wizard_steps.map do |wizard_step|
      active = current_step == wizard_step
      inactive_data = {} if active
      attributes = active ? { "aria-current": "step", "aria-label": "#{t("current_step", scope:)}: #{t(wizard_step, scope:)}", data: { active: "" } } : inactive_data
      (:li, t(wizard_step, scope:), attributes.merge(class: "w-1/2"))
    end.join.html_safe
  end
end