card 1.103.1 → 1.104.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/environments/development.rb +4 -2
  4. data/config/environments/production.rb +9 -9
  5. data/config/environments/test.rb +1 -1
  6. data/config/initializers/01_core_extensions/array.rb +4 -1
  7. data/config/initializers/01_core_extensions/object.rb +1 -1
  8. data/config/initializers/02_patches/active_record.rb +16 -17
  9. data/config/locales/de.yml +8 -564
  10. data/config/locales/es.yml +2 -3
  11. data/db/migrate/20110511221913_require_earlier_migrations.rb +1 -1
  12. data/db/migrate/20120105203350_require_1_8_migrations.rb +1 -1
  13. data/db/migrate/20121111025347_require_1_10_migrations.rb +1 -1
  14. data/db/migrate/20211128040849_virtuals_updated_at.rb +11 -0
  15. data/db/migrate_core_cards/20130411191151_renaming_for_menu.rb +0 -1
  16. data/db/migrate_core_cards/20140317035504_account_requests_to_signups.rb +0 -2
  17. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +0 -2
  18. data/db/migrate_core_cards/20190417142612_reorganize_scripts_2.rb +1 -3
  19. data/db/migrate_core_cards/20190502130029_add_shark_and_help_desk_role.rb +1 -2
  20. data/db/migrate_core_cards/20190710090209_homepage_tweaks.rb +3 -7
  21. data/db/migrate_core_cards/20190823220018_cleanup_for_decko_1_0.rb +2 -4
  22. data/db/migrate_core_cards/20190902193208_input_type.rb +3 -8
  23. data/db/migrate_core_cards/20190904174403_token_upgrade.rb +1 -1
  24. data/db/migrate_core_cards/data/1.12_stylesheets/traditional.scss +1 -2
  25. data/db/schema.rb +19 -16
  26. data/db/seed/new/card_actions.yml +2615 -3383
  27. data/db/seed/new/card_acts.yml +3 -3
  28. data/db/seed/new/card_references.yml +1588 -1707
  29. data/db/seed/new/cards.yml +5450 -8416
  30. data/db/seed/new/schema_migrations.yml +2 -0
  31. data/db/seed/new/schema_migrations_core_cards.yml +8 -0
  32. data/db/seed/test/fixtures/card_actions.yml +4304 -5144
  33. data/db/seed/test/fixtures/card_acts.yml +780 -840
  34. data/db/seed/test/fixtures/card_changes.yml +110 -110
  35. data/db/seed/test/fixtures/card_references.yml +2908 -2992
  36. data/db/seed/test/fixtures/cards.yml +8775 -11955
  37. data/db/seed/test/fixtures/schema_migrations.yml +2 -0
  38. data/db/seed/test/fixtures/schema_migrations_core_cards.yml +8 -0
  39. data/db/test_seed.rb +2 -5
  40. data/db/version.txt +1 -1
  41. data/db/version_core_cards.txt +1 -1
  42. data/lib/card/auth/current.rb +1 -1
  43. data/lib/card/auth/permissions.rb +37 -35
  44. data/lib/card/content/all.rb +3 -3
  45. data/lib/card/content/chunk.rb +1 -1
  46. data/lib/card/content/diff/summary.rb +14 -18
  47. data/lib/card/content.rb +9 -1
  48. data/lib/card/director/act_direction.rb +6 -6
  49. data/lib/card/director/card_methods.rb +0 -1
  50. data/lib/card/director/phases.rb +1 -0
  51. data/lib/card/director/stages.rb +2 -0
  52. data/lib/card/director.rb +1 -0
  53. data/lib/card/fetch/all.rb +3 -3
  54. data/lib/card/fetch/card_class.rb +5 -11
  55. data/lib/card/fetch/results.rb +8 -8
  56. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/abstract_file_card/migration_file.rb +0 -0
  57. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/abstract_file_card/ruby_file.rb +0 -0
  58. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/abstract_file_card/source_file.rb +0 -0
  59. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/abstract_file_card.rb +0 -5
  60. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/haml_card.rb +0 -0
  61. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/output_helper.rb +0 -0
  62. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/script_card.rb +0 -0
  63. data/lib/card/{tasks/card/file_card_creator → file_card_creator}/style_card.rb +0 -0
  64. data/lib/card/{tasks/card/file_card_creator.rb → file_card_creator.rb} +0 -5
  65. data/lib/card/format/content.rb +5 -7
  66. data/lib/card/format/render.rb +10 -10
  67. data/lib/card/format.rb +3 -8
  68. data/lib/card/lexicon.rb +30 -7
  69. data/lib/card/model/save_helper.rb +3 -3
  70. data/lib/card/name/all/descendants.rb +9 -7
  71. data/lib/card/name/all/parts.rb +1 -1
  72. data/lib/card/name/all.rb +4 -3
  73. data/lib/card/name/card_class.rb +2 -1
  74. data/lib/card/name/fields_and_traits.rb +6 -30
  75. data/lib/card/name/name_variants.rb +5 -1
  76. data/lib/card/name.rb +6 -14
  77. data/lib/card/query/abstract_query/tie.rb +2 -3
  78. data/lib/card/query/card_query/normalization.rb +1 -1
  79. data/lib/card/query/sql_statement/order.rb +5 -6
  80. data/lib/card/query/value.rb +10 -7
  81. data/lib/card/reference/all.rb +9 -7
  82. data/lib/card/reference.rb +36 -41
  83. data/lib/card/rule/all.rb +3 -3
  84. data/lib/card/set/advanced_api.rb +5 -0
  85. data/lib/card/set/card_methods.rb +13 -0
  86. data/lib/card/set/event/delayed_event.rb +8 -1
  87. data/lib/card/set/event/skip_and_trigger.rb +8 -0
  88. data/lib/card/set/event.rb +1 -0
  89. data/lib/card/set/format/abstract_format/wrapper.rb +1 -1
  90. data/lib/card/set/format/abstract_format.rb +2 -1
  91. data/lib/card/set/format.rb +2 -3
  92. data/lib/card/set/helpers.rb +68 -0
  93. data/lib/card/set/inheritance.rb +1 -1
  94. data/lib/card/set/pattern/all.rb +20 -10
  95. data/lib/card/set/pattern/base.rb +12 -18
  96. data/lib/card/set/pattern/class_methods.rb +13 -13
  97. data/lib/card/set/pattern.rb +46 -24
  98. data/lib/card/set/registrar.rb +8 -2
  99. data/lib/card/set/trait.rb +16 -1
  100. data/lib/card/set/type.rb +3 -0
  101. data/lib/card/set.rb +14 -7
  102. data/lib/card/subcards/add.rb +1 -3
  103. data/lib/card/subcards/all.rb +30 -56
  104. data/lib/card/view/classy.rb +15 -27
  105. data/lib/card/view/options/voo_api.rb +3 -1
  106. data/lib/card/view/options.rb +7 -5
  107. data/lib/card/view.rb +1 -0
  108. data/lib/card.rb +9 -11
  109. data/lib/cardio/cli.rb +1 -0
  110. data/lib/cardio/commands/custom.rb +60 -0
  111. data/lib/cardio/commands/rake_command/parser.rb +49 -48
  112. data/lib/cardio/commands/rake_command.rb +17 -15
  113. data/lib/cardio/commands/rspec_command.rb +2 -0
  114. data/lib/cardio/commands.rb +69 -69
  115. data/lib/cardio/generators/deck_helper.rb +0 -4
  116. data/lib/cardio/generators.rb +56 -3
  117. data/lib/cardio/migration/deck.rb +0 -0
  118. data/lib/cardio/migration/deck_structure.rb +2 -0
  119. data/lib/cardio/migration/import/import_data/card_content.rb +1 -1
  120. data/lib/cardio/migration/import.rb +2 -2
  121. data/lib/cardio/migration.rb +26 -2
  122. data/lib/cardio/mod/class_methods.rb +112 -0
  123. data/lib/cardio/mod/dirs.rb +15 -11
  124. data/lib/cardio/mod/eat/edibles.rb +92 -0
  125. data/lib/cardio/mod/eat.rb +81 -0
  126. data/lib/cardio/mod/load_strategy/set_tmp_files.rb +10 -4
  127. data/lib/cardio/mod/load_strategy/tmp_files.rb +1 -1
  128. data/lib/cardio/mod/load_strategy.rb +3 -4
  129. data/lib/cardio/mod/loader/set_loader.rb +13 -13
  130. data/lib/cardio/mod/loader.rb +1 -1
  131. data/lib/cardio/mod/modfile_api.rb +5 -0
  132. data/lib/cardio/mod/poop.rb +135 -0
  133. data/lib/cardio/mod.rb +20 -80
  134. data/lib/cardio/railtie.rb +21 -5
  135. data/lib/cardio/schema.rb +11 -10
  136. data/lib/cardio/version.rb +35 -0
  137. data/lib/cardio.rb +4 -0
  138. data/lib/generators/deck/templates/Gemfile.erb +1 -5
  139. data/lib/generators/deck/templates/Rakefile.erb +6 -2
  140. data/lib/generators/deck/templates/rspec.erb +1 -1
  141. data/lib/generators/deck/templates/simplecov.rb.erb +7 -11
  142. data/lib/generators/deck/templates/spec/javascripts/support/decko_jasmine.yml.erb +0 -1
  143. data/lib/generators/mod/USAGE +1 -0
  144. data/lib/{card/tasks → tasks}/card/create.rake +0 -0
  145. data/lib/{card/tasks → tasks}/card/migrate.rake +41 -1
  146. data/lib/{card/tasks → tasks}/card/mod.rake +15 -8
  147. data/lib/tasks/card.rake +65 -0
  148. data/mod/admin/locales/de.yml +4 -0
  149. data/mod/admin/set/all/admin.rb +16 -0
  150. data/mod/admin/set/self/admin.rb +12 -14
  151. data/mod/admin/set/self/admin_info.rb +2 -5
  152. data/mod/core/data/production.yml +7 -0
  153. data/mod/core/data/test.yml +30 -0
  154. data/mod/core/locales/de.yml +28 -0
  155. data/mod/core/locales/en.yml +4 -5
  156. data/mod/core/set/all/assign_attributes.rb +1 -33
  157. data/mod/core/set/all/content.rb +3 -1
  158. data/mod/core/set/all/initialize.rb +1 -4
  159. data/mod/core/set/all/name_events.rb +3 -18
  160. data/mod/core/set/all/reference_events.rb +32 -36
  161. data/mod/core/set/all/subcards.rb +6 -2
  162. data/mod/core/set/all/trash.rb +4 -6
  163. data/mod/core/set/all/type.rb +67 -18
  164. data/mod/core/set/self/version.rb +1 -1
  165. data/mod/core/spec/set/all/name_events_spec.rb +10 -10
  166. data/mod/core/spec/set/all/trash_spec.rb +1 -1
  167. data/mod/core/spec/set/self/trash_spec.rb +1 -1
  168. data/mod/standard/{file → data/files}/favicon/image-icon.png +0 -0
  169. data/mod/standard/{file → data/files}/favicon/image-large.png +0 -0
  170. data/mod/standard/{file → data/files}/favicon/image-medium.png +0 -0
  171. data/mod/standard/{file → data/files}/favicon/image-original.png +0 -0
  172. data/mod/standard/{file → data/files}/favicon/image-small.png +0 -0
  173. data/mod/standard/{file → data/files}/logo/image-original.svg +0 -0
  174. metadata +66 -56
  175. data/db/migrate_core_cards/20150605115802_add_performance_log_card.rb +0 -7
  176. data/lib/card/set/basket.rb +0 -59
  177. data/lib/card/set/code_nest.rb +0 -15
  178. data/lib/card/tasks/card/asset.rake +0 -22
  179. data/lib/card/tasks/card.rake +0 -105
  180. data/lib/card/version.rb +0 -11
  181. data/lib/cardio/commands/USAGE +0 -28
  182. data/lib/cardio/generators/class_methods.rb +0 -35
  183. data/mod/core/spec/set/all/clean_me_spec.rb +0 -258
  184. data/mod/core/spec/set/all/export_spec.rb +0 -71
  185. data/tmpsets/set_pattern/100-all.rb +0 -22
  186. data/tmpsets/set_pattern/101-all_plus.rb +0 -24
  187. data/tmpsets/set_pattern/102-type.rb +0 -40
  188. data/tmpsets/set_pattern/103-star.rb +0 -26
  189. data/tmpsets/set_pattern/104-rstar.rb +0 -28
  190. data/tmpsets/set_pattern/105-rule.rb +0 -28
  191. data/tmpsets/set_pattern/106-right.rb +0 -35
  192. data/tmpsets/set_pattern/107-type_plus_right.rb +0 -43
  193. data/tmpsets/set_pattern/108-self.rb +0 -34
