card 1.19.1 → 1.19.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +3 -3
  3. data/VERSION +1 -1
  4. data/db/migrate_core_cards/20160908154210_add_trash_card.rb +7 -0
  5. data/lib/card.rb +2 -2
  6. data/lib/card/act_manager.rb +143 -0
  7. data/lib/card/act_manager/stage.rb +56 -0
  8. data/lib/card/act_manager/stage_director.rb +313 -0
  9. data/lib/card/act_manager/subdirector_array.rb +43 -0
  10. data/lib/card/set.rb +1 -0
  11. data/lib/card/set/i18n_scope.rb +52 -0
  12. data/lib/card/subcards.rb +2 -3
  13. data/lib/cardio.rb +4 -4
  14. data/mod/admin/set/self/admin.rb +1 -2
  15. data/mod/admin/set/self/trash.rb +29 -0
  16. data/mod/core/set/abstract/code_file.rb +5 -25
  17. data/mod/core/set/all/actify.rb +35 -0
  18. data/mod/core/set/all/fetch.rb +12 -15
  19. data/mod/core/set/all/i18n.rb +9 -0
  20. data/mod/core/set/all/phases.rb +1 -1
  21. data/mod/core/set/all/stages.rb +2 -2
  22. data/mod/developer/set/all/event_viz.rb +2 -1
  23. data/mod/email/set/all/notify.rb +1 -1
  24. data/mod/history/lib/card/act.rb +1 -1
  25. data/mod/history/lib/card/action.rb +1 -1
  26. data/mod/history/set/all/history.rb +1 -1
  27. data/mod/machines/set/abstract/machine.rb +1 -1
  28. data/mod/machines/spec/set/type/coffeescript_spec.rb +1 -1
  29. data/mod/machines/spec/set/type/css_spec.rb +1 -1
  30. data/mod/machines/spec/set/type/javascript_spec.rb +1 -1
  31. data/mod/machines/spec/set/type/scss_spec.rb +1 -1
  32. data/mod/machines/spec/set/type/skin_spec.rb +1 -1
  33. data/mod/machines/spec/{lib/shared_machine_examples.rb → shared_examples/machine.rb} +15 -24
  34. data/mod/machines/spec/{lib/shared_machine_input_examples.rb → shared_examples/machine_input.rb} +0 -0
  35. data/mod/settings/spec/set/right/script_spec.rb +1 -1
  36. data/mod/settings/spec/set/right/style_spec.rb +1 -4
  37. data/mod/solid_cache/set/abstract/solid_cache.rb +1 -1
  38. data/spec/lib/card/content_spec.rb +118 -132
  39. data/spec/lib/card/i18n_spec.rb +6 -7
  40. data/spec/lib/card/query_spec.rb +5 -4
  41. data/spec/lib/card/stage_director_spec.rb +1 -1
  42. data/spec/spec_helper.rb +3 -4
  43. data/tmpsets/set/{mod002-core → mod001-core}/abstract/code_file.rb +0 -0
  44. data/tmpsets/set/{mod002-core → mod001-core}/all/actify.rb +0 -0
  45. data/tmpsets/set/{mod002-core → mod001-core}/all/active_card.rb +0 -0
  46. data/tmpsets/set/{mod002-core → mod001-core}/all/collection.rb +0 -0
  47. data/tmpsets/set/{mod002-core → mod001-core}/all/content.rb +0 -0
  48. data/tmpsets/set/{mod002-core → mod001-core}/all/erb.rb +0 -0
  49. data/tmpsets/set/{mod002-core → mod001-core}/all/event.rb +0 -0
  50. data/tmpsets/set/{mod002-core → mod001-core}/all/export.rb +0 -0
  51. data/tmpsets/set/{mod002-core → mod001-core}/all/fetch.rb +12 -14
  52. data/tmpsets/set/{mod002-core → mod001-core}/all/haml.rb +0 -0
  53. data/tmpsets/set/{mod002-core → mod001-core}/all/initialize.rb +0 -0
  54. data/tmpsets/set/{mod002-core → mod001-core}/all/location_history.rb +0 -0
  55. data/tmpsets/set/{mod002-core → mod001-core}/all/name.rb +0 -0
  56. data/tmpsets/set/{mod002-core → mod001-core}/all/name_validations.rb +0 -0
  57. data/tmpsets/set/{mod002-core → mod001-core}/all/pattern.rb +0 -0
  58. data/tmpsets/set/{mod002-core → mod001-core}/all/permissions.rb +0 -0
  59. data/tmpsets/set/{mod002-core → mod001-core}/all/phases.rb +0 -0
  60. data/tmpsets/set/{mod002-core → mod001-core}/all/references.rb +0 -0
  61. data/tmpsets/set/{mod002-core → mod001-core}/all/rules.rb +0 -0
  62. data/tmpsets/set/{mod002-core → mod001-core}/all/stages.rb +0 -0
  63. data/tmpsets/set/{mod002-core → mod001-core}/all/states.rb +0 -0
  64. data/tmpsets/set/{mod002-core → mod001-core}/all/subcards.rb +0 -0
  65. data/tmpsets/set/{mod002-core → mod001-core}/all/templating.rb +0 -0
  66. data/tmpsets/set/{mod002-core → mod001-core}/all/tracked_attributes.rb +0 -0
  67. data/tmpsets/set/{mod002-core → mod001-core}/all/trash.rb +0 -50
  68. data/tmpsets/set/{mod002-core → mod001-core}/all/type.rb +0 -0
  69. data/tmpsets/set/{mod002-core → mod001-core}/all/utils.rb +33 -0
  70. data/tmpsets/set/{mod002-core → mod001-core}/all/view_cache.rb +0 -0
  71. data/tmpsets/set/{mod003-history → mod002-history}/all/actions.rb +0 -0
  72. data/tmpsets/set/{mod003-history → mod002-history}/all/content_history.rb +0 -0
  73. data/tmpsets/set/{mod003-history → mod002-history}/all/history.rb +0 -0
  74. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/all/all_css.rb +0 -0
  75. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/all/all_csv.rb +0 -0
  76. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/all/all_js.rb +0 -0
  77. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/all/base.rb +0 -0
  78. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/all/file.rb +0 -0
  79. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/all/json.rb +0 -0
  80. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/all/rss.rb +0 -0
  81. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/all/text.rb +0 -0
  82. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/self/01_head/javascript.rb +0 -0
  83. data/tmpsets/set/{mod004-basic_formats → mod003-basic_formats}/self/head.rb +1 -1
  84. data/tmpsets/set/{mod005-pointer → mod004-pointer}/abstract/01_pointer.rb +0 -0
  85. data/tmpsets/set/{mod005-pointer → mod004-pointer}/abstract/01_pointer/edit.rb +0 -0
  86. data/tmpsets/set/{mod005-pointer → mod004-pointer}/abstract/code_pointer.rb +0 -0
  87. data/tmpsets/set/{mod005-pointer → mod004-pointer}/self/script_editors.rb +0 -0
  88. data/tmpsets/set/{mod005-pointer → mod004-pointer}/self/script_mods.rb +0 -0
  89. data/tmpsets/set/{mod005-pointer → mod004-pointer}/self/script_pointer_config.rb +0 -0
  90. data/tmpsets/set/{mod005-pointer → mod004-pointer}/type/pointer.rb +0 -0
  91. data/tmpsets/set/{mod006-ace_editor → mod005-ace_editor}/abstract/ace_editor.rb +0 -0
  92. data/tmpsets/set/{mod006-ace_editor → mod005-ace_editor}/self/script_ace.rb +0 -0
  93. data/tmpsets/set/{mod006-ace_editor → mod005-ace_editor}/self/script_ace_config.rb +0 -0
  94. data/tmpsets/set/{mod007-prosemirror_editor → mod006-prosemirror_editor}/abstract/prosemirror_editor.rb +0 -0
  95. data/tmpsets/set/{mod007-prosemirror_editor → mod006-prosemirror_editor}/self/script_prosemirror.rb +0 -0
  96. data/tmpsets/set/{mod007-prosemirror_editor → mod006-prosemirror_editor}/self/script_prosemirror_config.rb +0 -0
  97. data/tmpsets/set/{mod009-solid_cache → mod008-solid_cache}/abstract/solid_cache.rb +1 -1
  98. data/tmpsets/set/{mod009-solid_cache → mod008-solid_cache}/all/solid_cache.rb +0 -0
  99. data/tmpsets/set/{mod009-solid_cache → mod008-solid_cache}/right/solid_cache.rb +0 -0
  100. data/tmpsets/set/{mod010-basic_types → mod009-basic_types}/type/html.rb +0 -0
  101. data/tmpsets/set/{mod010-basic_types → mod009-basic_types}/type/plain_text.rb +0 -0
  102. data/tmpsets/set/{mod011-machines → mod010-machines}/abstract/script.rb +0 -0
  103. data/tmpsets/set/{mod011-machines → mod010-machines}/all/reset_machines.rb +0 -0
  104. data/tmpsets/set/{mod011-machines → mod010-machines}/right/machine_cache.rb +0 -0
  105. data/tmpsets/set/{mod011-machines → mod010-machines}/right/machine_input.rb +0 -0
  106. data/tmpsets/set/{mod011-machines → mod010-machines}/right/machine_output.rb +1 -9
  107. data/tmpsets/set/{mod011-machines → mod010-machines}/self/script_card_menu.rb +0 -0
  108. data/tmpsets/set/{mod011-machines → mod010-machines}/self/script_html5shiv_printshiv.rb +0 -0
  109. data/tmpsets/set/{mod011-machines → mod010-machines}/self/script_jquery.rb +0 -0
  110. data/tmpsets/set/{mod011-machines → mod010-machines}/self/script_jquery_helper.rb +0 -0
  111. data/tmpsets/set/{mod011-machines → mod010-machines}/self/script_slot.rb +0 -0
  112. data/tmpsets/set/{mod011-machines → mod010-machines}/self/style_bootstrap_compatible.rb +0 -0
  113. data/tmpsets/set/{mod011-machines → mod010-machines}/self/style_cards.rb +0 -0
  114. data/tmpsets/set/{mod011-machines → mod010-machines}/self/style_jquery_ui_smoothness.rb +0 -0
  115. data/tmpsets/set/{mod011-machines → mod010-machines}/type/coffee_script.rb +6 -2
  116. data/tmpsets/set/{mod011-machines → mod010-machines}/type/css.rb +2 -2
  117. data/tmpsets/set/{mod011-machines → mod010-machines}/type/java_script.rb +2 -2
  118. data/tmpsets/set/{mod011-machines → mod010-machines}/type/scss.rb +0 -0
  119. data/tmpsets/set/{mod011-machines → mod010-machines}/type/skin.rb +2 -2
  120. data/tmpsets/set/{mod012-settings → mod011-settings}/abstract/permission.rb +0 -0
  121. data/tmpsets/set/{mod012-settings → mod011-settings}/right/add_help.rb +0 -0
  122. data/tmpsets/set/{mod012-settings → mod011-settings}/right/comment.rb +0 -0
  123. data/tmpsets/set/{mod012-settings → mod011-settings}/right/create.rb +0 -0
  124. data/tmpsets/set/{mod012-settings → mod011-settings}/right/default.rb +0 -0
  125. data/tmpsets/set/{mod012-settings → mod011-settings}/right/delete.rb +0 -0
  126. data/tmpsets/set/{mod012-settings → mod011-settings}/right/help.rb +0 -0
  127. data/tmpsets/set/{mod012-settings → mod011-settings}/right/read.rb +0 -0
  128. data/tmpsets/set/{mod012-settings → mod011-settings}/right/script.rb +1 -1
  129. data/tmpsets/set/{mod012-settings → mod011-settings}/right/structure.rb +0 -0
  130. data/tmpsets/set/{mod012-settings → mod011-settings}/right/style.rb +1 -1
  131. data/tmpsets/set/{mod012-settings → mod011-settings}/right/update.rb +0 -0
  132. data/tmpsets/set/{mod012-settings → mod011-settings}/self/accountable.rb +0 -0
  133. data/tmpsets/set/{mod012-settings → mod011-settings}/self/add_help.rb +0 -0
  134. data/tmpsets/set/{mod012-settings → mod011-settings}/self/autoname.rb +0 -0
  135. data/tmpsets/set/{mod012-settings → mod011-settings}/self/captcha.rb +0 -0
  136. data/tmpsets/set/{mod012-settings → mod011-settings}/self/create.rb +0 -0
  137. data/tmpsets/set/{mod012-settings → mod011-settings}/self/default.rb +0 -0
  138. data/tmpsets/set/{mod012-settings → mod011-settings}/self/default_html_view.rb +0 -0
  139. data/tmpsets/set/{mod012-settings → mod011-settings}/self/delete.rb +0 -0
  140. data/tmpsets/set/{mod012-settings → mod011-settings}/self/follow_fields.rb +0 -0
  141. data/tmpsets/set/{mod012-settings → mod011-settings}/self/help.rb +0 -0
  142. data/tmpsets/set/{mod012-settings → mod011-settings}/self/input.rb +0 -0
  143. data/tmpsets/set/{mod012-settings → mod011-settings}/self/layout.rb +0 -0
  144. data/tmpsets/set/{mod012-settings → mod011-settings}/self/on_create.rb +0 -0
  145. data/tmpsets/set/{mod012-settings → mod011-settings}/self/on_delete.rb +0 -0
  146. data/tmpsets/set/{mod012-settings → mod011-settings}/self/on_update.rb +0 -0
  147. data/tmpsets/set/{mod012-settings → mod011-settings}/self/options.rb +0 -0
  148. data/tmpsets/set/{mod012-settings → mod011-settings}/self/options_label.rb +0 -0
  149. data/tmpsets/set/{mod012-settings → mod011-settings}/self/read.rb +0 -0
  150. data/tmpsets/set/{mod012-settings → mod011-settings}/self/recent_settings.rb +0 -0
  151. data/tmpsets/set/{mod012-settings → mod011-settings}/self/script.rb +0 -0
  152. data/tmpsets/set/{mod012-settings → mod011-settings}/self/structure.rb +0 -0
  153. data/tmpsets/set/{mod012-settings → mod011-settings}/self/style.rb +0 -0
  154. data/tmpsets/set/{mod012-settings → mod011-settings}/self/table_of_contents.rb +0 -0
  155. data/tmpsets/set/{mod012-settings → mod011-settings}/self/thanks.rb +0 -0
  156. data/tmpsets/set/{mod012-settings → mod011-settings}/self/update.rb +0 -0
  157. data/tmpsets/set/{mod012-settings → mod011-settings}/type/setting.rb +0 -0
  158. data/tmpsets/set/{mod013-email → mod012-email}/all/email_html.rb +0 -0
  159. data/tmpsets/set/{mod013-email → mod012-email}/all/email_text.rb +0 -0
  160. data/tmpsets/set/{mod013-email → mod012-email}/all/follow.rb +0 -0
  161. data/tmpsets/set/{mod013-email → mod012-email}/all/notify.rb +0 -0
  162. data/tmpsets/set/{mod013-email → mod012-email}/all/observer.rb +0 -0
  163. data/tmpsets/set/{mod013-email → mod012-email}/right/bcc.rb +0 -0
  164. data/tmpsets/set/{mod013-email → mod012-email}/right/cc.rb +0 -0
  165. data/tmpsets/set/{mod013-email → mod012-email}/right/follow.rb +0 -0
  166. data/tmpsets/set/{mod013-email → mod012-email}/right/follow_fields.rb +0 -0
  167. data/tmpsets/set/{mod013-email → mod012-email}/right/followers.rb +0 -0
  168. data/tmpsets/set/{mod013-email → mod012-email}/right/following.rb +0 -0
  169. data/tmpsets/set/{mod013-email → mod012-email}/right/from.rb +0 -0
  170. data/tmpsets/set/{mod013-email → mod012-email}/right/html_message.rb +0 -0
  171. data/tmpsets/set/{mod013-email → mod012-email}/right/to.rb +0 -0
  172. data/tmpsets/set/{mod013-email → mod012-email}/self/always.rb +0 -0
  173. data/tmpsets/set/{mod013-email → mod012-email}/self/created.rb +0 -0
  174. data/tmpsets/set/{mod013-email → mod012-email}/self/edited.rb +0 -0
  175. data/tmpsets/set/{mod013-email → mod012-email}/self/follow.rb +0 -0
  176. data/tmpsets/set/{mod013-email → mod012-email}/self/follow_defaults.rb +0 -0
  177. data/tmpsets/set/{mod013-email → mod012-email}/self/never.rb +0 -0
  178. data/tmpsets/set/{mod013-email → mod012-email}/type/email_template.rb +0 -0
  179. data/tmpsets/set/{mod013-email → mod012-email}/type_plus_right/user/follow.rb +8 -4
  180. data/tmpsets/set/mod016-standard/all/links.rb +2 -2
  181. data/tmpsets/set/mod018-bootstrap/all/bootstrap/table.rb +1 -1
  182. data/tmpsets/set/mod018-bootstrap/self/bootswatch_shared.rb +1 -1
  183. metadata +149 -163
  184. data/lib/card/director_register.rb +0 -101
  185. data/lib/card/stage.rb +0 -106
  186. data/lib/card/stage_director.rb +0 -310
  187. data/lib/card/subdirector_array.rb +0 -43
  188. data/tmpsets/set/mod001-admin/self/admin.rb +0 -130
  189. data/tmpsets/set/mod001-admin/self/admin_info.rb +0 -110
  190. data/tmpsets/set/mod001-admin/self/version.rb +0 -15
  191. data/tmpsets/set/mod002-core/all/debug.rb +0 -30
  192. data/tmpsets/set/mod002-core/all/update_read_rules.rb +0 -91
  193. data/tmpsets/set/mod011-machines/abstract/machine.rb +0 -277
  194. data/tmpsets/set/mod011-machines/abstract/machine_input.rb +0 -83
  195. data/tmpsets/set/mod014-developer/all/event_viz.rb +0 -59
  196. data/tmpsets/set/mod014-developer/all/view_viz.rb +0 -30
  197. data/tmpsets/set/mod014-developer/right/debug.rb +0 -96
  198. data/tmpsets/set/mod015-carrierwave/abstract/attachment.rb +0 -118
  199. data/tmpsets/set/mod015-carrierwave/abstract/attachment/paths.rb +0 -57
  200. data/tmpsets/set/mod015-carrierwave/abstract/attachment/storage_type.rb +0 -326
  201. data/tmpsets/set/mod015-carrierwave/abstract/attachment/upload_cache.rb +0 -84
  202. data/tmpsets/set/mod015-carrierwave/all/file_utils.rb +0 -35
  203. data/tmpsets/set/mod015-carrierwave/self/admin.rb +0 -30
  204. data/tmpsets/set/mod015-carrierwave/type/file.rb +0 -158
  205. data/tmpsets/set/mod015-carrierwave/type/image.rb +0 -97
