ed-precompiled_erb 5.0.3

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/lib/erb/util.rb ADDED
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load CGI.escapeHTML and CGI.escapeURIComponent.
4
+ # CRuby:
5
+ # cgi.gem v0.1.0+ (Ruby 2.7-3.4) and Ruby 3.5+ stdlib have 'cgi/escape' and CGI.escapeHTML.
6
+ # cgi.gem v0.3.3+ (Ruby 3.2-3.4) and Ruby 3.5+ stdlib have CGI.escapeURIComponent.
7
+ # JRuby: cgi.gem has a Java extension 'cgi/escape'.
8
+ # TruffleRuby: lib/truffle/cgi/escape.rb requires 'cgi/util'.
9
+ require 'cgi/escape'
10
+
11
+ # Load or define ERB::Escape#html_escape.
12
+ # We don't build the C extention 'cgi/escape' for JRuby, TruffleRuby, and WASM.
13
+ # miniruby (used by CRuby build scripts) also fails to load erb/escape.so.
14
+ begin
15
+ ruby_version = /(\d+\.\d+)/.match(::RUBY_VERSION)
16
+ require "erb/#{ruby_version}/escape"
17
+ rescue LoadError
18
+ # ERB::Escape
19
+ #
20
+ # A subset of ERB::Util. Unlike ERB::Util#html_escape, we expect/hope
21
+ # Rails will not monkey-patch ERB::Escape#html_escape.
22
+ module ERB::Escape
23
+ def html_escape(s)
24
+ CGI.escapeHTML(s.to_s)
25
+ end
26
+ module_function :html_escape
27
+ end
28
+ end
29
+
30
+ # ERB::Util
31
+ #
32
+ # A utility module for conversion routines, often handy in HTML generation.
33
+ module ERB::Util
34
+ #
35
+ # A utility method for escaping HTML tag characters in _s_.
36
+ #
37
+ # require "erb"
38
+ # include ERB::Util
39
+ #
40
+ # puts html_escape("is a > 0 & a < 10?")
41
+ #
42
+ # _Generates_
43
+ #
44
+ # is a &gt; 0 &amp; a &lt; 10?
45
+ #
46
+ include ERB::Escape # html_escape
47
+ module_function :html_escape
48
+ alias h html_escape
49
+ module_function :h
50
+
51
+ if CGI.respond_to?(:escapeURIComponent)
52
+ #
53
+ # A utility method for encoding the String _s_ as a URL.
54
+ #
55
+ # require "erb"
56
+ # include ERB::Util
57
+ #
58
+ # puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
59
+ #
60
+ # _Generates_
61
+ #
62
+ # Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
63
+ #
64
+ def url_encode(s)
65
+ CGI.escapeURIComponent(s.to_s)
66
+ end
67
+ else # cgi.gem <= v0.3.2
68
+ def url_encode(s)
69
+ s.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) do |m|
70
+ sprintf("%%%02X", m.unpack1("C"))
71
+ end
72
+ end
73
+ end
74
+ alias u url_encode
75
+ module_function :u
76
+ module_function :url_encode
77
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ class ERB
3
+ # The string \ERB version.
4
+ VERSION = '5.0.3'
5
+ end