card 1.108.1 → 1.109.1

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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/environments/development.rb +1 -1
  4. data/config/environments/production.rb +5 -2
  5. data/config/initializers/01_core_extensions/array.rb +1 -0
  6. data/config/initializers/01_core_extensions/hash.rb +4 -0
  7. data/config/initializers/02_patches/active_record.rb +1 -1
  8. data/config/initializers/core_extensions.rb +0 -1
  9. data/config/initializers/deck_config.rb +3 -3
  10. data/config/initializers/patches.rb +6 -6
  11. data/config/locales/es.yml +2 -3
  12. data/db/seeds.rb +0 -1
  13. data/lib/card/auth/current.rb +8 -6
  14. data/lib/card/auth/permissions.rb +1 -1
  15. data/lib/card/auth/proxy.rb +2 -2
  16. data/lib/card/auth/setup.rb +2 -2
  17. data/lib/card/auth.rb +7 -6
  18. data/lib/card/cache/all.rb +1 -1
  19. data/lib/card/cache/class_methods.rb +2 -4
  20. data/lib/card/cache/shared.rb +1 -1
  21. data/lib/card/cache/temporary.rb +2 -2
  22. data/lib/card/codename.rb +1 -1
  23. data/lib/card/content/chunk/abstract.rb +1 -0
  24. data/lib/card/content/chunk.rb +0 -1
  25. data/lib/card/content/clean.rb +4 -2
  26. data/lib/card/content/diff/l_c_s.rb +1 -2
  27. data/lib/card/content/diff/result.rb +2 -1
  28. data/lib/card/content/diff.rb +2 -1
  29. data/lib/card/content/parser.rb +8 -7
  30. data/lib/card/content.rb +1 -1
  31. data/lib/card/director/subdirector_array.rb +1 -0
  32. data/lib/card/director.rb +1 -1
  33. data/lib/card/dirty/method_factory.rb +1 -0
  34. data/lib/card/env/location.rb +3 -3
  35. data/lib/card/env/location_history.rb +20 -20
  36. data/lib/card/env/success/target.rb +4 -4
  37. data/lib/card/env/support.rb +25 -2
  38. data/lib/card/error.rb +1 -0
  39. data/lib/card/fetch/store.rb +1 -1
  40. data/lib/card/format/error.rb +13 -2
  41. data/lib/card/format/method_delegation.rb +6 -4
  42. data/lib/card/format/registration.rb +5 -3
  43. data/lib/card/format/render.rb +51 -47
  44. data/lib/card/format/wrapper.rb +1 -0
  45. data/lib/card/lexicon.rb +5 -2
  46. data/lib/card/mailer.rb +1 -14
  47. data/lib/card/name/all/parts.rb +1 -1
  48. data/lib/card/name/all.rb +5 -0
  49. data/lib/card/name/name_variants.rb +1 -0
  50. data/lib/card/query/abstract_query/query_helper.rb +1 -2
  51. data/lib/card/query/abstract_query/tie.rb +1 -1
  52. data/lib/card/query/abstract_query.rb +3 -3
  53. data/lib/card/query/card_class.rb +1 -0
  54. data/lib/card/query/card_query/relational_attributes.rb +1 -1
  55. data/lib/card/query/card_query/run.rb +5 -1
  56. data/lib/card/query/clause.rb +1 -0
  57. data/lib/card/query/join.rb +3 -3
  58. data/lib/card/query/sql_statement.rb +7 -1
  59. data/lib/card/query.rb +1 -1
  60. data/lib/card/reference/all.rb +6 -7
  61. data/lib/card/rule/cache.rb +1 -0
  62. data/lib/card/rule/preference_cache.rb +2 -0
  63. data/lib/card/rule/read_rule_cache.rb +3 -0
  64. data/lib/card/set/event/all.rb +6 -4
  65. data/lib/card/set/event/callbacks.rb +1 -0
  66. data/lib/card/set/event/options.rb +3 -2
  67. data/lib/card/set/event/skip_and_trigger.rb +1 -1
  68. data/lib/card/set/event.rb +2 -2
  69. data/lib/card/set/format/abstract_format/view_definition.rb +1 -1
  70. data/lib/card/set/format/haml_paths.rb +1 -1
  71. data/lib/card/set/format.rb +4 -4
  72. data/lib/card/set/helpers.rb +4 -4
  73. data/lib/card/set/i18n_scanner.rb +23 -22
  74. data/lib/card/set/i18n_scope.rb +4 -3
  75. data/lib/card/set/pattern/all.rb +1 -1
  76. data/lib/card/set/pattern/base.rb +6 -3
  77. data/lib/card/set/pattern/class_methods.rb +1 -1
  78. data/lib/card/set/pattern.rb +1 -1
  79. data/lib/card/set/required_field.rb +3 -0
  80. data/lib/card/set/trait.rb +6 -1
  81. data/lib/card/subcards/all.rb +12 -4
  82. data/lib/card/view/cache/cache_action.rb +9 -3
  83. data/lib/card/view/cache.rb +17 -15
  84. data/lib/card/view/classy.rb +5 -5
  85. data/lib/card/view/options/key_lists.rb +1 -0
  86. data/lib/card/view/options/voo_api.rb +2 -2
  87. data/lib/card/view/options.rb +1 -0
  88. data/lib/card/view.rb +1 -1
  89. data/lib/cardio/command/application.rb +1 -1
  90. data/lib/cardio/command/custom.rb +7 -6
  91. data/lib/cardio/command/rake_command.rb +3 -2
  92. data/lib/cardio/command/rspec_command.rb +1 -0
  93. data/lib/cardio/generators/deck_generator_loader.rb +1 -1
  94. data/lib/cardio/generators.rb +4 -3
  95. data/lib/cardio/migration/port.rb +2 -0
  96. data/lib/cardio/migration/stamp.rb +1 -0
  97. data/lib/cardio/migration/transform.rb +1 -0
  98. data/lib/cardio/migration.rb +2 -0
  99. data/lib/cardio/mod/class_methods.rb +1 -2
  100. data/lib/cardio/mod/dirs.rb +2 -4
  101. data/lib/cardio/mod/eat/edibles.rb +8 -6
  102. data/lib/cardio/mod/eat.rb +7 -9
  103. data/lib/cardio/mod/load_strategy/set_binding_magic.rb +1 -1
  104. data/lib/cardio/mod/load_strategy/tmp_files.rb +3 -2
  105. data/lib/cardio/mod/load_strategy.rb +1 -0
  106. data/lib/cardio/mod/loader/set_pattern_loader.rb +4 -0
  107. data/lib/cardio/mod/loader/set_template.rb +14 -4
  108. data/lib/cardio/mod/loader.rb +2 -2
  109. data/lib/cardio/mod/sow/card_source.rb +1 -1
  110. data/lib/cardio/mod/sow/remote_source.rb +32 -0
  111. data/lib/cardio/mod/sow.rb +10 -10
  112. data/lib/cardio/railtie.rb +1 -0
  113. data/lib/cardio/script_loader.rb +1 -1
  114. data/lib/cardio/seed.rb +2 -2
  115. data/lib/cardio/utils.rb +1 -1
  116. data/lib/cardio/version.rb +2 -1
  117. data/lib/cardio.rb +3 -0
  118. data/lib/generators/deck/templates/config.ru.erb +1 -1
  119. data/mod/core/config/locales/de.yml +1 -1
  120. data/mod/core/config/locales/en.yml +2 -1
  121. data/mod/core/data/fixtures/real/cards.yml +1 -1
  122. data/mod/core/data/real.yml +1 -1
  123. data/mod/core/data/recode.yml +1 -0
  124. data/mod/core/data/schema/20141001105348_move_revisions_to_actions.rb +2 -2
  125. data/mod/core/data/schema/20241017160402_unique_codename.rb +8 -0
  126. data/mod/core/data/transform/20150724123438_update_file_and_image_cards.rb +1 -1
  127. data/mod/core/lib/tasks/card/export.rake +28 -0
  128. data/mod/core/lib/tasks/card/migrate.rake +3 -3
  129. data/mod/core/lib/tasks/card/mod.rake +1 -1
  130. data/mod/core/lib/tasks/card/seed.rake +2 -1
  131. data/mod/core/lib/tasks/card.rake +48 -16
  132. data/mod/core/set/all/admin.rb +1 -2
  133. data/mod/core/set/all/assign_attributes.rb +3 -2
  134. data/mod/core/set/all/codename.rb +7 -1
  135. data/mod/core/set/all/debug.rb +3 -3
  136. data/mod/core/set/all/initialize.rb +1 -0
  137. data/mod/core/set/all/states.rb +13 -16
  138. data/mod/core/set/all/type.rb +3 -1
  139. data/mod/core/set/all/utils.rb +0 -1
  140. data/mod/core/set/self/admin.rb +2 -1
  141. data/mod/core/set/self/autoname.rb +1 -1
  142. data/mod/core/set/self/mod.rb +4 -4
  143. data/mod/core/set/self/trash.rb +1 -1
  144. data/mod/core/set/type/mod.rb +18 -15
  145. data/mod/core/set_pattern/09_self.rb +4 -0
  146. data/mod/core/spec/set/all/admin_spec.rb +1 -1
  147. data/mod/core/spec/set/all/trash_spec.rb +9 -9
  148. metadata +42 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae50e986081ed9e3618c1b92ccfbedfc19a9076529cb17360700506fd8acb054
4
- data.tar.gz: c383ab4419aee1792ff33d7e667858a40f3063d6132d03f5bd9530725b56ac78
3
+ metadata.gz: bbc2d91a4b4e085e2dd391ba227f58cefe096a055354fb5850d5a983db9b389f
4
+ data.tar.gz: 0c8ced971a5730ae8f4898b967fb3063beb0ba4415957ead6c963619eabd7674
5
5
  SHA512:
6
- metadata.gz: 1241479974329e34712f63ef0b3e00942a7a775a87c7e397bca3540114e1ef4a1757be95ee3dd7e8511963db768990e02b14dae74b8c31f1aea8b52ebffb948f
7
- data.tar.gz: ea15daab38b40f7a41a272459f4c197724f22d9d7d37582ca30c70b01ad73b3140ade6fde2d990b6877fbc8beab9158e351622a2d8f7dd02029d5f8c32875a10
6
+ metadata.gz: 8e92113ce1c6777355ba6f4e0d81936c0b2a80ff8718b50acca6782b9f029268e087183fc2a77c179805a4bb7e12a3b54f025acab6acde19df470f2215e51d1d
7
+ data.tar.gz: abba860d2387151ba48e3690fddb88c552e31c7770aa7a37fc75006db47f667a422a8632950e2e162742428f461144330a4d0e2487637c99889312106a07d18c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.18.1
1
+ 0.19.1
@@ -26,7 +26,7 @@ Cardio.application.class.configure do
26
26
  config.action_controller.perform_caching = false