@@ -1,26 +1,26 @@
1
1
  class Card
2
2
  module Set
3
- class Pattern
3
+ module Pattern
4
4
  # pattern-related Card instance methods
5
5
  module All
6
6
  def patterns?
7
7
  defined? @patterns
8
8
  end
9
9
 
10
- def all_patterns
11
- @all_patterns ||= set_patterns.map { |sub| sub.new self }.compact
10
+ def concrete_patterns
11
+ @concrete_patterns ||= Pattern.concrete.map { |sub| sub.new self }.compact
12
12
  end
13
13
 
14
14
  # new cards do not
15
15
  def patterns
16
- @patterns ||= (new_card? ? all_patterns[1..-1] : all_patterns)
16
+ @patterns ||= (new_card? ? concrete_patterns[1..-1] : concrete_patterns)
17
17
  end
18
18
 
19
19
  def reset_patterns
20
20
  # Rails.logger.info "resetting patterns: #{name}"
21
- @patterns = @all_patterns = nil
21
+ @patterns = @concrete_patterns = nil
22
22
  @template = @virtual = nil
23
- @set_mods_loaded = @set_modules = @set_names = @rule_set_keys = nil
23
+ @set_mods_loaded = @set_modules = @set_names = @rule_lookup_keys = nil
24
24
  @junction_only = nil # only applies to set cards
