card 1.99.1 → 1.99.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/01_core_extensions/array.rb +1 -0
  4. data/config/initializers/01_core_extensions/persistent_identifiers.rb +1 -1
  5. data/config/initializers/02_patches/zeitwerk.rb +13 -0
  6. data/config/initializers/patches.rb +7 -0
  7. data/config/initializers/recaptcha.rb +1 -2
  8. data/config/initializers/zeitwerk.rb +5 -0
  9. data/config/locales/de.yml +1 -1
  10. data/config/locales/en.yml +1 -1
  11. data/config/locales/es.yml +1 -1
  12. data/db/migrate/20110511221913_require_earlier_migrations.rb +0 -3
  13. data/db/migrate/20141001105348_move_revisions_to_actions.rb +1 -1
  14. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +5 -5
  15. data/db/migrate_core_cards/20141120120605_fix_notification_html_message.rb +1 -1
  16. data/db/migrate_core_cards/20141204061304_watchers_to_following.rb +1 -1
  17. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +2 -2
  18. data/db/migrate_core_cards/20150317162412_bootstrap_themes.rb +4 -4
  19. data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
  20. data/db/migrate_core_cards/20190204195039_add_rule_card.rb +1 -1
  21. data/db/migrate_core_cards/20191008201046_fixture_fix.rb +3 -1
  22. data/db/migrate_core_cards/20191028135243_add_link_editor_to_tiny_mce_config.rb +8 -0
  23. data/db/migrate_core_cards/20191115160748_history_cleanup.rb +27 -0
  24. data/db/migrate_core_cards/20191118145629_codename_fixes.rb +6 -0
  25. data/db/seed/new/card_actions.yml +874 -874
  26. data/db/seed/new/card_acts.yml +2 -2
  27. data/db/seed/new/card_references.yml +2 -2
  28. data/db/seed/new/cards.yml +1576 -1576
  29. data/db/seed/new/schema_migrations_core_cards.yml +8 -0
  30. data/db/seed/test/fixtures/card_actions.yml +1815 -1815
  31. data/db/seed/test/fixtures/card_acts.yml +499 -499
  32. data/db/seed/test/fixtures/card_changes.yml +66 -66
  33. data/db/seed/test/fixtures/card_references.yml +634 -634
  34. data/db/seed/test/fixtures/cards.yml +2730 -2730
  35. data/db/seed/test/fixtures/schema_migrations_core_cards.yml +8 -0
  36. data/db/test_seed.rb +10 -11
  37. data/lib/card.rb +9 -30
  38. data/lib/card/act_manager.rb +0 -2
  39. data/lib/card/auth.rb +0 -5
  40. data/lib/card/auth/current.rb +32 -59
  41. data/lib/card/auth/setup.rb +1 -1
  42. data/lib/card/codename.rb +5 -6
  43. data/lib/card/content.rb +5 -8
  44. data/lib/card/content/chunk.rb +0 -78
  45. data/lib/card/content/chunk/abstract.rb +88 -0
  46. data/lib/card/content/clean.rb +3 -3
  47. data/lib/card/content/diff/{lcs.rb → l_c_s.rb} +5 -7
  48. data/lib/card/content/diff/{processor.rb → l_c_s/processor.rb} +0 -0
  49. data/lib/card/content/parser.rb +1 -1
  50. data/lib/card/dirty.rb +25 -31
  51. data/lib/card/dirty/method_factory.rb +15 -0
  52. data/lib/card/env.rb +0 -3
  53. data/lib/card/error.rb +6 -2
  54. data/lib/card/format.rb +5 -5
  55. data/lib/card/format/nest/fetch.rb +2 -1
  56. data/lib/card/mark.rb +1 -0
  57. data/lib/card/migration.rb +4 -0
  58. data/lib/card/mod.rb +2 -5
  59. data/lib/card/mod/dirs.rb +1 -0
  60. data/lib/card/mod/load_strategy.rb +23 -12
  61. data/lib/card/mod/loader.rb +13 -13
  62. data/lib/card/mod/loader/set_loader.rb +7 -1
  63. data/lib/card/mod/loader/set_pattern_loader.rb +2 -2
  64. data/lib/card/mod/module_template.rb +1 -5
  65. data/lib/card/mod_inflector.rb +16 -0
  66. data/lib/card/model/save_helper.rb +2 -2
  67. data/lib/card/name.rb +2 -2
  68. data/lib/card/name/name_variants.rb +19 -0
  69. data/lib/card/query.rb +4 -2
  70. data/lib/card/query/card_query/reference_attributes.rb +2 -2
  71. data/lib/card/query/sql_statement.rb +4 -0
  72. data/lib/card/set.rb +18 -3
  73. data/lib/card/set/abstract.rb +6 -0
  74. data/lib/card/set/event.rb +13 -11
  75. data/lib/card/set/event/delayed_event.rb +2 -0
  76. data/lib/card/set/format.rb +3 -3
  77. data/lib/card/set/helpers.rb +20 -8
  78. data/lib/card/set/loader.rb +1 -1
  79. data/lib/card/set/pattern.rb +47 -0
  80. data/lib/card/{set_pattern.rb → set/pattern/base.rb} +11 -92
  81. data/lib/card/set/required_field.rb +64 -30
  82. data/lib/card/set/trait.rb +3 -2
  83. data/lib/card/set/type.rb +46 -0
  84. data/lib/card/subcards.rb +0 -4
  85. data/lib/card/tasks/card.rake +1 -0
  86. data/lib/card/tasks/card/migrate.rake +1 -1
  87. data/lib/card/view.rb +2 -7
  88. data/lib/card/view/cache.rb +3 -0
  89. data/lib/card/view/cache/stub.rb +5 -0
  90. data/lib/cardio.rb +73 -46
  91. data/mod/account/set/abstract/accountable.rb +49 -0
  92. data/mod/account/set/all/account.rb +3 -3
  93. data/mod/account/set/right/account.rb +1 -1
  94. data/mod/account/set/self/signin.rb +2 -2
  95. data/mod/account/set/type/role.rb +1 -1
  96. data/mod/account/set/type/signup.rb +2 -2
  97. data/mod/account/set/type/signup/views.rb +1 -1
  98. data/mod/account/set/type/user.rb +1 -1
  99. data/mod/account/spec/set/abstract/accountable_spec.rb +7 -0
  100. data/mod/account/spec/set/all/account_spec.rb +3 -3
  101. data/mod/account/spec/set/right/account_spec.rb +1 -1
  102. data/mod/account/spec/set/type/signup_spec.rb +4 -4
  103. data/mod/admin/set/self/admin.rb +1 -1
  104. data/mod/admin/set/self/admin_info.rb +2 -2
  105. data/mod/admin/set/self/version.rb +1 -1
  106. data/mod/basic_types/set/type/json.rb +4 -0
  107. data/mod/basic_types/spec/set/type/html_spec.rb +1 -1
  108. data/mod/bootstrap/db/migrate_core_cards/data/20181108181219_migrate_classic_skins_to_bootstrap.rb +2 -2
  109. data/mod/bootstrap/lib/bootstrap/component_loader.rb +1 -1
  110. data/mod/bootstrap/lib/stylesheets/style_bootstrap_cards.scss +1 -0
  111. data/mod/bootstrap/set/abstract/bootswatch_theme.rb +1 -1
  112. data/mod/bootstrap/set/all/bootstrap/tabs.rb +4 -4
  113. data/mod/bootstrap/set/type/customized_bootswatch_skin.rb +5 -4
  114. data/mod/carrierwave/config/core_initializers/carrierwave.rb +1 -3
  115. data/mod/carrierwave/lib/carrier_wave/{cardmount.rb → card_mount.rb} +2 -2
  116. data/mod/carrierwave/lib/carrier_wave/file_card_uploader.rb +27 -12
  117. data/mod/carrierwave/set/abstract/attachment.rb +0 -2
  118. data/mod/carrierwave/set/all/file_utils.rb +5 -1
  119. data/mod/carrierwave/set/self/admin.rb +1 -1
  120. data/mod/core/chunk/link.rb +99 -91
  121. data/mod/core/chunk/nest.rb +2 -2
  122. data/mod/core/chunk/query_reference.rb +79 -74
  123. data/mod/core/chunk/view_stub.rb +10 -1
  124. data/mod/core/format/html_format.rb +1 -1
  125. data/mod/core/set/abstract/code_file.rb +6 -6
  126. data/mod/core/set/all/content.rb +1 -1
  127. data/mod/core/set/all/event_conditions.rb +1 -2
  128. data/mod/core/set/all/fetch.rb +22 -19
  129. data/mod/core/set/all/fetch_helper.rb +7 -5
  130. data/mod/core/set/all/initialize.rb +35 -9
  131. data/mod/core/set/all/item.rb +16 -6
  132. data/mod/core/set/all/name.rb +19 -15
  133. data/mod/core/set/all/pattern.rb +4 -0
  134. data/mod/core/set/all/permissions.rb +13 -11
  135. data/mod/core/set/all/rename.rb +1 -0
  136. data/mod/core/set/all/rules.rb +4 -4
  137. data/mod/core/set/all/subcards.rb +36 -1
  138. data/mod/core/set/all/type.rb +1 -1
  139. data/mod/core/set_pattern/03_type.rb +2 -0
  140. data/mod/core/spec/chunk/nest_spec.rb +7 -2
  141. data/mod/core/spec/set/all/fetch_spec.rb +1 -1
  142. data/mod/core/spec/set/all/permissions_spec.rb +11 -12
  143. data/mod/core/spec/set/all/rules_spec.rb +3 -3
  144. data/mod/edit/set/all/bridge.rb +1 -3
  145. data/mod/edit/set/all/bridge/tab_views.rb +0 -7
  146. data/mod/edit/set/all/bridge/tab_visibility.rb +5 -7
  147. data/mod/edit/set/all/form_buttons.rb +1 -1
  148. data/mod/edit/set/all/form_elements.rb +1 -0
  149. data/mod/edit/set/all/new.rb +2 -2
  150. data/mod/edit/spec/set/all/bridge/tab_views_spec.rb +1 -1
  151. data/mod/edit/spec/set/all/{nest_editor → reference_editor/nest_editor}/nest_parser_spec.rb +1 -1
  152. data/mod/edit/spec/set/all/{nest_editor_spec.rb → reference_editor/nest_editor_spec.rb} +6 -3
  153. data/mod/edit/spec/set/all/{nest_image_spec.rb → reference_editor/nest_image_spec.rb} +1 -1
  154. data/mod/email/set/abstract/test_context.rb +1 -1
  155. data/mod/email/set/type/email_template/email_config.rb +1 -1
  156. data/mod/follow/set/all/notify.rb +1 -1
  157. data/mod/follow/set/all/notify/base_views.rb +1 -1
  158. data/mod/follow/set/right/account.rb +8 -6
  159. data/mod/follow/set/right/followers.rb +2 -5
  160. data/mod/follow/set/right/following.rb +1 -1
  161. data/mod/follow/spec/set/all/follow_spec.rb +3 -3
  162. data/mod/follow/spec/set/all/notify_spec.rb +1 -1
  163. data/mod/follow/spec/set/right/followers_spec.rb +2 -2
  164. data/mod/history/lib/card/act.rb +3 -1
  165. data/mod/history/lib/card/action.rb +3 -3
  166. data/mod/history/lib/card/action/admin.rb +0 -11
  167. data/mod/history/set/all/history_bridge.rb +1 -1
  168. data/mod/machines/file/all_script_machine_output/file.js +38415 -69
  169. data/mod/machines/file/all_style_machine_output/file.css +2 -2
  170. data/mod/machines/file/script_html5shiv_printshiv_machine_output/file.js +1 -1
  171. data/mod/machines/lib/javascript/decko/filter.js.coffee +7 -1
  172. data/mod/machines/lib/javascript/decko/filter_links.js.coffee +13 -2
  173. data/mod/machines/lib/javascript/decko/link_editor.js.coffee +64 -0
  174. data/mod/machines/lib/javascript/decko/mod.js.coffee +3 -0
  175. data/mod/machines/lib/javascript/decko/nest_editor.js.coffee +49 -29
  176. data/mod/machines/lib/javascript/decko/nest_editor_name.js.coffee +30 -7
  177. data/mod/machines/lib/javascript/decko/slot.js.coffee +4 -1
  178. data/mod/machines/lib/stylesheets/style_cards.scss +31 -19
  179. data/mod/machines/set/abstract/machine/output_cache.rb +1 -1
  180. data/mod/machines/set/abstract/machine/output_update.rb +1 -1
  181. data/mod/machines/set/all/reset_machines.rb +2 -2
  182. data/mod/machines/set/self/script_decko.rb +1 -0
  183. data/mod/media/set/abstract/media.rb +1 -1
  184. data/mod/media/set/type/image.rb +1 -1
  185. data/mod/navbar/set/abstract/account_dropdown.rb +5 -1
  186. data/mod/navbar/set/right/enabled_roles.rb +1 -1
  187. data/mod/navbar/set/self/account_links.rb +1 -1
  188. data/mod/pointer/set/abstract/02_pointer.rb +1 -1
  189. data/mod/pointer/set/abstract/02_pointer/events.rb +30 -10
  190. data/mod/pointer/set/abstract/02_pointer/html_views.rb +6 -2
  191. data/mod/pointer/set/abstract/02_pointer/html_views/autocomplete_input.haml +1 -1
  192. data/mod/pointer/set/abstract/02_pointer/html_views/filter.rb +1 -1
  193. data/mod/pointer/set/abstract/02_pointer/item_api.rb +51 -31
  194. data/mod/pointer/set/abstract/id_pointer.rb +21 -0
  195. data/mod/pointer/set/type/link_list.rb +1 -1
  196. data/mod/pointer/set/type/mirror_list.rb +1 -1
  197. data/mod/pointer/set/type/mirrored_list.rb +2 -2
  198. data/mod/pointer/spec/set/abstract/paging_params_spec.rb +1 -1
  199. data/mod/pointer/spec/set/abstract/pointer/item_api_spec.rb +1 -1
  200. data/mod/recaptcha/set/all/recaptcha.rb +4 -9
  201. data/mod/rules/set/rule/editor.rb +2 -2
  202. data/mod/rules/set/type/set/html_views/rule_lists.rb +1 -1
  203. data/mod/rules/spec/set/type/set_spec.rb +1 -1
  204. data/mod/search/set/abstract/03_filter/filter_form.haml +1 -1
  205. data/mod/search/set/abstract/03_filter/filter_form.rb +23 -2
  206. data/mod/search/set/abstract/03_filter/quick_filters.haml +7 -10
  207. data/mod/search/template/abstract/search/checkbox_item.haml +5 -6
  208. data/mod/settings/set/abstract/permission.rb +2 -2
  209. data/mod/settings/set/right/input_type.rb +3 -3
  210. data/mod/settings/set/right/structure.rb +1 -1
  211. data/mod/settings/set/right/style.rb +1 -1
  212. data/mod/settings/set/type/setting.rb +2 -2
  213. data/mod/standard/set/all/rich_html/html_views/guide.rb +1 -1
  214. data/mod/standard/set/all/rich_html/menu.rb +6 -5
  215. data/mod/standard/set/self/cardtype.rb +1 -1
  216. data/mod/standard/set/type/cardtype.rb +33 -17
  217. data/mod/standard/set/type/session.rb +12 -0
  218. data/mod/standard/spec/set/type/email_template/email_config_spec.rb +1 -2
  219. data/mod/standard/spec/set/type/email_template_spec.rb +1 -3
  220. data/mod/tinymce_editor/lib/javascript/script_tinymce_config.js.coffee +3 -2
  221. data/mod/tinymce_editor/public/assets/tinymce/plugins/nest/plugin.min.js +1 -1
  222. data/mod/tinymce_editor/set/all/reference_editor.rb +23 -0
  223. data/mod/tinymce_editor/set/all/reference_editor/_link_editor.haml +18 -0
  224. data/mod/tinymce_editor/set/all/reference_editor/_nest_editor.haml +17 -0
  225. data/mod/tinymce_editor/set/all/reference_editor/link_editor.rb +33 -0
  226. data/mod/tinymce_editor/set/all/reference_editor/link_editor/link_parser.rb +35 -0
  227. data/mod/tinymce_editor/set/all/reference_editor/nest_editor.rb +174 -0
  228. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/_help.haml +0 -0
  229. data/mod/tinymce_editor/set/all/reference_editor/nest_editor/_options.haml +12 -0
  230. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/_options_select.haml +0 -0
  231. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/_options_select_row.haml +0 -0
  232. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/nest_parser.rb +7 -1
  233. data/mod/tinymce_editor/set/all/reference_editor/nest_image.rb +70 -0
  234. data/mod/tinymce_editor/set/all/reference_editor/reference_editor.haml +18 -0
  235. metadata +39 -21
  236. data/mod/account/set/abstract/accounted.rb +0 -15
  237. data/mod/edit/set/all/bridge/account_section.rb +0 -16
  238. data/mod/edit/set/all/nest_editor.rb +0 -122
  239. data/mod/edit/set/all/nest_editor/_options.haml +0 -12
  240. data/mod/edit/set/all/nest_editor/nest_editor.haml +0 -31
  241. data/mod/edit/set/all/nest_image.rb +0 -37