27
27
 
28
28
  # Don't care if the mailer can't send
29
- config.action_mailer.raise_delivery_errors = false
29
+ # config.action_mailer.raise_delivery_errors = false
30
30
 
31
31
  # Print deprecation notices to the Rails logger
32
32
  config.active_support.deprecation = :log
@@ -4,6 +4,7 @@ Cardio.application.class.configure do
4
4
  # Settings specified here will take precedence over those in config/application.rb
5
5
 
6
6
  config.eager_load = true
7
+ config.view_cache = true
7
8
 
8
9
  # temporary fix for formerly autoloaded files that stopped autoloading in Rails 5
9
10
  # TODO: configure eager_load_paths explicitly (and remove this)
@@ -35,7 +36,8 @@ Cardio.application.class.configure do
35
36
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
36
37
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
37
38
 
38
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
39
+ # Force all access to the app over SSL, use Strict-Transport-Security,
40
+ # and use secure cookies.
39
41
  # config.force_ssl = true
40
42
 
41
43
  # See everything in the log (default is :info)
@@ -50,7 +52,8 @@ Cardio.application.class.configure do
50
52
  # Enable serving of images, stylesheets, and JavaScripts from an asset server
51
53
  # config.action_controller.asset_host = "http://assets.example.com"
52
54
 
53
- # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
55
+ # Precompile additional assets (application.js, application.css,
56
+ # and all non-JS/CSS are already added)
54
57
  # config.assets.precompile += %w[application-all.css application-print.css barebones.css
55
58
  # html5shiv-printshiv.js]
56
59
 
@@ -1,4 +1,5 @@
1
1
  module CoreExtensions
2
+ # extensions for Ruby Arrays
2
3
  module Array
3
4
  def to_pointer_content
4
5
  map do |item|
@@ -1,6 +1,9 @@
1
1
  module CoreExtensions
2
+ # extensions for Ruby Hashes
2
3
  module Hash
