card 1.16.15 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/recaptcha.rb +21 -4
  4. data/db/migrate_core_cards/20130823192433_add_style_cards.rb +1 -1
  5. data/db/migrate_core_cards/20140512155840_add_script_cards.rb +1 -1
  6. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +2 -2
  7. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
  8. data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +1 -1
  9. data/db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb +63 -0
  10. data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
  11. data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +1 -1
  12. data/db/schema.rb +1 -1
  13. data/db/seed/new/card_actions.yml +602 -394
  14. data/db/seed/new/card_acts.yml +595 -1
  15. data/db/seed/new/card_changes.yml +26282 -10262
  16. data/db/seed/new/card_references.yml +1252 -1084
  17. data/db/seed/new/cards.yml +1899 -1423
  18. data/db/seed/test/fixtures/card_actions.yml +1653 -1413
  19. data/db/seed/test/fixtures/card_acts.yml +1063 -445
  20. data/db/seed/test/fixtures/card_changes.yml +29674 -13637
  21. data/db/seed/test/fixtures/card_references.yml +1976 -1815
  22. data/db/seed/test/fixtures/cards.yml +3194 -2719
  23. data/lib/card.rb +14 -13
  24. data/lib/card/auth.rb +10 -6
  25. data/lib/card/cache.rb +58 -120
  26. data/lib/card/cache/persistent.rb +50 -0
  27. data/lib/card/cache/temporary.rb +38 -0
  28. data/lib/card/chunk.rb +34 -25
  29. data/lib/card/content.rb +3 -3
  30. data/lib/card/env.rb +3 -0
  31. data/lib/card/format.rb +56 -53
  32. data/lib/card/migration.rb +6 -2
  33. data/lib/card/name.rb +9 -1
  34. data/lib/card/query.rb +1 -1
  35. data/lib/card/reference.rb +17 -11
  36. data/lib/card/set.rb +1 -1
  37. data/lib/card/subcards.rb +6 -6
  38. data/lib/card/view_cache.rb +45 -28
  39. data/lib/generators/card/migration/templates/card_migration.erb +1 -2
  40. data/mod/01_core/chunk/include.rb +71 -48
  41. data/mod/01_core/chunk/link.rb +6 -3
  42. data/mod/01_core/chunk/query_reference.rb +38 -29
  43. data/mod/01_core/chunk/reference.rb +23 -24
  44. data/mod/01_core/set/all/collection.rb +1 -1
  45. data/mod/01_core/set/all/fetch.rb +39 -12
  46. data/mod/01_core/set/all/permissions.rb +2 -4
  47. data/mod/01_core/set/all/references.rb +50 -75
  48. data/mod/01_core/set/all/rules.rb +19 -18
  49. data/mod/01_core/set/all/subcards.rb +1 -1
  50. data/mod/01_core/set/all/templating.rb +31 -88
  51. data/mod/01_core/set/all/tracked_attributes.rb +7 -14
  52. data/mod/01_core/set/all/utils.rb +77 -66
  53. data/mod/01_core/set_pattern/07_type_plus_right.rb +6 -3
  54. data/mod/01_core/spec/set/all/fetch_spec.rb +148 -96
  55. data/mod/01_core/spec/set/all/templating_spec.rb +49 -40
  56. data/mod/01_core/spec/set/all/trash_spec.rb +1 -1
  57. data/mod/01_history/set/all/actions.rb +1 -1
  58. data/mod/02_basic_types/set/all/base.rb +13 -7
  59. data/mod/02_basic_types/set/all/rss.rb +17 -22
  60. data/mod/02_basic_types/set/type/plain_text.rb +5 -2
  61. data/mod/02_basic_types/spec/set/all/base_spec.rb +1 -0
  62. data/mod/02_basic_types/spec/set/all/rss_spec.rb +7 -6
  63. data/mod/03_machines/lib/javascript/wagn.js.coffee +22 -9
  64. data/mod/03_machines/set/right/machine_output.rb +1 -1
  65. data/mod/04_settings/lib/card/setting.rb +45 -31
  66. data/mod/04_settings/set/right/structure.rb +47 -1
  67. data/mod/04_settings/set/self/default_html_view.rb +2 -0
  68. data/mod/04_settings/set/self/follow_fields.rb +2 -0
  69. data/mod/04_settings/set/self/recent_settings.rb +1 -1
  70. data/mod/05_standard/file/favicon/image-icon.png +0 -0
  71. data/mod/05_standard/file/favicon/image-large.png +0 -0
  72. data/mod/05_standard/file/favicon/image-medium.png +0 -0
  73. data/mod/05_standard/file/favicon/image-original.png +0 -0
  74. data/mod/05_standard/file/favicon/image-small.png +0 -0
  75. data/mod/05_standard/set/all/links.rb +27 -26
  76. data/mod/05_standard/set/all/rich_html/editing.rb +1 -1
  77. data/mod/05_standard/set/all/rich_html/toolbar.rb +1 -1
  78. data/mod/05_standard/set/rstar/rules.rb +20 -325
  79. data/mod/05_standard/set/rstar/rules_editor.rb +362 -0
  80. data/mod/05_standard/set/self/admin_info.rb +82 -0
  81. data/mod/05_standard/set/self/all.rb +16 -10
  82. data/mod/05_standard/set/self/head.rb +20 -19
  83. data/mod/05_standard/set/type/signup.rb +0 -1
  84. data/mod/05_standard/spec/set/all/account_spec.rb +44 -43
  85. data/mod/05_standard/spec/set/right/account_spec.rb +4 -2
  86. data/mod/05_standard/spec/set/type/search_type_spec.rb +8 -0
  87. data/mod/05_standard/spec/set/type/signup_spec.rb +24 -17
  88. data/mod/06_bootstrap/set/all/bootstrap/helper.rb +1 -1
  89. data/spec/lib/card/cache_spec.rb +64 -70
  90. data/spec/lib/card/content_spec.rb +236 -150
  91. data/spec/lib/card/reference_spec.rb +22 -38
  92. data/spec/lib/card/subcards_spec.rb +38 -0
  93. data/spec/lib/card/view_cache_spec.rb +8 -0
  94. data/spec/spec_helper.rb +1 -1
  95. data/tmpsets/set/mod001-01_core/all/collection.rb +77 -74
  96. data/tmpsets/set/mod001-01_core/all/content.rb +14 -16
  97. data/tmpsets/set/mod001-01_core/all/fetch.rb +137 -110
  98. data/tmpsets/set/mod001-01_core/all/name.rb +58 -40
  99. data/tmpsets/set/mod001-01_core/all/pattern.rb +12 -11
  100. data/tmpsets/set/mod001-01_core/all/permissions.rb +125 -117
  101. data/tmpsets/set/mod001-01_core/all/phases.rb +2 -1
  102. data/tmpsets/set/mod001-01_core/all/references.rb +52 -77
  103. data/tmpsets/set/mod001-01_core/all/rules.rb +47 -53
  104. data/tmpsets/set/mod001-01_core/all/templating.rb +31 -87
  105. data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +12 -21
  106. data/tmpsets/set/mod001-01_core/all/trash.rb +4 -1
  107. data/tmpsets/set/mod001-01_core/all/type.rb +23 -21
  108. data/tmpsets/set/mod001-01_core/all/utils.rb +80 -64
  109. data/tmpsets/set/mod002-01_history/all/actions.rb +20 -16
  110. data/tmpsets/set/mod002-01_history/all/history.rb +18 -13
  111. data/tmpsets/set/mod003-02_basic_types/all/base.rb +37 -10
  112. data/tmpsets/set/mod003-02_basic_types/all/rss.rb +17 -22
  113. data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +5 -2
  114. data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +51 -39
  115. data/tmpsets/set/mod004-03_machines/right/machine_output.rb +10 -6
  116. data/tmpsets/set/mod005-04_settings/abstract/permission.rb +10 -5
  117. data/tmpsets/set/mod005-04_settings/right/structure.rb +47 -1
  118. data/tmpsets/set/mod005-04_settings/self/recent_settings.rb +1 -0
  119. data/tmpsets/set/mod005-04_settings/type/setting.rb +4 -1
  120. data/tmpsets/set/mod006-05_email/all/follow.rb +45 -54
  121. data/tmpsets/set/mod006-05_email/all/notify.rb +88 -73
  122. data/tmpsets/set/mod006-05_email/right/followers.rb +17 -14
  123. data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +22 -18
  124. data/tmpsets/set/mod006-05_email/type/email_template.rb +1 -1
  125. data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +94 -67
  126. data/tmpsets/set/mod007-05_standard/all/account.rb +18 -20
  127. data/tmpsets/set/mod007-05_standard/all/comment.rb +51 -29
  128. data/tmpsets/set/mod007-05_standard/all/error.rb +129 -99
  129. data/tmpsets/set/mod007-05_standard/all/links.rb +27 -26
  130. data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +115 -103
  131. data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +112 -78
  132. data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +123 -81
  133. data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +15 -58
  134. data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +2 -2
  135. data/tmpsets/set/mod007-05_standard/right/account.rb +71 -75
  136. data/tmpsets/set/mod007-05_standard/right/email.rb +16 -13
  137. data/tmpsets/set/mod007-05_standard/right/password.rb +20 -12
  138. data/tmpsets/set/mod007-05_standard/right/status.rb +2 -2
  139. data/tmpsets/set/mod007-05_standard/right/token.rb +49 -2
  140. data/tmpsets/set/mod007-05_standard/rstar/rules.rb +20 -325
  141. data/tmpsets/set/mod007-05_standard/self/all.rb +16 -10
  142. data/tmpsets/set/mod007-05_standard/self/head.rb +76 -62
  143. data/tmpsets/set/mod007-05_standard/self/search.rb +45 -22
  144. data/tmpsets/set/mod007-05_standard/self/signin.rb +14 -12
  145. data/tmpsets/set/mod007-05_standard/type/cardtype.rb +13 -11
  146. data/tmpsets/set/mod007-05_standard/type/file.rb +1 -1
  147. data/tmpsets/set/mod007-05_standard/type/search_type.rb +3 -2
  148. data/tmpsets/set/mod007-05_standard/type/set.rb +20 -16
  149. data/tmpsets/set/mod007-05_standard/type/signup.rb +19 -25
  150. data/tmpsets/set/mod007-05_standard/type/user.rb +1 -1
  151. data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +1 -1
  152. data/tmpsets/set_pattern/106-type_plus_right.rb +6 -3
  153. metadata +11 -2