25
25
  true
26
26
  end
@@ -30,13 +30,14 @@ class Card
30
30
  end
31
31
 
32
32
  def set_modules
33
- @set_modules ||= all_patterns[0..-2].reverse.map(&:module_list).flatten.compact
33
+ @set_modules ||=
34
+ concrete_patterns[0..-2].reverse.map(&:module_list).flatten.compact
34
35
  end
35
36
 
36
37
  def set_format_modules klass
37
38
  @set_format_modules ||= {}
38
39
  @set_format_modules[klass] =
39
- all_patterns[0..-2].reverse.map do |pattern|
40
+ concrete_patterns[0..-2].reverse.map do |pattern|
40
41
  pattern.format_module_list klass
41
42
  end.flatten.compact
42
43
  end
@@ -50,13 +51,22 @@ class Card
50
51
  patterns.map(&:module_key).include? set_module.shortname
51
52
  end
52
53
 
53
- def rule_set_keys
54
- @rule_set_keys ||= patterns.map(&:rule_set_key).compact
54
+ def rule_lookup_keys
55
+ @rule_lookup_keys ||= patterns.map(&:rule_lookup_key).compact
55
56
  end
56
57
 
57
58
  def include_module? set
58
59
  singleton_class&.include? set
59
60
  end
61
+
62
+ def each_type_assigning_module_key
63
+ patterns.each do |p|
64
+ next unless p.assigns_type
65
+
66
+ module_key = p.module_key
67
+ yield module_key if module_key
68
+ end
69
+ end
60
70
  end