@@ -0,0 +1,43 @@
1
+ class Card
2
+ class ActManager
3
+ class SubdirectorArray < Array
4
+ def self.initialize_with_subcards parent
5
+ dir_array = new(parent)
6
+ parent.card.subcards.each_card do |subcard|
7
+ dir_array.add subcard
8
+ end
9
+ dir_array
10
+ end
11
+
12
+ def initialize parent
13
+ @parent = parent
14
+ super()
15
+ end
16
+
17
+ def add card, opts={}
18
+ card = card.card if card.is_a? StageDirector
19
+ each { |dir| return dir if dir.card == card }
20
+ dir = ActManager.fetch card, parent: @parent
21
+ dir.main = false
22
+ dir.parent = @parent
23
+ dir.transact_in_stage = opts[:transact_in_stage]
24
+ self << dir
25
+ dir
26
+ end
27
+
28
+ alias_method :delete_director, :delete
29
+
30
+ def delete card
31
+ if card.is_a? StageDirector
32
+ delete_director card
33
+ else
34
+ delete_if { |dir| dir.card == card }
35
+ end
36
+ end
37
+
38
+ def add_director dir
39
+ add dir.card
40
+ end
41
+ end
42
+ end
43
+ end
@@ -74,6 +74,7 @@ class Card
74
74
  include AdvancedApi
