-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to call script components inline (#285)
- Loading branch information
Showing
10 changed files
with
277 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,18 @@ | ||
<script type="text/javascript"> | ||
function __templ_withoutParameters_6bbf(){alert("hello");} | ||
</script> | ||
<script type="text/javascript"> | ||
__templ_withoutParameters_6bbf() | ||
</script> | ||
<script type="text/javascript"> | ||
function __templ_withParameters_1056(a, b, c){console.log(a, b, c);} | ||
</script> | ||
<script type="text/javascript"> | ||
__templ_withParameters_1056("injected","test",123) | ||
</script> | ||
<script type="text/javascript"> | ||
__templ_withoutParameters_6bbf() | ||
</script> | ||
<script type="text/javascript"> | ||
__templ_withParameters_1056("injected","test",123) | ||
</script> |
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,23 @@ | ||
package testscriptinline | ||
|
||
import ( | ||
_ "embed" | ||
"testing" | ||
|
||
"github.com/a-h/templ/generator/htmldiff" | ||
) | ||
|
||
//go:embed expected.html | ||
var expected string | ||
|
||
func Test(t *testing.T) { | ||
component := InlineJavascript("injected") | ||
|
||
diff, err := htmldiff.Diff(component, expected) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff != "" { | ||
t.Error(diff) | ||
} | ||
} |
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,17 @@ | ||
package testscriptinline | ||
|
||
script withParameters(a string, b string, c int) { | ||
console.log(a, b, c); | ||
} | ||
|
||
script withoutParameters() { | ||
alert("hello"); | ||
} | ||
|
||
templ InlineJavascript(a string) { | ||
@withoutParameters() | ||
@withParameters(a, "test", 123) | ||
// Call once more, to ensure it's defined only once | ||
@withoutParameters() | ||
@withParameters(a, "test", 123) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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