4
+ # extend ruby Hash class
3
5
  module ClassMethods
6
+ # nested ruby hashes
4
7
  module Nesting
5
8
  # create hash with default nested structures
6
9
  # @example
@@ -21,6 +24,7 @@ module CoreExtensions
21
24
  end
22
25
  end
23
26
 
27
+ # special ruby hash merging behavior
24
28
  module Merging
25
29
  # attach CSS classes
26
30
  # @example
@@ -37,7 +37,7 @@ module Patches
37
37
 
38
38
  # Remove :id column if not in *columns
39
39
  def cleaned_batch_items items, remove_id
40
- items.map! { |row| row[1..-1] } if remove_id
40
+ items.map! { |row| row[1..] } if remove_id
41
41
  end
42
42
 
43
43
  def prepare_batch_pluck columns
@@ -1,7 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  # extend core Ruby object classes
4
-
5
4
  module CoreExtensions
6
5
  ::Kernel.include Kernel
7
6
  ::Object.include Object
@@ -1,3 +1,3 @@
1
- if File.exist? "config/deck.yml"
2
- Cardio.application.config.x = OpenStruct.new(Cardio.application.config_for(:deck))
3
- end
1
+ # if File.exist? "config/deck.yml"
2
+ # Cardio.application.config.x = OpenStruct.new(Cardio.application.config_for(:deck))
3
+ # end
@@ -1,4 +1,4 @@
1
- module Kaminari #:nodoc: all
1
+ module Kaminari # :nodoc: all
2
2
  module Helpers
3
3
  class Tag
4
4
  include Patches::Kaminari::Helpers::Tag
@@ -7,14 +7,14 @@ module Kaminari #:nodoc: all
7
7
  end
8
8
 
9
9
  if defined? BetterErrors
10
- module BetterErrors #:nodoc: all
10
+ module BetterErrors # :nodoc: all
11
11
  class StackFrame
12
12
  # suppress_warnings { include Patches::BetterErrors::StackFrame::TmpPath }
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
- module ActiveRecord #:nodoc: all
17
+ module ActiveRecord # :nodoc: all
18
18
  class Relation
19
19
  include Patches::ActiveRecord::Relation
20
20
  end
@@ -48,14 +48,14 @@ module ActiveRecord #:nodoc: all
48
48
  end
49
49
 
50
50
  module ActiveJob
51
- module Arguments #:nodoc: all
51
+ module Arguments # :nodoc: all
52
52
  class << self
53
53
  prepend Patches::ActiveJob::Arguments
54
54
  end
55
55
  end
56
56
  end
57
57
 
58
- module ActiveSupport #:nodoc: all
58
+ module ActiveSupport # :nodoc: all
59
59
  module Callbacks
60
60
  class Callback
61
61
  prepend Patches::ActiveSupport::Callbacks::Callback
@@ -63,7 +63,7 @@ module ActiveSupport #:nodoc: all
63
63
  end
64
64
  end
65
65
 
66
- module Zeitwerk #:nodoc: all
66
+ module Zeitwerk # :nodoc: all
67
67
  class Loader
68
68
  prepend Patches::Zeitwerk
69
69
  end
@@ -133,7 +133,7 @@ es:
133
133
  type:
134
134
  error_cant_change_errors: "de %{name} no se puede cambiar; creando nuevos errores %{type_id}: %{error_messages}"
135
135
  error_no_such_type: No hay tal tipo
136
- error_hard_templated: no se puede cambiar porque %{name} es una plantilla dificil de %{type_name}
136
+ error_structured: no se puede cambiar porque %{name} es una plantilla dificil de %{type_name}
137
137
  utils:
138
138
  exception_almost_deleted: Se evitó de forma muy estrecha eliminar el archivo actual
139
139
  set_pattern:
@@ -302,8 +302,7 @@ es:
302
302
  unsupported_view: vista (%{view}) no soportado para %{cardname}
303
303
  not_found_named: No pudo encontrar %{cardname}.
304
304
  not_found_no_name: la tarjeta solicitada
305
- server_error: "\nWagn Hitch! Error del Servidor. Yuck, perdon por eso.\nPara decirnos más y seguir la solución,\nagregue un ticket de soporte en %{ticket_link}\n"
306
- se_hitch: 'Wagn Hitch :('
305
+ server_error: "\nError del Servidor. Yuck, perdon por eso.\nPara decirnos más y seguir la solución,\nagregue un ticket de soporte en %{ticket_link}\n"
307
306
  se_sorry: Error del Servidor. Yuck, perdón por eso.