75
75
  include Helpers
76
76
 
77
+ extend I18nScope
77
78
  extend Loader
78
79
 
79
80
  mattr_accessor :modules, :traits
@@ -0,0 +1,52 @@
1
+ class Card
2
+ module Set
3
+ module I18nScope
4
+ # return scope for I18n
5
+ def scope backtrace
6
+ parts = tmp_set_path_parts backtrace
7
+ "mod.#{parts.first}.set.#{parts[1..-1].join '.'}"
8
+ end
9
+
10
+ # extract the mod name from the path of a set's tmp file
11
+ def mod_name backtrace
12
+ tmp_set_path_parts(backtrace).first
13
+ end
14
+
15
+ private
16
+
17
+ # extract mod and set from tmp path
18
+ # @example
19
+ # a tmp paths looks like ~/mydeck/tmp/set/mod002-core/all/event.rb/
20
+ # this method returns ["core", "all", "event"]
21
+ def tmp_set_path_parts backtrace
22
+ path_parts = find_tmp_set_path(backtrace).split(File::SEPARATOR)
23
+ res = path_parts[path_mod_index(path_parts)..-1]
24
+ res[0] = mod_name_from_tmp_dir res.first
25
+ res[-1] = res.last.split(".").first
26
+ res
27
+ end
28
+
29
+ def find_tmp_set_path backtrace
30
+ path = backtrace.find { |line| line.include? "tmp/set/" }
31
+ unless path
32
+ raise Error, "couldn't find set path in backtrace: #{backtrace}"
33
+ end
34
+ path
35
+ end
36
+
37
+ # index of the mod part in the tmp path
38
+ def path_mod_index parts
39
+ unless (set_index = parts.index("set")) &&
40
+ parts.size >= set_index + 2
41
+ raise Error, "not a valid set path: #{path}"
42
+ end
43
+ set_index + 1
44
+ end
45
+
46
+ def mod_name_from_tmp_dir dir
47
+ match = dir.match(/^mod\d+-(?<mod_name>.+)$/)
48
+ match[:mod_name]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -12,7 +12,6 @@
12
12
  class Card