@@ -0,0 +1,88 @@
1
+ class Card
2
+ class Content < SimpleDelegator
3
+ # A chunk is a pattern of text that can be protected
4
+ # and interrogated by a format. Each Chunk class has a
5
+ # +pattern+ that states what sort of text it matches.
6
+ # Chunks are initalized by passing in the result of a
7
+ # match by its pattern.
8
+ #
9
+ module Chunk
10
+ class Abstract
11
+ class_attribute :config
12
+ attr_reader :text, :process_chunk
13
+
14
+ class << self
15
+ # if the prefix regex matched check that chunk against the full regex
16
+ def full_match content, prefix=nil
17
+ content.match full_re(prefix)
18
+ end
19
+
20
+ def full_re _prefix
21
+ config[:full_re]
22
+ end
23
+
24
+ def context_ok? _content, _chunk_start
25
+ true
26
+ end
27
+ end
28
+
29
+ def reference_code
30
+ "I"
31
+ end
32
+
33
+ def initialize match, content
34
+ match = self.class.full_match(match) if match.is_a? String
35
+ @text = match[0]
36
+ @processed = nil
37
+ @content = content
38
+ interpret match, content
39
+ end
40
+
41
+ def interpret _match_string, _content
42
+ Rails.logger.info "no #interpret method found for chunk class: " \
43
+ "#{self.class}"
44
+ end
45
+
46
+ def format
47
+ @content.format
48
+ end
49
+
50
+ def card
51
+ @content.card
52
+ end
53
+
54
+ def to_s
55
+ result
56
+ end
57
+
58
+ def result
59
+ burn_read || @process_chunk || @processed || @text
60
+ end
61
+
62
+ def burn_read
63
+ return unless @burn_read
64
+
65
+ tmp = @burn_read
66
+ @burn_read = nil
67
+ tmp
68
+ end
69
+
70
+ # Temporarily overrides the processed nest content for single-use
71
+ # After using the nest's result
72
+ # (for example via `to_s`) the original result is restored
73
+ def burn_after_reading text
74
+ @burn_read = text
75
+ end
76
+
77
+ def inspect
78
+ "<##{self.class}##{self}>"
79
+ end
80
+
81
+ def as_json _options={}
82
+ burn_read || @process_chunk || @processed ||
83
+ "not rendered #{self.class}, #{card&.name}"
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -16,7 +16,7 @@ class Card
16
16
  "blockquote" => ["cite"]
