Sha256: 68f71feb530d9a9bafa4ec38aa7c28660b62f4123c94e4659889f22a933154cb

Contents?: true

Size: 1.31 KB

Versions: 13

Compression:

Stored size: 1.31 KB

Contents

class Card
  class View
    # A "stub" is a placeholder for a card view.
    #
    # Cached views use stubs so that _nesting_ content can remained cached
    # even while _nested_ content changes. The nested content's place is held
    # by a stub.
    #
    # A stub must contain all the information necessary to produce the view as intended.
    #
    module Stub

      class << self
        def escape stub_json
          stub_json.gsub "(", "_OParEN_"
        end

        def unescape stub_json
          stub_json.gsub "_OParEN_", "("
        end
      end

      # @return [String]
      def stub
        "(stub)#{Stub.escape stub_json}(/stub)".html_safe
      end

      # @return [String] the stub_hash as JSON
      def stub_json
        JSON.generate stub_hash
      end

      # @return [Hash]
      def stub_hash
        { cast: card.cast,
          view_opts: normalized_options,
          format_opts: { nest_mode: format.nest_mode, override: root? } }
        # nest mode handling:
        # typically modes only override views on nests, but stubs create non-standard nests
        # mode-based view overrides should NOT apply to standard render calls that have
        # been replaced with stubs - only to standard nest calls. therefore modes are not
        # stored in non-standard nest stubs
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
card-1.96.8 lib/card/view/stub.rb
card-1.96.7 lib/card/view/stub.rb
card-1.96.6 lib/card/view/stub.rb
card-1.96.5 lib/card/view/stub.rb
card-1.96.4 lib/card/view/stub.rb
card-1.96.3 lib/card/view/stub.rb
card-1.96.2 lib/card/view/stub.rb
card-1.96.1 lib/card/view/stub.rb
card-1.96.0 lib/card/view/stub.rb
card-1.95.3 lib/card/view/stub.rb
card-1.95.2 lib/card/view/stub.rb
card-1.95.1 lib/card/view/stub.rb
card-1.95.0 lib/card/view/stub.rb