Sha256: 5db90be1cf0884d483c09b3882f5384d461a35e418b6187138cdef85c4ab8f4b

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

module <%= class_name %><%= step_alias.pluralize.camelize %>Helper
  <%= step_alias.pluralize.upcase %> = %w(<%= steps.to_a.join(' ') %>)

  def <%= file_path %>_<%= step_alias %>_model
    <%= file_path %>_class = "<%= class_name %>::#{<%= step_alias %>.camelcase}".constantize rescue <%= class_name %>
    <%= file_path %>_class.find(params[:<%= file_path %>_id])
  end

  def <%= step_alias %>
    <%= step_alias.pluralize.upcase %>.find {|a_<%= step_alias %>| a_<%= step_alias %> == params[:id].to_s.downcase}
  end

  def previous_<%= step_alias %>
    current_<%= step_alias %>_index = <%= step_alias.pluralize.upcase %>.index(<%= step_alias %>)
    previous_<%= step_alias %>_index = current_<%= step_alias %>_index-1
    previous_<%= step_alias %>_index < 0 ? nil : <%= step_alias.pluralize.upcase %>[previous_<%= step_alias %>_index]
  end

  def next_<%= step_alias %>
    current_<%= step_alias %>_index = <%= step_alias.pluralize.upcase %>.index(<%= step_alias %>)
    <%= step_alias.pluralize.upcase %>[current_<%= step_alias %>_index+1]
  end

  <% %w(path url).each do |route_term| %>
  def first_<%= step_alias %>_<%= route_term %>
    <%= file_path %>_<%= step_alias %>_model_<%= route_term %>(<%= step_alias.pluralize.upcase %>.first)
  end

  def previous_<%= step_alias %>_<%= route_term %>
    <%= file_path %>_<%= step_alias %>_model_<%= route_term %>(previous_<%= step_alias %>)
  end

  def next_<%= step_alias %>_<%= route_term %>
    <%= file_path %>_<%= step_alias %>_model_<%= route_term %>(next_<%= step_alias %>)
  end

  def last_<%= step_alias %>_<%= route_term %>
    <%= file_path %>_<%= step_alias %>_model_<%= route_term %>(<%= step_alias.pluralize.upcase %>.last)
  end

  def <%= file_path %>_<%= step_alias %>_model_<%= route_term %>(<%= step_alias %>)
    edit_<%= file_path %>_<%= file_path %>_<%= step_alias %>_<%= route_term %>(<%= file_path %>_<%= step_alias %>_model, <%= step_alias %>)
  end
  <% end %>
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ultra_light_wizard-0.0.4 lib/generators/templates/app/helpers/wizard_steps_helper.rb.erb