17
17
  )
18
18
 
19
- if Card.config.allow_inline_styles
19
+ if Cardio.config.allow_inline_styles
20
20
  allowed_tags["table"] += %w[cellpadding align border cellspacing data-mce-style]
21
21
  allowed_tags["td"] += %w[scope data-mce-style]
22
22
  allowed_tags["th"] += %w[scope data-mce-style]
@@ -24,7 +24,7 @@ class Card
24
24
 
25
25
  allowed_tags.each_key do |k|
26
26
  allowed_tags[k] << "class"
27
- allowed_tags[k] << "style" if Card.config.allow_inline_styles
27
+ allowed_tags[k] << "style" if Cardio.config.allow_inline_styles
28
28
  allowed_tags[k]
29
29
  end
30
30
 
@@ -52,7 +52,7 @@ class Card
52
52
  end.gsub(/<\!--.*?-->/, "")
53
53
  end
54
54
 
55
- if Card.config.space_last_in_multispace
55
+ if Cardio.config.space_last_in_multispace
56
56
  def clean_with_space_last! string, tags=ALLOWED_TAGS
57
57
  cwo = clean_without_space_last!(string, tags)
58
58
  cwo.gsub(/(?:^|\b) ((?:&nbsp;)+)/, '\1 ')
@@ -1,4 +1,4 @@
1
- require_dependency "card/content/diff/processor"
1
+ # require "card/content/diff/processor"
2
2
 
