sinarey_support 0.0.2 → 0.0.3

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: a486c06e5234203bd2d4ce530e9832805a361a2c
4
- data.tar.gz: 028bb2d4393f58e5031e5482705c173211d209fe
3
+ metadata.gz: ee72ba2d2528255744df5fefedc614f0158970d0
4
+ data.tar.gz: 87f4cd9e9db9ed77ee81b8ed9bf002d7726d94f6
5
5
  SHA512:
6
- metadata.gz: 16986922046ac51e4d22e3870e02f5ceecbf08158122e0b5ed30e1ca2df42b70f0431c51303a417845279cfedc43f12e5d5461aa971723d6ded944c6e7367044
7
- data.tar.gz: bf054611eca57f512761718a4d7bbc6ea76100816e3d916ff64d98f77c5164b9955e3bf32d39f4f187d9a4fe09d6a29f64c77f88653cb88b5b423fc1339e9027
6
+ metadata.gz: 3384fd18fbe63b0e35fbd176c1e79e691bd3b82e17af9515a981b1e2c65cf2eb7bf9cf6617028cbde5ec2e86989f534dd02c9f47047823de12aaae5bbe7fd36c
7
+ data.tar.gz: 07fbfea17a38647618fb5349ee8caa2ba9316a79509483f337c80dc77a19ec2363302d312fe1cf52591256fe6d2032ed457e8f9a44e9e99314322305c4a78975
@@ -3,49 +3,31 @@ require 'sinarey_support/core_ext/kernel/singleton_class'
3
3
 
4
4
  class ERB
5
5
  module Util
6
- HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#39;' }
7
- JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
8
- HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
9
- JSON_ESCAPE_REGEXP = /[&"><]/
10
-
11
- # A utility method for escaping HTML without affecting existing escaped entities.
12
- #
13
- # html_escape_once('1 < 2 &amp; 3')
14
- # # => "1 &lt; 2 &amp; 3"
15
- #
16
- # html_escape_once('&lt;&lt; Accept & Checkout')
17
- # # => "&lt;&lt; Accept &amp; Checkout"
6
+
7
+ HTML_ECP = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#39;' }
8
+ JSON_ECP = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
9
+ HTML_ECP_ONCE = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
10
+ JSON_ECP_REGEXP = /[&"><]/
11
+
18
12
  def html_escape_once(s)
19
- result = s.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
13
+ result = s.to_s.gsub(HTML_ECP_ONCE, HTML_ECP)
20
14
  s.html_safe? ? result.html_safe : result
21
15
  end
22
16
 
23
17
  module_function :html_escape_once
24
18
 
25
- # A utility method for escaping HTML entities in JSON strings
26
- # using \uXXXX JavaScript escape sequences for string literals:
27
- #
28
- # json_escape('is a > 0 & a < 10?')
29
- # # => is a \u003E 0 \u0026 a \u003C 10?
30
- #
31
- # Note that after this operation is performed the output is not
32
- # valid JSON. In particular double quotes are removed:
33
- #
34
- # json_escape('{"name":"john","created_at":"2010-04-28T01:39:31Z","id":1}')
35
- # # => {name:john,created_at:2010-04-28T01:39:31Z,id:1}
36
19
  def json_escape(s)
37
- result = s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
20
+ result = s.to_s.gsub(JSON_ECP_REGEXP, JSON_ECP)
38
21
  s.html_safe? ? result.html_safe : result
39
22
  end
40
23
 
41
24
  module_function :json_escape
42
25
 
43
-
44
26
  def sinarey_escape(value)
45
27
  if value.html_safe?
46
28
  value.to_s
47
29
  else
48
- value.to_s.gsub(/[&"'><]/, HTML_ESCAPE)
30
+ value.to_s.gsub(/[&"'><]/, HTML_ECP)
49
31
  end
50
32
  end
51
33
 
@@ -84,7 +66,7 @@ class NilClass
84
66
  end
85
67
  end
86
68
 
87
- module ActiveSupport #:nodoc:
69
+ module SinareySupport #:nodoc:
88
70
  class SafeBuffer < String
89
71
  UNSAFE_STRING_METHODS = %w(
90
72
  capitalize chomp chop delete downcase gsub lstrip next reverse rstrip
@@ -193,6 +175,6 @@ end
193
175
 
194
176
  class String
195
177
  def html_safe
196
- ActiveSupport::SafeBuffer.new(self)
178
+ SinareySupport::SafeBuffer.new(self)
197
179
  end
198
180
  end
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "sinarey_support"
4
- spec.version = "0.0.2"
4
+ spec.version = "0.0.3"
5
5
  spec.authors = ["Jeffrey"]
6
6
  spec.email = ["jeffrey6052@163.com"]
7
7
  spec.description = "some useful methods for sinatra framework"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinarey_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-22 00:00:00.000000000 Z
11
+ date: 2014-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: some useful methods for sinatra framework
14
14
  email:
@@ -60,12 +60,12 @@ require_paths:
60
60
  - lib
61
61
  required_ruby_version: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - ">="
63
+ - - '>='
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []