card 1.15.7 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/card.gemspec +3 -2
  4. data/config/initializers/inflections.rb +1 -1
  5. data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +0 -1
  6. data/db/migrate_core_cards/20150601133433_add_recent_setting_session_card.rb +12 -0
  7. data/db/migrate_core_cards/20150610171702_add_debugger_session_card.rb +11 -0
  8. data/db/migrate_core_cards/20150611203506_rails_inflection_updates.rb +82 -0
  9. data/db/migrate_core_cards/20150627205133_fix_script_bootstrap_card_type.rb +7 -0
  10. data/db/migrate_core_cards/20150702130543_remove_edit_toolbar_pinned.rb +9 -0
  11. data/db/schema.rb +81 -81
  12. data/db/seed/new/card_actions.yml +12581 -1647
  13. data/db/seed/new/card_acts.yml +1 -1
  14. data/db/seed/new/card_changes.yml +39326 -7569
  15. data/db/seed/new/card_references.yml +518 -455
  16. data/db/seed/new/cards.yml +1547 -1291
  17. data/db/seed/test/fixtures/card_actions.yml +13700 -2717
  18. data/db/seed/test/fixtures/card_acts.yml +314 -272
  19. data/db/seed/test/fixtures/card_changes.yml +45409 -13573
  20. data/db/seed/test/fixtures/card_references.yml +1223 -1125
  21. data/db/seed/test/fixtures/cards.yml +2694 -2433
  22. data/db/seed/test/fixtures/file1.txt +1 -0
  23. data/db/seed/test/fixtures/file2.txt +1 -0
  24. data/db/version_core_cards.txt +1 -1
  25. data/lib/card.rb +23 -13
  26. data/lib/card/auth.rb +6 -6
  27. data/lib/card/cache.rb +24 -5
  28. data/lib/card/env.rb +10 -10
  29. data/lib/card/format.rb +29 -12
  30. data/lib/card/log.rb +5 -3
  31. data/lib/card/migration.rb +17 -41
  32. data/lib/card/name.rb +12 -0
  33. data/lib/card/reference.rb +11 -12
  34. data/lib/card/set.rb +59 -6
  35. data/lib/card/simplecov_helper.rb +6 -1
  36. data/lib/card/spec_helper.rb +3 -2
  37. data/lib/card/view_cache.rb +77 -0
  38. data/lib/cardio.rb +30 -22
  39. data/mod/01_core/format/html_format.rb +17 -9
  40. data/mod/01_core/layout/blank.html +1 -1
  41. data/mod/01_core/layout/default.html +6 -16
  42. data/mod/01_core/layout/modal.html +9 -0
  43. data/mod/01_core/layout/noside.html +5 -12
  44. data/mod/01_core/layout/simple.html +1 -1
  45. data/mod/01_core/set/all/collection.rb +57 -5
  46. data/mod/01_core/set/all/content.rb +5 -7
  47. data/mod/01_core/set/all/name.rb +8 -10
  48. data/mod/01_core/set/all/permissions.rb +1 -2
  49. data/mod/01_core/set/all/phases.rb +5 -13
  50. data/mod/01_core/set/all/references.rb +10 -10
  51. data/mod/01_core/set/all/rules.rb +2 -2
  52. data/mod/01_core/set/all/tracked_attributes.rb +5 -3
  53. data/mod/01_core/set/all/utils.rb +79 -9
  54. data/mod/01_core/set/all/view_cache.rb +9 -0
  55. data/mod/01_core/spec/format/html_format_spec.rb +2 -2
  56. data/mod/01_core/spec/set/all/collection_spec.rb +1 -1
  57. data/mod/01_history/lib/card/act.rb +3 -1
  58. data/mod/01_history/lib/card/action.rb +20 -12
  59. data/mod/01_history/lib/card/change.rb +12 -8
  60. data/mod/01_history/set/all/actions.rb +2 -2
  61. data/mod/01_history/set/all/content_history.rb +3 -2
  62. data/mod/01_history/set/all/history.rb +57 -19
  63. data/mod/02_basic_types/set/all/rss.rb +5 -6
  64. data/mod/{05_standard → 02_basic_types}/set/type/html.rb +4 -3
  65. data/mod/02_basic_types/set/type/plain_text.rb +1 -1
  66. data/mod/02_basic_types/set/type/pointer.rb +7 -4
  67. data/mod/02_basic_types/spec/set/type/pointer_spec.rb +21 -17
  68. data/mod/03_machines/lib/card/machine.rb +33 -31
  69. data/mod/03_machines/lib/javascript/script_card_menu.js.coffee +2 -10
  70. data/mod/03_machines/lib/javascript/wagn.js.coffee +10 -10
  71. data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +87 -40
  72. data/mod/03_machines/lib/stylesheets/style_cards.scss +26 -28
  73. data/mod/03_machines/set/right/machine_output.rb +3 -3
  74. data/mod/03_machines/set/type/coffee_script.rb +6 -6
  75. data/mod/03_machines/set/type/css.rb +1 -1
  76. data/mod/03_machines/set/type/java_script.rb +5 -6
  77. data/mod/03_machines/spec/lib/shared_machine_examples.rb +3 -1
  78. data/mod/03_machines/spec/set/type/scss_spec.rb +9 -10
  79. data/mod/04_settings/lib/card/setting.rb +16 -14
  80. data/mod/04_settings/set/right/structure.rb +6 -0
  81. data/mod/04_settings/set/self/add_help.rb +1 -1
  82. data/mod/04_settings/set/self/autoname.rb +1 -1
  83. data/mod/04_settings/set/self/captcha.rb +1 -1
  84. data/mod/04_settings/set/self/default.rb +1 -1
  85. data/mod/04_settings/set/self/help.rb +1 -1
  86. data/mod/04_settings/set/self/input.rb +1 -1
  87. data/mod/04_settings/set/self/layout.rb +1 -1
  88. data/mod/04_settings/set/self/on_create.rb +1 -1
  89. data/mod/04_settings/set/self/on_delete.rb +1 -1
  90. data/mod/04_settings/set/self/on_update.rb +1 -1
  91. data/mod/04_settings/set/self/options.rb +1 -1
  92. data/mod/04_settings/set/self/options_label.rb +1 -1
  93. data/mod/04_settings/set/self/script.rb +1 -1
  94. data/mod/04_settings/set/self/structure.rb +1 -1
  95. data/mod/04_settings/set/self/style.rb +1 -1
  96. data/mod/04_settings/set/self/table_of_contents.rb +1 -1
  97. data/mod/04_settings/set/self/thanks.rb +1 -1
  98. data/mod/05_email/set/all/follow.rb +3 -21
  99. data/mod/05_email/set/all/notify.rb +20 -4
  100. data/mod/05_email/set/right/follow.rb +16 -18
  101. data/mod/05_email/set/self/follow.rb +1 -1
  102. data/mod/05_email/spec/set/all/follow_spec.rb +6 -13
  103. data/mod/05_standard/set/all/attach.rb +23 -9
  104. data/mod/05_standard/set/all/error.rb +5 -7
  105. data/mod/05_standard/set/all/event_viz.rb +10 -6
  106. data/mod/05_standard/set/all/links.rb +37 -13
  107. data/mod/05_standard/set/all/rich_html/content.rb +46 -18
  108. data/mod/05_standard/set/all/rich_html/editing.rb +29 -25
  109. data/mod/05_standard/set/all/rich_html/form.rb +17 -10
  110. data/mod/05_standard/set/all/rich_html/header.rb +26 -4
  111. data/mod/05_standard/set/all/rich_html/menu.rb +17 -34
  112. data/mod/05_standard/set/all/rich_html/modal.rb +50 -12
  113. data/mod/05_standard/set/all/rich_html/toolbar.rb +178 -186
  114. data/mod/05_standard/set/all/rich_html/wrapper.rb +44 -21
  115. data/mod/05_standard/set/rstar/rules.rb +43 -53
  116. data/mod/05_standard/set/self/all.rb +2 -1
  117. data/mod/05_standard/set/self/head.rb +2 -2
  118. data/mod/05_standard/set/self/signin.rb +18 -18
  119. data/mod/05_standard/set/self/stats.rb +14 -2
  120. data/mod/05_standard/set/type/search_type.rb +9 -4
  121. data/mod/05_standard/set/type/session.rb +12 -7
  122. data/mod/05_standard/set/type/set.rb +135 -18
  123. data/mod/05_standard/spec/chunk/include_spec.rb +15 -16
  124. data/mod/05_standard/spec/set/all/account_spec.rb +21 -21
  125. data/mod/05_standard/spec/set/all/event_viz_spec.rb +7 -7
  126. data/mod/05_standard/spec/set/all/history_spec.rb +54 -24
  127. data/mod/05_standard/spec/set/all/rich_html/editing_spec.rb +42 -40
  128. data/mod/05_standard/spec/set/rstar/rules_spec.rb +1 -1
  129. data/mod/05_standard/spec/set/type/search_type_spec.rb +9 -1
  130. data/mod/05_standard/spec/set/type/signup_spec.rb +42 -42
  131. data/mod/06_bootstrap/lib/stylesheets/bootstrap_cards.scss +6 -0
  132. data/mod/06_bootstrap/set/all/bootstrap/form.rb +4 -5
  133. data/mod/06_bootstrap/set/all/bootstrap/helper.rb +145 -0
  134. data/mod/06_bootstrap/set/all/rich_bootstrap.rb +0 -59
  135. data/spec/lib/card/action_spec.rb +1 -1
  136. data/spec/lib/card/log_spec.rb +7 -7
  137. data/spec/models/card/cardtype_spec.rb +1 -1
  138. data/spec/spec_helper.rb +1 -1
  139. metadata +31 -6
  140. data/mod/04_settings/set/self/comment.rb +0 -2
@@ -0,0 +1,9 @@
1
+ event :clear_view_cache, :after=>:store do
2
+ Card::ViewCache.reset
3
+ end
4
+
5
+ format do
6
+ def view_caching?
7
+ false
8
+ end
9
+ end
@@ -116,7 +116,7 @@ describe Card::HtmlFormat do
116
116
  Card::Auth.as_bot { @layout_card.save }
117
117
 
118
118
  rendered = expect(@layout_card.format.render(:layout)).to eq(
119
- %{Mainly <div id="main"><div class="CodeRay">\n <div class="code"><pre>Mainly {{_main|core}}</pre></div>\n</div>\n</div>}
119
+ %{Mainly <div id="main"><div class="CodeRay">\n <div class="code"><pre>Mainly {{_main|core}}</pre></div>\n</div>\n</div>\n<div class="modal fade" role="dialog" id="modal-main-slot"><div class="modal-dialog"><div class="modal-content"></div></div></div>}
120
120
  )
121
121
  #probably better to check that it matches "Mainly" exactly twice.
122
122
  end
@@ -129,7 +129,7 @@ describe Card::HtmlFormat do
129
129
  Card.create :name=>"outer space", :content=>"{{_main|name}}"
130
130
  end
131
131
 
132
- expect(@layout_card.format.render(:layout)).to eq('Joe User')
132
+ expect(@layout_card.format.render(:layout)).to eq(%{Joe User\n<div class="modal fade" role="dialog" id="modal-main-slot"><div class="modal-dialog"><div class="modal-content"></div></div></div>})
133
133
  end