13
13
  def subcards
14
14
  @subcards ||= Subcards.new(self)
15
- # @subcards ||= (director && director.subcards)
16
15
  end
17
16
 
18
17
  def expire_subcards
@@ -82,7 +81,7 @@ class Card
82
81
  def clear
83
82
  @keys.each do |key|
84
83
  if (subcard = fetch_subcard key)
85
- Card::DirectorRegister.delete subcard.director
84
+ ActManager.delete subcard.director
86
85
  end
87
86
  Card.cache.soft.delete key
88
87
  end
@@ -104,7 +103,7 @@ class Card
104
103
  @keys.delete key
105
104
  removed_card = fetch_subcard key
106
105
  removed_card.current_action.delete if removed_card.current_action
107
- Card::DirectorRegister.deep_delete removed_card.director
106
+ ActManager.deep_delete removed_card.director
108
107
  Card.cache.soft.delete key
109
108
  removed_card
110
109
  end
@@ -1,7 +1,8 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  require "active_support/core_ext/numeric/time"
4
- require "delayed_job_active_record"
4
+ djar = "delayed_job_active_record"
5
+ require djar if Gem::Specification.find_all_by_name(djar).any?
5
6
  require "cardio/schema.rb"
6
7
 
7
8
  ActiveSupport.on_load :card do