308
307
  se_ticket: <a href="%{ticket_link}">Agregue un ticket de soporte</a> para decirnos más y seguir la solución.
309
308
  denial: Permiso denegado
data/db/seeds.rb CHANGED
@@ -7,7 +7,6 @@ Card::Cache.reset_all
7
7
 
8
8
  # get rid of bad constants
9
9
  Card::Codename.reset_cache
10
- Card::Codename.generate_id_constants
11
10
 
12
11
  # TODO: explain why this is necessary
13
12
  # (card:seed:build breaks without it)
@@ -34,14 +34,16 @@ class Card
34
34
 
35
35
  # set current user in process and session
36
36
  def signin cardish
37
- session[session_user_key] =
38
- self.current_id = Card.id(cardish) || Card::AnonymousID
37
+ user_id = Card.id(cardish) || AnonymousID
38
+ (session[session_user_key] = self.current_id = user_id).tap do
39
+ Env.update_session_options
40
+ end
39
41
  end
40
42
 
41
43
  # current user is not anonymous
42
44
  # @return [true/false]
43
45
  def signed_in?
44
- current_id != Card::AnonymousID
46
+ current_id != AnonymousID
45
47
  end
46
48
 
47
49
  # set current from token, api_key, or session
@@ -63,7 +65,7 @@ class Card
63
65
  # get session object from Env
64
66
  # return [Session]
65
67
  def session
66
- Card::Env.session
68
+ Env.session
67
69
  end
68
70
 
69
71
  # find +\*account card by +\*email card
@@ -89,8 +91,8 @@ class Card
89
91
  # @return [+*account card, nil]
90
92
  def find_account_by fieldcode, value
91
93
  Auth.as_bot do
