simple_workflow 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/Manifest.txt +1 -0
- data/Rakefile +1 -1
- data/lib/simple_workflow.rb +2 -2
- data/lib/simple_workflow/simple_workflow_helper.rb +131 -0
- metadata +2 -1
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/lib/simple_workflow'
|
|
4
4
|
|
5
5
|
# Generate all the Rake tasks
|
6
6
|
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
7
|
-
$hoe = Hoe.new('simple_workflow',
|
7
|
+
$hoe = Hoe.new('simple_workflow', SimpleWorkflow::VERSION) do |p|
|
8
8
|
p.developer('Uwe Kubosch', 'uwe@kubosch.no')
|
9
9
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
10
10
|
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
data/lib/simple_workflow.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
module
|
5
|
-
VERSION = '0.0.
|
4
|
+
module SimpleWorkflow
|
5
|
+
VERSION = '0.0.2'
|
6
6
|
end
|
7
7
|
|
8
8
|
require 'simple_workflow/simple_workflow_helper'
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module SimpleWorkflowHelper
|
2
|
+
def image_button_to(image_source, title, options, html_options = {})
|
3
|
+
image_submit_tag image_source, {:class => 'image-submit', :alt => title, :title => title,
|
4
|
+
:id => "#{title}_#{options[:id]}", :name => title,
|
5
|
+
:onclick => "form.action='#{url_for(options)}'"}.update(html_options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def detour_to(title, options, html_options = nil)
|
9
|
+
link_to title, with_detour(options), html_options
|
10
|
+
end
|
11
|
+
|
12
|
+
def with_detour(options)
|
13
|
+
detour_options = {:detour => params.reject {|k, v| [:detour, :return_from_detour].include? k.to_sym}}.update(options)
|
14
|
+
if options[:layout]== false
|
15
|
+
if params[:action] !~ /_no_layout$/
|
16
|
+
detour_options[:detour].update({:action => params[:action] + '_no_layout'})
|
17
|
+
end
|
18
|
+
elsif params[:action] =~ /_no_layout$/
|
19
|
+
detour_options[:detour].update({:action => params[:action][0..-11]})
|
20
|
+
end
|
21
|
+
detour_options
|
22
|
+
end
|
23
|
+
|
24
|
+
def image_detour_to(image_source, title, url_options, image_options = nil, post = false)
|
25
|
+
image_options ||= {:class => 'image-submit'}
|
26
|
+
image_options.update :alt => title, :title => title
|
27
|
+
detour_to image_tag(image_source, image_options), url_options, post ? {:method => :post} : nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def image_link_to(image_source, title, url_options, image_options = nil, post = false)
|
31
|
+
image_options ||= {:class => 'image-submit'}
|
32
|
+
image_options.update :alt => title, :title => title
|
33
|
+
link_to image_tag(image_source, image_options), url_options, post ? {:method => :post} : nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def image_link_to_remote(image_source, title, url_options, image_options = nil, post = false)
|
37
|
+
image_options ||= {:class => 'image-submit'}
|
38
|
+
image_options.update :alt => title, :title => title
|
39
|
+
link_to_remote image_tag(image_source, image_options), {:url => url_options}, post ? {:method => :post} : nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def detour?
|
43
|
+
not session[:detours].nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def back_or_link_to(title, options = nil, html_options = nil)
|
47
|
+
if session[:detours]
|
48
|
+
options = {:return_from_detour => true}.update(session[:detours].last)
|
49
|
+
logger.debug "linked return from detour: #{options}"
|
50
|
+
end
|
51
|
+
link_to(title, options, html_options) if options
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
module SimpleWorkflowController
|
57
|
+
def detour_to(options)
|
58
|
+
store_detour(params)
|
59
|
+
redirect_to(options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def rjs_detour_to(options)
|
63
|
+
store_detour(params, request.post?)
|
64
|
+
rjs_redirect_to(options)
|
65
|
+
end
|
66
|
+
|
67
|
+
def rjs_redirect_to(options)
|
68
|
+
@options = options
|
69
|
+
render :template => 'redirect', :layout => false
|
70
|
+
end
|
71
|
+
|
72
|
+
def store_detour(options, post = false)
|
73
|
+
options[:request_method] = :post if post
|
74
|
+
if session[:detours] && session[:detours].last == options
|
75
|
+
logger.debug "duplicate detour: #{options}"
|
76
|
+
return
|
77
|
+
end
|
78
|
+
logger.debug "adding detour: #{options}"
|
79
|
+
session[:detours] ||= []
|
80
|
+
session[:detours] << options
|
81
|
+
end
|
82
|
+
|
83
|
+
def store_detour_from_params
|
84
|
+
if params[:detour]
|
85
|
+
store_detour(params[:detour])
|
86
|
+
end
|
87
|
+
if params[:return_from_detour] && session[:detours]
|
88
|
+
pop_detour
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def back
|
93
|
+
return false if session[:detours].nil?
|
94
|
+
detour = pop_detour
|
95
|
+
post = detour.delete(:request_method) == :post
|
96
|
+
if post
|
97
|
+
redirect_to_post(detour)
|
98
|
+
else
|
99
|
+
redirect_to detour
|
100
|
+
end
|
101
|
+
return true
|
102
|
+
end
|
103
|
+
|
104
|
+
def back_or_redirect_to(options)
|
105
|
+
back or redirect_to options
|
106
|
+
end
|
107
|
+
|
108
|
+
def pop_detour
|
109
|
+
detours = session[:detours]
|
110
|
+
return nil unless detours
|
111
|
+
detour = detours.pop
|
112
|
+
logger.debug "popped detour: #{detour.inspect} #{session[:detours].size} more"
|
113
|
+
if detours.empty?
|
114
|
+
session[:detours] = nil
|
115
|
+
end
|
116
|
+
detour
|
117
|
+
end
|
118
|
+
|
119
|
+
def redirect_to_post(options)
|
120
|
+
url = url_for options
|
121
|
+
render :text => <<EOF, :layout => false
|
122
|
+
<html>
|
123
|
+
<body onload="document.getElementById('form').submit()">
|
124
|
+
<form id="form" action="#{url}" method="POST">
|
125
|
+
</form>
|
126
|
+
</body>
|
127
|
+
</html>
|
128
|
+
EOF
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uwe Kubosch
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- README.rdoc
|
62
62
|
- Rakefile
|
63
63
|
- lib/simple_workflow.rb
|
64
|
+
- lib/simple_workflow/simple_workflow_helper.rb
|
64
65
|
- script/console
|
65
66
|
- script/destroy
|
66
67
|
- script/generate
|