61
71
  end
62
72
  end
@@ -1,19 +1,21 @@
1
1
  class Card
2
2
  module Set
3
- class Pattern
3
+ module Pattern
4
4
  # class from which set patterns inherit
5
5
  class Base
6
6
  extend ClassMethods
7
+ delegate :pattern_code, :pattern, :anchorless?, :anchor_parts_count,
8
+ :assigns_type, to: :class
7
9
 
8
10
  def initialize card
9
- return if self.class.anchorless?
11
+ return if anchorless?
10
12
 
11
13
  @anchor_name = self.class.anchor_name(card).to_name
12
14
  @anchor_id = find_anchor_id card
13
15
  end
14
16
 
15
17
  def find_anchor_id card
16
- self.class.try(:anchor_id, card) || Card.fetch_id(@anchor_name)
18
+ self.class.try(:anchor_id, card) || @anchor_name.card_id
17
19
  end
18
20
 
19
21
  def module_key
@@ -53,16 +55,8 @@ class Card
53
55
  end
54
56
  end
55
57
 
56
- def anchor_parts_count
57
- self.class.anchor_parts_count
58
- end
59
-
60
- def pattern
61
- @pattern ||= self.class.pattern
62
- end
63
-
64
58
  def to_s
65
- self.class.anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}"
59
+ anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}"
66
60
  end
67
61
 
68
62
  def inspect
@@ -70,15 +64,15 @@ class Card
70
64
  end
71
65
 
72
66
  def safe_key
73
- caps_part = self.class.pattern_code.to_s.tr(" ", "_").upcase
74
- self.class.anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}"
67
+ caps_part = pattern_code.to_s.tr(" ", "_").upcase
68
+ anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}"
75
69
  end
76
70
 
77
- def rule_set_key
78
- if self.class.anchorless?
79
- self.class.pattern_code.to_s
71
+ def rule_lookup_key
72
+ if anchorless?
73
+ pattern_code.to_s
80
74
  elsif @anchor_id
81
- "#{@anchor_id}+#{self.class.pattern_code}"
75
+ "#{@anchor_id}+#{pattern_code}"
82
76
  end
83
77
  end
84
78
  end
@@ -1,10 +1,9 @@
1
1
  class Card
2
2
  module Set
3
- class Pattern
3
+ module Pattern
4
4
  # methods for Set::Pattern classes
5
5
  module ClassMethods
6
- attr_accessor :pattern_code, :pattern_id, :junction_only,
7
- :assigns_type, :anchorless
6
+ attr_accessor :pattern_code, :junction_only, :assigns_type, :anchorless
8
7
  attr_writer :anchor_parts_count
