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
@@ -1,111 +1,120 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  describe Card::Set::All::Templating do
4
-
5
- describe "#structurees" do
6
- it "for User+*type+*structure should return all Users" do
4
+ describe '#structurees' do
5
+ it 'for User+*type+*structure should return all Users' do
7
6
  Card::Auth.as_bot do
8
- c=Card.create(name: 'User+*type+*structure')
7
+ c = Card.create name: 'User+*type+*structure'
9
8
  users
10
9
 
11
- expect(c.structuree_names.sort).to eq(["Big Brother", "Joe Admin", "Joe Camel", "Joe User", "John", "Narcissist", "No Count", "Optic fan", "Sample User", "Sara", "Sunglasses fan", "u1", "u2", "u3"])
10
+ expect(c.structuree_names.sort).to eq(
11
+ ['Big Brother', 'Joe Admin', 'Joe Camel', 'Joe User', 'John',
12
+ 'Narcissist', 'No Count', 'Optic fan', 'Sample User', 'Sara',
13
+ 'Sunglasses fan', 'u1', 'u2', 'u3'
14
+ ])
12
15
  end
13
16
  end
14
17
  end
15
18
 
16
- it "#expire_structuree_references" do
17
- #TESTME
18
- end
19
-
20
-
21
- describe "with right structure" do
19
+ describe 'with right structure' do
22
20
  before do
23
21
  Card::Auth.as_bot do
24
- @bt = Card.create! name: "birthday+*right+*structure", type: 'Date', content: "Today!"
22
+ @bt = Card.create! name: 'birthday+*right+*structure',
23
+ type: 'Date',
24
+ content: 'Today!'
25
25
  end
26
- @jb = Card.create! name: "Jim+birthday"
26
+ @jb = Card.create! name: 'Jim+birthday'
27
27
  end
28
28
 
29
- it "should have default content" do
29
+ it 'should have default content' do
30
30
  expect(@jb.format._render_raw).to eq('Today!')
31
31
  end
32
32
 
33
- it "should change type and content with template" do
33
+ it 'should change type and content with template' do
34
34
  Card::Auth.as_bot do
35
- @bt.content = "Tomorrow"
35
+ @bt.content = 'Tomorrow'
36
36
  @bt.type = 'Phrase'
37
37
  @bt.save!
38
38
  end
39
- jb = @jb.refresh force=true
40
- expect(jb.format.render(:raw)).to eq('Tomorrow')
39
+ jb = @jb.refresh true
40
+ expect(jb.format.render :raw).to eq('Tomorrow')
41
41
  expect(jb.type_id).to eq(Card::PhraseID)
42
42
  end
43
43
 
44
- it "should have type and content overridden by (new) type_plus_right set" do
44
+ it 'should have type and content overridden by (new) type_plus_right set' do
45
45
  Card::Auth.as_bot do
46
- Card.create! name: 'Basic+birthday+*type plus right+*structure', type: 'PlainText', content: 'Yesterday'
46
+ Card.create! name: 'Basic+birthday+*type plus right+*structure',
47
+ type: 'PlainText',
48
+ content: 'Yesterday'
47
49
  end
48
- jb = @jb.refresh force=true
50
+ jb = @jb.refresh true
49
51
  expect(jb.raw_content).to eq('Yesterday')
50
52
  expect(jb.type_id).to eq(Card::PlainTextID)
51
53
  end
52
54
  end
53
55
 
54
-
55
- describe "with right default" do
56
+ describe 'with right default' do
56
57
  before do
57
58
  Card::Auth.as_bot do
58
- @bt = Card.create! name: "birthday+*right+*default", type: 'Date', content: "Today!"
59
+ @bt = Card.create! name: 'birthday+*right+*default',
60
+ type: 'Date',
61
+ content: 'Today!'
59
62
  end
60
63
  @bb = Card.new name: 'Bob+birthday'
61
- @jb = Card.create! name: "Jim+birthday"
64
+ @jb = Card.create! name: 'Jim+birthday'
62
65
  end
63
66
 
64
- it "should have default cardtype" do
67
+ it 'should have default cardtype' do
65
68
  expect(@jb.type_code).to eq(:date)
66
69
  end
67
70
 
68
- it "should have default content" do
71
+ it 'should have default content' do
69
72
  expect(Card['Jim+birthday'].content).to eq('Today!')
70
73
  end
71
74
 
72
- it "should apply to new cards" do
73
- pb = Card.new name: "Pete+birthday"
75
+ it 'should apply to new cards' do
76
+ pb = Card.new name: 'Pete+birthday'
74
77
  expect(pb.raw_content).to eq('Today!')
