card 1.108.1 → 1.109.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 (128) 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/lib/card/auth/current.rb +8 -6
  12. data/lib/card/auth.rb +7 -6
  13. data/lib/card/cache/class_methods.rb +2 -4
  14. data/lib/card/cache/shared.rb +1 -1
  15. data/lib/card/cache/temporary.rb +2 -2
  16. data/lib/card/codename.rb +0 -1
  17. data/lib/card/content/chunk/abstract.rb +1 -0
  18. data/lib/card/content/chunk.rb +0 -1
  19. data/lib/card/content/clean.rb +4 -2
  20. data/lib/card/content/diff/l_c_s.rb +1 -2
  21. data/lib/card/content/diff/result.rb +2 -1
  22. data/lib/card/content/diff.rb +2 -1
  23. data/lib/card/content/parser.rb +8 -7
  24. data/lib/card/content.rb +1 -1
  25. data/lib/card/director/subdirector_array.rb +1 -0
  26. data/lib/card/director.rb +1 -1
  27. data/lib/card/dirty/method_factory.rb +1 -0
  28. data/lib/card/env/location.rb +3 -3
  29. data/lib/card/env/location_history.rb +12 -11
  30. data/lib/card/env/success/target.rb +4 -4
  31. data/lib/card/env/support.rb +24 -2
  32. data/lib/card/error.rb +1 -0
  33. data/lib/card/fetch/store.rb +1 -1
  34. data/lib/card/format/error.rb +1 -0
  35. data/lib/card/format/method_delegation.rb +6 -4
  36. data/lib/card/format/registration.rb +5 -3
  37. data/lib/card/format/wrapper.rb +1 -0
  38. data/lib/card/mailer.rb +1 -14
  39. data/lib/card/name/all/parts.rb +1 -1
  40. data/lib/card/name/all.rb +1 -0
  41. data/lib/card/name/name_variants.rb +1 -0
  42. data/lib/card/query/abstract_query/query_helper.rb +1 -2
  43. data/lib/card/query/abstract_query/tie.rb +1 -1
  44. data/lib/card/query/abstract_query.rb +3 -3
  45. data/lib/card/query/card_class.rb +1 -0
  46. data/lib/card/query/clause.rb +1 -0
  47. data/lib/card/query/join.rb +3 -3
  48. data/lib/card/reference/all.rb +6 -7
  49. data/lib/card/rule/cache.rb +1 -0
  50. data/lib/card/rule/preference_cache.rb +2 -0
  51. data/lib/card/rule/read_rule_cache.rb +3 -0
  52. data/lib/card/set/event/all.rb +6 -4
  53. data/lib/card/set/event/callbacks.rb +1 -0
  54. data/lib/card/set/event/options.rb +3 -2
  55. data/lib/card/set/event/skip_and_trigger.rb +1 -1
  56. data/lib/card/set/event.rb +2 -2
  57. data/lib/card/set/format/abstract_format/view_definition.rb +1 -1
  58. data/lib/card/set/format/haml_paths.rb +1 -1
  59. data/lib/card/set/format.rb +4 -4
  60. data/lib/card/set/helpers.rb +4 -4
  61. data/lib/card/set/i18n_scanner.rb +23 -22
  62. data/lib/card/set/i18n_scope.rb +4 -3
  63. data/lib/card/set/pattern/all.rb +1 -1
  64. data/lib/card/set/pattern/base.rb +6 -3
  65. data/lib/card/set/pattern/class_methods.rb +1 -1
  66. data/lib/card/set/pattern.rb +1 -1
  67. data/lib/card/set/required_field.rb +3 -0
  68. data/lib/card/set/trait.rb +6 -1
  69. data/lib/card/subcards/all.rb +12 -4
  70. data/lib/card/view/cache/cache_action.rb +1 -1
  71. data/lib/card/view/cache.rb +1 -1
  72. data/lib/card/view/classy.rb +5 -5
  73. data/lib/card/view/options/key_lists.rb +1 -0
  74. data/lib/card/view/options/voo_api.rb +1 -1
  75. data/lib/cardio/command/application.rb +1 -1
  76. data/lib/cardio/command/custom.rb +7 -6
  77. data/lib/cardio/command/rake_command.rb +3 -2
  78. data/lib/cardio/command/rspec_command.rb +1 -0
  79. data/lib/cardio/generators/deck_generator_loader.rb +1 -1
  80. data/lib/cardio/generators.rb +4 -3
  81. data/lib/cardio/migration/port.rb +2 -0
  82. data/lib/cardio/migration/stamp.rb +1 -0
  83. data/lib/cardio/migration/transform.rb +1 -0
  84. data/lib/cardio/migration.rb +2 -0
  85. data/lib/cardio/mod/class_methods.rb +1 -2
  86. data/lib/cardio/mod/dirs.rb +2 -4
  87. data/lib/cardio/mod/eat/edibles.rb +8 -6
  88. data/lib/cardio/mod/eat.rb +6 -5
  89. data/lib/cardio/mod/load_strategy/set_binding_magic.rb +1 -1
  90. data/lib/cardio/mod/load_strategy/tmp_files.rb +3 -2
  91. data/lib/cardio/mod/load_strategy.rb +1 -0
  92. data/lib/cardio/mod/loader/set_pattern_loader.rb +4 -0
  93. data/lib/cardio/mod/loader/set_template.rb +14 -4
  94. data/lib/cardio/mod/loader.rb +2 -2
  95. data/lib/cardio/mod/sow/card_source.rb +1 -1
  96. data/lib/cardio/mod/sow/remote_source.rb +32 -0
  97. data/lib/cardio/mod/sow.rb +10 -10
  98. data/lib/cardio/railtie.rb +1 -0
  99. data/lib/cardio/script_loader.rb +1 -1
  100. data/lib/cardio/seed.rb +1 -1
  101. data/lib/cardio/utils.rb +1 -1
  102. data/lib/cardio/version.rb +2 -1
  103. data/lib/cardio.rb +3 -0
  104. data/lib/generators/deck/templates/config.ru.erb +1 -1
  105. data/mod/core/config/locales/en.yml +1 -0
  106. data/mod/core/data/schema/20141001105348_move_revisions_to_actions.rb +2 -2
  107. data/mod/core/data/schema/20241017160402_unique_codename.rb +8 -0
  108. data/mod/core/data/transform/20150724123438_update_file_and_image_cards.rb +1 -1
  109. data/mod/core/lib/tasks/card/export.rake +28 -0
  110. data/mod/core/lib/tasks/card/migrate.rake +3 -3
  111. data/mod/core/lib/tasks/card/seed.rake +2 -1
  112. data/mod/core/lib/tasks/card.rake +47 -16
  113. data/mod/core/set/all/admin.rb +1 -2
  114. data/mod/core/set/all/assign_attributes.rb +3 -2
  115. data/mod/core/set/all/codename.rb +7 -0
  116. data/mod/core/set/all/debug.rb +3 -3
  117. data/mod/core/set/all/initialize.rb +1 -0
  118. data/mod/core/set/all/states.rb +7 -6
  119. data/mod/core/set/all/type.rb +2 -0
  120. data/mod/core/set/all/utils.rb +0 -1
  121. data/mod/core/set/self/admin.rb +2 -1
  122. data/mod/core/set/self/autoname.rb +1 -1
  123. data/mod/core/set/self/mod.rb +4 -4
  124. data/mod/core/set/self/trash.rb +1 -1
  125. data/mod/core/set/type/mod.rb +18 -15
  126. data/mod/core/set_pattern/09_self.rb +4 -0
  127. data/mod/core/spec/set/all/trash_spec.rb +7 -7
  128. 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: 9ae89c5e6253fdbcea6b9ea9e1a5ca94b8f22f0c13c47186d8a2d66d6bfb525b