9
8
 
10
9
  def new card
@@ -12,14 +11,10 @@ class Card
12
11
  end
13
12
 
14
13
  def register pattern_code, opts={}
15
- if (self.pattern_id = Card::Codename.id(pattern_code))
16
- self.pattern_code = pattern_code
17
- Card.set_patterns.insert opts.delete(:index).to_i, self
18
- self.anchorless = !respond_to?(:anchor_name)
19
- opts.each { |key, val| send "#{key}=", val }
20
- else
21
- warn "no codename for pattern_code #{pattern_code}"
22
- end
14
+ self.pattern_code = pattern_code
15
+ Pattern.concrete.insert opts.delete(:index).to_i, self
16
+ self.anchorless = !respond_to?(:anchor_name)
17
+ opts.each { |key, val| send "#{key}=", val }
23
18
  end
24
19
 
25
20
  def junction_only?
@@ -30,8 +25,13 @@ class Card
30
25
  anchorless
31
26
  end
32
27
 
28
+ def pattern_id
29
+ pattern_code.card_id
30
+ end
31
+
32
+ # TODO: change to #name or #pattern_name
33
33
  def pattern
34
- Card.fetch(pattern_id, skip_modules: true).name
34
+ pattern_id.cardname
35
35
  end
36
36
 
37
37
  def pattern_applies? card
@@ -44,7 +44,7 @@ class Card
44
44
 
45
45
  def module_key anchor_codes
46
46
  return pattern_code.to_s.camelize if anchorless?
47
- return unless anchor_codes # is this not an error?
47
+ return unless anchor_codes # not all anchors have codenames
48
48
 
49
49
  ([pattern_code] + anchor_codes).map { |code| code.to_s.camelize }.join "::"
50
50
  end
@@ -1,43 +1,65 @@
1
1
  class Card
2
2
  module Set
3
- class Pattern
3
+ # Each deck can have countless sets of cards, each of which follows one of a small
4
+ # list of patterns. This module provides methods for managing those patterns.
5
+ module Pattern
4
6
  class << self
5
- def reset
6
- nonbase_loadables.each do |set_pattern|
7
- Card::Set.const_remove_if_defined set_pattern.to_s.split("::").last
8
- end
9
- Card.set_patterns = []
10
- @card_keys = nil
7
+ # Pattern classes all the patterns except for Abstract.
8
+ # They are concrete because they are defined on a set of cards
9
+ # (while abstract sets must be included on them explicitly).
10
+ #
11
+ # @return [Array <Class>]
12
+ def concrete
13
+ @concrete ||= []
11
14
  end
12
15
 
13
- def loadables
14
- Card.set_patterns.push(Card::Set::Abstract).reverse
16
+ # Pattern classes that can be reloaded without reloading Card
17
+ # (everything but all)
18
+ # @return [Array <Class>]
19
+ def reloadables
20
+ concrete - [Set::All] + Abstract
15
21
  end
16
22
 
17
- def nonbase_loadables
18
- l = loadables
19
- l.delete Card::Set::All
20
- l
23
+ # remove reloadable sets and prepare for reloading
24
+ def reset
25
+ reloadables.each do |set_pattern|
26
+ Set.const_remove_if_defined set_pattern.to_s.split("::").last
27
+ end
28
+ @concrete = @codes = @type_assigner_codes = @nonbase_codes = @ids = nil
21
29
  end
22
30
 
31
+ # finds pattern class associated with codename
32
+ # e.g. find(:type) returns `Card::Set::Type`
33
+ #
34
+ # @return [Class] pattern class
23
35
  def find pattern_code
24
- Card.set_patterns.find { |sub| sub.pattern_code == pattern_code }
36
+ concrete.find { |sub| sub.pattern_code == pattern_code }
25
37
  end
26
38
 
27
- def card_keys
28
- @card_keys ||=
29
- Card.set_patterns.each_with_object({}) do |set_pattern, hash|
30
- card_key = Card.quick_fetch(set_pattern.pattern_code).key
31
- hash[card_key] = true
32
- end
39
+ # list of codenames of pattern cards
40
+ # @return [Array <Symbol>]
41
+ def codes
42
+ @codes ||= concrete.map(&:pattern_code).to_set
33
43
  end
34
44
 
35
- def nonbase_codes
36
- codes.tap { |list| list.delete :all }
45
+ # list of lists of codenames in pattern load order
46
+ # @return [Array <Array <Symbol>>]
47
+ def grouped_codes with_all: true
48
+ g = [[:abstract], nonbase_codes.reverse]
49
+ g.unshift [:all] if with_all
50
+ g
37
51
  end
38
52
 