@@ -16,11 +17,11 @@ module Cardio
16
17
  extend Schema
17
18
  CARD_GEM_ROOT = File.expand_path("../..", __FILE__)
18
19
 
19
- mattr_reader :paths, :config, :cache
20
+ mattr_reader :paths, :config
20
21
 
21
22
  class << self
22
23
  def cache
23
- @@cache ||= ::Rails.cache
24
+ @cache ||= ::Rails.cache
24
25
  end
25
26
 
26
27
  def default_configs
@@ -63,7 +64,6 @@ module Cardio
63
64
 
64
65
  def set_config config
65
66
  @@config = config
66
- @@root = config.root
67
67
 
68
68
  config.autoload_paths += Dir["#{gem_root}/lib/**/"]
69
69
  config.autoload_paths += Dir["#{gem_root}/mod/*/lib/**/"]
@@ -5,7 +5,6 @@ basket :tasks
5
5
  event :admin_tasks, :initialize, on: :update do
6
6
  return unless (task = Env.params[:task])
7
7
  raise Card::Error::PermissionDenied, self unless Auth.always_ok?
8
-
9
8
  case task.to_sym
10
9
  when :clear_cache then Card::Cache.reset_all
11
10
  when :repair_references then Card::Reference.repair_all
@@ -15,7 +14,7 @@ event :admin_tasks, :initialize, on: :update do
15
14
  when :clear_solid_cache then Card.clear_solid_cache
