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,7 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  describe Card::Reference do
4
-
5
4
  before do
6
5
  Card::Auth.current_id = Card::WagnBotID
7
6
  end
@@ -11,47 +10,38 @@ describe Card::Reference do
11
10
  Card.create! name: 'JoeForm', type: 'UserForm'
12
11
  Card['JoeForm'].format.render(:core)
13
12
  assert_equal ['joe_form+age', 'joe_form+description', 'joe_form+name'],
14
- Card['JoeForm'].includees.map(&:key).sort
15
- expect(Card['JoeForm'].references_expired).not_to eq(true)
13
+ Card['JoeForm'].includees.map(&:key).sort
16
14
  end
17
15
 
18
16
  it 'on template creation' do
19
17
  Card.create! name: 'SpecialForm', type: 'Cardtype'
20
18
  Card.create! name: 'Form1', type: 'SpecialForm', content: 'foo'
21
- c = Card['Form1']
22
- expect(c.references_expired).to be_nil
23
19
  Card.create! name: 'SpecialForm+*type+*structure', content: '{{+bar}}'
24
- c = Card['Form1']
25
- expect(c.references_expired).to be_truthy
26
20
  Card['Form1'].format.render(:core)
27
- c = Card['Form1']
28
- expect(c.references_expired).to be_nil
29
21
  expect(Card['Form1'].includees.map(&:key)).to eq(['form1+bar'])
30
22
  end
31
23
 
32
24
  it 'on template update' do
33
25
  Card.create! name: 'JoeForm', type: 'UserForm'
34
26
  tmpl = Card['UserForm+*type+*structure']
35
- tmpl.content = '{{+monkey}} {{+banana}} {{+fruit}}';
27
+ tmpl.content = '{{+monkey}} {{+banana}} {{+fruit}}'
36
28
  tmpl.save!
37
- expect(Card['JoeForm'].references_expired).to be_truthy
38
29
  Card['JoeForm'].format.render(:core)
39
30
  assert_equal ['joe_form+banana', 'joe_form+fruit', 'joe_form+monkey'],
40
- Card['JoeForm'].includees.map(&:key).sort
41
- expect(Card['JoeForm'].references_expired).not_to eq(true)
31
+ Card['JoeForm'].includees.map(&:key).sort
42
32
  end
43
33
  end
44
34
 
45
35
  it 'in references should survive cardtype change' do
46
- newcard('Banana','[[Yellow]]')
47
- newcard('Submarine','[[Yellow]]')
48
- newcard('Sun','[[Yellow]]')
49
- newcard('Yellow')
36
+ newcard 'Banana', '[[Yellow]]'
37
+ newcard 'Submarine', '[[Yellow]]'
38
+ newcard 'Sun', '[[Yellow]]'
39
+ newcard 'Yellow'
50
40
  yellow_refs = Card['Yellow'].referencers.map(&:name).sort
51
41
  expect(yellow_refs).to eq(%w{ Banana Submarine Sun })
52
42
 
53
- y=Card['Yellow'];
54
- y.type_id= Card.fetch_id 'UserForm';
43
+ y = Card['Yellow']
44
+ y.type_id = Card.fetch_id 'UserForm'
55
45
  y.save!
56
46
 
57
47
  yellow_refs = Card['Yellow'].referencers.map(&:name).sort
@@ -75,13 +65,13 @@ describe Card::Reference do
75
65
  end
76
66
 
77
67
  it 'should update references on rename when requested' do
78
- watermelon = newcard('watermelon', 'mmmm')
79
- watermelon_seeds = newcard('watermelon+seeds', 'black')
68
+ newcard 'watermelon', 'mmmm'
69
+ newcard 'watermelon+seeds', 'black'
80
70
  lew = newcard('Lew', 'likes [[watermelon]] and [[watermelon+seeds|seeds]]')
81
71
 
82
72
  watermelon = Card['watermelon']
83
73
  watermelon.update_referencers = true
84
- watermelon.name='grapefruit'
74
+ watermelon.name = 'grapefruit'
85
75
  watermelon.save!
86
76
  result = 'likes [[grapefruit]] and [[grapefruit+seeds|seeds]]'
87
77
  expect(lew.reload.content).to eq(result)
@@ -90,25 +80,22 @@ describe Card::Reference do
90
80
  it 'should update referencers on rename when requested (case 2)' do
91
81
  card = Card['Administrator Menu+*self+*read']
92
82
  old_refs = Card::Reference.where(referee_id: Card::AdministratorID)
93
- old_referers = old_refs.map(&:referer_id).sort
94
83
 
95
84
  card.update_referencers = true
96
- card.name='Administrator Menu+*type+*read'
85
+ card.name = 'Administrator Menu+*type+*read'
97
86
  card.save
98
87
 
99
88
  new_refs = Card::Reference.where(referee_id: Card::AdministratorID)
100
- new_referers = new_refs.map(&:referer_id).sort
101
89
  expect(old_refs).to eq(new_refs)
102
90
  end
103
91
 
104
92
  it 'should not update references when not requested' do
105
-
106
- watermelon = newcard('watermelon', 'mmmm')
107
- watermelon_seeds = newcard('watermelon+seeds', 'black')
93
+ newcard 'watermelon', 'mmmm'
94
+ newcard 'watermelon+seeds', 'black'
108
95
  lew = newcard('Lew', 'likes [[watermelon]] and [[watermelon+seeds|seeds]]')
109
96
 
110
97
  assert_equal [1, 1, 1, 1], lew.references_to.map(&:present),
111
- 'links should not be Wanted before'
98
+ 'links should not be Wanted before'
112
99
 
113
100
  watermelon = Card['watermelon']
114
101
  watermelon.update_referencers = false
@@ -118,21 +105,21 @@ describe Card::Reference do
118
105
  expect(lew.reload.content).to eq(correct_content)
119
106
 
120
107
  ref_types = lew.references_to.order(:id).map(&:ref_type)
121
- assert_equal ref_types, ['L','P','P','L'], 'links should be a LINK'
108
+ assert_equal ref_types, ['L', 'P', 'P', 'L'], 'links should be a LINK'
122
109
  refs_are_present = lew.references_to.order(:id).map(&:present)
123
110
  assert_equal refs_are_present, [0, 0, 1, 0],
124
- 'only reference to +seeds should be present'
111
+ 'only reference to +seeds should be present'
125
112
  end
126
113
 
127
114
  it 'update referencing content on rename junction card' do
128
- @ab = Card['A+B'] #linked to from X, included by Y
115
+ @ab = Card['A+B'] # linked to from X, included by Y
129
116
  @ab.update_attributes! name: 'Peanut+Butter', update_referencers: true
130
117
  @x = Card['X']
131
118
  expect(@x.content).to eq('[[A]] [[Peanut+Butter]] [[T]]')
132
119
  end
133
120
 
134
121
  it 'update referencing content on rename junction card' do
135
- @ab = Card['A+B'] #linked to from X, included by Y
122
+ @ab = Card['A+B'] # linked to from X, included by Y
136
123
  @ab.update_attributes! name: 'Peanut+Butter', update_referencers: false
137
124
  @x = Card['X']
138
125
  expect(@x.content).to eq('[[A]] [[A+B]] [[T]]')
@@ -142,7 +129,7 @@ describe Card::Reference do
142
129
  Card.create! name: 'ColorType', type: 'Cardtype', content: ''
143
130
  Card.create! name: 'ColorType+*type+*structure', content: '{{+rgb}}'
144
131
  green = Card.create! name: 'green', type: 'ColorType'
145
- rgb = newcard 'rgb'
132
+ newcard 'rgb'
146
133
  green_rgb = Card.create! name: 'green+rgb', content: '#00ff00'
147
134
 
148
135
  expect(green.reload.includees.map(&:name)).to eq(['green+rgb'])
@@ -163,7 +150,6 @@ describe Card::Reference do
163
150
  expect(Card['alpha card'].referencers.map(&:name)).to eq(['beta card'])
164
151
  end
165
152
 
166
-
167
153
  it 'simple inclusion' do
168
154
  Card.create name: 'alpha'
169
155
  Card.create name: 'beta', content: 'I nest {{alpha}}'
@@ -188,7 +174,7 @@ describe Card::Reference do
188
174
  expect(y_referencers).to include('search with references')
189
175
 
190
176
  search_referees = Card['search with references'].referees.map(&:name).sort
191
- expect(search_referees).to eq ['A','B','X','Y']
177
+ expect(search_referees).to eq(%w{ A B X Y })
192
178
  end
193
179
 
194
180
  it 'handles contextual names in Basic cards' do