@@ -3,105 +3,149 @@ require 'card/content'
3
3
 
4
4
  EXAMPLES = {
5
5
  nests: {
6
- content: [
7
- "Some Literals: \\[{I'm not| a link]}, and ",
8
- "\\{{This Card|Is not Included}}",
9
- ", but ",
10
- "{{this is}}",
11
- ", and some tail"
12
- ].join(''),
13
- rendered: [
14
- "Some Literals: \\[{I'm not| a link]}, and ",
15
- "<span>{</span>{This Card|Is not Included}}",
16
- ", but ",
17
- {options: {inc_name: "this is",inc_syntax: "this is"}},
18
- ", and some tail"
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: %(Some Links and includes: [[the card|the text]], and {{This Card|Is Included}}{{this too}}
25
- and [[http://external.wagn.org/path|link text]]{{Included|open}}),
26
- rendered: [
27
- "Some Links and includes: ",
28
- "<a class=\"wanted-card\" href=\"/the_card?card%5Bname%5D=the+card\">the text</a>",
29
- ", and ",
30
- { options: { view: "Is Included", inc_name: "This Card", inc_syntax: "This Card|Is Included"}},
31
- { options: { inc_name: "this too", inc_syntax: "this too"}},
32
- "\n and ",
33
- "<a target=\"_blank\" class=\"external-link\" href=\"http://external.wagn.org/path\">link text</a>",
34
- { options: { view: "open", inc_name: "Included", inc_syntax: "Included|open" }}
35
- ],
36
- classes: [String, :Link, String, :Include, :Include, String, :Link, :Include ]
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: %(Some URIs and Links: http://a.url.com/
41
- More urls: wagn.com/a/path/to.html
42
- http://localhost:2020/path?cgi=foo&bar=baz [[http://brain.org/Home|extra]]
43
- [ http://gerry.wagn.com/a/path ]
44
- { https://brain.org/more?args }),
45
- rendered: [
46
- "Some URIs and Links: ", '<a target="_blank" class="external-link" href="http://a.url.com/">http://a.url.com/</a>',
47
- "\n More urls: ",
48
- "<a target=\"_blank\" class=\"external-link\" href=\"http://wagn.com/a/path/to.html\">wagn.com/a/path/to.html</a>",
49
- "\n ",
50
- "<a target=\"_blank\" class=\"external-link\" href=\"http://localhost:2020/path?cgi=foo&amp;bar=baz\">http://localhost:2020/path?cgi=foo&bar=baz</a>",
51
- " ",
52
- "<a target=\"_blank\" class=\"external-link\" href=\"http://brain.org/Home\">extra</a>",
53
- "\n [ ",
54
- "<a target=\"_blank\" class=\"external-link\" href=\"http://gerry.wagn.com/a/path\">http://gerry.wagn.com/a/path</a>",
55
- " ]\n { ",
56
- "<a target=\"_blank\" class=\"external-link\" href=\"https://brain.org/more?args\">https://brain.org/more?args</a>",
57
- " }"
58
- ],
59
- text_rendered: [
60
- "Some URIs and Links: ", 'http://a.url.com/',
61
- "\n More urls: ",
62
- "wagn.com/a/path/to.html[http://wagn.com/a/path/to.html]",
63
- "\n ",
64
- "http://localhost:2020/path?cgi=foo&bar=baz",
65
- " ",
66
- "extra[http://brain.org/Home]",
67
- "\n [ ",
68
- "http://gerry.wagn.com/a/path",
69
- " ]\n { ",
70
- "https://brain.org/more?args",
71
- " }"
72
- ],
73
- classes: [String, :URI, String, :HostURI, String, :URI, String, :Link, String, :URI, String, :URI, String ]
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&amp;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: %(Some URIs and Links: http://a.url.com
78
- More urls: wagn.com/a/path/to.html
79
- [ http://gerry.wagn.com/a/path ]
80
- { https://brain.org/more?args }
81
- http://localhost:2020/path?cgi=foo&bar=baz [[http://brain.org/Home|extra]]),
82
- rendered: [
83
- "Some URIs and Links: ","<a target=\"_blank\" class=\"external-link\" href=\"http://a.url.com\">http://a.url.com</a>",
84
- "\n More urls: ",
85
- "<a target=\"_blank\" class=\"external-link\" href=\"http://wagn.com/a/path/to.html\">wagn.com/a/path/to.html</a>",
86
- "\n [ ",
87
- "<a target=\"_blank\" class=\"external-link\" href=\"http://gerry.wagn.com/a/path\">http://gerry.wagn.com/a/path</a>",
88
- " ]\n { ",
89
- "<a target=\"_blank\" class=\"external-link\" href=\"https://brain.org/more?args\">https://brain.org/more?args</a>",
90
- " }\n ",
91
- "<a target=\"_blank\" class=\"external-link\" href=\"http://localhost:2020/path?cgi=foo&amp;bar=baz\">http://localhost:2020/path?cgi=foo&bar=baz</a>",
92
- " ",
93
- "<a target=\"_blank\" class=\"external-link\" href=\"http://brain.org/Home\">extra</a>"
94
- ],
95
- classes: [String, :URI, String, :HostURI, String, :URI, String, :URI, String, :URI, String, :Link ]
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&amp;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: "No chunks",
100
- rendered: "No chunks"
143
+ content: 'No chunks',
144
+ rendered: 'No chunks'
101
145
  },
102
146
 
103
147
  single_nest: {
104
- content: "{{one inclusion|size;large}}",
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 "instance" do
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
- wrong_class ? false : ( is_last ? true : m[1..-1] )
161
- else false end
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["One"]
206
+ assert card = Card['One']
165
207
  @card = card
166
208
 
167
209
  # non-nil valued opts only ...
168
- @render_block = Proc.new do |opts| {options: opts.inject({}) {|i,v| !v[1].nil? && i[v[0]]=v[1]; i } } end
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.find_all {|c| String != c }
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 "finds all the chunks and strings" do
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 "gives just the chunks" do
243
+ it 'gives just the chunks' do
195
244
  @example = :nests
196
245
  check_chunk_classes
197
246
  end
198
247
 
199
- it "finds all the chunks links and trasclusions" do
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 "finds uri chunks " do
205
- # tried some tougher cases that failed, don't know the spec, so hard to form better tests for URIs here
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 "finds uri chunks (b)" do
211
- # tried some tougher cases that failed, don't know the spec, so hard to form better tests for URIs here
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 "parses just a string" do
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 "parses a single chunk" do
272
+ it 'parses a single chunk' do
222
273
  @example = :single_nest
223
274
  check_chunk_classes
224
275
  end
225
276
 
226
- it "leaves css alone" do
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 "render" do
233
- it "renders all nests" do
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.process_content_object &@render_block
237
- expect(rdr=cobj.as_json.to_json).not_to match /not rendered/
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 "renders links and nests" do
293
+ it 'renders links and nests' do
242
294
  @example = :links_and_nests
243
- cobj.process_content_object &@render_block
244
- expect(rdr=cobj.as_json.to_json).not_to match /not rendered/
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 "renders links correctly for text formatters" do
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.process_content_object &@render_block
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 "does not need rendering if no nests" do
310
+ it 'does not need rendering if no nests' do
258
311
  @example = :uris_and_links
259
- cobj.process_content_object &@render_block
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 "does not need rendering if no nests (b)" do
316
+ it 'does not need rendering if no nests (b)' do
264
317
  @example = :uris_and_links_2
265
- expect(rdr=cobj.as_json.to_json).to match /not rendered/ # links are rendered too, but not with a block
266
- cobj.process_content_object &@render_block
267
- expect(rdr=cobj.as_json.to_json).not_to match /not rendered/
268
- expect(rdr).to eq(rendered.to_json)
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 = [ ' [grrew][/wiki/grrew]ss ', ' {{this is a test}}, {{this|view|is:too}} and',
274
- ' so is http://foo.bar.come//', ' and foo="my attr, not int a tag" <not a=tag ', ' p class"foobar"> and more' ]
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 "class" do
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>', Card::Content.clean!('<p>html<div class="boo">with</div><monkey>funky</butts>tags</p>')
286
- assert_equal '<span>foo</span>', Card::Content.clean!('<span class="banana">foo</span>')
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
- assert_equal '<span class="w-spotlight">foo</span>', Card::Content.clean!('<span class="w-spotlight">foo</span>')
291
- assert_equal '<p class="w-highlight w-ok">foo</p>', Card::Content.clean!('<p class="w-highlight w-ok">foo</p>')
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 but not permitted ones when both are present' do
295
- assert_equal "<span class='w-spotlight w-ok'>foo</span>", Card::Content.clean!("<span class='w-spotlight banana w-ok'>foo</span>")
296
- assert_equal '<p class="w-highlight">foo</p>', Card::Content.clean!('<p class="w-highlight bad-at end">foo</p>')
297
- assert_equal '<p class="w-highlight">foo</p>', Card::Content.clean!('<p class="bad-class w-highlight">foo</p>')
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">', Card::Content.clean!('<img src="foo">')
302
- assert_equal "<img alt='foo'>", Card::Content.clean!("<img alt='foo'>")
303
- assert_equal '<img title="foo">', Card::Content.clean!('<img title=foo>')
304
- assert_equal '<a href="foo">', Card::Content.clean!('<a href="foo">')
305
- assert_equal '<code lang="foo">', Card::Content.clean!('<code lang="foo">')
306
- assert_equal '<blockquote cite="foo">', Card::Content.clean!('<blockquote cite="foo">')
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', Card::Content.clean!('<!-- not me -->joe<!-- not me -->')
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&nbsp; test&nbsp; two&nbsp;&nbsp; space',
321
- Card::Content.clean!('space&nbsp; test &nbsp;two &nbsp;&nbsp;space')
404
+ Card::Content.clean!(
405
+ 'space&nbsp; test &nbsp;two &nbsp;&nbsp;space'
406
+ )
322
407
  end
323
408
 
324
- it 'doesn\'t fix regular nbsp order with setting' do
325
- # manually configure this setting, then make this one live (test above will then fail)
326
- pending "Can't set Card.config.space_last_in_multispace= false for one test"
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&nbsp; test &nbsp;two &nbsp;&nbsp;space',
328
- Card::Content.clean!('space&nbsp; test &nbsp;two &nbsp;&nbsp;space')
415
+ Card::Content.clean!(
416
+ 'space&nbsp; test &nbsp;two &nbsp;&nbsp;space'
417
+ )
329
418
  end
330
419
  end
331
420
  end
332
-
333
-
334
421
  end
335
-