-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow turbo stream instances to be created from
Marten::Model
- Loading branch information
Showing
7 changed files
with
73 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require "./concerncs/**" | ||
require "./turbo_stream" | ||
require "./ext/**" | ||
require "./handlers/**" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module MartenTurbo | ||
module Identifiable | ||
def create_dom_id(value : Marten::Template::Value, prefix : Marten::Template::Value? = nil) | ||
if value.raw.is_a? Marten::Model | ||
create_dom_id(value.raw.as(Marten::Model), prefix) | ||
else | ||
dom_id = value.to_s | ||
prefix ? "#{prefix}_#{dom_id}" : dom_id | ||
end | ||
end | ||
|
||
def create_dom_id(model : Marten::Model, prefix : Marten::Template::Value? = nil) | ||
generate_id_for_model(model, prefix) | ||
end | ||
|
||
private def formatted_prefix(prefix) | ||
prefix ? "#{prefix}_" : "" | ||
end | ||
|
||
private def generate_id_for_model(model, prefix) | ||
identifier = model.class.name.downcase.gsub(RE_NAMESPACE_IDENTIFIER, '_') | ||
if model.new_record? | ||
"#{formatted_prefix(prefix)}new_#{identifier}" | ||
else | ||
"#{formatted_prefix(prefix)}#{identifier}_#{model.pk}" | ||
end | ||
end | ||
|
||
RE_NAMESPACE_IDENTIFIER = /(?:\:\:|\.)/ | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require "./concerncs/dom_identifier" | ||
|
||
module MartenTurbo | ||
module Template | ||
module Tag | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require "./concerncs/dom_identifier" | ||
|
||
module MartenTurbo | ||
module Template | ||
module Tag | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters