card 1.95.3 → 1.96.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 (85) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/card.rb +10 -2
  4. data/lib/card/migration/import.rb +1 -1
  5. data/lib/card/set.rb +1 -1
  6. data/lib/card/set/event.rb +63 -65
  7. data/lib/card/set/event/callbacks.rb +21 -0
  8. data/lib/card/set/event/delayed_event.rb +11 -16
  9. data/lib/card/set/event/options.rb +78 -0
  10. data/lib/card/set/format.rb +5 -93
  11. data/lib/card/set/format/abstract_format.rb +104 -0
  12. data/mod/Modfile +1 -0
  13. data/mod/basic_formats/set/all/all_csv.rb +1 -1
  14. data/mod/basic_formats/set/all/json.rb +61 -4
  15. data/mod/basic_formats/spec/set/all/json_spec.rb +51 -1
  16. data/mod/basic_formats/spec/shared_context/json_shared_context.rb +40 -0
  17. data/mod/bootstrap/lib/stylesheets/style_bootstrap_cards.scss +17 -1
  18. data/mod/bootstrap/set/abstract/bootswatch_theme.rb +2 -12
  19. data/mod/bootstrap/set/abstract/bootswatch_theme/html_views.rb +31 -0
  20. data/mod/bootstrap/set/type/customized_bootswatch_skin.rb +12 -0
  21. data/mod/bootstrap/set/type/customized_bootswatch_skin/core.haml +5 -0
  22. data/mod/bootstrap/set/type/customized_bootswatch_skin/html_views.rb +36 -0
  23. data/mod/bootstrap/set/type_plus_right/customized_bootswatch_skin/colors.rb +14 -10
  24. data/mod/bootstrap/set/type_plus_right/customized_bootswatch_skin/colors/_colorpicker.haml +1 -1
  25. data/mod/bootstrap/set/type_plus_right/customized_bootswatch_skin/colors/editor.haml +13 -9
  26. data/mod/core/chunk/link.rb +8 -0
  27. data/mod/core/set/abstract/code_file.rb +5 -0
  28. data/mod/core/set/all/chunk.rb +46 -24
  29. data/mod/core/set/all/event_conditions.rb +32 -11
  30. data/mod/core/set/all/export.rb +3 -5
  31. data/mod/core/set/all/item.rb +16 -0
  32. data/mod/core/set/all/name.rb +1 -0
  33. data/mod/core/set/all/references.rb +25 -16
  34. data/mod/core/set/all/rename.rb +20 -21
  35. data/mod/core/set/all/trash.rb +13 -4
  36. data/mod/core/spec/set/all/actify_spec.rb +4 -4
  37. data/mod/core/spec/set/all/event_conditions_spec.rb +68 -10
  38. data/mod/core/spec/set/all/export_spec.rb +7 -4
  39. data/mod/core/spec/set/all/references_spec.rb +38 -1
  40. data/mod/core/spec/set/all/rename_spec.rb +15 -9
  41. data/mod/follow/spec/set/right/followers_spec.rb +1 -1
  42. data/mod/follow/spec/set/right/following_spec.rb +4 -8
  43. data/mod/follow/spec/set/type/notification_template_spec.rb +1 -1
  44. data/mod/history/set/all/act_view.rb +2 -2
  45. data/mod/item/set/all/bar.haml +12 -0
  46. data/mod/item/set/all/bar.rb +77 -0
  47. data/mod/item/set/all/box.haml +10 -0
  48. data/mod/item/set/all/box.rb +8 -0
  49. data/mod/item/set/all/expanded_bar.haml +10 -0
  50. data/mod/machines/file/all_script_machine_output/file.js +30622 -66
  51. data/mod/machines/file/all_style_machine_output/file.css +3 -3
  52. data/mod/machines/file/script_html5shiv_printshiv_machine_output/file.js +1 -1
  53. data/mod/machines/lib/javascript/decko_slot.js.coffee +18 -13
  54. data/mod/machines/set/abstract/skin_box.rb +34 -0
  55. data/mod/machines/set/abstract/skin_box/box_bottom.haml +4 -0
  56. data/mod/machines/set/type/skin.rb +1 -1
  57. data/mod/pointer/set/abstract/01_paging.rb +49 -4
  58. data/mod/pointer/set/abstract/01_paging/paging_links.rb +6 -6
  59. data/mod/pointer/set/abstract/02_pointer/html_views.rb +10 -0
  60. data/mod/pointer/set/abstract/02_pointer/other_views.rb +9 -5
  61. data/mod/pointer/spec/set/abstract/pointer/html_views_spec.rb +4 -10
  62. data/mod/pointer/spec/set/abstract/pointer/other_views_spec.rb +20 -1
  63. data/mod/search/set/abstract/01_filter_form_helper.rb +4 -4
  64. data/mod/search/set/abstract/02_search_params.rb +1 -1
  65. data/mod/search/set/abstract/03_filter.rb +8 -0
  66. data/mod/search/set/abstract/search.rb +10 -0
  67. data/mod/settings/set/right/style.rb +13 -0
  68. data/mod/settings/set/right/style/editor.haml +4 -4
  69. data/mod/standard/set/all/path.rb +6 -0
  70. data/mod/standard/set/type/list.rb +3 -2
  71. data/mod/standard/set/type/listed_by.rb +5 -1
  72. data/mod/standard/spec/content/chunk/include_spec.rb +2 -2
  73. data/mod/standard/spec/set/all/rich_html/editing_spec.rb +4 -69
  74. data/mod/standard/spec/set/type/listed_by_spec.rb +2 -2
  75. data/mod/standard/spec/set/type/search_type_spec.rb +56 -0
  76. data/mod/standard/spec/set/type/set/html_views_spec.rb +5 -9
  77. data/mod/utility/set/abstract/bs_badge.rb +21 -0
  78. data/mod/utility/set/abstract/bs_badge/bs_badge.haml +5 -0
  79. data/mod/utility/set/abstract/bs_badge/labeled_badge.haml +5 -0
  80. data/mod/utility/set/abstract/bs_badge/tab_badge.haml +5 -0
  81. data/mod/utility/set/abstract/media.rb +27 -0
  82. data/mod/utility/set/abstract/media/media_snippet.haml +9 -0
  83. metadata +28 -10
  84. data/mod/machines/set/abstract/skin_thumbnail.rb +0 -28
  85. data/mod/machines/set/abstract/skin_thumbnail/thumbnail.haml +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6051bed4929802033973d16097fd41ae8b90b8b2