16
15
  when :clear_machine_cache then Card.reset_all_machines
17
16
  else
18
- task_data = tasks.find { |h| h[:name].to_sym == task }
17
+ task_data = tasks.find { |h| h[:name].to_sym == task.to_sym }
19
18
  task_data[:execute_policy].call if task_data
20
19
  end
21
20
  abort :success
@@ -0,0 +1,29 @@
1
+ format :html do
2
+ def trashed_cards
3
+ Card.where(trash: true)
4
+ end
5
+
6
+ view :core do |_args|
7
+ rows =
8
+ trashed_cards.map do |card|
9
+ [card.name, Card[card.updater_id].name, put_back_link(card)]
10
+ end
11
+ output [
12
+ (content_tag(:p, empty_trash_link) if rows.present?),
13
+ table(rows, header: ["card", "deleted by", ""])
14
+ ]
15
+ end
16
+
17
+ def empty_trash_link
18
+ card_link :admin, path_opts: { action: :update, task: :empty_trash,
19
+ success: { id: "~#{card.id}" } },
20
+ text: "empty trash"
21
+ end
22
+
23
+ def put_back_link card
24
+ before_delete = card.actions[-2]
25
+ link_path = path action: :update, view: :open, action_ids: [before_delete],
26
+ success: { id: card.name }
27
+ link_to "put back", link_path, method: :post, rel: "nofollow"
28
+ end
29
+ end
@@ -1,24 +1,6 @@
1
1
  def self.included host_class
2
2
  host_class.mattr_accessor :file_content_mod_name
