iron-web 1.1.4 → 1.1.5
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.
- checksums.yaml +4 -4
- data/History.txt +5 -0
- data/README.rdoc +2 -2
- data/Version.txt +1 -1
- data/lib/iron-web.rb +1 -0
- data/lib/iron/web/html.rb +31 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/web/html_spec.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0ae26b5b55908940fb087539868211db2c4fe87
|
4
|
+
data.tar.gz: 7a48ab544ab37e93db0d321025e8de437561f26b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70a20cfa63fe5d761ce8f7435a6d41d7e448d7410804c654f16e5bc7d5418abc4e23613e72e172cbcd0429dbc4998fdad8ea8295626291cae0d59c6b8c2c9545
|
7
|
+
data.tar.gz: f33c36381b5babc95a9b4410368ce6a92fc19d747981712826b8399558fce5602eea16cf51d36487754dc343714ec6c192c0d04f62b358d6c1f037f0c6fa4296
|
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -53,7 +53,7 @@ A set of classes useful in the generation of HTML content.
|
|
53
53
|
|
54
54
|
To use:
|
55
55
|
|
56
|
-
require 'iron
|
56
|
+
require 'iron-web'
|
57
57
|
|
58
58
|
Sample usage of all components:
|
59
59
|
|
@@ -78,7 +78,7 @@ Which would result in:
|
|
78
78
|
<a href="http://irongaze.com#incoming">Say hello to my log file</a>
|
79
79
|
|
80
80
|
Notice the darkened and correctly formatted CSS color value and the newly fragment-ized url.
|
81
|
-
HTML elements are
|
81
|
+
HTML elements are built by calling their tag name on the Html instance. Similarly, element
|
82
82
|
attributes are added by calling the attribute's name on the element instance, or by simply
|
83
83
|
setting them during construction.
|
84
84
|
|
data/Version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.5
|
data/lib/iron-web.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'iron/web'
|
data/lib/iron/web/html.rb
CHANGED
@@ -13,10 +13,12 @@ require 'iron/web/html/element'
|
|
13
13
|
# html.em('HTML is neat!')
|
14
14
|
# }
|
15
15
|
# end
|
16
|
+
#
|
16
17
|
class Html
|
17
18
|
|
18
19
|
# Constants
|
19
20
|
HTML_ESCAPE = {"&"=>"&", ">"=>">", "<"=>"<", "\""=>"""}.freeze
|
21
|
+
JS_ESCAPE = {'\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'"}.freeze
|
20
22
|
|
21
23
|
# Remove everything that would normally come from Object and Kernel etc. so our keys can be anything
|
22
24
|
instance_methods.each do |m|
|
@@ -35,12 +37,41 @@ class Html
|
|
35
37
|
builder.render.html_safe
|
36
38
|
end
|
37
39
|
|
40
|
+
# The escape methods #escape_once and #escape_javascript are both taken from Rails, which like this library is MIT
|
41
|
+
# licensed. The following license statement applies to those two methods and the constants they reference. Thanks
|
42
|
+
# Rails team!
|
43
|
+
#
|
44
|
+
# Copyright © 2004-2013 David Heinemeier Hansson
|
45
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
46
|
+
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
|
47
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
48
|
+
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
49
|
+
#
|
50
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
51
|
+
# of the Software.
|
52
|
+
#
|
53
|
+
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
54
|
+
# TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
55
|
+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
56
|
+
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
57
|
+
# DEALINGS IN THE SOFTWARE.
|
58
|
+
#
|
38
59
|
# Ripped from Rails...
|
39
60
|
def self.escape_once(html)
|
40
61
|
return html if html.html_safe?
|
41
62
|
html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| HTML_ESCAPE[special] }.html_safe
|
42
63
|
end
|
43
64
|
|
65
|
+
# And again, thanks Rails team!
|
66
|
+
def self.escape_javascript(js)
|
67
|
+
if js
|
68
|
+
res = js.gsub(/(\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"'])/u) {|special| JS_ESCAPE[special] }
|
69
|
+
js.html_safe? ? res.html_safe : res
|
70
|
+
else
|
71
|
+
''
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
44
75
|
# Sets up internal state, natch, and accepts a block that customizes the resulting object.
|
45
76
|
def initialize
|
46
77
|
@items = []
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'iron',
|
|
4
4
|
RSpec.configure do |config|
|
5
5
|
#config.add_formatter 'documentation'
|
6
6
|
config.color = true
|
7
|
-
config.
|
7
|
+
config.backtrace_exclusion_patterns = [/rspec/]
|
8
8
|
end
|
9
9
|
|
data/spec/web/html_spec.rb
CHANGED
@@ -17,4 +17,16 @@ describe Html do
|
|
17
17
|
end.should == "<!-- Important stuff -->\n\n<h1>\n Da header\n</h1>\n"
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'should escape javascript' do
|
21
|
+
{
|
22
|
+
'abc' => 'abc',
|
23
|
+
nil => '',
|
24
|
+
'a "quote"' => 'a \\"quote\\"',
|
25
|
+
"single's quotin'" => "single\\'s quotin\\'",
|
26
|
+
"abc\r\n123" => 'abc\n123'
|
27
|
+
}.each_pair do |src, res|
|
28
|
+
Html.escape_javascript(src).should == res
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
20
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron-web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iron-extensions
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- LICENSE
|
52
52
|
- README.rdoc
|
53
53
|
- Version.txt
|
54
|
+
- lib/iron-web.rb
|
54
55
|
- lib/iron/web.rb
|
55
56
|
- lib/iron/web/color.rb
|
56
57
|
- lib/iron/web/html.rb
|