4
- data.tar.gz: 1392cf213a98410aac04baa57362e73666f9dad4
3
+ metadata.gz: a73062a82222809672762110ca1f6892dcf22cd7
4
+ data.tar.gz: 5315e20f640bd0efa37e00c3f2551b18a2856160
5
5
  SHA512:
6
- metadata.gz: c8028cbb5aa77a58fe9b0cdaef9aa16067591023ba25f76fca6d6d33f1a8592c8621ed8f7ad34890ea2b97b48548275f39f1ab21c62470c2641bcd53165570df
7
- data.tar.gz: 3d0afe134f4cdac0c227dc51913e7b4fc134fa729f7957ed5b3e0ecbfc48313c7f012b1a326744f5647fb95484a380e0a42218368a023ba9ef58b6074cebdad0
6
+ metadata.gz: 03f59ad4c0428b43d47e2c81c202e630293000057e53648a702fff25401e2791d497895fe17e71ca9600b5a4d7c5182da361ef19aa9fbe0b75595be7566cc9b1
7
+ data.tar.gz: f9c7550d1c9ea23c1f3447bcc2c1611afe434d4bd92e778410827fc07aeb73ab2b89cf0ac3091e14905d267454fec508c14166e06ec8fda8de7fb98630b2e66b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.6.0
@@ -141,11 +141,19 @@ class Card < ApplicationRecord
141
141
  :silent_change, # and this probably too
142
142
  # :remove_rule_stash,
143
143
  :last_action_id_before_edit,