3
3
  class Card
4
4
  class Content
@@ -55,12 +55,10 @@ class Card
55
55
  def check_exclude_and_disjunction_pattern list
56
56
  list.each_with_index.each_with_object([[], []]) do |pair, res|
57
57
  element, index = pair
58
- if element.match @disjunction_pattern
59
- res[1] << { chunk_index: index, element: element,
60
- type: :disjunction }
61
- elsif element.match @exclude_pattern
62
- res[1] << { chunk_index: index, element: element, type:
63
- :excludee }
58
+ if element.match? @disjunction_pattern
59
+ res[1] << { chunk_index: index, element: element, type: :disjunction }
60
+ elsif element.match? @exclude_pattern
61
+ res[1] << { chunk_index: index, element: element, type: :excludee }
64
62
  else
65
63
  res[0] << element
66
64
  end
@@ -1,4 +1,4 @@
1
- require_dependency "card/content/chunk"
1
+ # require "card/content/chunk"
2
2
 
3
3
  class Card
4
4
  class Content
@@ -1,41 +1,35 @@
1
1
  class Card
2
- def self.define_dirty_methods field
3
- define_method "#{field}_before_act" do
4
- attribute_before_act field
5
- end
2
+ module Dirty
3
+ extend ::Card::Dirty::MethodFactory
6
4
 