4
+ data.tar.gz: babc949cb5a33a9385369e62136b60591e96ac03b09a06660bce43d30165cfce
5
5
  SHA512:
6
- metadata.gz: 1241479974329e34712f63ef0b3e00942a7a775a87c7e397bca3540114e1ef4a1757be95ee3dd7e8511963db768990e02b14dae74b8c31f1aea8b52ebffb948f
7
- data.tar.gz: ea15daab38b40f7a41a272459f4c197724f22d9d7d37582ca30c70b01ad73b3140ade6fde2d990b6877fbc8beab9158e351622a2d8f7dd02029d5f8c32875a10
6
+ metadata.gz: f70439a264188fa2f734ddf9ce6cbd8f7ca790bfcddde0c0accf8a2ffa9d2c575c90220d848678c7f1ac965e734ecf4a4d30e33aaed5b41345958210cd24db84
7
+ data.tar.gz: 6ff17cfaf5b5a7af5fcca9f95693b083b81aa781de06c244356c8b7e397e4621e7784995613252dae2c2d78406f0347f0977212cf91c79cd77c1b9917813e6ee
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.18.1
1
+ 0.19.0
@@ -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
@@ -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_cookie_setting !signed_in?
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
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
@@ -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
@@ -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
@@ -13,19 +13,11 @@ class Card
13
13
  return unless save_location?(card)
14
14
 
15
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)
16
+ location_history.push location_for_history(card)
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
@@ -35,7 +27,6 @@ class Card
35
27
  url_key.to_name.key == card.key
36
28
  end
37
29
  end.compact