75
78
  expect(pb.content).to eq('Today!')
76
79
  end
77
80
  end
78
81
 
79
- describe "with type structure" do
82
+ describe 'with type structure' do
80
83
  before do
81
84
  Card::Auth.as_bot do
82
- @dt = Card.create! name: "Date+*type+*structure", type: 'Basic', content: 'Tomorrow'
85
+ @dt = Card.create! name: 'Date+*type+*structure',
86
+ type: 'Basic',
87
+ content: 'Tomorrow'
83
88
  end
84
89
  end
85
90
 
86
- it "should return templated content even if content is passed in" do
87
- expect(Card.new(type: 'Date', content: '').format._render(:raw)).to eq('Tomorrow')
91
+ it 'should return templated content even if content is passed in' do
92
+ new_date_card = Card.new type: 'Date', content: ''
93
+ expect(new_date_card.format._render(:raw)).to eq('Tomorrow')
88
94
  end
89
95
 
90
96
  describe 'and right structure' do
91
97
  before do
92
98
  Card::Auth.as_bot do
93
- Card.create name: "Jim+birthday", content: 'Yesterday'
94
- @bt = Card.create! name: "birthday+*right+*structure", type: 'Date', content: "Today"
99
+ Card.create name: 'Jim+birthday', content: 'Yesterday'
100
+ @bt = Card.create! name: 'birthday+*right+*structure',
101
+ type: 'Date',
102
+ content: 'Today'
95
103
  end
96
104
  end
97
105
 
98
- it "*right setting should override *type setting" do
106
+ it '*right setting should override *type setting' do
99
107
  expect(Card['Jim+birthday'].raw_content).to eq('Today')
100
108
  end
101
109
 
102
- it "should defer to normal content when *structure rule's content is (exactly) '_self'" do
103
- Card::Auth.as_bot { Card.create! name: 'Jim+birthday+*self+*structure', content: '_self' }
110
+ it 'should defer to normal content ' \
111
+ "when *structure rule's content is (exactly) '_self'" do
112
+ Card::Auth.as_bot do
113
+ Card.create! name: 'Jim+birthday+*self+*structure', content: '_self'
114
+ end
104
115
  expect(Card['Jim+birthday'].raw_content).to eq('Yesterday')
105
116
  end
106
117
  end
107
118
  end
108
-
109
119
  end
110
120
 
111
-
@@ -48,7 +48,7 @@ describe Card::Set::All::Trash do
48
48
  )
49
49
  @signup.update_attributes!({})
50
50
  end
51
- Card::Cache.reset_global
51
+ Card::Cache.reset_all
52
52
 
53
53
  Card::Auth.as_bot do
54
54
  expect(Card.search :right=>'*account').not_to be_empty
@@ -46,7 +46,7 @@ def delete_old_actions
46
46
  Card::TRACKED_FIELDS.each do |field|
47
47
  # assign previous changes on each tracked field to the last action
48
48
  if (la = last_action) && !la.change_for(field).present? &&
49
- (last_change = last_change_on(field))
49
+ (last_change = last_change_on field)
50
50
  # last_change comes as readonly record
51
51
  last_change = Card::Change.find(last_change.id)
52
52
  last_change.update_attributes!(card_action_id: last_action_id)
@@ -6,8 +6,7 @@ format do
6
6
  end
7
7
 
8
8
  # NAME VIEWS
9
- simple_args = { closed: true, perms: :none }
10
- view :name, simple_args do |args|
9
+ view :name, closed: true, perms: :none do |args|
11
10
  return card.name unless args[:variant]
12
11
  args[:variant].split(/[\s,]+/).inject(card.name) do |name, variant|
13
12
  case variant.to_sym
@@ -30,11 +29,18 @@ format do
30
29
  end
31
30
  end
32
31
  end
33
- view(:key, simple_args) { card.key }
34
- view(:title, simple_args) { |args| args[:title] || card.name }
35
- view(:linkname, simple_args) { card.cardname.url_key }
36
- view(:url, simple_args) { card_url _render_linkname }
37
- view(:url_link, simple_args) { web_link card_url(_render_linkname) }
32
+
33
+ view(:key, closed: true, perms: :none) { card.key }
34
+ view(:linkname, closed: true, perms: :none) { card.cardname.url_key }
35
+ view(:url, closed: true, perms: :none) { card_url _render_linkname }
36
+
37
+ view :title, closed: true, perms: :none do |args|
38
+ args[:title] || card.name
39
+ end
40
+
41
+ view :url_link, closed: true, perms: :none do
42
+ web_link card_url(_render_linkname)
43
+ end
38
44
 
