weixin_rails_middleware 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/templates/initializer.rb +1 -1
- data/lib/weixin_rails_middleware/message.rb +3 -0
- data/lib/weixin_rails_middleware/unique_token_helper.rb +17 -0
- data/lib/weixin_rails_middleware/version.rb +1 -1
- data/lib/weixin_rails_middleware/weixin_token_form_helper.rb +42 -0
- data/lib/weixin_rails_middleware.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd7bcc751768e004541fe3255c61e12ec9e82269
|
4
|
+
data.tar.gz: cf259c502985e73347a1c80cc59680adeaf09c2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88f952a9729b8622b6ac8473949c30b099317d27bb38335960b6aed4cca319e5ec4380ca83fbb870e18545ac1e701cd454be32967ddff1324ddf34c942347544
|
7
|
+
data.tar.gz: f7e1bb19106a7e0d89e9ddc110c87ba98dbacea640d98be4eb1a547fab1dafe1509b4e17bcf8fe3cd1028410a9b84d62d9ababcae4a2d4b7944e2baea4a29ec2
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module WeixinRailsMiddleware
|
2
|
+
module UniqueToken
|
3
|
+
def self.generate(options = {})
|
4
|
+
# SecureRandom: hex, base64, random_bytes, urlsafe_base64, random_number, uuid
|
5
|
+
generator_method_type = options.delete(:generator).try(:to_sym) || :hex
|
6
|
+
generator_method = SecureRandom.method(generator_method_type)
|
7
|
+
token_size = options.delete(:size).try(:to_i) || 12
|
8
|
+
if generator_method_type != :uuid
|
9
|
+
generator_method.call(token_size)
|
10
|
+
else
|
11
|
+
generator_method.call()
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
WeiXinUniqueToken = WeixinRailsMiddleware::UniqueToken
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# custom weixin_token_field
|
2
|
+
# usage: +f.weixin_token_field: weixin_token+
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
module Tags # :nodoc:
|
6
|
+
class WeixinTokenField < TextField # :nodoc:
|
7
|
+
def render
|
8
|
+
# custom weixin_token value
|
9
|
+
@options["type"]="text"
|
10
|
+
@options = {value: generate_weixin_token }.merge!(@options)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
private
|
14
|
+
|
15
|
+
def generate_weixin_token
|
16
|
+
@options.fetch("value"){value_before_type_cast(object)} || WeiXinUniqueToken.generate
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end # end of Tags
|
20
|
+
|
21
|
+
module FormHelper
|
22
|
+
extend ActiveSupport::Concern
|
23
|
+
def weixin_token_field(object_name, method, options = {})
|
24
|
+
Tags::WeixinTokenField.new(object_name, method, self, options).render
|
25
|
+
end
|
26
|
+
end # end of FormHelper
|
27
|
+
|
28
|
+
class FormBuilder
|
29
|
+
selector = :weixin_token_field
|
30
|
+
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
31
|
+
def #{selector}(method, options = {}) # def text_field(method, options = {})
|
32
|
+
@template.send( # @template.send(
|
33
|
+
#{selector.inspect}, # "text_field",
|
34
|
+
@object_name, # @object_name,
|
35
|
+
method, # method,
|
36
|
+
objectify_options(options)) # objectify_options(options))
|
37
|
+
end # end
|
38
|
+
RUBY_EVAL
|
39
|
+
end # end of FormHelper
|
40
|
+
|
41
|
+
end # HELPERS
|
42
|
+
end
|
@@ -3,11 +3,13 @@ require "weixin_rails_middleware/configuration"
|
|
3
3
|
require "weixin_rails_middleware/message"
|
4
4
|
require "weixin_rails_middleware/reply_message"
|
5
5
|
require "weixin_rails_middleware/weixin_message_helper"
|
6
|
+
require "weixin_rails_middleware/weixin_token_form_helper"
|
7
|
+
require "weixin_rails_middleware/unique_token_helper"
|
6
8
|
|
7
9
|
module WeixinRailsMiddleware
|
8
10
|
|
9
11
|
DEFAULT_TOKEN_COLUMN_NAME = "weixin_token".freeze
|
10
|
-
DEFAULT_ENGINE_PATH = "/
|
12
|
+
DEFAULT_ENGINE_PATH = "/".freeze
|
11
13
|
|
12
14
|
class << self
|
13
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weixin_rails_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lanrion
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -112,8 +112,10 @@ files:
|
|
112
112
|
- lib/weixin_rails_middleware/engine.rb
|
113
113
|
- lib/weixin_rails_middleware/message.rb
|
114
114
|
- lib/weixin_rails_middleware/reply_message.rb
|
115
|
+
- lib/weixin_rails_middleware/unique_token_helper.rb
|
115
116
|
- lib/weixin_rails_middleware/version.rb
|
116
117
|
- lib/weixin_rails_middleware/weixin_message_helper.rb
|
118
|
+
- lib/weixin_rails_middleware/weixin_token_form_helper.rb
|
117
119
|
- lib/weixin_rails_middleware.rb
|
118
120
|
- MIT-LICENSE
|
119
121
|
- Rakefile
|