@@ -208,7 +194,6 @@ describe Card::Reference do
208
194
  expect(c.errors.any?).to be_falsey
209
195
  end
210
196
 
211
-
212
197
  it 'pickup new links on create' do
213
198
  @l = newcard('woof', '[[Lewdog]]') # no Lewdog card yet...
214
199
  @e = newcard('Lewdog') # now there is
@@ -223,5 +208,4 @@ describe Card::Reference do
223
208
  # now it's inititated
224
209
  expect(@e.name_referencers.map(&:name).include?('woof')).not_to eq(nil)
225
210
  end
226
-
227
211
  end
@@ -111,6 +111,16 @@ describe Card::Subcards do
111
111
  @card._add_subfield :phrase, content: 'this is a sub'
112
112
  expect(@card.subfield(':phrase').content).to eq 'this is a sub'
113
113
  end
114
+
115
+ it 'works together with type change' do
116
+ Card::Auth.as_bot do
117
+ @card = Card.create!(
118
+ name: 'card with subs', '+sub1' => 'first'
119
+ )
120
+ @card.update_attributes! type_id: Card::PhraseID, '+sub1' => 'second'
121
+ end
122
+ expect(Card['card with subs+sub1'].content).to eq 'second'
123
+ end
114
124
  end
115
125
 
116
126
  describe '#add' do
@@ -123,4 +133,32 @@ describe Card::Subcards do
123
133
  expect(Card['sub'].content).to eq 'sub content'
124
134
  end
125
135
  end
136
+ describe 'two levels of subcards' do
137
+ it 'creates cards with subcards with subcards' do
138
+ Card::Auth.as_bot do
139
+ in_phase before: :approve, trigger: -> {
140
+ Card.create! name: 'test'
141
+ } do
142
+ if name == 'test'
143
+ add_subfield('first-level')
144
+ subfield('first-level').add_subfield 'second-level', content: 'yeah'
145
+ end
146
+ end
147
+ end
148
+ expect(Card.fetch('test+first-level+second-level').content).to eq 'yeah'
149
+ end
150
+ it 'creates cards with subcards with subcards using codenames' do
151
+ Card::Auth.as_bot do
152
+ in_phase before: :approve, trigger: -> {
153
+ Card.create! name: 'test'
154
+ } do
155
+ if name == 'test'
156
+ add_subfield :children
157
+ subfield(:children).add_subfield :title, content: 'yeah'
158
+ end
159
+ end
160
+ end
161
+ expect(Card.fetch('test+*child+*title').content).to eq 'yeah'
162
+ end
163
+ end
126
164
  end
@@ -0,0 +1,8 @@
1
+ describe Card::ViewCache do
2
+ it 'gets cleared by Card::Cache.reset_all' do
3
+ Card::ViewCache.cache.write 'testkey', 1
4
+ expect(Card::ViewCache.cache.exist? 'testkey').to be_truthy
5
+ Card::Cache.reset_all
6
+ expect(Card::ViewCache.cache.exist? 'testkey').to be_falsey
7
+ end
8
+ end
@@ -33,7 +33,7 @@ Spork.prefork do
33
33
  config.include RSpec::Rails::Matchers::RoutingMatchers, {
34
34
  file_path: /\bspec\/controllers\//
35
35
  }
36
-
36
+ config.include RSpecHtmlMatchers
37
37
  # format_index = ARGV.find_index {|arg| arg =~ /--format|-f/ }
38
38
  # formatter = format_index ? ARGV[ format_index + 1 ] : 'documentation' #'textmate'
39
39
  # config.default_formatter=formatter
@@ -3,32 +3,33 @@ class Card; module Set; module All; module Collection; extend Card::Set
3
3
  # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/collection.rb ~~~~~~~~~~~
4
4
 
5
5
  module ClassMethods
6
- def search spec
7
- results = ::Card::Query.run(spec)
8
- if block_given? and Array===results
6
+ def search spec, comment=nil
7
+ results = ::Card::Query.run(spec, comment)
8
+ if block_given? && results.is_a?(Array)
9
9
  results.each { |result| yield result }
10
10
  end
11
11
  results
12
12
  end
13
13
 
14
- def count_by_wql(spec)
14
+ def count_by_wql spec
15
15
  spec = spec.clone
16
16
  spec.delete(:offset)
17
17
  search spec.merge(return: 'count')
18
18
  end
19
19
 