3
- host_class.file_content_mod_name = mod_name(caller)
4
- end
5
-
6
- # try to extract the mod name from the path of the set's tmp file
7
- # the caller that included the set file is set.rb
8
- def self.mod_name backtrace
9
- mod_dir = tmp_mod_dir backtrace
10
- raise Error, "not a valid set path: #{path}" unless mod_dir
11
- match = mod_dir.match(/^mod\d+-(?<mod_name>.+)$/)
12
- match[:mod_name]
13
- end
14
-
15
- def self.tmp_mod_dir backtrace
16
- path = backtrace.find { |line| line.include? "tmp/set/" }
17
- raise Error, "couldn't find set path in backtrace: #{backtrace}" unless path
18
- path_parts = path.split(File::SEPARATOR)
19
- path_parts.fetch(path_parts.index("set") + 1) do
20
- raise Error, "not a valid set path: #{path}"
21
- end
3
+ host_class.file_content_mod_name = Card::Set.mod_name(caller)
22
4
  end
23
5
 
24
6
  # @return [Array<String>, String] the name of file(s) to be loaded
@@ -39,12 +21,10 @@ def source_dir
39
21
  end
40
22
 
41
23
  def find_file filename
42
- Card.paths["mod"].to_a.each do |mod_path|
43
- file_path =
44
- File.join(mod_path, file_content_mod_name, "lib", source_dir, filename)
45
- return file_path if File.exist? file_path
46
- end
47
- nil
24
+ mod_path = Card::Mod::Loader.mod_dirs.path file_content_mod_name
25
+ file_path = File.join(mod_path, "lib", source_dir, filename)
26
+ return unless File.exist? file_path
27
+ file_path
48
28
  end
49
29
 
50
30
  def existing_source_paths
@@ -19,6 +19,41 @@ def abort status, msg="action canceled"
19
19
  raise Card::Error::Abort.new(status, msg)
20
20
  end
21
21
 
22
+ def act opts={}
23
+ if ActManager.act_card
24
+ add_to_act opts
25
+ main_act_block = false
26
+ else
27
+ start_new_act opts
28
+ main_act_block = true
29
+ end
30
+ yield
31
+ ensure
32
+ ActManager.clear if main_act_block
33
+ end
34
+
35
+ def start_new_act opts
36
+ ActManager.clear
37
+ self.director = nil
38
+ ActManager.act_card = self
39
+ if opts && opts[:success]
40
+ Env[:success] = Env::Success.new(cardname, Env.params[:success])
41
+ end
42
+ end
43
+
44
+ def add_to_act opts
45
+ # if only_storage_phase is true the card is already part of the act
46
+ return if ActManager.act_card == self || only_storage_phase
47
+ director.reset_stage
48
+ if opts && opts[:trash]
49
+ @action = :delete
50
+ else
51
+ identify_action
52
+ end
53
+ director.update_card self
54
+ self.only_storage_phase = true
55
+ end
56
+
22
57
  module ClassMethods
23
58
  def create! opts
24
59
  card = Card.new opts
@@ -8,21 +8,18 @@ module ClassMethods
8
8
  # * database
9
9
  # * virtual cards
10
10
  #
11
- # @param mark [Integer, String, Card::Name, Symbol, Array]
12
- # one of three unique identifiers
13
- # 1. a numeric id (Integer)
14
- # 2. a name/key (String or Card::Name)
15
- # 3. a codename (Symbol)
16
- # or any combination of those. If you pass more then one mark they get
17
- # joined with a '+'
18
- # @param options [Hash]
19
- # Options:
20
- # :skip_virtual Real cards only
21
- # :skip_modules Don't load Set modules
22
- # :look_in_trash Return trashed card objects
23
- # :local_only Use only local cache for lookup and storing
24
- # new: { opts for Card#new } Return a new card when not found
25
- #
11
+ # @param args [Integer, String, Card::Name, Symbol]
12
+ # one or more of the three unique identifiers
13
+ # 1. a numeric id (Integer)
14
+ # 2. a name/key (String or Card::Name)
15
+ # 3. a codename (Symbol)
16
+ # If you pass more then one mark they get joined with a '+'.
17
+ # The final argument can be a hash to set the following options
18
+ # :skip_virtual Real cards only
19
+ # :skip_modules Don't load Set modules
20
+ # :look_in_trash Return trashed card objects
21
+ # :local_only Use only local cache for lookup and storing
22
+ # new: { opts for Card#new } Return a new card when not found
26
23
  # @return [Card]
27
24
  def fetch *args
28
25
  mark, opts = normalize_fetch_args args