39
- def codes
40
- Card.set_patterns.map(&:pattern_code).push(:abstract).reverse
53
+ # list of ids of pattern cards
54
+ # @return [Array <Integer>]
55
+ def ids
56
+ @ids ||= concrete.map(&:pattern_id)
57
+ end
58
+
59
+ private
60
+
61
+ def nonbase_codes
62
+ @nonbase_codes ||= codes.to_a - [:all]
41
63
  end
42
64
  end
43
65
  end
@@ -48,6 +48,14 @@ class Card
48
48
  base_modules.clear
49
49
  end
50
50
 
51
+ def finalize_load
52
+ # basket.freeze
53
+ # basket.each_value(&:freeze)
54
+ clean_empty_modules
55
+ end
56
+
57
+ private
58
+
51
59
  def clean_empty_modules
52
60
  clean_empty_module_from_hash modules[:nonbase]
53
61
  modules[:nonbase_format].each_value do |hash|
@@ -62,8 +70,6 @@ class Card
62
70
  end
63
71
  end
64
72
 
65
- private
66
-
67
73
  # makes sets ready for dynamic loading via #include_set_modules
68
74
  def register_set_of_type set_module, set_type
69
75
  mods = modules[set_type]
@@ -1,6 +1,6 @@
1
1
  class Card
2
2
  module Set
3
- # ActiveCard support: accessing plus cards as attributes
3
+ # accessing plus cards as attributes
4
4
  module Trait
5
5
  def card_accessor *args
6
6
  options = args.extract_options!
@@ -45,11 +45,25 @@ class Card
45
45
  define_trait_card trait, new_opts
46
46
  define_trait_reader trait if options[:reader]
47
47
  define_trait_writer trait if options[:writer]
48
+ assign_trait_type trait, options[:type]
48
49
 
49
50
  mod_traits[trait.to_sym] = options
50
51
  end
51
52
  end
52
53
 
54
+ def assign_trait_type trait, type
55
+ return unless type && (parts = trait_module_key_parts trait)
56
+ assign_type type, normalize_const(parts)
57
+ end
58
+
59
+ def trait_module_key_parts trait
60
+ if all_set?
61
+ [:right, trait]
62
+ elsif type_set?
63
+ [:type_plus_right, set_name_parts.last, trait]
64
+ end
65
+ end
66
+
53
67
  def new_trait_opts options
54
68
  %i[type default_content].each_with_object({}).each do |key, hash|
55
69
  hash[key] = options[key] if options[key]
@@ -58,6 +72,7 @@ class Card
58
72
 
59
73
  def define_trait_card trait, opts
60
74
  define_method "#{trait}_card" do
75
+ # opts = opts.clone.merge supercard: card
61
76
  fetch trait.to_sym, new: opts.clone, eager_cache: true
62
77
  end
63
78
  end
data/lib/card/set/type.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  class Card
2
2
  module Set
3
3
  class Type < Pattern::Base
4
+ cattr_accessor :assignment
5
+ self.assignment = {}
6
+
4
7
  def initialize card
5
8
  super
6
9
  # support type inheritance
data/lib/card/set.rb CHANGED
@@ -48,7 +48,6 @@ class Card
48
48
  module Set
49
49
  include Event::Api
50
50
  include Trait
51
- include Basket
52
51
  include Inheritance
53
52
 
54
53
  include Format
@@ -58,15 +57,23 @@ class Card
58
57
  extend I18nScope
59
58
  extend Registrar
60
59
 
61
- mattr_accessor :modules, :traits
60
+ class << self
61
+ attr_accessor :modules, :traits, :basket
62
62
 
63
- def self.reset_modules
64
- self.modules = { base: [], base_format: {},
65
- nonbase: {}, nonbase_format: {},
66
- abstract: {}, abstract_format: {} }
63
+ def reset
64
+ self.modules = {
65
+ base: [], base_format: {},
66
+ nonbase: {}, nonbase_format: {},
67
+ abstract: {}, abstract_format: {}
68
+ }
69
+
70
+ self.basket = {}
71
+ end
67
72
  end
68
73
 
69
- reset_modules
74
+ delegate :basket, to: Set
75
+
76
+ reset
70
77
 
71
78
  # SET MODULE API
72
79
  #
@@ -53,9 +53,7 @@ class Card
53
53
 
54
54
  def new_by_card card
55
55
  card.supercard = @context_card
56
- if !card.name.simple? && card.name.field_of?(@context_card.name)
57
- card.superleft = @context_card
58
- end
56
+ card.update_superleft card.name
59
57
  @keys << card.key
60
58
  Card.write_to_soft_cache card