7
- define_method "#{field}_is_changing?" do
8
- attribute_is_changing? field
5
+ %i[name db_content trash type_id].each do |field|
6
+ define_dirty_methods field
9
7
  end
10
- end
11
-
12
- %i[name db_content trash type_id].each do |field|
13
- define_dirty_methods field
14
- end
15
8
 
16
- def attribute_before_act attr
17
- if saved_change_to_attribute? attr
18
- attribute_before_last_save attr
19
- elsif will_save_change_to_attribute? attr
20
- mutations_from_database.changed_values[attr]
21
- elsif not_in_callback?
22
- attribute_was attr
23
- else
24
- _read_attribute attr
9
+ def attribute_before_act attr
10
+ if saved_change_to_attribute? attr
11
+ attribute_before_last_save attr
12
+ elsif will_save_change_to_attribute? attr
13
+ mutations_from_database.changed_values[attr]
14
+ elsif not_in_callback?
15
+ attribute_was attr
16
+ else
17
+ _read_attribute attr
18
+ end
25
19
  end
26
- end
27
20
 
28
- def not_in_callback?
29
- # or in integrate_with_delay stage
30
- mutations_before_last_save.equal?(mutations_from_database)
31
- end
21
+ def not_in_callback?
22
+ # or in integrate_with_delay stage
23
+ mutations_before_last_save.equal?(mutations_from_database)
24
+ end
32
25
 