92
- Card.search({ right_id: Card::AccountID,
93
- right_plus: [Card::Codename.id(fieldcode), { content: value }] },
94
+ Card.search({ right_id: AccountID,
95
+ right_plus: [Codename.id(fieldcode), { content: value }] },
94
96
  "find +:account with +#{fieldcode} (#{value})").first
95
97
  end
96
98
  end
@@ -6,7 +6,7 @@ class Card
6
6
  # @return [true/false]
7
7
  def always_ok?
8
8
  case as_id
9
- when WagnBotID then true # cannot disable
9
+ when DeckoBotID then true # cannot disable
10
10
  when nil then false
11
11
  else
12
12
  always_ok_cached?
@@ -23,9 +23,9 @@ class Card
23
23
  end
24
24
  end
25
25
 
26
- # operate with the permissions of WagnBot (administrator)
26
+ # operate with the permissions of DeckoBot (administrator)
27
27
  def as_bot &block
28
- as Card::WagnBotID, &block
28
+ as Card::DeckoBotID, &block
29
29
  end
30
30
 
31
31
  # id of proxy user
@@ -41,8 +41,8 @@ class Card
41
41
  end
42
42
 
43
43
  def user_account_cql
44
- # every deck starts with two accounts: WagnBot and Anonymous
45
- { right: :account, creator_id: ["ne", Card::WagnBotID] }
44
+ # every deck starts with two accounts: DeckoBot and Anonymous
45
+ { right: :account, creator_id: ["ne", Card::DeckoBotID] }
46
46
  end
47
47
 
48
48
  def user_account_count
data/lib/card/auth.rb CHANGED
@@ -19,12 +19,9 @@ class Card
19
19
  # @return [+*account card, nil]
20
20
  def authenticate email, password
21
21
  account = Auth.find_account_by_email email
22
- case
23
- when !account then nil
24
- when !account.active? then nil
25
- when Card.config.no_authentication then account
26
- when password_valid?(account, password.strip) then account
27
- end
22
+ return nil unless account&.active?
23
+
24
+ account if not_required? || password_valid?(account, password.strip)
28
25
  end
29
26
 
30
27
  # check whether password is correct for account card
@@ -43,6 +40,10 @@ class Card
43
40
  def serialize
44
41
  { as_id: as_id, current_id: current_id }
45
42
  end
43
+
44
+ def not_required?
45
+ Card.config.no_authentication
46
+ end
46
47
  end
47
48
  end
48
49
  end
@@ -92,7 +92,7 @@ class Card
92
92
  def expire_id cache
93
93
  return unless id.present?
94
94
 
95
- cache.delete "~#{id}"
95
+ cache.delete id_string
96
96
  end
97
97
 
98
98
  def expire_view_cache_keys view_keys
@@ -1,12 +1,10 @@
1
-
2
1
  class Card
3
2
  class Cache
4
3
  # class methods for Card::Cache
5
4
  module ClassMethods
6
5
  include Populate
7
6
 
8
- attr_accessor :no_renewal
9
- attr_accessor :counter
7
+ attr_accessor :no_renewal, :counter
10
8
 
11
9
  # create a new cache for the ruby class provided
12
10
  # @param klass [Class]
@@ -109,7 +107,7 @@ class Card
109
107
  end
110
108
 
111
109
  def tallies
112
- "#{tally_total} Cache calls (" + counter.map { |k, v| "#{k}=#{v} " }.join + ")"
110
+ "#{tally_total} Cache calls (#{counter.map { |k, v| "#{k}=#{v} " }.join})"
113
111
  end
114
112
 
115
113
  private
@@ -82,7 +82,7 @@ class Card
82
82
  def read_multi keys
83
83
  map = keys.each_with_object({}) { |k, h| h[full_key k] = k }
84
84
  raw = @store.read_multi(*map.keys)
85
- raw.each_with_object({}) { |(k, v), h| h[map[k]] = v }
85
+ raw.transform_keys { |k| map[k] }
86
86
  end
87
87
 
88
88
  # update an attribute of an object already in the cache
@@ -11,7 +11,7 @@ class Card
11
11
  # Unlike the Shared cache, the Temporary cache can handle objects with
12
12
  # singleton classes.
13
13
  class Temporary
14
- MAX_KEYS = 10_000
14
+ MAX_KEYS = Cardio.config.max_temporary_cache_keys
15
15
  attr_reader :store
16
16
 
17
17
  def initialize klass
@@ -80,7 +80,7 @@ class Card
80
80
  def within_key_counts
81
81
  if @reps >= MAX_KEYS && (@reps = @store.size) > MAX_KEYS
82
82
  Rails.logger.info "RESETTING temporary #{@klass} cache. " \
83
- "MAX_KEYS (#{MAX_KEYS}) exceeded"
83
+ "MAX_KEYS (#{MAX_KEYS}) exceeded"
84
84
  reset
85
85
  end
86
86
  yield
data/lib/card/codename.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- # codename retrieval methods for cards
4
3
  class Card
5
4
  # @return [Symbol]
6
5
  def codename
@@ -82,6 +81,7 @@ class Card
82
81
  def reset_cache
83
82
  @codehash = nil
84
83
  ::Card.cache.delete "CODENAMES"
84
+ generate_id_constants
85
85
  end
86
86
 
87
87
  # @param codename [Symbol, String]
@@ -7,6 +7,7 @@ class Card
7
7
  # match by its pattern.
8
8
  #
9
9
  module Chunk
10
+ # Abstract class used for all different types of chunks of card content
10
11
  class Abstract
11
12
  class_attribute :config
12
13
  attr_reader :text, :process_chunk
@@ -9,7 +9,6 @@ class Card
9
9
  # +pattern+ that states what sort of text it matches.
10
10
  # Chunks are initalized by passing in the result of a
11
11
  # match by its pattern.
12
- #
13
12
  module Chunk
14
13
  mattr_accessor :raw_list, :prefix_regexp_by_list,
15
14
  :prefix_map_by_list, :prefix_map_by_chunkname
@@ -13,7 +13,9 @@ class Card
13
13
  "a" => %w[href title target],
14
14
  "img" => %w[src alt title],
15
15
  "code" => ["lang"],
16
- "blockquote" => ["cite"]
16
+ "blockquote" => ["cite"],
17
+ "ol" => ["type"],
18
+ "ul" => ["type"]
17
19
  )
18
20
 
19
21
  if Cardio.config.allow_inline_styles
@@ -86,7 +88,7 @@ class Card
86
88
 
87
89
  rest_value = match[0]
88
90
  if attrib == "class"
89
- rest_value.split(/\s+/).select { |s| s =~ /^w-/i }.join(" ")
91
+ rest_value.split(/\s+/).grep(/^w-/i).join " "
90
92
  else
