module SimpleWorkflow::Helper

View helper methods augmented with breadcrumb management.

Public Instance Methods

detour?() click to toggle source
# File lib/simple_workflow/helper.rb, line 85
def detour?
  !session[:detours].nil?
end
detour_to(title, options = nil, html_options = nil, &block) click to toggle source
# File lib/simple_workflow/helper.rb, line 17
def detour_to(title, options = nil, html_options = nil, &block)
  if block
    html_options     = options
    options          = title
    link_with_detour = link_to(with_detour(options), html_options, &block)
  else
    link_with_detour = link_to(title, with_detour(options), html_options)
  end
  if link_with_detour.size > 4096 # URL maximum size overflow
    link_with_detour = if block
                         link_to(options, html_options, &block)
                       else
                         link_to(title, options, html_options)
                       end
  end
  link_with_detour
end
image_button_to(image_source, title, options, html_options = {}) click to toggle source
# File lib/simple_workflow/helper.rb, line 9
def image_button_to(image_source, title, options, html_options = {})
  image_submit_tag image_source, {
    class: 'image-submit', alt: title, title: title,
    id: "#{title}_#{options[:id]}", name: title,
    onclick: "form.action='#{url_for(options)}'"
  }.update(html_options)
end
image_detour_to(image_source, title, url_options, image_options = nil, link_options = nil) click to toggle source
# File lib/simple_workflow/helper.rb, line 54
def image_detour_to(image_source, title, url_options, image_options = nil, link_options = nil)
  image_options ||= { class: 'image-submit' }
  image_options.update alt: title, title: title
  detour_to image_tag(image_source, image_options), url_options, link_options
end
origin_options() click to toggle source
# File lib/simple_workflow/helper.rb, line 50
def origin_options
  params.to_unsafe_h.reject { |k, _v| %i[detour return_from_detour].include? k.to_sym }
end
with_detour(options, origin = origin_options) click to toggle source

Takes a link destination and augments it with the current page as origin. If the optional second argument is given, it is used as the origin. If the given origin is only an anchor, it is added to the current page.

# File lib/simple_workflow/helper.rb, line 38
def with_detour(options, origin = origin_options)
  if origin.is_a?(String)
    uri = URI(origin)
    origin = Rails.application.routes.recognize_path uri.path
    origin.update anchor: uri.fragment if uri.fragment.present?
    origin.update Rack::Utils.parse_nested_query(uri.query) if uri.query.present?
  end
  origin.update(origin_options) if origin.keys == [:anchor]
  url = url_for(options)
  url + (url.include?('?') ? '&' : '?') + origin.to_h.to_param('detour')
end