form_relayer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +9 -0
- data/form_relayer.gemspec +27 -0
- data/lib/form_relayer/version.rb +3 -0
- data/lib/form_relayer.rb +23 -0
- data/spec/form_relayer_spec.rb +34 -0
- data/spec/helper.rb +21 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7eb5cbdf0cd544f5245bc7b837c822351b622c64
|
4
|
+
data.tar.gz: 93a43b6d67f3c489a1050fb3139522fc56078d66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf4d3ccdd5eeeb6b14dd6243115f51d7161e7e91bd4fc7fa32cf3d785b934280f4f0b227cc900b108d9ce8f167399518aab447b3bda7cbc4dccad2a6d9675ba2
|
7
|
+
data.tar.gz: 3475e432c193b3238b478d3a1f89ecb784cce6718a61d6fb461a8e43ae2c0bcfc81866d0d3e0ed554a772f11857affd15d73341beb9f0e9698012831c4db4a39
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 lulalala
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# FormRelayer
|
2
|
+
|
3
|
+
Makes it easier to relay received POST params in current form for further POSTing. This is ideal if you want to insert an intermediate page during POSTing, such as an order confirmation page.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'form_relayer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
In Rails view, place a call to `relay_received_post_params` inside the form.
|
18
|
+
|
19
|
+
<%= form_for @post do |f| %>
|
20
|
+
Are you sure you want to continue?
|
21
|
+
<%= relay_received_post_params %>
|
22
|
+
<%= f.submit 'Yes' %>
|
23
|
+
<% end %>
|
24
|
+
|
25
|
+
This will automatically turn POST params received by the current action into hidden input tags.
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/GoodLife/form_relayer/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'form_relayer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "form_relayer"
|
8
|
+
spec.version = FormRelayer::VERSION
|
9
|
+
spec.authors = ['GoodLife', 'lulalala']
|
10
|
+
spec.email = ["mark@goodlife.tw"]
|
11
|
+
spec.summary = %q{Makes it easier to make confirmation page by relaying received POST params for further POSTing}
|
12
|
+
spec.description = %q{Makes it easier to relay received POST params for further POSTing. This is ideal if you want to insert an intermediate page during POSTing, such as an order confirmation page.}
|
13
|
+
spec.homepage = 'https://github.com/GoodLife/form_relayer'
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", '~> 3.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake", '~> 10.3'
|
25
|
+
spec.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
26
|
+
spec.add_development_dependency 'mocha', '~> 1.0.0'
|
27
|
+
end
|
data/lib/form_relayer.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "form_relayer/version"
|
2
|
+
|
3
|
+
module FormRelayer
|
4
|
+
module ViewHelper
|
5
|
+
def relay_received_post_params
|
6
|
+
tags = []
|
7
|
+
|
8
|
+
raw_params= Rack::Utils.parse_query(request.raw_post)
|
9
|
+
raw_params.delete('utf8')
|
10
|
+
raw_params.delete('authenticity_token')
|
11
|
+
raw_params.each do |name, value|
|
12
|
+
tags << hidden_field_tag(name, value)
|
13
|
+
end
|
14
|
+
|
15
|
+
safe_join(tags)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require "action_view"
|
21
|
+
class ActionView::Base
|
22
|
+
include FormRelayer::ViewHelper
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'form_relayer'
|
3
|
+
|
4
|
+
describe FormRelayer do
|
5
|
+
it 'has version' do
|
6
|
+
FormRelayer.const_get('VERSION').wont_be_empty
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#relay_received_post_params' do
|
10
|
+
before do
|
11
|
+
@view = ActionView::Base.new
|
12
|
+
end
|
13
|
+
it 'handles post params' do
|
14
|
+
@view.stubs(:request).returns(mock('request', raw_post:'a=1'))
|
15
|
+
assert_equal %{<input id="a" name="a" type="hidden" value="1" />}, @view.relay_received_post_params
|
16
|
+
end
|
17
|
+
it 'handles post params with multiple value' do
|
18
|
+
@view.stubs(:request).returns(mock('request', raw_post:'a=1&b=2'))
|
19
|
+
assert_equal %{<input id="a" name="a" type="hidden" value="1" /><input id="b" name="b" type="hidden" value="2" />}, @view.relay_received_post_params
|
20
|
+
end
|
21
|
+
it 'handles post params which ends without value' do
|
22
|
+
@view.stubs(:request).returns(mock('request', raw_post:'a=1&b='))
|
23
|
+
assert_equal %{<input id="a" name="a" type="hidden" value="1" /><input id="b" name="b" type="hidden" value="" />}, @view.relay_received_post_params
|
24
|
+
end
|
25
|
+
it 'handles post params which has brackets in name' do
|
26
|
+
@view.stubs(:request).returns(mock('request', raw_post:'order%5Bshipping%5D=1&order%5Bemail%5D=aloha%40example.com'))
|
27
|
+
assert_equal %{<input id="order_shipping" name="order[shipping]" type="hidden" value="1" /><input id="order_email" name="order[email]" type="hidden" value="aloha@example.com" />}, @view.relay_received_post_params
|
28
|
+
end
|
29
|
+
it 'removes extra params added by Rails' do
|
30
|
+
@view.stubs(:request).returns(mock('request', raw_post:'utf8=%E2%9C%93&authenticity_token=ABCD1234%3D&order%5Bshipping%5D=1'))
|
31
|
+
assert_equal %{<input id="order_shipping" name="order[shipping]" type="hidden" value="1" />}, @view.relay_received_post_params
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
rescue LoadError => e
|
6
|
+
STDERR.puts e.message
|
7
|
+
STDERR.puts "Run `gem install bundler` to install Bundler."
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
Bundler.setup(:default, :development, :test)
|
13
|
+
rescue Bundler::BundlerError => e
|
14
|
+
STDERR.puts e.message
|
15
|
+
STDERR.puts "Run `bundle install` to install missing gems."
|
16
|
+
exit e.status_code
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'minitest/autorun'
|
20
|
+
require 'minitest/spec'
|
21
|
+
require "mocha/mini_test"
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: form_relayer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GoodLife
|
8
|
+
- lulalala
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.6'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.6'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.3'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.3'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rubygems-tasks
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.2'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.2'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: mocha
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.0.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.0.0
|
84
|
+
description: Makes it easier to relay received POST params for further POSTing. This
|
85
|
+
is ideal if you want to insert an intermediate page during POSTing, such as an order
|
86
|
+
confirmation page.
|
87
|
+
email:
|
88
|
+
- mark@goodlife.tw
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- form_relayer.gemspec
|
99
|
+
- lib/form_relayer.rb
|
100
|
+
- lib/form_relayer/version.rb
|
101
|
+
- spec/form_relayer_spec.rb
|
102
|
+
- spec/helper.rb
|
103
|
+
homepage: https://github.com/GoodLife/form_relayer
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.2.2
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Makes it easier to make confirmation page by relaying received POST params
|
127
|
+
for further POSTing
|
128
|
+
test_files:
|
129
|
+
- spec/form_relayer_spec.rb
|
130
|
+
- spec/helper.rb
|