91
93
  rest_value
92
94
  end
@@ -51,8 +51,7 @@ class Card
51
51
  end
52
52
 
53
53
  def check_exclude_and_disjunction_pattern list
54
- list.each_with_index.each_with_object([[], []]) do |pair, res|
55
- element, index = pair
54
+ list.each_with_index.with_object([[], []]) do |(element, index), res|
56
55
  if element.match? @disjunction_pattern
57
56
  res[1] << { chunk_index: index, element: element, type: :disjunction }
58
57
  elsif element.match? @exclude_pattern
@@ -3,7 +3,8 @@ class Card
3
3
  class Diff
4
4
  # Result object for Diff processing
5
5
  class Result
6
- attr_accessor :complete, :summary, :dels_cnt, :adds_cnt
6
+ attr_accessor :complete, :dels_cnt, :adds_cnt
7
+ attr_writer :summary
7
8
 
8
9
  def initialize summary_opts=nil
9
10
  @dels_cnt = 0
@@ -2,6 +2,7 @@
2
2
 
3
3
  class Card
4
4
  class Content
5
+ # handle comparisons of card content
5
6
  class Diff
6
7
  class << self
7
8
  def complete a, b, opts={}
@@ -57,7 +58,7 @@ class Card
57
58
  when :html
58
59
  opts[:exclude] = /^</
59
60
  when :text
60
- opts[:reject] = /^</
61
+ opts[:reject] = /^</
61
62
  opts[:postprocess] = proc { |word| word.gsub("\n", "<br>") }
62
63
  when :pointer
63
64
  opts[:preprocess] = proc { |word| word.gsub("[[", "").gsub("]]", "<br>") }
@@ -38,7 +38,7 @@ class Card
38
38
  @chunk_class = Chunk.find_class_by_prefix @prefix, @chunk_list
39
39
 
40
40
  # get the chunk class from the prefix
41
- content_slice = @content[@position..-1]
41
+ content_slice = @content[@position..]
42
42
  @chunk_class.full_match content_slice, @prefix
43
43
  end
44
44
 
@@ -59,7 +59,7 @@ class Card
59
59
  end
60
60
 
61
61
  def match_prefix prefix_regexp
62
- prefix_match = @content[@position..-1].match(prefix_regexp)
62
+ prefix_match = @content[@position..].match(prefix_regexp)
63
63
  if prefix_match
64
64
  @prefix = prefix_match[0]
65
65
  # prefix of matched chunk
@@ -79,10 +79,8 @@ class Card
79
79
  def record_chunk
80
80
  @position += (@match.end(0) - @offset.to_i)
81
81
  # move scanning position up to end of chunk
82
- if !@chunk_class.context_ok? @content, @chunk_start
83
- # make sure there aren't contextual reasons for ignoring this chunk
84
- false
85
- else
82
+
83
+ if @chunk_class.context_ok? @content, @chunk_start
86
84
  @chunks << @interval_string unless @interval_string.empty?
87
85
  @interval_string = ""
88
86
  # add the nonchunk string to the chunk list and
@@ -93,13 +91,16 @@ class Card
93
91
  # NOTE: that the end of the chunk was the last place where a
94
92
  # chunk was found (so far)
95
93
  true
94
+ else
95
+ # make sure there aren't contextual reasons for ignoring this chunk
96
+ false
96
97
  end
97
98
  end
98
99
 
99
100
  def handle_remainder
100
101
  if @chunks.any? && @last_position < @content.size
101
102
  # handle any leftover nonchunk string at the end of content
102
- @chunks << @content[@last_position..-1]
103
+ @chunks << @content[@last_position..]
103
104
  end
104
105
  end
105
106
  end
data/lib/card/content.rb CHANGED
@@ -73,7 +73,7 @@ class Card
73
73
  when String then return # no chunks
74
74
  else
75
75
  Rails.logger.warn "unrecognized type for #each_chunk: " \
76
- " #{self.class} #{__getobj__.class}"
76
+ "#{self.class} #{__getobj__.class}"
77
77
  return
78
78
  end
79
79
  send(iterator) { |item| yield item if item.is_a?(Chunk::Abstract) }
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  class Director
3
+ # extends array with special methods for handling lists of card subdirectors
3
4
  class SubdirectorArray < Array
