Class: ExpoTurbo::Rails::Streams::TagBuilder

Inherits:
Object
  • Object
show all
Includes:
Turbo::Streams::ActionHelper
Defined in:
lib/expo_turbo/rails/streams/tag_builder.rb

Constant Summary collapse

CONTENT_ATTRIBUTE_KEYS =
[:content, "content"].freeze
REQUEST_ID_ATTRIBUTE_KEYS =
[:"request-id", "request-id"].freeze
REQUEST_ID_UNSET =
Object.new.freeze

Instance Method Summary collapse

Constructor Details

#initialize(view_context, fragment_validator: nil) ⇒ TagBuilder

Returns a new instance of TagBuilder.



17
18
19
20
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 17

def initialize(view_context, fragment_validator: nil)
  @view_context = view_context
  @fragment_validator = fragment_validator
end

Instance Method Details

#after(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



46
47
48
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 46

def after(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  target_action(:after, target, content, partial:, layout:, locals:, attributes:, &)
end

#after_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



50
51
52
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 50

def after_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  targets_action(:after, targets, content, partial:, layout:, locals:, attributes:, &)
end

#append(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



22
23
24
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 22

def append(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  target_action(:append, target, content, partial:, layout:, locals:, attributes:, &)
end

#append_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



26
27
28
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 26

def append_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  targets_action(:append, targets, content, partial:, layout:, locals:, attributes:, &)
end

#before(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



38
39
40
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 38

def before(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  target_action(:before, target, content, partial:, layout:, locals:, attributes:, &)
end

#before_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



42
43
44
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 42

def before_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  targets_action(:before, targets, content, partial:, layout:, locals:, attributes:, &)
end

#prepend(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



30
31
32
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 30

def prepend(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  target_action(:prepend, target, content, partial:, layout:, locals:, attributes:, &)
end

#prepend_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



34
35
36
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 34

def prepend_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  targets_action(:prepend, targets, content, partial:, layout:, locals:, attributes:, &)
end

#refresh(request_id: REQUEST_ID_UNSET, layout: nil, **attributes) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 82

def refresh(request_id: REQUEST_ID_UNSET, layout: nil, **attributes)
  reject_content!(attributes)
  reject_request_id!(attributes)
  reject_layout!(layout)

  request_id = ::Turbo.current_request_id if request_id.equal?(REQUEST_ID_UNSET)
  if request_id.blank?
    validate_stream_fragment!(turbo_stream_action_tag(:refresh, **attributes))
  else
    validate_stream_fragment!(turbo_stream_refresh_tag(request_id:, **attributes))
  end
end

#remove(target, layout: nil, **attributes) ⇒ Object



70
71
72
73
74
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 70

def remove(target, layout: nil, **attributes)
  reject_content!(attributes)
  reject_layout!(layout)
  target_action(:remove, target, nil, partial: nil, locals: {}, attributes:)
end

#remove_all(targets, layout: nil, **attributes) ⇒ Object



76
77
78
79
80
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 76

def remove_all(targets, layout: nil, **attributes)
  reject_content!(attributes)
  reject_layout!(layout)
  targets_action(:remove, targets, nil, partial: nil, locals: {}, attributes:)
end

#replace(target, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



54
55
56
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 54

def replace(target, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  target_action(:replace, target, content, method:, partial:, layout:, locals:, attributes:, &)
end

#replace_all(targets, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



58
59
60
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 58

def replace_all(targets, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  targets_action(:replace, targets, content, method:, partial:, layout:, locals:, attributes:, &)
end

#update(target, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



62
63
64
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 62

def update(target, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  target_action(:update, target, content, method:, partial:, layout:, locals:, attributes:, &)
end

#update_all(targets, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object



66
67
68
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 66

def update_all(targets, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes, &)
  targets_action(:update, targets, content, method:, partial:, layout:, locals:, attributes:, &)
end