card 1.16.15 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/config/initializers/recaptcha.rb +21 -4
- data/db/migrate_core_cards/20130823192433_add_style_cards.rb +1 -1
- data/db/migrate_core_cards/20140512155840_add_script_cards.rb +1 -1
- data/db/migrate_core_cards/20140629222005_add_email_cards.rb +2 -2
- data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
- data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +1 -1
- data/db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb +63 -0
- data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
- data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +1 -1
- data/db/schema.rb +1 -1
- data/db/seed/new/card_actions.yml +602 -394
- data/db/seed/new/card_acts.yml +595 -1
- data/db/seed/new/card_changes.yml +26282 -10262
- data/db/seed/new/card_references.yml +1252 -1084
- data/db/seed/new/cards.yml +1899 -1423
- data/db/seed/test/fixtures/card_actions.yml +1653 -1413
- data/db/seed/test/fixtures/card_acts.yml +1063 -445
- data/db/seed/test/fixtures/card_changes.yml +29674 -13637
- data/db/seed/test/fixtures/card_references.yml +1976 -1815
- data/db/seed/test/fixtures/cards.yml +3194 -2719
- data/lib/card.rb +14 -13
- data/lib/card/auth.rb +10 -6
- data/lib/card/cache.rb +58 -120
- data/lib/card/cache/persistent.rb +50 -0
- data/lib/card/cache/temporary.rb +38 -0
- data/lib/card/chunk.rb +34 -25
- data/lib/card/content.rb +3 -3
- data/lib/card/env.rb +3 -0
- data/lib/card/format.rb +56 -53
- data/lib/card/migration.rb +6 -2
- data/lib/card/name.rb +9 -1
- data/lib/card/query.rb +1 -1
- data/lib/card/reference.rb +17 -11
- data/lib/card/set.rb +1 -1
- data/lib/card/subcards.rb +6 -6
- data/lib/card/view_cache.rb +45 -28
- data/lib/generators/card/migration/templates/card_migration.erb +1 -2
- data/mod/01_core/chunk/include.rb +71 -48
- data/mod/01_core/chunk/link.rb +6 -3
- data/mod/01_core/chunk/query_reference.rb +38 -29
- data/mod/01_core/chunk/reference.rb +23 -24
- data/mod/01_core/set/all/collection.rb +1 -1
- data/mod/01_core/set/all/fetch.rb +39 -12
- data/mod/01_core/set/all/permissions.rb +2 -4
- data/mod/01_core/set/all/references.rb +50 -75
- data/mod/01_core/set/all/rules.rb +19 -18
- data/mod/01_core/set/all/subcards.rb +1 -1
- data/mod/01_core/set/all/templating.rb +31 -88
- data/mod/01_core/set/all/tracked_attributes.rb +7 -14
- data/mod/01_core/set/all/utils.rb +77 -66
- data/mod/01_core/set_pattern/07_type_plus_right.rb +6 -3
- data/mod/01_core/spec/set/all/fetch_spec.rb +148 -96
- data/mod/01_core/spec/set/all/templating_spec.rb +49 -40
- data/mod/01_core/spec/set/all/trash_spec.rb +1 -1
- data/mod/01_history/set/all/actions.rb +1 -1
- data/mod/02_basic_types/set/all/base.rb +13 -7
- data/mod/02_basic_types/set/all/rss.rb +17 -22
- data/mod/02_basic_types/set/type/plain_text.rb +5 -2
- data/mod/02_basic_types/spec/set/all/base_spec.rb +1 -0
- data/mod/02_basic_types/spec/set/all/rss_spec.rb +7 -6
- data/mod/03_machines/lib/javascript/wagn.js.coffee +22 -9
- data/mod/03_machines/set/right/machine_output.rb +1 -1
- data/mod/04_settings/lib/card/setting.rb +45 -31
- data/mod/04_settings/set/right/structure.rb +47 -1
- data/mod/04_settings/set/self/default_html_view.rb +2 -0
- data/mod/04_settings/set/self/follow_fields.rb +2 -0
- data/mod/04_settings/set/self/recent_settings.rb +1 -1
- data/mod/05_standard/file/favicon/image-icon.png +0 -0
- data/mod/05_standard/file/favicon/image-large.png +0 -0
- data/mod/05_standard/file/favicon/image-medium.png +0 -0
- data/mod/05_standard/file/favicon/image-original.png +0 -0
- data/mod/05_standard/file/favicon/image-small.png +0 -0
- data/mod/05_standard/set/all/links.rb +27 -26
- data/mod/05_standard/set/all/rich_html/editing.rb +1 -1
- data/mod/05_standard/set/all/rich_html/toolbar.rb +1 -1
- data/mod/05_standard/set/rstar/rules.rb +20 -325
- data/mod/05_standard/set/rstar/rules_editor.rb +362 -0
- data/mod/05_standard/set/self/admin_info.rb +82 -0
- data/mod/05_standard/set/self/all.rb +16 -10
- data/mod/05_standard/set/self/head.rb +20 -19
- data/mod/05_standard/set/type/signup.rb +0 -1
- data/mod/05_standard/spec/set/all/account_spec.rb +44 -43
- data/mod/05_standard/spec/set/right/account_spec.rb +4 -2
- data/mod/05_standard/spec/set/type/search_type_spec.rb +8 -0
- data/mod/05_standard/spec/set/type/signup_spec.rb +24 -17
- data/mod/06_bootstrap/set/all/bootstrap/helper.rb +1 -1
- data/spec/lib/card/cache_spec.rb +64 -70
- data/spec/lib/card/content_spec.rb +236 -150
- data/spec/lib/card/reference_spec.rb +22 -38
- data/spec/lib/card/subcards_spec.rb +38 -0
- data/spec/lib/card/view_cache_spec.rb +8 -0
- data/spec/spec_helper.rb +1 -1
- data/tmpsets/set/mod001-01_core/all/collection.rb +77 -74
- data/tmpsets/set/mod001-01_core/all/content.rb +14 -16
- data/tmpsets/set/mod001-01_core/all/fetch.rb +137 -110
- data/tmpsets/set/mod001-01_core/all/name.rb +58 -40
- data/tmpsets/set/mod001-01_core/all/pattern.rb +12 -11
- data/tmpsets/set/mod001-01_core/all/permissions.rb +125 -117
- data/tmpsets/set/mod001-01_core/all/phases.rb +2 -1
- data/tmpsets/set/mod001-01_core/all/references.rb +52 -77
- data/tmpsets/set/mod001-01_core/all/rules.rb +47 -53
- data/tmpsets/set/mod001-01_core/all/templating.rb +31 -87
- data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +12 -21
- data/tmpsets/set/mod001-01_core/all/trash.rb +4 -1
- data/tmpsets/set/mod001-01_core/all/type.rb +23 -21
- data/tmpsets/set/mod001-01_core/all/utils.rb +80 -64
- data/tmpsets/set/mod002-01_history/all/actions.rb +20 -16
- data/tmpsets/set/mod002-01_history/all/history.rb +18 -13
- data/tmpsets/set/mod003-02_basic_types/all/base.rb +37 -10
- data/tmpsets/set/mod003-02_basic_types/all/rss.rb +17 -22
- data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +5 -2
- data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +51 -39
- data/tmpsets/set/mod004-03_machines/right/machine_output.rb +10 -6
- data/tmpsets/set/mod005-04_settings/abstract/permission.rb +10 -5
- data/tmpsets/set/mod005-04_settings/right/structure.rb +47 -1
- data/tmpsets/set/mod005-04_settings/self/recent_settings.rb +1 -0
- data/tmpsets/set/mod005-04_settings/type/setting.rb +4 -1
- data/tmpsets/set/mod006-05_email/all/follow.rb +45 -54
- data/tmpsets/set/mod006-05_email/all/notify.rb +88 -73
- data/tmpsets/set/mod006-05_email/right/followers.rb +17 -14
- data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +22 -18
- data/tmpsets/set/mod006-05_email/type/email_template.rb +1 -1
- data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +94 -67
- data/tmpsets/set/mod007-05_standard/all/account.rb +18 -20
- data/tmpsets/set/mod007-05_standard/all/comment.rb +51 -29
- data/tmpsets/set/mod007-05_standard/all/error.rb +129 -99
- data/tmpsets/set/mod007-05_standard/all/links.rb +27 -26
- data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +115 -103
- data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +112 -78
- data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +123 -81
- data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +15 -58
- data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +2 -2
- data/tmpsets/set/mod007-05_standard/right/account.rb +71 -75
- data/tmpsets/set/mod007-05_standard/right/email.rb +16 -13
- data/tmpsets/set/mod007-05_standard/right/password.rb +20 -12
- data/tmpsets/set/mod007-05_standard/right/status.rb +2 -2
- data/tmpsets/set/mod007-05_standard/right/token.rb +49 -2
- data/tmpsets/set/mod007-05_standard/rstar/rules.rb +20 -325
- data/tmpsets/set/mod007-05_standard/self/all.rb +16 -10
- data/tmpsets/set/mod007-05_standard/self/head.rb +76 -62
- data/tmpsets/set/mod007-05_standard/self/search.rb +45 -22
- data/tmpsets/set/mod007-05_standard/self/signin.rb +14 -12
- data/tmpsets/set/mod007-05_standard/type/cardtype.rb +13 -11
- data/tmpsets/set/mod007-05_standard/type/file.rb +1 -1
- data/tmpsets/set/mod007-05_standard/type/search_type.rb +3 -2
- data/tmpsets/set/mod007-05_standard/type/set.rb +20 -16
- data/tmpsets/set/mod007-05_standard/type/signup.rb +19 -25
- data/tmpsets/set/mod007-05_standard/type/user.rb +1 -1
- data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +1 -1
- data/tmpsets/set_pattern/106-type_plus_right.rb +6 -3
- metadata +11 -2
@@ -3,105 +3,149 @@ require 'card/content'
|
|
3
3
|
|
4
4
|
EXAMPLES = {
|
5
5
|
nests: {
|
6
|
-
content:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
classes: [String, :EscapedLiteral, String, :Include, String
|
6
|
+
content: "Some Literals: \\[{I'm not| a link]}, and " \
|
7
|
+
'\\{{This Card|Is not Included}}' \
|
8
|
+
', but ' \
|
9
|
+
'{{this is}}' \
|
10
|
+
', and some tail',
|
11
|
+
rendered: ["Some Literals: \\[{I'm not| a link]}, and ",
|
12
|
+
'<span>{</span>{This Card|Is not Included}}',
|
13
|
+
', but ',
|
14
|
+
{ options: { inc_name: 'this is',
|
15
|
+
inc_syntax: 'this is'
|
16
|
+
}
|
17
|
+
},
|
18
|
+
', and some tail'
|
19
|
+
],
|
20
|
+
classes: [String, :EscapedLiteral, String, :Include, String]
|
21
21
|
},
|
22
22
|
|
23
23
|
links_and_nests: {
|
24
|
-
content:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
24
|
+
content: 'Some Links and includes: [[the card|the text]], ' \
|
25
|
+
'and {{This Card|Is Included}}{{this too}} ' \
|
26
|
+
'and [[http://external.wagn.org/path|link text]]' \
|
27
|
+
'{{Included|open}}',
|
28
|
+
rendered: ['Some Links and includes: ',
|
29
|
+
'<a class="wanted-card" ' \
|
30
|
+
'href="/the_card?card%5Bname%5D=the+card">' \
|
31
|
+
'the text</a>',
|
32
|
+
', and ',
|
33
|
+
{ options: { view: 'Is Included',
|
34
|
+
inc_name: 'This Card',
|
35
|
+
inc_syntax: 'This Card|Is Included'
|
36
|
+
}
|
37
|
+
},
|
38
|
+
{ options: { inc_name: 'this too',
|
39
|
+
inc_syntax: 'this too'
|
40
|
+
}
|
41
|
+
},
|
42
|
+
' and ',
|
43
|
+
'<a target="_blank" class="external-link" ' \
|
44
|
+
'href="http://external.wagn.org/path">link text</a>',
|
45
|
+
{ options: { view: 'open',
|
46
|
+
inc_name: 'Included',
|
47
|
+
inc_syntax: 'Included|open'
|
48
|
+
}
|
49
|
+
}
|
50
|
+
],
|
51
|
+
classes: [
|
52
|
+
String, :Link, String, :Include, :Include, String, :Link, :Include
|
53
|
+
]
|
37
54
|
},
|
38
55
|
|
39
56
|
uris_and_links: {
|
40
|
-
content:
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
57
|
+
content: 'Some URIs and Links: http://a.url.com/ ' \
|
58
|
+
'More urls: wagn.com/a/path/to.html ' \
|
59
|
+
'http://localhost:2020/path?cgi=foo&bar=baz ' \
|
60
|
+
'[[http://brain.org/Home|extra]] ' \
|
61
|
+
'[ http://gerry.wagn.com/a/path ] ' \
|
62
|
+
'{ https://brain.org/more?args } ',
|
63
|
+
rendered: ['Some URIs and Links: ',
|
64
|
+
'<a target="_blank" class="external-link" ' \
|
65
|
+
'href="http://a.url.com/">http://a.url.com/</a>',
|
66
|
+
' More urls: ',
|
67
|
+
'<a target="_blank" class="external-link" ' \
|
68
|
+
'href="http://wagn.com/a/path/to.html">' \
|
69
|
+
'wagn.com/a/path/to.html</a>',
|
70
|
+
' ',
|
71
|
+
'<a target="_blank" class="external-link" ' \
|
72
|
+
'href="http://localhost:2020/path?cgi=foo&bar=baz">' \
|
73
|
+
'http://localhost:2020/path?cgi=foo&bar=baz</a>',
|
74
|
+
' ',
|
75
|
+
'<a target="_blank" class="external-link" ' \
|
76
|
+
'href="http://brain.org/Home">extra</a>',
|
77
|
+
' [ ',
|
78
|
+
'<a target="_blank" class="external-link" ' \
|
79
|
+
'href="http://gerry.wagn.com/a/path">' \
|
80
|
+
'http://gerry.wagn.com/a/path</a>',
|
81
|
+
' ] { ',
|
82
|
+
'<a target="_blank" class="external-link" ' \
|
83
|
+
'href="https://brain.org/more?args">' \
|
84
|
+
'https://brain.org/more?args</a>',
|
85
|
+
' } '
|
86
|
+
],
|
87
|
+
text_rendered: ['Some URIs and Links: ', 'http://a.url.com/',
|
88
|
+
' More urls: ',
|
89
|
+
'wagn.com/a/path/to.html[http://wagn.com/a/path/to.html]',
|
90
|
+
' ',
|
91
|
+
'http://localhost:2020/path?cgi=foo&bar=baz',
|
92
|
+
' ',
|
93
|
+
'extra[http://brain.org/Home]',
|
94
|
+
' [ ',
|
95
|
+
'http://gerry.wagn.com/a/path',
|
96
|
+
' ] { ',
|
97
|
+
'https://brain.org/more?args',
|
98
|
+
' } '
|
99
|
+
],
|
100
|
+
classes: [
|
101
|
+
String, :URI, String, :HostURI, String, :URI, String, :Link,
|
102
|
+
String, :URI, String, :URI, String
|
103
|
+
]
|
74
104
|
},
|
75
105
|
|
76
106
|
uris_and_links_2: {
|
77
|
-
content:
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
107
|
+
content: 'Some URIs and Links: http://a.url.com ' \
|
108
|
+
'More urls: wagn.com/a/path/to.html ' \
|
109
|
+
'[ http://gerry.wagn.com/a/path ] ' \
|
110
|
+
'{ https://brain.org/more?args } ' \
|
111
|
+
'http://localhost:2020/path?cgi=foo&bar=baz ' \
|
112
|
+
'[[http://brain.org/Home|extra]]',
|
113
|
+
rendered: ['Some URIs and Links: ',
|
114
|
+
'<a target="_blank" class="external-link" ' \
|
115
|
+
'href="http://a.url.com">http://a.url.com</a>',
|
116
|
+
' More urls: ',
|
117
|
+
'<a target="_blank" class="external-link" ' \
|
118
|
+
'href="http://wagn.com/a/path/to.html">' \
|
119
|
+
'wagn.com/a/path/to.html</a>',
|
120
|
+
' [ ',
|
121
|
+
'<a target="_blank" class="external-link" ' \
|
122
|
+
'href="http://gerry.wagn.com/a/path">' \
|
123
|
+
'http://gerry.wagn.com/a/path</a>',
|
124
|
+
' ] { ',
|
125
|
+
'<a target="_blank" class="external-link" ' \
|
126
|
+
'href="https://brain.org/more?args">' \
|
127
|
+
'https://brain.org/more?args</a>',
|
128
|
+
' } ',
|
129
|
+
'<a target="_blank" class="external-link" ' \
|
130
|
+
'href="http://localhost:2020/path?cgi=foo&bar=baz">' \
|
131
|
+
'http://localhost:2020/path?cgi=foo&bar=baz</a>',
|
132
|
+
' ',
|
133
|
+
'<a target="_blank" class="external-link" ' \
|
134
|
+
'href="http://brain.org/Home">extra</a>'
|
135
|
+
],
|
136
|
+
classes: [
|
137
|
+
String, :URI, String, :HostURI, String, :URI, String, :URI, String, :URI,
|
138
|
+
String, :Link
|
139
|
+
]
|
96
140
|
},
|
97
141
|
|
98
142
|
no_chunks: {
|
99
|
-
content:
|
100
|
-
rendered:
|
143
|
+
content: 'No chunks',
|
144
|
+
rendered: 'No chunks'
|
101
145
|
},
|
102
146
|
|
103
147
|
single_nest: {
|
104
|
-
content:
|
148
|
+
content: '{{one inclusion|size;large}}',
|
105
149
|
classes: [:Include]
|
106
150
|
},
|
107
151
|
|
@@ -137,8 +181,7 @@ EXAMPLES = {
|
|
137
181
|
}
|
138
182
|
}
|
139
183
|
|
140
|
-
|
141
|
-
EXAMPLES.each do |key, val|
|
184
|
+
EXAMPLES.each_value do |val|
|
142
185
|
if val[:classes]
|
143
186
|
val[:classes] = val[:classes].map do |klass|
|
144
187
|
Class === klass ? klass : Card::Chunk.const_get(klass)
|
@@ -146,26 +189,32 @@ EXAMPLES.each do |key, val|
|
|
146
189
|
end
|
147
190
|
end
|
148
191
|
|
149
|
-
|
150
192
|
describe Card::Content do
|
151
|
-
context
|
152
|
-
|
193
|
+
context 'instance' do
|
153
194
|
before do
|
154
195
|
@check_proc = Proc.new do |m, v|
|
155
|
-
if Array===m
|
196
|
+
if Array === m
|
156
197
|
wrong_class = m[0] != v.class
|
157
|
-
is_last = m.size == 1
|
158
|
-
#warn "check M[#{is_last}]:#{wrong_class}, #{m[0]}, V#{v.inspect}" if wrong_class || is_last
|
159
198
|
expect(wrong_class).to be_falsey
|
160
|
-
|
161
|
-
|
199
|
+
is_last = m.size == 1
|
200
|
+
if !wrong_class
|
201
|
+
is_last ? true : m[1..-1]
|
202
|
+
end
|
203
|
+
end
|
162
204
|
end
|
163
205
|
|
164
|
-
assert card = Card[
|
206
|
+
assert card = Card['One']
|
165
207
|
@card = card
|
166
208
|
|
167
209
|
# non-nil valued opts only ...
|
168
|
-
@render_block =
|
210
|
+
@render_block = Proc.new do |opts|
|
211
|
+
options = opts.inject({}) do |i, v|
|
212
|
+
if !v[1].nil? && (i[v[0]] = v[1])
|
213
|
+
i
|
214
|
+
end
|
215
|
+
end
|
216
|
+
{ options: options }
|
217
|
+
end
|
169
218
|
end
|
170
219
|
|
171
220
|
let(:example) { EXAMPLES[@example] }
|
@@ -178,132 +227,165 @@ describe Card::Content do
|
|
178
227
|
describe 'parse' do
|
179
228
|
def check_chunk_classes
|
180
229
|
expect(cobj.inject(classes, &@check_proc)).to eq(true)
|
181
|
-
clist = classes.
|
230
|
+
clist = classes.select { |c| String != c }
|
182
231
|
cobj.each_chunk do |chk|
|
183
232
|
expect(chk).to be_instance_of clist.shift
|
184
233
|
end
|
185
234
|
expect(clist).to be_empty
|
186
235
|
end
|
187
236
|
|
188
|
-
it
|
237
|
+
it 'finds all the chunks and strings' do
|
189
238
|
# note the mixed [} that are considered matching, needs some cleanup ...
|
190
239
|
@example = :nests
|
191
240
|
expect(cobj.inject(classes, &@check_proc)).to eq(true)
|
192
241
|
end
|
193
242
|
|
194
|
-
it
|
243
|
+
it 'gives just the chunks' do
|
195
244
|
@example = :nests
|
196
245
|
check_chunk_classes
|
197
246
|
end
|
198
247
|
|
199
|
-
it
|
248
|
+
it 'finds all the chunks links and trasclusions' do
|
200
249
|
@example = :links_and_nests
|
201
250
|
expect(cobj.inject(classes, &@check_proc)).to eq(true)
|
202
251
|
end
|
203
252
|
|
204
|
-
it
|
205
|
-
# tried some tougher cases that failed, don't know the spec, so
|
253
|
+
it 'finds uri chunks ' do
|
254
|
+
# tried some tougher cases that failed, don't know the spec, so
|
255
|
+
# hard to form better tests for URIs here
|
206
256
|
@example = :uris_and_links
|
207
257
|
check_chunk_classes
|
208
258
|
end
|
209
259
|
|
210
|
-
it
|
211
|
-
# tried some tougher cases that failed, don't know the spec, so
|
260
|
+
it 'finds uri chunks (b)' do
|
261
|
+
# tried some tougher cases that failed, don't know the spec, so
|
262
|
+
# hard to form better tests for URIs here
|
212
263
|
@example = :uris_and_links_2
|
213
264
|
check_chunk_classes
|
214
265
|
end
|
215
266
|
|
216
|
-
it
|
267
|
+
it 'parses just a string' do
|
217
268
|
@example = :no_chunks
|
218
269
|
expect(cobj).to eq(rendered)
|
219
270
|
end
|
220
271
|
|
221
|
-
it
|
272
|
+
it 'parses a single chunk' do
|
222
273
|
@example = :single_nest
|
223
274
|
check_chunk_classes
|
224
275
|
end
|
225
276
|
|
226
|
-
it
|
277
|
+
it 'leaves css alone' do
|
227
278
|
@example = :css
|
228
279
|
expect(cobj).to eq(content)
|
229
280
|
end
|
230
281
|
end
|
231
282
|
|
232
|
-
describe
|
233
|
-
it
|
283
|
+
describe 'render' do
|
284
|
+
it 'renders all nests' do
|
234
285
|
@example = :nests
|
235
286
|
expect(cobj.as_json.to_s).to match /not rendered/
|
236
|
-
cobj.
|
237
|
-
|
287
|
+
cobj.process_each_chunk &@render_block
|
288
|
+
rdr = cobj.as_json.to_json
|
289
|
+
expect(rdr).not_to match /not rendered/
|
238
290
|
expect(rdr).to eq(rendered.to_json)
|
239
291
|
end
|
240
292
|
|
241
|
-
it
|
293
|
+
it 'renders links and nests' do
|
242
294
|
@example = :links_and_nests
|
243
|
-
cobj.
|
244
|
-
|
295
|
+
cobj.process_each_chunk &@render_block
|
296
|
+
rdr = cobj.as_json.to_json
|
297
|
+
expect(rdr).not_to match /not rendered/
|
245
298
|
expect(rdr).to eq(rendered.to_json)
|
246
299
|
end
|
247
300
|
|
248
|
-
it
|
301
|
+
it 'renders links correctly for text formatters' do
|
249
302
|
@example = :uris_and_links
|
250
303
|
card2 = Card[@card.id]
|
251
304
|
format = card2.format format: :text
|
252
305
|
cobj = Card::Content.new content, format
|
253
|
-
cobj.
|
306
|
+
cobj.process_each_chunk &@render_block
|
254
307
|
expect(cobj.as_json.to_json).to eq(text_rendered.to_json)
|
255
308
|
end
|
256
309
|
|
257
|
-
it
|
310
|
+
it 'does not need rendering if no nests' do
|
258
311
|
@example = :uris_and_links
|
259
|
-
cobj.
|
312
|
+
cobj.process_each_chunk &@render_block
|
260
313
|
expect(cobj.as_json.to_json).to eq(rendered.to_json)
|
261
314
|
end
|
262
315
|
|
263
|
-
it
|
316
|
+
it 'does not need rendering if no nests (b)' do
|
264
317
|
@example = :uris_and_links_2
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
318
|
+
rdr1 = cobj.as_json.to_json
|
319
|
+
expect(rdr1).to match /not rendered/
|
320
|
+
# links are rendered too, but not with a block
|
321
|
+
cobj.process_each_chunk &@render_block
|
322
|
+
rdr2 = cobj.as_json.to_json
|
323
|
+
expect(rdr2).not_to match /not rendered/
|
324
|
+
expect(rdr2).to eq(rendered.to_json)
|
269
325
|
end
|
270
326
|
end
|
271
327
|
end
|
272
328
|
|
273
|
-
UNTAGGED_CASES = [
|
274
|
-
|
329
|
+
UNTAGGED_CASES = [' [grrew][/wiki/grrew]ss ',
|
330
|
+
' {{this is a test}}, {{this|view|is:too}} and',
|
331
|
+
' so is http://foo.bar.come//',
|
332
|
+
' and foo="my attr, not int a tag" <not a=tag ',
|
333
|
+
' p class"foobar"> and more'
|
334
|
+
]
|
275
335
|
|
276
|
-
context
|
336
|
+
context 'class' do
|
277
337
|
describe '#clean!' do
|
278
338
|
it 'should not alter untagged content' do
|
279
339
|
UNTAGGED_CASES.each do |test_case|
|
280
|
-
assert_equal test_case,Card::Content.clean!(test_case)
|
340
|
+
assert_equal test_case, Card::Content.clean!(test_case)
|
281
341
|
end
|
282
342
|
end
|
283
343
|
|
284
344
|
it 'should strip disallowed html class attributes' do
|
285
|
-
assert_equal '<p>html<div>with</div> funky tags</p>',
|
286
|
-
|
345
|
+
assert_equal '<p>html<div>with</div> funky tags</p>',
|
346
|
+
Card::Content.clean!(
|
347
|
+
'<p>html<div class="boo">with</div>' \
|
348
|
+
'<monkey>funky</butts>tags</p>'
|
349
|
+
)
|
350
|
+
assert_equal '<span>foo</span>',
|
351
|
+
Card::Content.clean!('<span class="banana">foo</span>')
|
287
352
|
end
|
288
353
|
|
289
354
|
it 'should not strip permitted_classes' do
|
290
|
-
|
291
|
-
assert_equal
|
355
|
+
has_stripped1 = '<span class="w-spotlight">foo</span>'
|
356
|
+
assert_equal has_stripped1,
|
357
|
+
Card::Content.clean!(has_stripped1)
|
358
|
+
has_stripped2 = '<p class="w-highlight w-ok">foo</p>'
|
359
|
+
assert_equal has_stripped2,
|
360
|
+
Card::Content.clean!(has_stripped2)
|
292
361
|
end
|
293
362
|
|
294
|
-
it 'should strip permitted_classes
|
295
|
-
|
296
|
-
assert_equal '<
|
297
|
-
|
363
|
+
it 'should strip permitted_classes ' \
|
364
|
+
'but not permitted ones when both are present' do
|
365
|
+
assert_equal '<span class="w-spotlight w-ok">foo</span>',
|
366
|
+
Card::Content.clean!(
|
367
|
+
'<span class="w-spotlight banana w-ok">foo</span>'
|
368
|
+
)
|
369
|
+
assert_equal '<p class="w-highlight">foo</p>',
|
370
|
+
Card::Content.clean!(
|
371
|
+
'<p class="w-highlight bad-at end">foo</p>'
|
372
|
+
)
|
373
|
+
assert_equal '<p class="w-highlight">foo</p>',
|
374
|
+
Card::Content.clean!(
|
375
|
+
'<p class="bad-class w-highlight">foo</p>'
|
376
|
+
)
|
298
377
|
end
|
299
378
|
|
300
379
|
it 'should allow permitted attributes' do
|
301
|
-
assert_equal '<img src="foo">',
|
302
|
-
assert_equal "<img alt='foo'>",
|
303
|
-
assert_equal '<img title="foo">',
|
304
|
-
|
305
|
-
assert_equal '<
|
306
|
-
assert_equal '<
|
380
|
+
assert_equal '<img src="foo">', Card::Content.clean!('<img src="foo">')
|
381
|
+
assert_equal "<img alt='foo'>", Card::Content.clean!("<img alt='foo'>")
|
382
|
+
assert_equal '<img title="foo">',
|
383
|
+
Card::Content.clean!('<img title=foo>')
|
384
|
+
assert_equal '<a href="foo">', Card::Content.clean!('<a href="foo">')
|
385
|
+
assert_equal '<code lang="foo">',
|
386
|
+
Card::Content.clean!('<code lang="foo">')
|
387
|
+
assert_equal '<blockquote cite="foo">',
|
388
|
+
Card::Content.clean!('<blockquote cite="foo">')
|
307
389
|
end
|
308
390
|
|
309
391
|
it 'should not allow nonpermitted attributes' do
|
@@ -313,23 +395,27 @@ describe Card::Content do
|
|
313
395
|
|
314
396
|
it 'should remove comments' do
|
315
397
|
assert_equal 'yo', Card::Content.clean!('<!-- not me -->yo')
|
316
|
-
assert_equal 'joe',
|
398
|
+
assert_equal 'joe',
|
399
|
+
Card::Content.clean!('<!-- not me -->joe<!-- not me -->')
|
317
400
|
end
|
318
401
|
|
319
402
|
it 'fixes regular nbsp order by default' do
|
320
403
|
assert_equal 'space test two space',
|
321
|
-
|
404
|
+
Card::Content.clean!(
|
405
|
+
'space test two space'
|
406
|
+
)
|
322
407
|
end
|
323
408
|
|
324
|
-
it
|
325
|
-
# manually configure this setting, then make this one live
|
326
|
-
|
409
|
+
it "doesn't fix regular nbsp order with setting" do
|
410
|
+
# manually configure this setting, then make this one live
|
411
|
+
# (test above will then fail)
|
412
|
+
pending "Can't set Card.config.space_last_in_multispace= false "\
|
413
|
+
'for one test'
|
327
414
|
assert_equal 'space test two space',
|
328
|
-
|
415
|
+
Card::Content.clean!(
|
416
|
+
'space test two space'
|
417
|
+
)
|
329
418
|
end
|
330
419
|
end
|
331
420
|
end
|
332
|
-
|
333
|
-
|
334
421
|
end
|
335
|
-
|