39
45
  view :link, closed: true, perms: :none do |args|
40
46
  card_link(
@@ -1,7 +1,4 @@
1
-
2
-
3
1
  format :rss do
4
-
5
2
  attr_accessor :xml
6
3
 
7
4
  def initialize card, args
@@ -15,10 +12,10 @@ format :rss do
15
12
  end
16
13
 
17
14
  # FIXME: integrate this with common XML features when it is added
18
- view :feed do |args|
15
+ view :feed do
19
16
  begin
20
- @xml.instruct! :xml, version: "1.0"
21
- @xml.rss version: "2.0" do
17
+ @xml.instruct! :xml, version: '1.0'
18
+ @xml.rss version: '2.0' do
22
19
  @xml.channel do
23
20
  @xml.title render_feed_title
24
21
  @xml.description render_feed_description
@@ -35,41 +32,39 @@ format :rss do
35
32
  [card]
36
33
  end
37
34
 
38
- view :feed_body do |args|
35
+ view :feed_body do |_args|
39
36
  render_feed_item_list
40
37
  end
41
38
 
42
39
  view :feed_item_list do |args|
43
40
  raw_feed_items(args).each do |item|
44
41
  @xml.item do
45
- subformat(item).render_feed_item view_changes: (card.id==RecentID) #FIXME! yuck.
42
+ # FIXME: yuck.
43
+ subformat(item).render_feed_item view_changes: (card.id == RecentID)
46
44
  end
47
45
  end
48
46
  end
49
47
 
50
-
51
- view :feed_title do |args|
52
- Card.setting(:title) + " : " + card.name.gsub(/^\*/,'')
48
+ view :feed_title do
49
+ Card.global_setting(:title) + ' : ' + card.name.gsub(/^\*/,'')
53
50
  end
54
51
 
55
52
  view :feed_item do |args|
56
53
  @xml.title card.name
57
54
  add_name_context
58
55
  @xml.description render((args[:view_changes] ? :change : :open_content))
59
- @xml.pubDate card.revised_at.to_s(:rfc822) #updated_at fails on virtual cards, because not all to_s's take args (just actual dates)
56
+ @xml.pubDate card.revised_at.to_s(:rfc822) # updated_at fails on virtual
57
+ # cards, because not all to_s's take args (just actual dates)
60
58
  @xml.link render_url
61
59
  @xml.guid render_url
62
60
  end
63
61
 
62
+ view :feed_description do '' end
63
+ view :comment_box do '' end
64
+ view :menu do '' end
64
65
 
65
- view :feed_description do |args| '' end
66
- view :comment_box do |args| '' end
67
- view :menu do |args| '' end
68
-
69
-
70
- view :open, { view: :titled, mod: All::Base::Format }
71
- view :content, { view: :core, mod: All::Base::Format }
72
- view :open_content, { view: :core, mod: All::Base::Format }
73
- view :closed, { view: :link, mod: All::Base::Format }
74
-
66
+ view :open, view: :titled, mod: All::Base::Format
67
+ view :content, view: :core, mod: All::Base::Format
68
+ view :open_content, view: :core, mod: All::Base::Format
69
+ view :closed, view: :link, mod: All::Base::Format
75
70
  end
@@ -1,10 +1,13 @@
1
1
  format :html do
2
2
 
3
3
  view :editor do |args|
4
- text_area :content, rows: 5, class: 'card-content', "data-card-type-code"=>card.type_code
4
+ text_area :content,
5
+ rows: 5,
6
+ class: 'card-content',
7
+ 'data-card-type-code' => card.type_code
5
8
  end
6
9
 
7
10
  view :core do |args|
8
- process_content_object( CGI.escapeHTML _render_raw )
11
+ process_content_object(CGI.escapeHTML _render_raw)
9
12
  end
10
13
  end
@@ -1,4 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
+ require 'rspec-html-matchers'
2
3
 
3
4
  describe Card::Set::All::Base do
4
5
  describe 'handles view' do
@@ -2,20 +2,21 @@
2
2
 
3
3
  describe Card::Set::All::Rss do
4
4
  it 'should render recent.rss' do
5
- rendered = Card[:recent].format(:rss).show( nil, {} )
5
+ rendered = Card[:recent].format(:rss).show(nil, {})
6
6
  expect(rendered).to match(/xml/)
7
7
  end
8
8
 
9
9
  it 'should handle faulty search queries' do
10
- bad_search = Card.create! name: 'Bad Search', type: 'Search', content: 'not no search'
10
+ bad_search = Card.create! name: 'Bad Search',
11
+ type: 'Search', content: 'not no search'
11
12
  rendered = bad_search.format(:rss).render_feed_body
12
- expect(rendered).to have_tag("item",:text => /JSON::ParserError/)
13
+ expect(rendered).to have_tag('item', text: /JSON::ParserError/)
13
14
  end
14
15
 
15
16
  it 'should handle bad queries' do
16
- bad_search = Card.create! :name=>'Bad Search', :type=>'Search', :content=>'{"found_by":"home"}'
17
+ bad_search = Card.create! name: 'Bad Search',
18
+ type: 'Search', content: '{"found_by":"home"}'
17
19
  rendered = bad_search.format(:rss).render_feed_body
18
- expect(rendered).to have_tag("item",:text => /Card::BadQuery/)
20
+ expect(rendered).to have_tag('item', text: /Card::BadQuery/)
19
21
  end
20
-
21
22
  end
@@ -81,7 +81,7 @@ jQuery.fn.extend {
81
81
  if status == 409 #edit conflict
82
82
  @slot().find('.current_revision_id').val @slot().find('.new-current-revision-id').text()
83
83
  else if status == 449
84
- @slot().find('.recaptcha-box').loadCaptcha()
84
+ @slot().find('g-recaptcha').reloadCaptcha()
85
85
 
86
86
  notify: (message) ->
87
87
  slot = @slot()
@@ -106,7 +106,10 @@ jQuery.fn.extend {
106
106
 
107
107
  isMain: -> @slot().parent('#main')[0]
108
108
 
109
- loadCaptcha: -> Recaptcha.create wagn.recaptchaKey, this[0]
109
+ reloadCaptcha: ->
110
+ this[0].empty()
111
+ grecaptcha.render this[0],
112
+ sitekey: wagn.recaptchaKey
110
113
 
111
114
  autosave: ->
112
115
  slot = @slot()
@@ -189,9 +192,12 @@ $(window).ready ->
189
192
  opt.url = wagn.prepUrl opt.url, $(this).slot()
190
193
 
191
194
  if $(this).is('form')
192
- if wagn.recaptchaKey and $(this).attr('recaptcha')=='on' and !($(this).find('.recaptcha-box')[0])
193
- newCaptcha(this)
194
- return false
195
+ if wagn.recaptchaKey and $(this).attr('recaptcha')=='on' and !($(this).find('.g-recaptcha')[0])
196
+ if $('.g-recaptcha')[0] # if there is already a recaptcha on the page then we don't have to load the recaptcha script
197
+ addCaptcha(this)
198
+ else
199
+ initCaptcha(this)
200
+ return false
195
201
 
196
202
  if data = $(this).data 'file-data'
197
203
  # NOTE - this entire solution is temporary.
@@ -337,11 +343,18 @@ $(window).ready ->
337
343
  # }
338
344
 
339
345
 
340
- newCaptcha = (form)->
341
- recapUri = 'https://www.google.com/recaptcha/api/js/recaptcha_ajax.js'
342
- recapDiv = $('<div class="recaptcha-box"></div>')
346
+ initCaptcha = (form)->
347
+ recapDiv = $("<div class='g-recaptcha' data-sitekey='#{wagn.recaptchaKey}'></div>")
348
+ $(form).children().last().after recapDiv
349
+ recapUri = "https://www.google.com/recaptcha/api.js"
350
+ $.getScript recapUri # renders the first element with "g-recaptcha" class when loaded
351
+
352
+ # call this if the recaptcha script is already initialized (via initCaptcha)
353
+ addCaptcha = (form)->
354
+ recapDiv = $('<div class="g-recaptcha"></div>')
343
355
  $(form).children().last().after recapDiv
344
- $.getScript recapUri, -> recapDiv.loadCaptcha()
356
+ grecaptcha.render recapDiv,
357
+ sitekey: wagn.recaptchaKey
345
358
 
346
359
  snakeCase = (str)->
347
360
  str.replace /([a-z])([A-Z])/g, (match)-> match[0] + '_' + match[1].toLowerCase()
@@ -9,7 +9,7 @@ end
9
9
  format do
10
10
  view :not_found do |args|
11
11
  if update_machine_output_live?
12
- Card::Cache.reset_global # FIXME: wow, this is overkill, no?
12
+ Card::Cache.reset_all # FIXME: wow, this is overkill, no?
13
13
  root.error_status = 302
14
14
  card.left.update_machine_output
15
15
  card_path card.left.machine_output_url
@@ -1,29 +1,34 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
-
4
3
  class Card
5
-
6
- # Used to extend setting modules like Card::Set::Self::Create in the settings mod
4
+ # Used to extend setting modules like Card::Set::Self::Create in the
5
+ # settings mod
7
6
  module Setting
8
7
  # Let M = Card::Setting (module)
9
8
  # E = Card::Set::Self::Create (module extended with M)
10
- # O = Card["*create"] (object)
11
- attr_accessor :codename # accessible in E
12
- mattr_accessor :groups, :group_names, :user_specific # accessible in E and M
13
- def self.extended(host_class)
14
- host_class.mattr_accessor :restricted_to_type, :rule_type_editable # accessible in E and O
9
+ # O = Card['*create'] (object)
10
+ # accessible in E
11
+ attr_accessor :codename
12
+ # accessible in E and M
13
+ mattr_accessor :groups, :group_names, :user_specific
14
+ def self.extended host_class
15
+ # accessible in E and O
16
+ host_class.mattr_accessor :restricted_to_type, :rule_type_editable
15
17
  end
16
18
 
17
19
  @@group_names = {
18
- templating: "Templating",
19
- permission: "Permissions",
20
- webpage: "Webpage",
21
- pointer: "Pointer",
22
- editing_cue: "Editing cues",
23
- event: "Events",
24
- other: "Other"
20
+ templating: 'Templating',
21
+ permission: 'Permissions',
22
+ webpage: 'Webpage',
23
+ pointer: 'Pointer',
24
+ editing_cue: 'Editing cues',
25
+ event: 'Events',
26
+ other: 'Other',
27
+ config: 'Config'
25
28
  }
26
- @@groups = @@group_names.keys.each_with_object({}) { |key, groups| groups[key] = [] }
29
+ @@groups = @@group_names.keys.each_with_object({}) do |key, groups|
30
+ groups[key] = []
31
+ end
27
32
  @@user_specific = ::Set.new
28
33
 
29
34
  def self.user_specific? codename
@@ -35,34 +40,43 @@ class Card
35
40
  end
36
41
 
37
42
  # usage:
38
- # setting_opts group: :permission | :event | ...
39
- # position: <Fixnum> (starting at 1, default: add to end)
43
+ # setting_opts group: :permission | :event | ...
44
+ # position: <Fixnum> (starting at 1, default: add to end)
40
45
  # rule_type_editable: true | false (default: false)
41
46
  # restricted_to_type: <cardtype> | [ <cardtype>, ...]
42
47
  def setting_opts opts
43
48
  group = opts[:group] || :other
44
49
  @@groups[group] ||= []
45
- if opts[:position]
46
- if @@groups[group][opts[:position]-1]
47
- @@groups[group].insert(opts[:position]-1, self)
50
+ set_position group, opts[:position]
51
+
52
+ @codename = opts[:codename] ||
53
+ name.match(/::(\w+)$/)[1].underscore.to_sym
54
+ self.rule_type_editable = opts[:rule_type_editable]
55
+ self.restricted_to_type =
56
+ if opts[:restricted_to_type]
57
+ type_ids = [opts[:restricted_to_type]].flatten.map do |cardtype|
58
+ to_type_id(cardtype)
59
+ end
60
+ ::Set.new(type_ids)
61
+ end
62
+ return unless opts[:user_specific]
63
+ @@user_specific << @codename
64
+ end
65
+
66
+ def set_position group, pos
67
+ if pos
68
+ if @@groups[group][pos - 1]
69
+ @@groups[group].insert(pos - 1, self)
48
70
  else
49
- @@groups[group][opts[:position]-1] = self
71
+ @@groups[group][pos - 1] = self
50
72
  end
51
73
  else
52
74
  @@groups[group] << self
53
75
  end
54
-
55
- @codename = opts[:codename] || self.name.match(/::(\w+)$/)[1].underscore.to_sym
56
- self.rule_type_editable = opts[:rule_type_editable]
57
- self.restricted_to_type = opts[:restricted_to_type] ? ::Set.new([opts[:restricted_to_type]].flatten.map{ |cardtype| to_type_id(cardtype) }) : false
58
- if opts[:user_specific]
59
- @@user_specific << @codename
60
- end
61
76
  end
62
77
 
63
78
  def applies_to_cardtype type_id
64
- !self.restricted_to_type or self.restricted_to_type.include? type_id
79
+ !restricted_to_type || restricted_to_type.include?(type_id)
65
80
  end
66
81
  end
67
82
  end
68
-