38
- session[:previous_location] = nil
39
30
  end
40
31
 
41
32
  def save_interrupted_action uri
@@ -46,9 +37,19 @@ class Card
46
37
  session.delete :interrupted_action
47
38
  end
48
39
 
40
+ private
41
+
42
+ def location_for_history card
43
+ Env::Location.card_path card.name.url_key
44
+ end
45
+
49
46
  def url_key_for_location location
50
47
  %r{/([^/]*$)} =~ location ? Regexp.last_match[1] : nil
51
48
  end
49
+
50
+ def save_location? card
51
+ !Env.ajax? && Env.html? && card.known? && (card.codename != :signin)
52
+ end
52
53
  end
53
54
  end
54
55
  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
@@ -21,10 +21,32 @@ class Card
21
21
  def reset_session
22
22
  if session.is_a? Hash
23
23
  @session = {}
24
- else
25
- controller&.reset_session
24
+ elsif request
25
+ update_cookie_setting false
26
+ controller.reset_session
27
+ # destroy_cookie unless Cardio.config.anonymous_cookies
26
28
  end
27
29
  end
30
+
31
+ def update_cookie_setting is_anonymous=true
32
+ return unless request && !Cardio.config.anonymous_cookies
33
+
34
+ request.session_options[:drop] = is_anonymous
35
+ end
36
+
37
+ # private
38
+
39
+ # FIXME: not working
40
+ # the response generally works to destroy a cookie, but
41
+ # the deletion doesn't appear to work in a redirect. Since signing out
42
+ # has a redirect response, we're still left with a cookie
43
+ # def destroy_cookie
44
+ # app = Cardio.application
45
+ # app_name = app.class.name ? app.railtie_name.chomp("_application") : ""
46
+ # expire_in_past = "expires=Thu, 01 Jan 1970 00:00:00 GMT;"
47
+ # controller.response.set_header "SET-COOKIE",
48
+ # "_#{app_name}_session=deleted; #{expire_in_past}"
49
+ # end
28
50
  end
29
51
  end
30
52
  end
data/lib/card/error.rb CHANGED
@@ -78,6 +78,7 @@ class Card
78
78
  class BadQuery < UserError
79
79
  end
80
80
 
81
+ # error with url
81
82
  class BadAddress < UserError
82
83
  self.status_code = 404
83
84
  self.view = :bad_address
@@ -36,7 +36,7 @@ class Card
36
36
  end
37
37
 
38
38
  def needs_prep?
39
- return unless card.present?
39
+ return false unless card.present?
40
40
 
41
41
  !(skip_modules? || card.patterns?)
42
42
  end
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  class Format
3
+ # permissions and errors in card format classes
3
4
  module Error
4
5
  def ok? task
5
6
  task = :create if task == :update && card.new_card?
@@ -1,5 +1,7 @@
1
1
  class Card
2
2
  class Format
3
+ # missing methods may be render calls or action view methods
4
+ # these methods sort that out
3
5
  module MethodDelegation
4
6
  RENDER_METHOD_RE =
5
7
  /^
@@ -40,7 +42,7 @@ class Card
40
42
  if (match = api_render? method)
41
43
  api_render match, opts
42
44
  else
43
- delegate_to_action_view(method, opts, proc) { yield }
45
+ delegate_to_action_view method, opts, &proc
44
46
  end
45
47
  end
46
48
 
@@ -66,9 +68,9 @@ class Card
66
68
  end
67
69
  end
68
70
 
69
- def delegate_to_action_view method, opts, proc
70
- proc = proc { |*a| raw yield(*a) } if proc
71
- response = action_view.send method, *opts, &proc
71
+ def delegate_to_action_view method, opts, &old_proc
72
+ new_proc = proc { |*a| raw yield(*a) } if old_proc
73
+ response = action_view.send method, *opts, &new_proc
72
74
  response.is_a?(String) ? action_view.raw(response) : response
73
75
  end
74
76
  end
@@ -1,5 +1,7 @@
1
1
  class Card
2
2
  class Format
3
+ # handles format registry, tracking which formats (html, css, json, etc) are
4
+ # available
3
5
  module Registration
4
6
  def register format
5
7
  registered << format.to_s
@@ -7,11 +9,11 @@ class Card
7
9
  end
8
10
 
9
11
  def new card, opts={}
10
- if self != Format
11
- super
12
- else
12
+ if self == Format
13
13
  klass = format_class opts
14
14
  self == klass ? super : klass.new(card, opts)
15
+ else
16
+ super
15
17
  end
16
18
  end
17
19
 
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  class Format
3
+ # handles view wrapping, including with layouts and slots
3
4
  module Wrapper
4
5
  def with_wrapper
5
6
  if voo.layout.present?