Module: SimpleWorkflow::Helper
Instance Method Summary
collapse
-
#back_or_link_to(title, options = nil, html_options = nil) ⇒ Object
-
#detour? ⇒ Boolean
-
#detour_to(title, options = nil, html_options = nil, &block) ⇒ Object
-
#image_button_to(image_source, title, options, html_options = {}) ⇒ Object
-
#image_detour_to(image_source, title, url_options, image_options = nil, link_options = nil) ⇒ Object
-
#image_link_to(image_source, title, url_options, image_options = nil, link_options = nil) ⇒ Object
-
#image_link_to_remote(image_source, title, link_options, image_options = nil, html_options = {}) ⇒ Object
-
#origin_options ⇒ Object
-
#with_detour(options, origin = origin_options) ⇒ Object
Takes a link destination and augments it with the current page as origin.
Methods included from Detour
#pop_detour, #reset_workflow, #store_detour_in_session
Instance Method Details
#back_or_link_to(title, options = nil, html_options = nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/simple_workflow/helper.rb', line 74
def back_or_link_to(title, options = nil, html_options = nil)
if session[:detours]
link_options = { return_from_detour: true }.update(session[:detours].last)
link_options['id'] ||= nil
logger.debug "linked return from detour: #{link_options.inspect}"
else
link_options = options
end
link_to(title, link_options, html_options) if options
rescue ActionController::UrlGenerationError => e
if session[:detours]
logger.error "Exception linking to origin: #{e.class} #{e}"
pop_detour(session)
retry
end
raise
end
|
#detour? ⇒ Boolean
70
71
72
|
# File 'lib/simple_workflow/helper.rb', line 70
def detour?
!session[:detours].nil?
end
|
#detour_to(title, options = nil, html_options = nil, &block) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/simple_workflow/helper.rb', line 11
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
link_with_detour = if block
link_to(options, html_options, &block)
else
link_to(title, options, html_options)
end
end
link_with_detour
end
|
5
6
7
8
9
|
# File 'lib/simple_workflow/helper.rb', line 5
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) ⇒ Object
42
43
44
45
46
|
# File 'lib/simple_workflow/helper.rb', line 42
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
|
#image_link_to(image_source, title, url_options, image_options = nil, link_options = nil) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/simple_workflow/helper.rb', line 48
def image_link_to(image_source, title, url_options, image_options = nil, link_options = nil)
if link_options == true
link_options = { method: :post }
elsif link_options == false
link_options = nil
end
image_options ||= { class: 'image-submit' }
image_options.update alt: title, title: title
link_to image_tag(image_source, image_options), url_options, link_options
end
|
#image_link_to_remote(image_source, title, link_options, image_options = nil, html_options = {}) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/simple_workflow/helper.rb', line 59
def image_link_to_remote(image_source, title, link_options, image_options = nil, html_options = {})
if html_options == true
html_options = { method: :post }
elsif html_options == false
html_options = {}
end
image_options ||= { class: 'image-submit' }
image_options.update alt: title, title: title
link_to image_tag(image_source, image_options), link_options, html_options.merge(remote: true)
end
|
#origin_options ⇒ Object
38
39
40
|
# File 'lib/simple_workflow/helper.rb', line 38
def origin_options
params.reject { |k, _v| i(detour return_from_detour).include? k.to_sym }
end
|
#with_detour(options, origin = origin_options) ⇒ Object
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.
32
33
34
35
36
|
# File 'lib/simple_workflow/helper.rb', line 32
def with_detour(options, origin = origin_options)
origin.update(origin_options) if origin.keys == [:anchor]
url = url_for(options)
url + (url =~ /\?/ ? '&' : '?') + origin.to_h.to_param('detour')
end
|