61
59
  card.director = @context_card.director.subdirectors.add card
@@ -2,18 +2,6 @@ class Card
2
2
  class Subcards
3
3
  # subcard-related Card instance methods
4
4
  module All
5
- def subcard card_name
6
- subcards.card card_name
7
- end
8
-
9
- def subfield field_name
10
- subcards.field field_name
11
- end
12
-
13
- def field? tag
14
- field(tag) || subfield(tag)
15
- end
16
-
17
5
  def subcards
18
6
  @subcards ||= Card::Subcards.new self
19
7
  end
@@ -22,66 +10,50 @@ class Card
22
10
  subcards.present?
23
11
  end
24
12
 
25
- def expire_subcards
26
- subcards.clear
27
- end
28
-
29
- # phase_method :attach_subcard, before: :store do |name_or_card, args=nil|
30
- # TODO: handle differently in different stages
31
- def add_subcard name_or_card, args={}
32
- subcards.add name_or_card, args
33
- end
34
- alias_method :attach_subcard, :add_subcard
35
-
36
- def add_subcard! name_or_card, args={}
37
- subcard = subcards.add name_or_card, args
38
- subcard.director.reset_stage
39
- subcard
13
+ def subcard card_name, args={}
14
+ if (sc = subcards.card card_name)
15
+ sc.assign_attributes args
16
+ sc
17
+ else
18
+ subcards.add card_name, args
19
+ end
40
20
  end
41
- alias_method :attach_subcard!, :add_subcard!
42
21
 
43
- # phase_method :attach_subfield, before: :approve do |name_or_card, args=nil|
44
- def attach_subfield name_or_card, args={}
45
- subcards.add_field name_or_card, args
22
+ def subcard_content card_name
23
+ subcards.card(card_name)&.content
46
24
  end
47
- alias_method :add_subfield, :attach_subfield
48
25
 
49
- def attach_subfield! name_or_card, args={}
50
- subcard = subcards.add_field name_or_card, args
51
- subcard.director.reset_stage
52
- subcard
26
+ def subcard? card_name
27
+ subcards.card(card_name).present?
53
28
  end
54
29
 
55
- def detach_subcard name_or_card
56
- subcards.remove name_or_card
30
+ def subfield field_name, args={}
31
+ if (sf = subcards.field field_name)
32
+ sf.assign_attributes args
33
+ sf
34
+ else
35
+ subcards.add_field field_name, args
36
+ end
57
37
  end
58
- alias_method :remove_subcard, :detach_subcard
59
38
 
60
- def detach_subfield name_or_card
61
- subcards.remove_field name_or_card
39
+ def subfield_content field_name
40
+ subcards.field(field_name)&.content
62
41
  end
63
- alias_method :remove_subfield, :detach_subfield
64
42
 
65
- def clear_subcards
66
- subcards.clear
43
+ def subfield? field_name
44
+ subcards.field(field_name).present?
67
45
  end
68
46
 
69
- # ensures subfield is present
70
- # does NOT override subfield content if already present
71
- def ensure_subfield field_name, args={}
72
- if subfield_present? field_name
73
- subfield field_name
74
- else
75
- add_subfield field_name, args
76
- end
47
+ def field? tag
48
+ field(tag) || subfield?(tag)
77
49
  end
78
50
 
79
- def subfield_present? field_name
80
- subfield(field_name)&.content&.present?
51
+ def drop_subcard name_or_card
52
+ subcards.remove name_or_card
81
53
  end
82
54
 
83
- def deep_clear_subcards
84
- subcards.deep_clear
55
+ def drop_subfield name_or_card
56
+ subcards.remove_field name_or_card
85
57
  end
86
58
 
87
59
  def handle_subcard_errors
@@ -93,6 +65,8 @@ class Card
93
65
  end
94
66
  end
95
67
 
68
+ private
69
+
96
70
  def subcard_error subcard, error
97
71
  msg = error.message
98
72
  msg = "#{error.attribute} #{msg}" unless %i[content abort].member? error.attribute
@@ -24,9 +24,7 @@ class Card
24
24
  # :single_use the same as :nests but is removed after the first use
25
25
  # :global always everywhere
26
26
  def class_up klass, classier, scope=:subviews
27
- klass = klass.to_s
28
-
29
- storage_voo(scope).add_extra_classes klass, classier, scope
27
+ storage_voo(scope).add_extra_classes klass.to_s, classier, scope
30
28
  end
31
29
 
32
30
  def class_down klass, classier
@@ -55,10 +53,8 @@ class Card
55
53
  end
56
54
 
57
55
  def add_extra_classes key, classier, scope
