Module: ExpoTurbo::Rails::Frames

Defined in:
lib/expo_turbo/rails/frames.rb,
lib/expo_turbo/rails/frames/helper.rb

Defined Under Namespace

Modules: Helper

Constant Summary collapse

CACHE_VARIANT_NAMESPACE =
:expo_turbo

Class Method Summary collapse

Class Method Details

.cache_variant(frame_id) ⇒ Object



24
25
26
27
28
# File 'lib/expo_turbo/rails/frames.rb', line 24

def cache_variant(frame_id)
  return [CACHE_VARIANT_NAMESPACE, :document].freeze if frame_id.nil?

  [CACHE_VARIANT_NAMESPACE, :frame, frame_id.dup.freeze].freeze
end

.valid_id?(value) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/expo_turbo/rails/frames.rb', line 10

def valid_id?(value)
  value.is_a?(String) &&
    value.encoding == Encoding::UTF_8 &&
    value.valid_encoding? &&
    !value.blank? &&
    value.each_codepoint.none? { |codepoint| codepoint <= 31 || codepoint == 127 || codepoint.between?(0xFFFE, 0xFFFF) }
end

.validate_id!(value, label: "Frame") ⇒ Object

Raises:



18
19
20
21
22
# File 'lib/expo_turbo/rails/frames.rb', line 18

def validate_id!(value, label: "Frame")
  return value if valid_id?(value)

  raise TemplateError, "Expo Turbo #{label} id must be a nonblank UTF-8 string without control characters"
end