144
- :only_storage_phase, # used to save subcards
144
+ :only_storage_phase, # used to save subcards
145
145
  :changed_attributes,
146
- :skip_event
146
+ :skip, # skip event(s) for all cards in act
147
+ :skip_in_action, # skip event for just this card
148
+ :trigger, # trigger event(s) for all cards in act
149
+ :trigger_in_action # trigger event for just this card
147
150
  )
148
151
 
152
+ alias_method :skip_event, :skip
153
+ alias_method :skip_event_in_action, :skip_in_action
154
+ alias_method :trigger_event, :trigger
155
+ alias_method :trigger_event_in_action, :trigger_in_action
156
+
149
157
  def serializable_attributes
150
158
  self.class.serializable_attributes + set_specific.keys
151
159
  end
@@ -99,7 +99,7 @@ class Card
99
99
 
100
100
  def fetch_local_data name, view
101
101
  Card::Auth.as_bot do
102
- Card[name].format(format: :json).render!(view || :content)
102
+ Card[name].format(format: :json).render!(view || :page)
103
103
  end
104
104
  end
105
105
 
@@ -36,7 +36,7 @@ class Card
36
36
  # b) then uses Card::Set module to provide API for the most common set methods.
37
37
  #
38
38
  module Set
39
- include Event
39
+ include Event::Api
40
40
  include Trait
41
41
  include Basket
42
42
  include Inheritance
@@ -8,99 +8,97 @@ class Card
8
8
  # * __integration__ deals with any ramifications of those changes
9
9
  #
10
10
  #
11
- module Event
12
- include DelayedEvent
13
-
14
- def event event, stage_or_opts={}, opts={}, &final
15
- opts = event_opts stage_or_opts, opts
16
- Card.define_callbacks event
17
- define_event event, opts, &final
18
- set_event_callbacks event, opts
11
+ class Event
12
+ module Api
13
+ def event event, stage_or_opts={}, opts={}, &final
14
+ Event.new(event, stage_or_opts, opts, self, &final).register
15
+ end
19
16
  end
20
17
 
21
- private
18
+ CONDITION_OPTIONS = {
19
+ on: %i[create update delete save read],
20
+ changed: %i[name content db_content type type_id codename key],
21
+ skip: :allowed,
22
+ trigger: :required, # the event is only executed if triggered explicitly with
23
+ # trigger: [event_name]
24
+ }.freeze
25
+
26
+ CONDITIONS = ::Set.new(%i[on changed when skip trigger]).freeze
22
27
 
23
- # EVENT OPTS
28
+ include DelayedEvent
29
+ include Options
30
+ include Callbacks
24
31
 
25
- def event_opts stage_or_opts, opts
26
- opts = normalize_opts stage_or_opts, opts
27
- process_stage_opts opts
28
- process_action_opts opts
29
- opts
32
+ attr_reader :set_module, :opts
33
+
34
+ def initialize event, stage_or_opts, opts, set_module, &final
35
+ @event = event
36
+ @set_module = set_module
37
+ @opts = event_opts stage_or_opts, opts
38
+ @event_block = final
30
39
  end
31
40
 
32
- def normalize_opts stage_or_opts, opts
33
- if stage_or_opts.is_a? Symbol
34
- opts[:in] = stage_or_opts
35
- else
36
- opts = stage_or_opts
37
- end
38
- opts
41
+ def register
42
+ validate_conditions
43
+ Card.define_callbacks @event
44
+ define_event
45
+ set_event_callbacks
39
46
  end
40
47
 
41
- def process_action_opts opts
42
- opts[:on] = [:create, :update] if opts[:on] == :save
48
+ # @return the name of the event
49
+ def name
50
+ @event
43
51
  end
44
52
 
45
- def process_stage_opts opts
46
- if opts[:after] || opts[:before]
47
- # ignore :in options
48
- elsif (in_opt = opts.delete :in)
49
- opts[:after] = callback_name in_opt, opts.delete(:after_subcards)
50
- end
53
+ def block
54
+ @event_block
55
+ end
56
+
57
+ # the name for the method that only executes the code
58
+ # defined in the event
59
+ def simple_method_name
60
+ "#{@event}_without_callbacks"
51
61
  end