58
- type = class_list_type scope
59
-
60
- class_list(type)[key] =
61
- [class_list(type)[key], classier].flatten.compact.join(" ")
56
+ list = class_list class_list_type(scope)
57
+ list[key] = [list[key], classier].flatten.compact.join " "
62
58
  end
63
59
 
64
60
  # remove classes everywhere where they are visible for the given scope
@@ -83,9 +79,7 @@ class Card
83
79
 
84
80
  def extra_classes klass
85
81
  klass = klass.first if klass.is_a?(Array)
86
- klass = klass.to_s
87
-
88
- deep_extra_classes klass, :self
82
+ deep_extra_classes klass.to_s, :self
89
83
  end
90
84
 
91
85
  # recurse through voos and formats to find all extra classes
@@ -135,33 +129,27 @@ class Card
135
129
  end
136
130
 
137
131
  def class_list type=:private
138
- case type
139
- when :private, :format_private, :public, :single_use
140
- @class_list ||= {}
141
- @class_list[type] ||= {}
142
- else
132
+ unless type.in? %i[private format_private public single_use]
143
133
  raise ArgumentError, "#{type} not a valid class list"
144
134
  end
135
+ @class_list ||= {}
136
+ @class_list[type] ||= {}
145
137
  end
146
138
 
139
+ CLASS_LIST_TYPE = { view: :private,
140
+ format: :format_private,
141
+ subviews: :format_private,
142
+ nests: :public,
143
+ global: :public,
144
+ single_use: :single_use }.freeze
145
+
147
146
  # Translates scopes to the privacy types used to manage the class lists.
148
147
  # A #classy calls looks in the following class_lists:
149
148
  # private - only in the same voo
150
149
  # format_private - the same voo and all parent voos in the same format
151
150
  # public - in all voos in all parent formats
152
151
  def class_list_type scope
153
- case scope
154
- when :view
155
- :private
156
- when :format, :subviews
157
- :format_private
158
- when :nests, :global
159
- :public
160
- when :single_use
161
- :single_use
162
- else
163
- raise ArgumentError, "invalid class_up scope: #{scope}"
164
- end
152
+ CLASS_LIST_TYPE[scope] || raise(ArgumentError, "invalid class_up scope: #{scope}")
165
153
  end
166
154
  end
167
155
  end
@@ -49,7 +49,9 @@ class Card
49
49
  # because they can get changed after. current solution is a compromise.
50
50
  # @return [Hash]
51
51
  def slot_options
52
- normalized_options.merge(view: requested_view).slice(*Options.slot_keys)
52
+ normalized_options.merge(view: requested_view)
53
+ .merge(normalized_visibility_options)
54
+ .slice(*Options.slot_keys)
53
55
  end
54
56
 
55
57
  # ACCESSOR_HELPERS
@@ -40,6 +40,7 @@ class Card
40
40
  heir: [
41
41
  :main, # format object is page's "main" object (Boolean)
42
42
  :home_view, # view for slot to return to when no view specified
43
+ :buttons_view,
43
44
  :edit_structure, # use a different structure for editing (Array)
44
45
  :cql, # contextual cql alterations for search cards (Hash)
45
46
  :action_id, # a Card::Action id (Integer)
@@ -50,20 +51,21 @@ class Card
50
51
  :help, # cue text when editing
51
52
  :structure, # overrides the content of the card
52
53
  :title, # overrides the name of the card
53
- :variant, # override the canonical version of the name with a different
54
- # variant
54
+ :variant, # override the standard name with a different variant
55
55
  :input_type, # inline_nests makes a form within standard content (Symbol)
56
56
  :type, # set the default type of new cards
57
57
  :size, # set an image size
58
- # (also used for character limit in one_line_content)
59
- :params, # parameters for add button. deprecated!
58
+ # (also used for character limit in one_line_content)
60
59
  :items, # options for items (Hash)
61
60
  :cache, # change view cache behaviour
62
61
  # (Symbol<:always, :standard, :never>)
63
62
  :edit, # edit mode
64
63
  # (Symbol<:inline, :standard, :full>)
65
64
  :separator, # item separator in certain lists
66
- :filter
65
+ :filter,
66
+
67
+ # DEPRECATED
68
+ :params # parameters for add button
67
69
  ],
68
70
  none: [
69
71
  :skip_perms, # do not check permissions for this view (Boolean)
data/lib/card/view.rb CHANGED
@@ -27,6 +27,7 @@ class Card
27
27
  extend View::Cache::ClassMethods
28
28
 
29
29
  attr_reader :format, :parent, :card
30
+ attr_accessor :interior
30
31
 
31
32
  class << self
32
33
  # @return [Symbol] viewname as Symbol