134
134
  end
135
135
 
@@ -70,7 +70,7 @@ describe Card::Set::All::Collection do
70
70
  end
71
71
  end
72
72
  it 'handles links and nest arguments' do
73
- result = @list.format.map_nests do |name,args|
73
+ result = @list.format.map_references_with_args do |name,args|
74
74
  [name, args]
75
75
  end
76
76
  expect(result).to eq [
@@ -2,7 +2,9 @@
2
2
  class Card
3
3
  class Act < ActiveRecord::Base
4
4
  before_save :set_actor
5
- has_many :actions, :foreign_key=>:card_act_id, :inverse_of=> :act, :order => :id, :class_name=> "Card::Action"
5
+ has_many :actions, -> { order :id },
6
+ { :foreign_key=>:card_act_id, :inverse_of=> :act, :class_name=> "Card::Action" }
7
+
6
8
  belongs_to :actor, class_name: "Card"
7
9
  belongs_to :card
8
10
  def set_actor
@@ -5,7 +5,8 @@ class Card
5
5
  class Action < ActiveRecord::Base
6
6
  belongs_to :card
7
7
  belongs_to :act, :foreign_key=>:card_act_id, :inverse_of=>:actions
8
- has_many :changes, :foreign_key=>:card_action_id, :inverse_of=>:action, :dependent=>:delete_all
8
+ has_many :card_changes, :foreign_key=>:card_action_id, :inverse_of=>:action,
9
+ :dependent=>:delete_all, :class_name=> "Card::Change"
9
10
 
10
11
  belongs_to :super_action, :class_name=> "Action", :inverse_of=>:sub_actions
11
12
  has_many :sub_actions, :class_name=> "Action", :inverse_of=>:super_action
@@ -28,7 +29,7 @@ class Card
28
29
 
29
30
 
30
31
  def delete_cardless
31
- Card::Action.where( Card.where( :id=>arel_table[:card_id] ).exists.not ).delete_all
32
+ Card::Action.joins('LEFT JOIN cards ON card_actions.card_id = cards.id').where('cards.id IS NULL').delete_all
32
33
  end
33
34
 
34
35
  def delete_old
@@ -72,7 +73,8 @@ class Card
72
73
  end
73
74
 
74
75
  def new_values
75
- @new_values ||= {
76
+ @new_values ||=
77
+ {
76
78
  :content => new_value_for(:db_content),
77
79
  :name => new_value_for(:name),
78
80
  :cardtype => ( typecard = Card[new_value_for(:type_id).to_i] and typecard.name.capitalize )
@@ -89,29 +91,37 @@ class Card
89
91
  end
90
92
 
91
93
  def last_value_for field
92
- ch = self.card.last_change_on(field, :before=>self) and ch.value
94
+ ch = self.card.last_change_on(field, :before=>self) and ch.value
93
95
  end
94
96
 
95
- def new_value_for(field)
96
- ch = changes.find_by_field(field) and ch.value
97
+ def field_index field
98
+ if field.is_a? Integer
99
+ field
100
+ else
101
+ Card::TRACKED_FIELDS.index(field.to_s)
102
+ end
97
103
  end
98
- def change_for(field)
99
- field_integer = ( field.is_a?(Integer) ? field : Card::TRACKED_FIELDS.index(field.to_s) )
100
- changes.where 'card_changes.field = ?', field_integer
104
+
105
+ def new_value_for field
106
+ ch = card_changes.find_by(field: field_index(field)) and ch.value
101
107
  end
102
108
 
109
+ def change_for field
110
+ card_changes.where 'card_changes.field = ?', field_index(field)
111
+ end
103
112
 
104
113
  def new_type?
105
114
  new_value_for(:type_id)
106
115
  end
116
+
107
117
  def new_content?
108
118
  new_value_for(:db_content)
109
119
  end
120
+
110
121
  def new_name?
111
122
  new_value_for(:name)
112
123
  end
113
124
 
114
-
115
125
  def action_type=(value)
116
126
  write_attribute(:action_type, TYPE.index(value))
117
127
  end
@@ -136,12 +146,10 @@ class Card
136
146
  content_diff_builder.green?
137
147
  end
138
148
 
139
-
140
149
  # def diff
141
150
  # @diff ||= { :cardtype=>type_diff, :content=>content_diff, :name=>name_diff}
142
151
  # end
143
152
 
144
-
145
153
  def name_diff opts={}
146
154
  if new_name?
147
155
  Card::Diff.complete old_values[:name], new_values[:name], opts
@@ -1,27 +1,31 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  class Card
3
3
  class Change < ActiveRecord::Base
4
- belongs_to :action, :foreign_key=>:card_action_id, :inverse_of=>:changes
5
-
6
- # replace with enum if we start using rails 4
4
+ belongs_to :action, :foreign_key=>:card_action_id, :inverse_of=>:card_changes
5
+
7
6
  def field=(value)
8
7
  write_attribute(:field, Card::TRACKED_FIELDS.index(value.to_s))
9
8
  end
10
-
9
+
11
10
  def field
12
11
  Card::TRACKED_FIELDS[read_attribute(:field)]
13
12
  end
14
-
13
+
15
14
  def self.delete_actionless
16
15
  Card::Change.where(
17
16
  "card_action_id NOT IN (?)",
18
17
  Card::Action.pluck("id"),
19
18
  ).delete_all
20
19
  end
21
-
22
- def self.find_by_field(value)
20
+
21
+ def find_by_field_name(value)
22
+ index = value.is_a?(Integer) ? value : Card::TRACKED_FIELDS.index(value.to_s)
23
+ find_by_field(index)
24
+ end
25
+
26
+ def self.find_by_field_name(value)
23
27
  index = value.is_a?(Integer) ? value : Card::TRACKED_FIELDS.index(value.to_s)
24
- super(index)
28
+ find_by_field(index)
25
29
  end
26
30
  end
27
31
  end
@@ -28,7 +28,7 @@ def revision action
28
28
  action = Card::Action.fetch(action)
29
29
  end
30
30
  action and Card::TRACKED_FIELDS.inject({}) do |attr_changes, field|
31
- last_change = action.changes.find_by_field(field) || last_change_on(field, :not_after=>action)
31
+ last_change = action.card_changes.find_by_field_name(field) || last_change_on(field, :not_after=>action)
32
32
  attr_changes[field.to_sym] = (last_change ? last_change.value : self[field])
33
33
  attr_changes
34
34
  end
@@ -37,7 +37,7 @@ end
37
37
  def delete_old_actions
38
38
  Card::TRACKED_FIELDS.each do |field|
39
39
  # assign previous changes on each tracked field to the last action
40
- if (la=last_action) && !la.change_for(field).present? && (last_change = last_change_on(field))
40
+ if (la = last_action) && !la.change_for(field).present? and (last_change = last_change_on(field))
41
41
  last_change = Card::Change.find(last_change.id) # last_change comes as readonly record
42
42
  last_change.update_attributes!(:card_action_id=>last_action_id)
43
43
  end
@@ -19,7 +19,7 @@ end
19
19
  def save_content_draft content
20
20
  super
21
21
  acts.create do |act|
22
- act.actions.build(:draft => true, :card_id=>id).changes.build(:field=>:db_content, :value=>content)
22
+ act.actions.build(:draft => true, :card_id=>id).card_changes.build(:field=>:db_content, :value=>content)
23
23
  end
24
24
  end
25
25
 
@@ -125,9 +125,10 @@ def draft_acts
125
125
  drafts.created_by(Card::Auth.current_id).map(&:act)
126
126
  end
127
127
 
128
- event :detect_conflict, :before=>:approve, :on=>:update do
128
+ event :detect_conflict, :before=>:approve, :on=>:update, :when=>proc {|c| c.history? } do
129
129
  if last_action_id_before_edit and last_action_id_before_edit.to_i != last_action_id and last_action.act.actor_id != Auth.current_id
130
130
  errors.add :conflict, "changes not based on latest revision"
131
131
  end
132
132
  end
133
133
 
134
+
@@ -4,15 +4,61 @@ def history?
4
4
  true
5
5
  end
6
6
 
7
+ event :create_act_and_action_for_save, :before=>:process_subcards, :on=>:save, :when=>proc {|c| c.history?} do
8
+ create_act_and_action
9
+ end
10
+ event :create_act_and_action_for_delete, :before =>:validate_delete_children, :on=>:delete, :when=>proc {|c| c.history? } do
11
+ create_act_and_action
12
+ end
13
+
14
+ event :create_card_changes, :after =>:stored, :when=>proc {|c| c.history? } do
15
+ store_changes
16
+ end
17
+
18
+ event :finalize_act, :after=>:create_card_changes, :when=>proc {|c| c.history? } do
19
+ if !@supercard
20
+ if @current_act.actions(true).empty?
21
+ @current_act.delete
22
+ @current_act = nil
23
+ else
24
+ @current_act.update_attributes! :card_id=>id
25
+ end
26
+ end
27
+ end
28
+
29
+
7
30
  # must be called on all actions and before :set_name, :process_subcards and :validate_delete_children
8
31
  def create_act_and_action
32
+ @current_act = (@supercard && @supercard.current_act) || Card::Act.create(:ip_address=>Env.ip)
33
+ @current_action = Card::Action.create(:card_act_id=>@current_act.id, :action_type=>@action, :draft=>(Env.params['draft'] == 'true') )
34
+ if (@supercard and @supercard !=self)
35
+ @current_action.super_action = @supercard.current_action
36
+ end
37
+ end
38
+
39
+ def store_changes
40
+ if @current_action
41
+ @changed_fields = Card::TRACKED_FIELDS.select{ |f| changed_attributes.member? f }
42
+ if @changed_fields.present?
43
+ @changed_fields.each{ |f| Card::Change.create :field => f, :value => self[f], :card_action_id=>@current_action.id }
44
+ @current_action.update_attributes! :card_id => id
45
+ elsif @current_action.card_changes(true).empty?
46
+ @current_action.delete
47
+ @current_action = nil
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+ # alternative to #create_act_and_action
54
+ # currently not used
55
+ def build_act_and_action
9
56
  @current_act = if @supercard
10
57
  @supercard.current_act || @supercard.acts.build(:ip_address=>Env.ip)
11
58
  else
12
59
  acts.build(:ip_address=>Env.ip)
13
60
  end
14
-
15
- @current_action = actions.build(:action_type=>@action, :draft=>(Env.params['draft'] == 'true') )
61
+ @current_action = actions(true).build(:action_type=>@action, :draft=>(Env.params['draft'] == 'true') )
16
62
  @current_action.act = @current_act
17
63
 
18
64
  if (@supercard and @supercard !=self)
@@ -22,20 +68,6 @@ end
22
68
 
23
69
 
24
70
 
25
- event(:create_act_and_action_for_save, :before=>:process_subcards, :on=>:save, :when=>proc {|c| c.history?} ) { create_act_and_action }
26
- event(:create_act_and_action_for_delete, :before =>:validate_delete_children, :on=>:delete, :when=>proc {|c| c.history? }) { create_act_and_action }
27
-
28
-
29
- event :remove_empty_act, :after=>:extend, :when=>proc {|c| c.history? } do
30
- # if not @supercard and not @current_act.actions.empty?
31
- # @current_act.save
32
- # end
33
- @current_act.reload
34
- if not @supercard and @current_act.actions.empty?
35
- @current_act.delete
36
- @current_act = nil
37
- end
38
- end
39
71
 
40
72
 
41
73
 
@@ -99,10 +131,16 @@ end
99
131
 
100
132
  format :html do
101
133
  view :history do |args|
102
- frame args.merge(:body_class=>"history-slot list-group", :content=>true, :subheader=>revision_subheader ) do
103
- _render_revisions
134
+ frame args.merge(:body_class=>"history-slot list-group", :content=>true) do
135
+ [
136
+ history_legend,
137
+ _render_revisions
138
+ ]
104
139
  end
105
140
  end
141
+ def default_history_args args
142
+ args[:optional_toolbar] ||= :show
143
+ end
106
144
 
107
145
  view :revisions do |args|
108
146
  page = params['page'] || 1
@@ -113,7 +151,7 @@ format :html do
113
151
  end.join
114
152
  end
115
153
 
116
- def revision_subheader
154
+ def history_legend
117
155
  intr = card.intrusive_acts.page(params['page']).per(REVISIONS_PER_PAGE)
118
156
  render_haml :intr=>intr do
119
157
  %{
@@ -32,13 +32,12 @@ format :rss do
32
32
  end
33
33
  end
34
34
 
35
+ def raw_feed_items
36
+ [card]
37
+ end
38
+
35
39
  view :feed_item_list do |args|
36
- items = if card.type_id == Card::SearchTypeID #FIXME! yuck.
37
- card.item_cards( search_params.merge(:default_limit => 25) )
38
- else
39
- [card]
40
- end
41
- items.each do |item|
40
+ raw_feed_items.each do |item|
42
41
  @xml.item do
43
42
  subformat(item).render_feed_item :view_changes=>(card.id==RecentID) #FIXME! yuck.
44
43
  end
@@ -1,6 +1,7 @@
1
-
2
- view :editor do |args|
3
- text_area :content, :rows=>5, :class=>'card-content', "data-card-type-code"=>card.type_code
1
+ format :html do
2
+ view :editor do |args|
3
+ text_area :content, :rows=>5, :class=>'card-content ace-editor-textarea', "data-card-type-code"=>card.type_code
4
+ end
4
5
  end
5
6
 
6
7
  view :closed_content do |args|
@@ -3,7 +3,7 @@ format :html do
3
3
  view :editor do |args|
4
4
  text_area :content, :rows=>5, :class=>'card-content', "data-card-type-code"=>card.type_code
5
5
  end
6
-
6
+
7
7
  view :core do |args|
8
8
  process_content_object( CGI.escapeHTML _render_raw )
9
9
  end
@@ -211,13 +211,18 @@ format :data do
211
211
  end
212
212
  end
213
213
 
214
-
215
- event :standardize_items, :before=>:approve, :on=>:save do
214
+ # while a card's card type and content are updated in the same request,
215
+ # the new module will override the old module's events and functions.
216
+ # this event is only on pointer card. Other type cards do not have this event,
217
+ # so it is not overridden and will be run while updating type and content in the same request.
218
+ event :standardize_items, :before=>:approve, :on=>:save, :when=>proc{ |c| c.type_id == Card::PointerID } do
216
219
  if db_content_changed?
217
220
  self.content = item_names(:context=>:raw).map { |name| "[[#{name}]]" }.join "\n"
218
221
  end
219
222
  end
220
223
 
224
+
225
+
221
226
  def diff_args
222
227
  {:format => :pointer}
223
228
  end
@@ -252,8 +257,6 @@ def item_names args={}
252
257
  end
253
258
 
254
259
 
255
-
256
-
257
260
  def item_ids args={}
258
261
  item_names(args).map do |name|
259
262
  Card.fetch_id name
@@ -45,7 +45,9 @@ describe Card::Set::Type::Pointer do
45
45
  pointer.content.should == ""
46
46
  end
47
47
  end
48
-
48
+
49
+
50
+
49
51
  describe "html" do
50
52
  before do
51
53
  Card::Auth.as_bot do
@@ -58,25 +60,27 @@ describe Card::Set::Type::Pointer do
58
60
  end
59
61
  end
60
62
  it "should include nonexistingcardmustnotexistthisistherule in radio options" do
61
- option_html ="<input checked=\"checked\" class=\"pointer-radio-button\" id=\"pointer-radio-nonexistingcardmustnotexistthisistherule\" name=\"pointer_radio_button-tp\" type=\"radio\" value=\"nonexistingcardmustnotexistthisistherule\" />"
62
- @pointer.format.render_radio.should include(option_html)
63
- option_html ="<input checked=\"checked\" class=\"pointer-radio-button\" id=\"pointer-radio-nonexistingcardmustnotexistthisistherule\" name=\"pointer_radio_button-ip\" type=\"radio\" value=\"nonexistingcardmustnotexistthisistherule\" />"
64
- @inherit_pointer.format.render_radio.should include(option_html)
63
+ common_html = 'input[class="pointer-radio-button"][checked="checked"][type="radio"][value="nonexistingcardmustnotexistthisistherule"][id="pointer-radio-nonexistingcardmustnotexistthisistherule"]'
64
+ option_html = common_html + '[name="pointer_radio_button-tp"]'
65
+ assert_view_select @pointer.format.render_radio, option_html
66
+ option_html = common_html + '[name="pointer_radio_button-ip"]'
67
+ assert_view_select @inherit_pointer.format.render_radio, option_html
65
68
  end
69
+
66
70
  it "should include nonexistingcardmustnotexistthisistherule in checkbox options" do
67
- option_html = "<input checked=\"checked\" class=\"pointer-checkbox-button\" id=\"pointer-checkbox-nonexistingcardmustnotexistthisistherule\" name=\"pointer_checkbox\" type=\"checkbox\" value=\"nonexistingcardmustnotexistthisistherule\" />"
68
- @pointer.format.render_checkbox.should include(option_html)
69
- @inherit_pointer.format.render_checkbox.should include(option_html)
71
+ option_html = 'input[class="pointer-checkbox-button"][checked="checked"][name="pointer_checkbox"][type="checkbox"][value="nonexistingcardmustnotexistthisistherule"][id="pointer-checkbox-nonexistingcardmustnotexistthisistherule"]'
72
+ assert_view_select @pointer.format.render_checkbox, option_html
73
+ assert_view_select @inherit_pointer.format.render_checkbox, option_html
70
74
  end
71
75
  it "should include nonexistingcardmustnotexistthisistherule in select options" do
72
- option_html = %{<option value="#{@card_name}" selected="selected">#{@card_name}</option>}
73
- @pointer.format.render_select.should include(option_html)
74
- @inherit_pointer.format.render_select.should include(option_html)
76
+ option_html = "option[value='#{@card_name}'][selected='selected']"
77
+ assert_view_select @pointer.format.render_select, option_html, @card_name
78
+ assert_view_select @inherit_pointer.format.render_select, option_html, @card_name
75
79
  end
76
80
  it "should include nonexistingcardmustnotexistthisistherule in multiselect options" do
77
- option_html = %{<option value="#{@card_name}" selected="selected">#{@card_name}</option>}
78
- @pointer.format.render_multiselect.should include(option_html)
79
- @inherit_pointer.format.render_multiselect.should include(option_html)
81
+ option_html = "option[value='#{@card_name}'][selected='selected']"
82
+ assert_view_select @pointer.format.render_multiselect, option_html, @card_name
83
+ assert_view_select @inherit_pointer.format.render_multiselect, option_html, @card_name
80
84
  end
81
85
  end
82
86
  describe "css" do
@@ -85,15 +89,15 @@ describe Card::Set::Type::Pointer do
85
89
  Card.create :name=>'my css', :content=> @css
86
90
  end
87
91
  it "should render CSS of items" do
88
- css_list = render_card :content,
89
- { :type=>Card::PointerID, :name=>'my style list', :content=>'[[my css]]' },
92
+ css_list = render_card :content,
93
+ { :type=>Card::PointerID, :name=>'my style list', :content=>'[[my css]]' },
90
94
  :format=>:css
91
95
  # css_list.should =~ /STYLE GROUP\: \"my style list\"/
92
96
  # css_list.should =~ /Style Card\: \"my css\"/
93
97
  css_list.should =~ /#{ Regexp.escape @css }/
94
98
  end
95
99
  end
96
-
100
+
97
101
  describe '#standardize_item' do
98
102
  it "should handle unlinked items" do
99
103
  pointer1 = Card.create! :name=>'pointer1', :type=>'Pointer', :content=>'bracketme'