33
- def attribute_is_changing? attr
34
- if not_in_callback?
35
- attribute_changed? attr
36
- else
37
- saved_change_to_attribute?(attr) ||
38
- will_save_change_to_attribute?(attr)
26
+ def attribute_is_changing? attr
27
+ if not_in_callback?
28
+ attribute_changed? attr
29
+ else
30
+ saved_change_to_attribute?(attr) ||
31
+ will_save_change_to_attribute?(attr)
32
+ end
39
33
  end
40
34
  end
41
35
  end
@@ -0,0 +1,15 @@
1
+ class Card
2
+ module Dirty
3
+ module MethodFactory
4
+ def define_dirty_methods field
5
+ define_method "#{field}_before_act" do
6
+ attribute_before_act field
7
+ end
8
+
9
+ define_method "#{field}_is_changing?" do
10
+ attribute_is_changing? field
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,3 @@
1
- require_dependency "card/env/location"
2
- require_dependency "card/env/location_history"
3
-
4
1
  class Card
5
2
  # Card::Env is a module for containing the variable details of the environment
6
3
  # in which Card operates.
@@ -42,13 +42,17 @@ class Card
42
42
  # error attributable to code (as opposed to card configuration)
43
43
  class ServerError < Error
44
44
  def self.view
45
- Card[:debugger]&.content =~ /on/ ? :debug_server_error : :server_error
45
+ debugger_on? ? :debug_server_error : :server_error
46
46
  end
47
47
 