@@ -0,0 +1,9 @@
1
+ def t key, args={}
2
+ I18n.t key, args.merge(scope: Card::Set.scope(caller))
3
+ end
4
+
5
+ format do
6
+ def t key, args={}
7
+ I18n.t key, args.merge(scope: Card::Set.scope(caller))
8
+ end
9
+ end
@@ -12,5 +12,5 @@ delegate :storage_phase, to: :director
12
12
  delegate :integration_phase, to: :director
13
13
 
14
14
  def clean_up
15
- Card::DirectorRegister.clear
15
+ Card::ActManager.clear
16
16
  end
@@ -1,8 +1,8 @@
1
1
  attr_writer :director
2
- delegate :stage, to: :director
2
+ delegate :act_manager, to: :director
3
3
 
4
4
  def director
5
- @director ||= Card::DirectorRegister.fetch self
5
+ @director ||= Card::ActManager.fetch self
6
6
  end
7
7
 
8
8
  def identify_action
@@ -15,7 +15,8 @@ require_dependency 'active_support/callbacks_ext'
15
15
  # prevent events from showing up in the tree.
16
16
  def events action
17
17
  @action = action
18
- events = Card::Stage::STAGES.map { |stage| events_tree("#{stage}_stage") }
18
+ events =
19
+ ActManager::Stage::STAGES.map { |stage| events_tree("#{stage}_stage") }
19
20
  @action = nil
20
21
  puts_events events
21
22
  end
@@ -68,7 +68,7 @@ def silent_change
68
68
  end
69
69
 
70
70
  def silent_change?
71
- silent_change.nil? ? !Card::Env[:controller] : silent_change
71
+ silent_change || !Card::Env[:controller]
72
72
  end
73
73
 
74
74
  def notable_change?
@@ -70,7 +70,7 @@ class Card
70
70
  # @return [Card]
71
71
  def card
72
72
  res = Card.fetch card_id, look_in_trash: true, skip_modules: true
73
- return res unless res.type_id.in? [FileID, ImageID]
73
+ return res unless res && res.type_id.in?([FileID, ImageID])
74
74
  res.include_set_modules
75
75
  end
76
76
 
@@ -62,7 +62,7 @@ class Card
62
62
  # @return [Card]
63
63
  def card
64
64
  res = Card.fetch card_id, look_in_trash: true, skip_modules: true
65
- return res unless res.type_id.in? [FileID, ImageID]
65
+ return res unless res && res.type_id.in?([FileID, ImageID])
66
66
  res.include_set_modules
67
67
  end
68
68
 
@@ -62,7 +62,7 @@ event :finalize_act,
62
62
  end
63
63
 
64
64
  def act_card?
65
- self == DirectorRegister.act_card
65
+ self == Card::ActManager.act_card
66
66
  end
67
67
 
68
68
  event :rollback_actions, :prepare_to_validate,
@@ -239,7 +239,7 @@ def unlock!
239
239
  end
240
240
 
241
241
  def update_input_card
242
- if DirectorRegister.running_act?
242
+ if Card::ActManager.running_act?
243
243
  input_card = attach_subcard! machine_input_card
244
244
  input_card.content = ""
245
245
  engine_input.each { |input| input_card << input }
@@ -6,7 +6,7 @@ describe Card::Set::Type::CoffeeScript do
6
6
  let(:changed_coffee) { 'alert "Hello" ' }
7
7
  let(:compressed_changed_coffee) { '(function(){alert("Hello")}).call(this);' }
8
8
 
9
- it_should_behave_like "content machine", that_produces_js do
9
+ it_should_behave_like "content machine", that_produces: :js do
10
10
  let(:machine_card) do
11
11
  Card.gimme! "coffee machine", type: Card::CoffeeScriptID,
12
12
  content: coffee
@@ -30,7 +30,7 @@ describe Card::Set::Type::Css do
30
30
  end
31
31
  end
32
32
 
33
- it_behaves_like "content machine", that_produces_css do
33
+ it_behaves_like "content machine", that_produces: :css do
34
34
  let(:machine_card) { Card.gimme! "test css", type: :css, content: css }
35
35
  let(:card_content) do
36
36
  { in: css, out: compressed_css,
@@ -10,7 +10,7 @@ describe Card::Set::Type::JavaScript do
10
10
  "//#{source}\n#{content}"
11
11
  end
12
12
 
13
- it_should_behave_like "content machine", that_produces_js do
13
+ it_should_behave_like "content machine", that_produces: :js do
14
14
  let(:machine_card) do
15
15
  Card.gimme! "test javascript", type: :java_script, content: js
16
16
  end