canvas_cc 0.0.36 → 0.0.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/canvas_cc/canvas_cc/models/page.rb +115 -1
- data/lib/canvas_cc/version.rb +1 -1
- data/spec/moodle2cc/canvas_cc/models/page_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be03da1087647bda88d651eb4c5864b6cd079081
|
4
|
+
data.tar.gz: 7f65e6d609b7693980c656728f9f6873d4aa6620
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62e6a1aabede03fb93939edd46d76ad246a95a33860f9423ac80d1748361a0df13e9eac80b0f95ef995ad01792d445f6634dad9ea7ed0e9eb785fe636836badd
|
7
|
+
data.tar.gz: 51919500c772c0914fad0b1be6679ad949214650e22f360e99f6bfc8967c121649aade8fcaa65e6c2193860e240892dad06624b6ed3925734ba7c5148f27e751
|
data/Gemfile.lock
CHANGED
@@ -31,12 +31,126 @@ module CanvasCc::CanvasCC::Models
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.convert_name_to_url(name)
|
34
|
-
url =
|
34
|
+
url = urlify(name)
|
35
35
|
if url.length > MAX_URL_LENGTH
|
36
36
|
url = url[0,MAX_URL_LENGTH][/.{0,#{MAX_URL_LENGTH}}/mu]
|
37
37
|
end
|
38
38
|
url
|
39
39
|
end
|
40
40
|
|
41
|
+
def self.urlify(name)
|
42
|
+
name = name.downcase.gsub(/\s/, '-').gsub('.', '-dot-')
|
43
|
+
name.gsub!('(', '-')
|
44
|
+
name.gsub!(')', '-')
|
45
|
+
name.gsub!('_', '-')
|
46
|
+
name.gsub!('--', '-')
|
47
|
+
name.gsub!('"', '')
|
48
|
+
name.gsub!('$', ' dollars ')
|
49
|
+
name.gsub!(/[äöüß]/) do |match|
|
50
|
+
case match
|
51
|
+
when "ä" then 'a'
|
52
|
+
when "ö" then 'o'
|
53
|
+
when "ü" then 'u'
|
54
|
+
when "ß" then 'ss'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
name = to_url(name)
|
58
|
+
CGI::escape(name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.to_url(title)
|
62
|
+
title = remove_formatting(title).downcase
|
63
|
+
title = replace_whitespace(title, "-")
|
64
|
+
title = collapse(title, "-")
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.remove_formatting(title)
|
68
|
+
title = strip_html_tags(title)
|
69
|
+
title = convert_accented_entities(title)
|
70
|
+
title = convert_misc_entities(title)
|
71
|
+
title = convert_misc_characters(title)
|
72
|
+
collapse(title)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.strip_html_tags(title, leave_whitespace = false)
|
76
|
+
name = /[\w:_-]+/
|
77
|
+
value = /([A-Za-z0-9]+|('[^']*?'|"[^"]*?"))/
|
78
|
+
attr = /(#{name}(\s*=\s*#{value})?)/
|
79
|
+
rx = /<[!\/?\[]?(#{name}|--)(\s+(#{attr}(\s+#{attr})*))?\s*([!\/?\]]+|--)?>/
|
80
|
+
(leave_whitespace) ? title.gsub(rx, "").strip : title.gsub(rx, "").gsub(/\s+/, " ").strip
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.convert_accented_entities(title)
|
84
|
+
title.gsub(/&([A-Za-z])(grave|acute|circ|tilde|uml|ring|cedil|slash);/, '\1')
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.convert_misc_entities(title)
|
88
|
+
{
|
89
|
+
"#822[01]" => "\"",
|
90
|
+
"#821[67]" => "'",
|
91
|
+
"#8230" => "...",
|
92
|
+
"#8211" => "-",
|
93
|
+
"#8212" => "--",
|
94
|
+
"#215" => "x",
|
95
|
+
"gt" => ">",
|
96
|
+
"lt" => "<",
|
97
|
+
"(#8482|trade)" => "(tm)",
|
98
|
+
"(#174|reg)" => "(r)",
|
99
|
+
"(#169|copy)" => "(c)",
|
100
|
+
"(#38|amp)" => "and",
|
101
|
+
"nbsp" => " ",
|
102
|
+
"(#162|cent)" => " cent",
|
103
|
+
"(#163|pound)" => " pound",
|
104
|
+
"(#188|frac14)" => "one fourth",
|
105
|
+
"(#189|frac12)" => "half",
|
106
|
+
"(#190|frac34)" => "three fourths",
|
107
|
+
"(#176|deg)" => " degrees"
|
108
|
+
}.each do |textiled, normal|
|
109
|
+
title.gsub!(/&#{textiled};/, normal)
|
110
|
+
end
|
111
|
+
title.gsub(/&[^;]+;/, "")
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.convert_misc_characters(title)
|
115
|
+
title = title.gsub(/\.{3,}/, " dot dot dot ")
|
116
|
+
# Special rules for money
|
117
|
+
{
|
118
|
+
/(\s|^)\$(\d+)\.(\d+)(\s|$)/ => '\2 dollars \3 cents',
|
119
|
+
/(\s|^)£(\d+)\.(\d+)(\s|$)/u => '\2 pounds \3 pence',
|
120
|
+
}.each do |found, replaced|
|
121
|
+
replaced = " #{replaced} " unless replaced =~ /\\1/
|
122
|
+
title.gsub!(found, replaced)
|
123
|
+
end
|
124
|
+
# Back to normal rules
|
125
|
+
{
|
126
|
+
/\s*&\s*/ => "and",
|
127
|
+
/\s*#/ => "number",
|
128
|
+
/\s*@\s*/ => "at",
|
129
|
+
/(\S|^)\.(\S)/ => '\1 dot \2',
|
130
|
+
/(\s|^)\$(\d*)(\s|$)/ => '\2 dollars',
|
131
|
+
/(\s|^)£(\d*)(\s|$)/u => '\2 pounds',
|
132
|
+
/(\s|^)¥(\d*)(\s|$)/u => '\2 yen',
|
133
|
+
/\s*\*\s*/ => "star",
|
134
|
+
/\s*%\s*/ => "percent",
|
135
|
+
/\s*(\\|\/)\s*/ => "slash",
|
136
|
+
}.each do |found, replaced|
|
137
|
+
replaced = " #{replaced} " unless replaced =~ /\\1/
|
138
|
+
title.gsub!(found, replaced)
|
139
|
+
end
|
140
|
+
title.gsub(/(^|\w)'(\w|$)/, '\1\2').gsub(/[\.,:;()\[\]\/\?!\^'"_]/, " ")
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.replace_whitespace(title, replace = " ")
|
144
|
+
title.gsub(/\s+/, replace)
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.collapse(title, character = " ")
|
148
|
+
title.sub(/^#{character}*/, "").sub(/#{character}*$/, "").squeeze(character)
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.path_safe
|
152
|
+
gsub(/[^a-zA-Z0-9\-_]+/, '-')
|
153
|
+
end
|
154
|
+
|
41
155
|
end
|
42
156
|
end
|
data/lib/canvas_cc/version.rb
CHANGED
@@ -28,5 +28,11 @@ module CanvasCc::CanvasCC::Models
|
|
28
28
|
expect(page.href).to eq expected
|
29
29
|
end
|
30
30
|
|
31
|
+
it "generates urls from page name" do
|
32
|
+
name = '2.1_nutrition(mythbustercarbohydrates).html'
|
33
|
+
url = Page.convert_name_to_url(name)
|
34
|
+
expect(url).to eq '2-dot-1-nutrition-mythbustercarbohydrates-dot-html'
|
35
|
+
end
|
36
|
+
|
31
37
|
end
|
32
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canvas_cc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.37
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Instructure
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|