48
48
  def self.status_code
49
49
  # Errors with status code 900 are displayed as modal instead of inside
50
50
  # the "card-notice" div``
51
- Card[:debugger]&.content =~ /on/ ? 900 : 500
51
+ debugger_on? ? 900 : 500
52
+ end
53
+
54
+ def self.debugger_on?
55
+ Card::Codename[:debugger] && Card[:debugger]&.content =~ /on/
52
56
  end
53
57
 
54
58
  def report
@@ -10,10 +10,13 @@ class Card
10
10
  #
11
11
  # {Card::Mod} explains how to set up a mod.
12
12
  # {Card::Set::Format} explains how to use this and other format classes within a mod.
13
- # {Card::Set::Abstract::Format} introduces the view API, which is organized with these
14
- # format classes.
13
+ # {Card::Set::Format::AbstractFormat} introduces the view API, which is organized with
14
+ # these format classes.
15
15
  #
16
16
  class Format
17
+ extend ActiveSupport::Autoload
18
+ extend Registration
19
+
17
20
  include Card::Env::Location
18
21
  include Nesting
19
22
  include Render
@@ -22,8 +25,6 @@ class Card
22
25
  include Error
23
26
  include MethodDelegation
24
27
 
25
- extend Registration
26
-
27
28
  cattr_accessor :registered, :aliases
28
29
  self.registered = []
29
30
  self.aliases = {}
@@ -40,7 +41,6 @@ class Card
40
41
  require_card_to_initialize!
41
42
  opts.each { |key, value| instance_variable_set "@#{key}", value }
42
43
  include_set_format_modules
43
- self
44
44
  end
45
45
 
46
46
  def require_card_to_initialize!
@@ -34,7 +34,8 @@ class Card
34
34
  end
35
35
 
36
36
  def new_card_args
37
- args = { name: view_opts[:nest_name], type: view_opts[:type] }
37
+ args = { name: view_opts[:nest_name] }
38
+ args[:type] = view_opts[:type] if view_opts[:type]
38
39
  args.merge(new_supercard_args)
39
40
  .merge(new_main_args)
40
41
  .merge(new_content_args)
@@ -31,6 +31,7 @@ class Card
31
31
  when Integer then mark
32
32
  when Symbol then Card::Codename.id! mark
33
33
  when String then id_from_string mark
34
+ when Card then mark.id
34
35
  end
35
36
  end
36
37
 
@@ -70,6 +70,10 @@ class Card
70
70
  end
71
71
  end
72
72
 
73
+ # def disable_ddl_transaction #:nodoc:
74
+ # true
75
+ # end
76
+
73
77
  def import_json filename, merge_opts={}
74
78
  Card::Mailer.perform_deliveries = false
75
79
  output_file = File.join data_path, "unmerged_#{filename}"
@@ -1,6 +1,3 @@
1
- require_dependency "card/mod/loader"
2
- require_dependency "card/mod/dirs"
3
-
4
1
  class Card
5
2
  # A Card Mod (short for "module" or "modification") is a discrete piece of Decko
6
3
  # functionality. Mods are how the Decko community develops and shares code.
@@ -70,7 +67,7 @@ class Card
70
67
  return if ENV["CARD_MODS"] == "none"
71
68
 
72
69
  if Card.take
73
- Loader.load_mods
70
+ Card::Mod::Loader.load_mods
74
71
  else
75
72
  Rails.logger.warn "empty database"
76
73
  end
@@ -78,7 +75,7 @@ class Card
78
75
 
79
76
  # @return an array of Rails::Path objects
80
77
  def dirs
81
- @dirs ||= Dirs.new(Card.paths["mod"].existent)
78
+ @dirs ||= Mod::Dirs.new(Card.paths["mod"].existent)
82
79
  end
83
80
  end
84
81
  end
@@ -153,6 +153,7 @@ class Card
153
153
  return unless File.exist? modfile_path
154
154
 
155
155
  eval File.read(modfile_path), binding
156
+ true
156
157
  end
157
158
 
158
159
  def load_from_dir
@@ -1,10 +1,10 @@
1
1
  class Card
2
2
  module Mod