4
5
  def self.initialize_with_subcards parent
5
6
  dir_array = new(parent)
data/lib/card/director.rb CHANGED
@@ -208,7 +208,7 @@ class Card
208
208
  def to_s level=1
209
209
  str = @card.name.to_s.clone
210
210
  if @subdirectors.present?
211
- subs = subdirectors.map { |d| " " * level + d.to_s(level + 1) }.join "\n"
211
+ subs = subdirectors.map { |d| (" " * level) + d.to_s(level + 1) }.join "\n"
212
212
  str << "\n#{subs}"
213
213
  end
214
214
  str
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  module Dirty
3
+ # handles special method definitions for dirty cards
3
4
  module MethodFactory
4
5
  def define_dirty_methods field
5
6
  define_method "#{field}_before_act" do
@@ -1,12 +1,11 @@
1
1
  class Card
2
2
  module Env
3
+ # shared methods for handling paths/urls
3
4
  module Location
4
5
  # card_path makes a relative path site-absolute (if not already)
5
- # card_url makes it a full url (if not already)
6
-
7
6
  def card_path rel_path
8
7
  unless rel_path.is_a? String
9
- Rails.logger.warn "Pass only strings to card_path. "\
8
+ Rails.logger.warn "Pass only strings to card_path. " \
10
9
  "(#{rel_path} = #{rel_path.class})"
11
10
  end
12
11
  if rel_path.match? %r{^(https?:)?/}
@@ -16,6 +15,7 @@ class Card
16
15
  end
17
16
  end
18
17
 
18
+ # card_url makes it a full url (if not already)
19
19
  def card_url rel
20
20
  rel.match?(/^https?:/) ? rel : "#{Env.origin}#{card_path rel}"
21
21
  end
@@ -10,32 +10,20 @@ class Card
10
10
  end
11
11
 
12
12
  def save_location card
13
- return unless save_location?(card)
13
+ return unless save_location? card
14
14
 
15
- discard_locations_for card
16
- session[:previous_location] =
17
- Env::Location.card_path card.name.url_key
18
- location_history.push previous_location
19
- end
20
-
21
- def save_location? card
22
- !Env.ajax? && Env.html? && card.known? && (card.codename != :signin)
15
+ location = request ? request.original_url : location_for_history(card)
16
+ location_history.push(location).uniq!
23
17
  end
24
18
 
25
19
  def previous_location
26
- return unless location_history
27
-
28
- session[:previous_location] ||= location_history.last
20
+ location_history&.last
29
21
  end
30
22
 
31
23
  def discard_locations_for card
32
- # quoting necessary because cards have things like "+*" in the names..
33
- session[:history] = location_history.reject do |loc|
34
- if (url_key = url_key_for_location(loc))
35
- url_key.to_name.key == card.key
36
- end
24
+ session[:history] = location_history.reject do |l|
25
+ location_cardname(l) == card.name
37
26
  end.compact
38
- session[:previous_location] = nil
39
27
  end
40
28
 
41
29
  def save_interrupted_action uri
@@ -46,8 +34,20 @@ class Card
46
34
  session.delete :interrupted_action
47
35
  end
48
36
 
49
- def url_key_for_location location
50
- %r{/([^/]*$)} =~ location ? Regexp.last_match[1] : nil
37
+ private
38
+
39
+ def location_for_history card
40
+ Env::Location.card_path card.name.url_key
41
+ end
42
+
43
+ def location_cardname location
44
+ URI.parse(location).path.sub(/^\//, "").sub(/\/.*$/, "")&.cardname
45
+ end
46
+
47
+ def save_location? card
48
+ # return false unless Auth.signed_in? || Cardio.config.allow_anonymous_cookies
49
+
50
+ !Env.ajax? && Env.html? && card.known? && (card.codename != :signin)
51
51
  end
52
52
  end
53
53
  end
@@ -14,11 +14,11 @@ class Card
14
14
  card(name_context) || @target || Card.fetch(name_context)
15
15
  end
16
16
 
17
- # TODO: refactor to use cardish
18
17
  def mark= value
19
- case value
20
- when Integer then @id = value
21
- when Card then @card = value
18
+ if (id = Card.id value)
19
+ @id = id
20
+ elsif value.is_a? Card
21
+ @card = value
22
22
  else
23
23
  self.target = value
24
24
  end