52
62
 
53
- def callback_name stage, after_subcards=false
54
- name = after_subcards ? "#{stage}_final_stage" : "#{stage}_stage"
55
- name.to_sym
63
+ # the name for the method that adds the event to
64
+ # the delayed job queue
65
+ def delaying_method_name
66
+ "#{@event}_with_delay"
56
67
  end
57
68
 
69
+ private
70
+
58
71
  # EVENT DEFINITION
59
72
 
60
- def define_event event, opts, &final
61
- simple_method_name = "#{event}_without_callbacks"
62
- define_simple_method event, simple_method_name, &final
63
- define_event_method event, simple_method_name, opts
73
+ def define_event
74
+ define_simple_method
75
+ define_event_method
64
76
  end
65
77
 
66
- def define_simple_method _event, method_name, &method
67
- class_eval do
68
- define_method method_name, &method
78
+ def define_simple_method
79
+ @set_module.class_exec(self) do |event|
80
+ define_method event.simple_method_name, &event.block
69
81
  end
70
82
  end
71
83
 
72
- def define_event_method event, method_name, opts
73
- event_type = with_delay?(opts) ? :delayed : :standard
74
- send "define_#{event_type}_event_method", event, method_name
84
+ def define_event_method
85
+ send "define_#{event_type}_event_method"
86
+ end
87
+
88
+ def event_type
89
+ with_delay?(@opts) ? :delayed : :standard
75
90
  end
76
91
 
77
- def define_standard_event_method event, method_name
78
- class_eval do
79
- define_method event do
80
- log_event_call event
81
- run_callbacks event do
92
+ def define_standard_event_method method_name=simple_method_name
93
+ @set_module.class_exec(@event) do |event_name|
94
+ define_method event_name do
95
+ log_event_call event_name
96
+ run_callbacks event_name do
82
97
  send method_name
83
98
  end
84
99
  end
85
100
  end
86
101
  end
87
-
88
- # EVENT CALLBACKS
89
-
90
- def set_event_callbacks event, opts
91
- opts[:set] ||= self
92
- [:before, :after, :around].each do |kind|
93
- next unless (object_method = opts.delete kind)
94
- set_event_callback object_method, kind, event, opts
95
- end
96
- end
97
-
98
- def set_event_callback object_method, kind, event, opts
99
- Card.class_eval do
100
- set_callback object_method, kind, event,
101
- prepend: true, if: proc { |c| c.event_applies?(event, opts) }
102
- end
103
- end
104
102
  end
105
103
  end
106
104
 
@@ -0,0 +1,21 @@
1
+ class Card
2
+ module Set
3
+ class Event
4
+ module Callbacks
5
+ def set_event_callbacks
6
+ %i[before after around].each do |kind|
7
+ next unless (object_method = @opts.delete kind)
8
+ set_event_callback object_method, kind
9
+ end
10
+ end
11
+
12
+ def set_event_callback object_method, kind
13
+ Card.class_exec(self) do |event|
14
+ set_callback object_method, kind, event.name,
15
+ prepend: true, if: proc { |c| c.event_applies?(event) }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,6 @@
1
1
  class Card
2
2
  module Set
3
- module Event
3
+ class Event
4
4
  module DelayedEvent
5
5
  DELAY_STAGES = ::Set.new([:integrate_with_delay_stage,
6
6
  :integrate_with_delay_final_stage]).freeze
@@ -11,28 +11,23 @@ class Card
11
11
  DELAY_STAGES.include?(opts[:after]) || DELAY_STAGES.include?(opts[:before])
12
12
  end
13
13
 
14
- def define_delayed_event_method event, simple_method_name
15
- delaying_method = "#{event}_with_delay"
16
- define_event_delaying_method event, delaying_method, simple_method_name
17
- define_standard_event_method event, delaying_method
14
+ def define_delayed_event_method
15
+ define_event_delaying_method
16
+ define_standard_event_method delaying_method_name
18
17
  end