3
- require_dependency "card/mod/load_strategy/eval"
4
- require_dependency "card/mod/load_strategy/pattern_tmp_files"
5
- require_dependency "card/mod/load_strategy/set_binding_magic"
6
- require_dependency "card/mod/load_strategy/set_tmp_files"
7
- require_dependency "card/mod/load_strategy/tmp_files"
3
+ # require "card/mod/load_strategy/eval"
4
+ # require "card/mod/load_strategy/pattern_tmp_files"
5
+ # require "card/mod/load_strategy/set_binding_magic"
6
+ # require "card/mod/load_strategy/set_tmp_files"
7
+ # require "card/mod/load_strategy/tmp_files"
8
8
 
9
9
  # Shared code for the three different load strategies: Eval, TmpFiles and BindingMagic
10
10
  class LoadStrategy
@@ -36,18 +36,29 @@ class Card
36
36
  end
37
37
 
38
38
  def each_file &block
39
- @mod_dirs.each module_type do |base_dir|
40
- if module_type == :set
41
- # I'm not sure if we really need this ordering by pattern for sets -pk
42
- Card::Set::Pattern.in_load_order.each do |pattern|
43
- each_file_in_dir base_dir, pattern.to_s, &block
44
- end
45
- else
39
+ if module_type == :set
40
+ each_set_file(&block)
41
+ else
42
+ each_mod_dir module_type do |base_dir|
46
43
  each_file_in_dir base_dir, &block
47
44
  end
48
45
  end
49
46
  end
50
47
 
48
+ def each_set_file &block
49
+ each_mod_dir :set do |base_dir|
50
+ @loader.patterns.each do |pattern|
51
+ each_file_in_dir base_dir, pattern.to_s, &block
52
+ end
53
+ end
54
+ end
55
+
56
+ def each_mod_dir module_type
57
+ @mod_dirs.each module_type do |base_dir|
58
+ yield base_dir
59
+ end
60
+ end
61
+
51
62
  def each_file_in_dir base_dir, subdir=nil
52
63
  pattern = File.join(*[base_dir, subdir, "**/*.rb"].compact)
53
64
  Dir.glob(pattern).sort.each do |abs_path|
@@ -1,10 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- require_dependency "card/set"
4
- require_dependency "card/set_pattern"
5
- require_dependency "card/mod/loader/set_loader"
6
- require_dependency "card/mod/loader/set_pattern_loader"
7
-
8
3
  class Card
9
4
  module Mod
10
5
  # Card::Mod::Loader is used to load all part of a mod,
@@ -17,7 +12,7 @@ class Card
17
12
  # The mods are given by a Mod::Dirs object.
18
13
  # SetLoader can use three different strategies to load the set modules.
19
14
  class Loader
20
- def initialize load_strategy=nil, mod_dirs=nil
15
+ def initialize load_strategy: nil, mod_dirs: nil
21
16
  load_strategy ||= Cardio.config.load_strategy
22
17
  mod_dirs ||= Mod.dirs
23
18
  klass = load_strategy_class load_strategy
@@ -40,17 +35,20 @@ class Card
40
35
  attr_reader :module_type
41
36
 
42
37
  def load_mods
43
- SetPatternLoader.new.load
44
38
  load_formats
45
- SetLoader.new.load
39
+ Card::Mod::Loader::SetPatternLoader.new.load
40
+ Card::Mod::Loader::SetLoader.new.load
41
+ Card::Set.process_base_modules
46
42
  load_initializers
47
- # rescue
48
- # raise Card::Error, "unrescued error loading mods"
49
43
  end
50
44
 
51
- def reload_mods
45
+ def reload_sets
52
46
  Card::Set::Pattern.reset
53
- load_mods
47
+ Card::Set.reset_modules
48
+ Card::Mod::Loader::SetPatternLoader.new.load
49
+ Card::Mod::Loader::SetLoader.new(
50
+ patterns: Card::Set::Pattern.nonbase_loadable_codes
51
+ ).load
54
52
  end
55
53
 
56
54
  def load_chunks
@@ -84,7 +82,9 @@ class Card
84
82
  def load_dir dir
85
83
  Dir["#{dir}/*.rb"].sort.each do |file|
86
84
  # puts Benchmark.measure("from #load_dir: rd: #{file}") {
87
- require_dependency file
85
+ # require file
86
+ # "require" breaks the reloading in development env
87
+ load file
88
88
  # }.format('%n: %t %r')
89
89
  end
90
90
  end