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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d128e1d2b81e176bb75001856e03d73e9c8d71aa
4
- data.tar.gz: fb2de8d37a073640704c044cc51eea3a29bd8f04
3
+ metadata.gz: bd7bcc751768e004541fe3255c61e12ec9e82269
4
+ data.tar.gz: cf259c502985e73347a1c80cc59680adeaf09c2e
5
5
  SHA512:
6
- metadata.gz: ed967dd85e73d8c4d09e76833e61da722c69361241941982dbf12594e7cef6980169fa888efe46703ce37da0463d33f06888fa0b0030ad747d14b99fa0a6b7ee
7
- data.tar.gz: 25e54350aa7f6fe52550246fd639d85783984e52d3c44eb03d4b3dc5950e798d4f3ac0b38ebff5b7544fb213208163f233a2c755ebdaa93239500bc0e4ca9199
6
+ metadata.gz: 88f952a9729b8622b6ac8473949c30b099317d27bb38335960b6aed4cca319e5ec4380ca83fbb870e18545ac1e701cd454be32967ddff1324ddf34c942347544
7
+ data.tar.gz: f7e1bb19106a7e0d89e9ddc110c87ba98dbacea640d98be4eb1a547fab1dafe1509b4e17bcf8fe3cd1028410a9b84d62d9ababcae4a2d4b7944e2baea4a29ec2
@@ -15,6 +15,6 @@ WeixinRailsMiddleware.configure do |config|
15
15
  # config.token_string = "token string"
16
16
 
17
17
  # router
18
- config.engine_path = "/"
18
+ # config.engine_path = "/"
19
19
 
20
20
  end
@@ -4,6 +4,9 @@ require 'roxml'
4
4
  require 'multi_xml'
5
5
  require 'ostruct'
6
6
 
7
+ # multi_xml will use Nokogiri if it is available
8
+ MultiXml.parser = :nokogiri
9
+
7
10
  module WeixinRailsMiddleware
8
11
 
9
12
  class Message
@@ -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
@@ -1,3 +1,3 @@
1
1
  module WeixinRailsMiddleware
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -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 = "/weixin_rails".freeze
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.1
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-01-27 00:00:00.000000000 Z
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