19
18
 
20
- # creates an ActiveJob.
19
+ # creates a method that creates an ActiveJob that calls the event method.
21
20
  # The scheduled job gets the card object as argument and all serializable
22
21
  # attributes of the card.
23
22
  # (when the job is executed ActiveJob fetches the card from the database
24
23
  # so all attributes get lost)
25
- # @param event [String] the event used as queue name
26
- # @param method_name [String] the name of the method we define to trigger
27
- # the actjve job
28
- # @param final_method_name [String] the name of the method that get called
29
- # by the active job and finally executes the event
30
- def define_event_delaying_method event, method_name, final_method_name
31
- class_eval do
32
- define_method(method_name, proc do
33
- IntegrateWithDelayJob.set(queue: event).perform_later(
24
+ # It uses the event as queue name
25
+ def define_event_delaying_method
26
+ @set_module.class_exec(self) do |event|
27
+ define_method(event.delaying_method_name, proc do
28
+ IntegrateWithDelayJob.set(queue: event.name).perform_later(
34
29
  Card::ActManager.act&.id, self, serialize_for_active_job, Card::Env.serialize,
35
- Card::Auth.serialize, final_method_name
30
+ Card::Auth.serialize, event.simple_method_name
36
31
  )
37
32
  end)
38
33
  end
@@ -0,0 +1,78 @@
1
+ class Card
2
+ module Set
3
+ class Event
4
+ module Options
5
+ def validate_conditions
6
+ @opts.each do |key, val|
7
+ next if key.in? %i[in before after around]
8
+ validate_condition_name key
9
+ validate_condition_value key, val
10
+ end
11
+ end
12
+
13
+ def validate_condition_name condition
14
+ return if Card::Set::Event::CONDITIONS.include? condition
15
+ raise ArgumentError,
16
+ "invalid condition key '#{condition}' in event '#{@event}'\n" \
17
+ "valid conditions are #{Card::Set::Event::CONDITIONS.to_a.join ', '}"
18
+ end
19
+
20
+ def validate_condition_value condition, val
21
+ if condition == :when
22
+ validate_when_value val
23
+ else
24
+ invalid = Array.wrap(val) - Array.wrap(valid_values(condition))
25
+ return if invalid.empty?
26
+ raise ArgumentError,
27
+ "invalid option#{'s' if invalid.size > 1} '#{invalid}' "\
28
+ "for condition '#{condition}' in event '#{@event}'"
29
+ end
30
+ end
31
+
32
+ def validate_when_value val
33
+ return if val.is_a?(Symbol) || val.is_a?(Proc)
34
+ raise ArgumentError,
35
+ "invalid value for condition 'when' in event '#{@event}'\n" \
36
+ "must be a symbol or a proc"
37
+ end
38
+
39
+ def valid_values condition
40
+ Card::Set::Event::CONDITION_OPTIONS[condition]
41
+ end
42
+
43
+ def event_opts stage_or_opts, opts
44
+ opts = normalize_opts stage_or_opts, opts
45
+ process_stage_opts opts
46
+ process_action_opts opts
47
+ opts
48
+ end
49
+
50
+ def normalize_opts stage_or_opts, opts
51
+ if stage_or_opts.is_a? Symbol
52
+ opts[:in] = stage_or_opts
53
+ else
54
+ opts = stage_or_opts
55
+ end
56
+ opts
57
+ end
58
+
59
+ def process_action_opts opts
60
+ opts[:on] = [:create, :update] if opts[:on] == :save
61
+ end
62
+
63
+ def process_stage_opts opts
64
+ if opts[:after] || opts[:before]
65
+ # ignore :in options
66
+ elsif (in_opt = opts.delete :in)
67
+ opts[:after] = callback_name in_opt, opts.delete(:after_subcards)
68
+ end
69
+ end
70
+
71
+ def callback_name stage, after_subcards=false
72
+ name = after_subcards ? "#{stage}_final_stage" : "#{stage}_stage"
73
+ name.to_sym
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -21,6 +21,7 @@ class Card
21
21
  #
22
22
  module Format
23
23
  require_dependency "card/set/format/haml_views"
24
+ require_dependency "card/set/format/abstract_format"
24
25
 
25
26
  def format *format_names, &block
26
27
  format_names.compact!
@@ -39,6 +40,10 @@ class Card
39
40
  format { view(*args, &block) }
40
41
  end
41
42
 
43
+ def view_for_override *args, &block
44
+ format { view_for_override(*args, &block) }
45
+ end
46
+
42
47
  def before view, &block
43
48
  format { before view, &block }
44
49
  end
@@ -75,99 +80,6 @@ class Card
75
80
  modules[:base_format][format_class] ||= []
76
81
  modules[:base_format][format_class] << mod
77
82
  end
78
-
79
- # All Format modules are extended with this module in order to support
80
- # the basic format API (ok, view definitions. It's just view
81
- # definitions.)
82
- # No longer just view definitions. Also basket definitions now.
83
- module AbstractFormat
84
- include Set::Basket
85
- include Set::Format::HamlViews
86
-
87
- mattr_accessor :views
88
- self.views = Hash.new { |h, k| h[k] = {} }
89
-
90
- def before view, &block
91
- define_method "_before_#{view}", &block
92
- end
93
-
94
- def view view, *args, &block
95
- #view = view.to_viewname.key.to_sym
96
- interpret_view_opts view, args[0] if block_given?
97
- view_method_block = view_block(view, args, &block)
98
- if async_view? args
99
- # This case makes only sense for HtmlFormat
100
- # but I don't see an easy way to override class methods for a specific
101
- # format. All formats are extended with this general module. So
102
- # a HtmlFormat.view method would be overridden by AbstractFormat.view
103
- # We need something like AbstractHtmlFormat for that.
104
- define_async_view_method view, &view_method_block
105
- else
106
- define_standard_view_method view, &view_method_block
107
- end
108
- end
109
-
110
- def define_standard_view_method view, &block
111
- views[self][view] = block
112
- define_method "_view_#{view}", &block
113
- end
114
-
115
- def define_async_view_method view, &block
116
- view_content = "#{view}_async_content"
117
- define_standard_view_method view_content, &block
118
- define_standard_view_method view do
119
- %(<card-view-placeholder data-url="#{path view: view_content}" />)
120
- end
121
- end
122
-
123
- def interpret_view_opts view, opts
124
- return unless opts.present?
125
- Card::Format.interpret_view_opts view, opts
126
- extract_view_cache_rules view, opts.delete(:cache)
127
- end
128
-
129
- def extract_view_cache_rules view, cache_rule
130
- return unless cache_rule
131
- methodname = Card::Format.view_cache_setting_method view
132
- define_method(methodname) { cache_rule }
133
- end
134
-
135
- def view_block view, args, &block
136
- return haml_view_block(view, wrap_with_slot?(args), &block) if haml_view?(args)
137
- block_given? ? block : lookup_alias_block(view, args)
138
- end
139
-
140
- def haml_view? args
141
- args.first.is_a?(Hash) && args.first[:template] == :haml
142
- end
143
-
144
- def wrap_with_slot? args
145
- args.first.is_a?(Hash) && args.first[:slot]
146
- end
147
-
148
- def async_view? args
149
- args.first.is_a?(Hash) && args.first[:async]
150
- end
151
-
152
- def lookup_alias_block view, args
153
- opts = args[0].is_a?(Hash) ? args.shift : { view: args.shift }
154
- opts[:mod] ||= self
155
- opts[:view] ||= view
156
- views[opts[:mod]][opts[:view]] || begin
157
- raise "cannot find #{opts[:view]} view in #{opts[:mod]}; " \
158
- "failed to alias #{view} in #{self}"
159
- end
160
- end
161
-
162
- def source_location
163
- set_module.source_location
164
- end
165
-
166
- # remove the format part of the module name
167
- def set_module
168
- Card.const_get name.split("::")[0..-2].join("::")
169
- end
170
- end
171
83
  end
172
84
  end
173
85
  end