20
- def find_each(options = {})
21
- #this is a copy from rails (3.2.16) and is needed because this is performed by a relation (ActiveRecord::Relation)
20
+ def find_each options={}
21
+ # this is a copy from rails (3.2.16) and is needed because this
22
+ # is performed by a relation (ActiveRecord::Relation)
22
23
  find_in_batches(options) do |records|
23
24
  records.each { |record| yield record }
24
25
  end
25
26
  end
26
27
 
27
- def find_in_batches(options = {})
28
+ def find_in_batches options={}
28
29
  if block_given?
29
30
  super(options) do |records|
30
31
  yield(records)
31
- Card::Cache.reset_global
32
+ Card::Cache.reset_all
32
33
  end
33
34
  else
34
35
  super(options)
@@ -36,11 +37,11 @@ module ClassMethods
36
37
  end
37
38
  end
38
39
 
39
- def item_names(args={})
40
+ def item_names _args={}
40
41
  format._render_raw.split /[,\n]/
41
42
  end
42
43
 
43
- def item_cards(args={}) ## FIXME this is inconsistent with item_names
44
+ def item_cards _args={} # FIXME: this is inconsistent with item_names
44
45
  [self]
45
46
  end
46
47
 
@@ -55,39 +56,32 @@ def item_keys args={}
55
56
  end
56
57
 
57
58
  def include_item? item
58
- key = if Card === item
59
- item.cardname.key
60
- else
61
- item.to_name.key
62
- end
63
- item_names.map{|name| name.to_name.key}.member? key
59
+ key = item.is_a?(Card) ? item.cardname.key : item.to_name.key
60
+ item_names.map { |name| name.to_name.key }.member? key
64
61
  end
65
62
 
66
63
  def add_item item
67
- unless include_item? item
68
- self.content="#{self.content}\n#{name}"
69
- end
64
+ return if include_item? item
65
+ self.content = "#{content}\n#{name}"
70
66
  end
71
67
 
72
68
  def drop_item item
73
- if include_item? item
74
- new_names = item_names.reject{ |i| i == item }
75
- self.content = new_names.empty? ? '' : new_names.join("\n")
76
- end
69
+ return unless include_item? item
70
+ new_names = item_names.reject { |i| i == item }
71
+ self.content = new_names.empty? ? '' : new_names.join("\n")
77
72
  end
78
73
 
79
74
  def insert_item index, name
80
75
  new_names = item_names
81
- new_names.delete(name)
82
- new_names.insert(index,name)
83
- self.content = new_names.join "\n"
76
+ new_names.delete name
77
+ new_names.insert index, name
78
+ self.content = new_names.join "\n"
84
79
  end
85
80
 
86
-
87
81
  def extended_item_cards context = nil
88
- context = (context ? context.cardname : self.cardname)
89
- args={ limit: '' }
90
- items = self.item_cards(args.merge(context: context))
82
+ context = (context ? context.cardname : cardname)
83
+ args = { limit: '' }
84
+ items = item_cards(args.merge(context: context))
91
85
  extended_list = []
92
86
  already_extended = ::Set.new # avoid loops
93
87
 
@@ -106,42 +100,44 @@ def extended_item_cards context = nil
106
100
  extended_list
107
101
  end
108
102
 
109
- def extended_item_contents context = nil
103
+ def extended_item_contents context=nil
110
104
  extended_item_cards(context).map(&:item_names).flatten
111
105
  end
112
106
 
113
- def extended_list context = nil
114
- context = (context ? context.cardname : self.cardname)
115
- args={ limit: '' }
116
- self.item_cards(args.merge(context: context)).map do |x|
107
+ def extended_list context=nil
108
+ context = (context ? context.cardname : cardname)
109
+ args = { limit: '' }
110
+ item_cards(args.merge(context: context)).map do |x|
117
111
  x.item_cards(args)
118
112
  end.flatten.map do |x|
119
113
  x.item_cards(args)
120
114
  end.flatten.map do |y|
121
115
  y.item_names(args)
122
116
  end.flatten
123
- # this could go on and on. more elegant to recurse until you don't have a collection
117
+ # this could go on and on. more elegant to recurse until you don't have
118
+ # a collection
124
119
  end
125
120
 
126
121
  def contextual_content context_card, format_args={}, view_args={}
127
122
  context_card.format(format_args).process_content(
128
- self.format(format_args)._render_raw(view_args), view_args
123
+ format(format_args)._render_raw(view_args), view_args
129
124
  )
