Skip to content

Commit f0e7d02

Browse files
authored
Merge pull request #53 from rameel/remove-metacharacter-option
Remove `MetaCharacter` configuration option
2 parents a6e46c9 + fec6ef2 commit f0e7d02

9 files changed

Lines changed: 14 additions & 96 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ For example, values declared on a parent element can be inherited by its childre
325325
</div>
326326
```
327327

328-
When `HtmxV4Config.MetaCharacter` is configured, that character is used instead of `:` in the generated attribute name.
329328
Alternatively, set `HtmxV4Config.ImplicitInheritance` to `true` to enable inheritance globally.
330329
For HTMX 1.9.x and 2.x, the Tag Helper attributes above do not change the generated attribute names.
331330

src/Ramstack.HtmxToolkit/Configuration/HtmxV4Config.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ public string? Prefix
3030
set => SetField(ref field, value);
3131
}
3232

33-
/// <summary>
34-
/// Gets or sets the character used instead of <c>:</c> in attribute names.
35-
/// The HTMX default is <c>undefined</c>.
36-
/// </summary>
37-
public string? MetaCharacter
38-
{
39-
get;
40-
set => SetField(ref field, value);
41-
}
42-
4333
/// <summary>
4434
/// Gets or sets how HTMX history restoration is handled.
4535
/// The HTMX default is <see cref="HtmxHistoryMode.Enabled" />.

src/Ramstack.HtmxToolkit/TagHelpers/HtmxHeaderTagHelper.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ public override Task ProcessAsync(TagHelperContext context, TagHelperOutput outp
5959
{
6060
var name = "hx-headers";
6161
if (Inherited && options.Value.TargetVersion == HtmxTargetVersion.V4)
62-
{
63-
if (options.Value.HtmxConfig is HtmxV4Config config)
64-
name = string.IsNullOrEmpty(config.MetaCharacter)
65-
? "hx-headers:inherited"
66-
: $"hx-headers{config.MetaCharacter}inherited";
67-
}
62+
name = "hx-headers:inherited";
6863

6964
var info = HtmxDictionaryJsonSerializerContext.Default.IDictionaryStringString;
7065
var json = JsonSerializer.Serialize(Headers, info);

src/Ramstack.HtmxToolkit/TagHelpers/HtmxRequestTagHelper.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,12 @@ public override Task ProcessAsync(TagHelperContext context, TagHelperOutput outp
164164

165165
if (json != "{}")
166166
{
167-
var name = "hx-request";
168-
169-
if (options.Value.TargetVersion == HtmxTargetVersion.V4)
167+
var name = options.Value.TargetVersion switch
170168
{
171-
if (Inherited)
172-
{
173-
if (options.Value.HtmxConfig is HtmxV4Config config)
174-
name = string.IsNullOrEmpty(config.MetaCharacter)
175-
? "hx-config:inherited"
176-
: $"hx-config{config.MetaCharacter}inherited";
177-
}
178-
else
179-
{
180-
name = "hx-config";
181-
}
182-
}
169+
HtmxTargetVersion.V4 when Inherited => "hx-config:inherited",
170+
HtmxTargetVersion.V4 => "hx-config",
171+
_ => "hx-request"
172+
};
183173

184174
output.Attributes.SetAttribute(
185175
new TagHelperAttribute(name, new HtmlString(json), HtmlAttributeValueStyle.SingleQuotes));

src/Ramstack.HtmxToolkit/TagHelpers/HtmxValsTagHelper.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ public override Task ProcessAsync(TagHelperContext context, TagHelperOutput outp
5959
{
6060
var name = "hx-vals";
6161
if (Inherited && options.Value.TargetVersion == HtmxTargetVersion.V4)
62-
if (options.Value.HtmxConfig is HtmxV4Config config)
63-
name = string.IsNullOrEmpty(config.MetaCharacter)
64-
? "hx-vals:inherited"
65-
: $"hx-vals{config.MetaCharacter}inherited";
62+
name = "hx-vals:inherited";
6663

6764
var info = HtmxDictionaryJsonSerializerContext.Default.IDictionaryStringString;
6865
var json = JsonSerializer.Serialize(values, info);

tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxConfigTagHelperTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ public async Task ProcessAsync_SerializesOnlyHtmx4Options()
247247
{
248248
htmx.LogAll = true;
249249
htmx.Prefix = "data-custom-";
250-
htmx.MetaCharacter = "-";
251250
htmx.History = HtmxHistoryMode.Reload;
252251
htmx.DefaultSwap = HtmxSwap.OuterMorph;
253252
htmx.AllowEmptySwapAfterOob = true;
@@ -273,7 +272,7 @@ public async Task ProcessAsync_SerializesOnlyHtmx4Options()
273272

274273
Assert.That(json.Keys, Is.EquivalentTo(new[]
275274
{
276-
"logAll", "prefix", "metaCharacter", "history", "defaultSwap", "allowEmptySwapAfterOOB",
275+
"logAll", "prefix", "history", "defaultSwap", "allowEmptySwapAfterOOB",
277276
"defaultSettleDelay", "includeIndicatorCSS", "indicatorClass", "requestClass",
278277
"inlineScriptNonce", "extensions", "implicitInheritance", "defaultTimeout", "mode",
279278
"defaultFocusScroll", "transitions", "morphIgnore", "morphSkip", "morphSkipChildren",

tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxHeaderTagHelperTests.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,6 @@ public async Task ProcessAsync_Htmx4_Inherited_UsesInheritedAttribute()
8080
Assert.That(output.Attributes["hx-headers"], Is.Null);
8181
}
8282

83-
[Test]
84-
public async Task ProcessAsync_Htmx4_Inherited_UsesConfiguredMetaCharacter()
85-
{
86-
var output = TestHelper.CreateTagHelperOutput();
87-
var helper = CreateHelper(HtmxTargetVersion.V4, "-");
88-
89-
helper.Inherited = true;
90-
helper.Headers["X-Custom"] = "value";
91-
92-
await helper.ProcessAsync(TestHelper.CreateTagHelperContext(), output);
93-
var attribute = output.Attributes["hx-headers-inherited"];
94-
95-
Assert.That(attribute!.Value.ToString(), Is.EqualTo("{\"X-Custom\":\"value\"}"));
96-
Assert.That(output.Attributes["hx-headers:inherited"], Is.Null);
97-
}
98-
9983
[Test]
10084
public async Task ProcessAsync_Htmx4_NotInherited_UsesOrdinaryAttribute()
10185
{
@@ -140,7 +124,7 @@ public async Task ProcessAsync_Htmx1_Htmx2_Inherited_UsesOrdinaryAttribute(HtmxT
140124
Assert.That(output.Attributes["hx-inherit"], Is.Null);
141125
}
142126

143-
private static HtmxHeaderTagHelper CreateHelper(HtmxTargetVersion version = HtmxTargetVersion.V2, string? metachar = null)
127+
private static HtmxHeaderTagHelper CreateHelper(HtmxTargetVersion version = HtmxTargetVersion.V2)
144128
{
145129
var options = new HtmxToolkitOptions();
146130

@@ -153,7 +137,7 @@ private static HtmxHeaderTagHelper CreateHelper(HtmxTargetVersion version = Htmx
153137
options.UseHtmxV2();
154138
break;
155139
case HtmxTargetVersion.V4:
156-
options.UseHtmxV4(config => config.MetaCharacter = metachar);
140+
options.UseHtmxV4();
157141
break;
158142
default:
159143
throw new ArgumentOutOfRangeException(nameof(version));

tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxRequestTagHelperTests.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,6 @@ public async Task ProcessAsync_Htmx4_Inherited_UsesInheritedAttribute()
193193
Assert.That(output.Attributes["hx-config"], Is.Null);
194194
}
195195

196-
[Test]
197-
public async Task ProcessAsync_Htmx4_Inherited_UsesConfiguredMetaCharacter()
198-
{
199-
var output = TestHelper.CreateTagHelperOutput();
200-
var helper = CreateHelper(HtmxTargetVersion.V4, "-");
201-
202-
helper.Inherited = true;
203-
helper.Timeout = 500;
204-
205-
await helper.ProcessAsync(TestHelper.CreateTagHelperContext(), output);
206-
var attribute = output.Attributes["hx-config-inherited"];
207-
208-
Assert.That(attribute!.Value.ToString(), Is.EqualTo("{\"timeout\":500}"));
209-
Assert.That(output.Attributes["hx-config:inherited"], Is.Null);
210-
}
211-
212196
[Test]
213197
public async Task ProcessAsync_Htmx4_Inherited_WithImplicitInheritance_StillUsesInheritedAttribute()
214198
{
@@ -269,7 +253,7 @@ public async Task ProcessAsync_Htmx1_Htmx2_Inherited_UsesOrdinaryAttribute(HtmxT
269253
Assert.That(output.Attributes["hx-inherit"], Is.Null);
270254
}
271255

272-
private static HtmxRequestTagHelper CreateHelper(HtmxTargetVersion version, string? metachar = null, bool? implicitInheritance = null)
256+
private static HtmxRequestTagHelper CreateHelper(HtmxTargetVersion version, bool? implicitInheritance = null)
273257
{
274258
var options = new HtmxToolkitOptions();
275259

@@ -282,11 +266,7 @@ private static HtmxRequestTagHelper CreateHelper(HtmxTargetVersion version, stri
282266
options.UseHtmxV2();
283267
break;
284268
case HtmxTargetVersion.V4:
285-
options.UseHtmxV4(config =>
286-
{
287-
config.MetaCharacter = metachar;
288-
config.ImplicitInheritance = implicitInheritance;
289-
});
269+
options.UseHtmxV4(config => config.ImplicitInheritance = implicitInheritance);
290270
break;
291271
default:
292272
throw new ArgumentOutOfRangeException(nameof(version));

tests/Ramstack.HtmxToolkit.Tests/TagHelpers/HtmxValsTagHelperTests.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,6 @@ public async Task ProcessAsync_Htmx4_Inherited_UsesInheritedAttribute()
7575
Assert.That(output.Attributes["hx-vals"], Is.Null);
7676
}
7777

78-
[Test]
79-
public async Task ProcessAsync_Htmx4_Inherited_UsesConfiguredMetaCharacter()
80-
{
81-
var output = TestHelper.CreateTagHelperOutput();
82-
var helper = CreateHelper(HtmxTargetVersion.V4, "-");
83-
84-
helper.Inherited = true;
85-
helper.Values["sort"] = "title";
86-
87-
await helper.ProcessAsync(TestHelper.CreateTagHelperContext(), output);
88-
var attribute = output.Attributes["hx-vals-inherited"];
89-
90-
Assert.That(attribute!.Value.ToString(), Is.EqualTo("{\"sort\":\"title\"}"));
91-
Assert.That(output.Attributes["hx-vals:inherited"], Is.Null);
92-
}
93-
9478
[Test]
9579
public async Task ProcessAsync_Htmx4_NotInherited_UsesOrdinaryAttribute()
9680
{
@@ -135,7 +119,7 @@ public async Task ProcessAsync_Htmx1_Htmx2_Inherited_UsesOrdinaryAttribute(HtmxT
135119
Assert.That(output.Attributes["hx-inherit"], Is.Null);
136120
}
137121

138-
private static HtmxValsTagHelper CreateHelper(HtmxTargetVersion version = HtmxTargetVersion.V2, string? metachar = null)
122+
private static HtmxValsTagHelper CreateHelper(HtmxTargetVersion version = HtmxTargetVersion.V2)
139123
{
140124
var options = new HtmxToolkitOptions();
141125

@@ -148,7 +132,7 @@ private static HtmxValsTagHelper CreateHelper(HtmxTargetVersion version = HtmxTa
148132
options.UseHtmxV2();
149133
break;
150134
case HtmxTargetVersion.V4:
151-
options.UseHtmxV4(config => config.MetaCharacter = metachar);
135+
options.UseHtmxV4();
152136
break;
153137
default:
154138
throw new ArgumentOutOfRangeException(nameof(version));

0 commit comments

Comments
 (0)