Class: ExpoTurbo::Rails::Streams::TagBuilder
- Inherits:
-
Object
- Object
- ExpoTurbo::Rails::Streams::TagBuilder
- 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
- #after(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #after_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #append(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #append_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #before(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #before_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
-
#initialize(view_context, partial_resolver:, fragment_validator: nil) ⇒ TagBuilder
constructor
A new instance of TagBuilder.
- #prepend(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #prepend_all(targets, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #refresh(request_id: REQUEST_ID_UNSET, layout: nil, **attributes) ⇒ Object
- #remove(target, layout: nil, **attributes) ⇒ Object
- #remove_all(targets, layout: nil, **attributes) ⇒ Object
- #replace(target, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #replace_all(targets, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #update(target, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
- #update_all(targets, content = nil, method: nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
Constructor Details
#initialize(view_context, partial_resolver:, fragment_validator: nil) ⇒ TagBuilder
Returns a new instance of TagBuilder.
38 39 40 41 42 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 38 def initialize(view_context, partial_resolver:, fragment_validator: nil) @view_context = view_context @fragment_validator = fragment_validator @partial_resolver = partial_resolver end |
Instance Method Details
#after(target, content = nil, partial: nil, layout: nil, locals: {}, **attributes) ⇒ Object
68 69 70 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 68 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
72 73 74 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 72 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
44 45 46 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 44 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
48 49 50 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 48 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
60 61 62 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 60 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
64 65 66 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 64 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
52 53 54 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 52 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
56 57 58 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 56 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
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 104 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
92 93 94 95 96 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 92 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
98 99 100 101 102 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 98 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
76 77 78 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 76 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
80 81 82 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 80 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
84 85 86 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 84 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
88 89 90 |
# File 'lib/expo_turbo/rails/streams/tag_builder.rb', line 88 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 |