130
125
  end
131
126
 
132
127
  format do
133
-
134
- def item_links(args={})
128
+ def item_links _args={}
135
129
  raw(render_core).split /[,\n]/
136
130
  end
137
131
 
138
132
  def item_view args
139
- args[:item] || (@inclusion_opts && @inclusion_opts[:view]) || default_item_view
133
+ args[:item] ||
134
+ (@inclusion_opts && @inclusion_opts[:view]) ||
135
+ default_item_view
140
136
  end
141
137
 
142
138
  def item_args args
143
- i_args = { view: item_view(args)}
144
- if type = card.item_type
139
+ i_args = { view: item_view(args) }
140
+ if (type = card.item_type)
145
141
  i_args[:type] = type
146
142
  end
147
143
  i_args
@@ -174,24 +170,24 @@ format do
174
170
 
175
171
  def set_search_params_variables! hash
176
172
  hash[:vars] = params[:vars] || {}
177
- params.each do |key,val|
173
+ params.each do |key, val|
178
174
  case key.to_s
179
- when '_wql' ; hash.merge! val
180
- when /^\_(\w+)$/ ; hash[:vars][$1.to_sym] = val
175
+ when '_wql' then hash.merge! val
176
+ when /^\_(\w+)$/ then hash[:vars][$1.to_sym] = val
181
177
  end
182
178
  end
183
179
  end
184
180
 
185
-
186
181
  def each_reference_with_args args={}
187
- Card::Content.new(_render_raw(args), card).find_chunks( Card::Chunk::Reference ).each do |chunk|
188
- yield(chunk.referee_name.to_s, nest_args(args,chunk))
182
+ content_object = Card::Content.new _render_raw(args), card
183
+ content_object.find_chunks(Card::Chunk::Reference).each do |chunk|
184
+ yield chunk.referee_name.to_s, nest_args(args, chunk)
189
185
  end
190
186
  end
191
187
 
192
-
193
188
  def each_nested_chunk args={}
194
- Card::Content.new(_render_raw(args), card).find_chunks( Card::Chunk::Include).each do |chunk|
189
+ content_object = Card::Content.new(_render_raw(args), card)
190
+ content_object.find_chunks(Card::Chunk::Include).each do |chunk|
195
191
  yield(chunk) if chunk.referee_name # filter commented nests
196
192
  end
197
193
  end
@@ -205,19 +201,21 @@ format do
205
201
  end
206
202
 
207
203
  def unique_chunks chunk, processed_set, &block
208
- if !processed_set.include? chunk.referee_name.key
209
- processed_set << chunk.referee_name.key
210
- block.call(chunk)
211
- end
204
+ return if processed_set.include? chunk.referee_name.key
205
+ processed_set << chunk.referee_name.key
206
+ block.call(chunk)
212
207
  end
213
208
 
214
209
  def each_nested_field args, &block
215
210
  processed_chunk_keys = ::Set.new([card.key])
216
211
 
217
212
  each_nested_chunk(args) do |chunk|
218
- # TODO handle structures that are non-virtual
213
+ # TODO: handle structures that are non-virtual
219
214
  if chunk.referee_name.to_name.field_of? card.name
220
- if chunk.referee_card && chunk.referee_card.virtual? && !processed_chunk_keys.include?(chunk.referee_name.key)
215
+ if chunk.referee_card &&
216
+ chunk.referee_card.virtual? &&
217
+ !processed_chunk_keys.include?(chunk.referee_name.key)
218
+
221
219
  processed_chunk_keys << chunk.referee_name.key
222
220
  subformat(chunk.referee_card).each_nested_field(args) do |sub_chunk|
223
221
  unique_chunks sub_chunk, processed_chunk_keys, &block
@@ -227,7 +225,6 @@ format do
227
225
  end
228
226
  end
229
227
  end
230
-
231
228
  end
232
229
 
233
230
  def map_references_with_args args={}, &block
@@ -241,21 +238,19 @@ format do
241
238
  # process args for links and nests
242
239
  def nest_args args, chunk=nil
243
240
  r_args = item_args(args)
244
- if @inclusion_opts
245
- r_args.merge! @inclusion_opts.clone
246
- end
247
- if chunk.kind_of? Card::Chunk::Include
241
+ r_args.merge! @inclusion_opts.clone if @inclusion_opts
242
+
243
+ case chunk
244
+ when Card::Chunk::Include
248
245
  r_args.merge!(chunk.options)
249
- elsif chunk.kind_of? Card::Chunk::Link
246
+ when Card::Chunk::Link
250
247
  r_args.reverse_merge!(view: :link)
251
248
  r_args.reverse_merge!(title: chunk.link_text) if chunk.link_text
252
249
  end
253
250
  r_args
254
251
  end
255
-
256
252
  end
257
253
 
258
-
259
254
  format :html do
260
255
  view :count do |args|
261
256
  card.item_names(args).size
@@ -269,11 +264,13 @@ format :html do
269
264
  id = "#{card.cardname.safe_key}-#{name.to_name.safe_key}"
270
265
  url = nest_path name, nest_args
271
266
  tab_name = nest_args[:title] || name
272
- tab_buttons += tab_button( "##{id}", tab_name, active_tab, 'data-url'=>url.html_safe, class: (active_tab ? nil : 'load'))
267
+ tab_buttons += tab_button(
268
+ "##{id}", tab_name, active_tab, 'data-url' => url.html_safe,
269
+ class: (active_tab ? nil : 'load'))
273
270
 
274
271
  # only render the first active tab, other tabs get loaded via ajax
275
272
  tab_content = active_tab ? nest(Card.fetch(name, new: {}), nest_args) : ''
276
- tab_panes += tab_pane( id, tab_content, active_tab )
273
+ tab_panes += tab_pane(id, tab_content, active_tab)
277
274
  active_tab = false
278
275
  end
279
276
  tab_panel tab_buttons, tab_panes, args[:tab_type]
@@ -282,7 +279,6 @@ format :html do
282
279
  args[:tab_type] ||= 'tabs'
283
280
  end
284
281
 
285
-
286
282
  # create a path for a nest with respect ot the inclusion options
287
283
  def nest_path name, nest_args
288
284
  path_args = {}
@@ -302,9 +298,9 @@ format :html do
302
298
  tab_panes = ''
303
299
  card.item_cards.each_with_index do |item, index|
304
300
  id = "#{card.cardname.safe_key}-#{item.cardname.safe_key}"
305
- tab_buttons += tab_button( "##{id}", item.name, index == 0 )
301
+ tab_buttons += tab_button("##{id}", item.name, index == 0)
306
302
  tab_content = nest item, item_args(args)
307
- tab_panes += tab_pane( id, tab_content, index == 0 )
303
+ tab_panes += tab_pane(id, tab_content, index == 0)
308
304
  end
309
305
  tab_panel tab_buttons, tab_panes, args[:tab_type]
310
306
  end
@@ -318,28 +314,35 @@ format :html do
318
314
  end
319
315
 
320
316
  def tab_panel tab_buttons, tab_panes, tab_type='tabs'
321
- wrap_with :div, role: "tabpanel" do
317
+ wrap_with :div, role: 'tabpanel' do
322
318
  [
323
- content_tag(:ul, tab_buttons.html_safe, class: "nav nav-#{tab_type}", role: "tablist"),
319
+ content_tag(:ul, tab_buttons.html_safe, class: "nav nav-#{tab_type}",
320
+ role: 'tablist'),
324
321
  content_tag(:div, tab_panes.html_safe, class: 'tab-content')
325
322
  ]
326
323
  end
327
324
  end
328
325
 
329
326
  def tab_button target, text, active=false, link_attr={}
330
- link = link_to fancy_title(text), target, link_attr.merge('role'=>'tab','data-toggle'=>'tab')
327
+ link = link_to(
328
+ fancy_title(text),
329
+ target,
330
+ link_attr.merge('role' => 'tab', 'data-toggle' => 'tab'))
331
331
  li_args = { role: :presentation }
332
332
  li_args[:class] = 'active' if active
333
333
  content_tag :li, link, li_args
334
334
  end
335
335
 
336
336
  def tab_pane id, content, active=false
337
- div_args = {role: :tabpanel, id: id, class: "tab-pane #{'active' if active}"}
337
+ div_args = {
338
+ role: :tabpanel,
339
+ id: id,
340
+ class: "tab-pane #{'active' if active}"
341
+ }
338
342
  content_tag :div, content.html_safe, div_args
339
343
  end
340
344
  end
341
345
 
342
346
 
343
-
344
347
  # ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/collection.rb ~~~~~~~~~~~
345
348
  end;end;end;end;