Skip to content

Commit 3876265

Browse files
committed
fix edge cases
1 parent a5d27b2 commit 3876265

File tree

5 files changed

+37
-41
lines changed

5 files changed

+37
-41
lines changed

liquid/strftime.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@ func strftime(t *time.Time, format string) string {
1515
// Map of strftime codes to Go format codes
1616
// Go uses the reference time: Mon Jan 2 15:04:05 MST 2006
1717
replacements := map[string]string{
18-
"%a": "Mon", // Abbreviated weekday name
19-
"%A": "Monday", // Full weekday name
20-
"%b": "Jan", // Abbreviated month name
21-
"%B": "January", // Full month name
18+
"%a": "Mon", // Abbreviated weekday name
19+
"%A": "Monday", // Full weekday name
20+
"%b": "Jan", // Abbreviated month name
21+
"%B": "January", // Full month name
2222
"%c": "Mon Jan 2 15:04:05 2006", // Preferred date and time
23-
"%d": "02", // Day of the month (01-31)
24-
"%e": "_2", // Day of the month, space-padded ( 1-31)
25-
"%H": "15", // Hour (00-23)
26-
"%I": "03", // Hour (01-12)
27-
"%j": "002", // Day of the year (001-366)
28-
"%m": "01", // Month (01-12)
29-
"%M": "04", // Minute (00-59)
30-
"%p": "PM", // AM or PM
31-
"%P": "pm", // am or pm (lowercase)
32-
"%S": "05", // Second (00-60)
33-
"%U": "", // Week number of year (Sunday first)
34-
"%w": "", // Day of the week (0-6, Sunday is 0)
35-
"%W": "", // Week number of year (Monday first)
36-
"%x": "01/02/06", // Preferred date representation
37-
"%X": "15:04:05", // Preferred time representation
38-
"%y": "06", // Year without century (00-99)
39-
"%Y": "2006", // Year with century
40-
"%z": "-0700", // Numeric timezone offset (+0000)
41-
"%Z": "MST", // Time zone name
42-
"%%": "%", // Literal percent sign
23+
"%d": "02", // Day of the month (01-31)
24+
"%e": "_2", // Day of the month, space-padded ( 1-31)
25+
"%H": "15", // Hour (00-23)
26+
"%I": "03", // Hour (01-12)
27+
"%j": "002", // Day of the year (001-366)
28+
"%m": "01", // Month (01-12)
29+
"%M": "04", // Minute (00-59)
30+
"%p": "PM", // AM or PM
31+
"%P": "pm", // am or pm (lowercase)
32+
"%S": "05", // Second (00-60)
33+
"%U": "", // Week number of year (Sunday first)
34+
"%w": "", // Day of the week (0-6, Sunday is 0)
35+
"%W": "", // Week number of year (Monday first)
36+
"%x": "01/02/06", // Preferred date representation
37+
"%X": "15:04:05", // Preferred time representation
38+
"%y": "06", // Year without century (00-99)
39+
"%Y": "2006", // Year with century
40+
"%z": "-0700", // Numeric timezone offset (+0000)
41+
"%Z": "MST", // Time zone name
42+
"%%": "%", // Literal percent sign
4343
}
4444

4545
result := format
46-
46+
4747
// Replace all strftime codes with Go format codes
4848
for code, goFormat := range replacements {
4949
if goFormat == "" {
@@ -72,4 +72,3 @@ func strftime(t *time.Time, format string) string {
7272

7373
return t.Format(result)
7474
}
75-

liquid/tags/case.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewCaseTag(tagName, markup string, parseContext liquid.ParseContextInterfac
6969
func (c *CaseTag) parseMarkup(markup string, parseContext liquid.ParseContextInterface) error {
7070
// Trim whitespace to match Ruby behavior
7171
markup = strings.TrimSpace(markup)
72-
72+
7373
matches := caseSyntax.FindStringSubmatch(markup)
7474
if len(matches) == 0 {
7575
return liquid.NewSyntaxError("invalid case tag syntax")

liquid/tags/case_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func TestCaseTagRenderToOutputBufferElseBlock(t *testing.T) {
509509
func TestCaseTagWithComma(t *testing.T) {
510510
env := liquid.NewEnvironment()
511511
RegisterStandardTags(env)
512-
512+
513513
template := `{%- case 1 -%}
514514
{%- when 2, 1 -%}
515515
one
@@ -533,7 +533,7 @@ two
533533
func TestCaseTagWithOr(t *testing.T) {
534534
env := liquid.NewEnvironment()
535535
RegisterStandardTags(env)
536-
536+
537537
template := `{%- case 1 -%}
538538
{%- when 2 or 1 -%}
539539
one
@@ -557,7 +557,7 @@ two
557557
func TestCaseTagNodelistIntegration(t *testing.T) {
558558
env := liquid.NewEnvironment()
559559
RegisterStandardTags(env)
560-
560+
561561
template := `{% case var %}{% when true %}WHEN{% else %}ELSE{% endcase %}`
562562
tmpl, err := liquid.ParseTemplate(template, &liquid.TemplateOptions{Environment: env})
563563
if err != nil {
@@ -581,8 +581,8 @@ func TestCaseTagNodelistIntegration(t *testing.T) {
581581
func TestCaseTagIntegrationMultipleConditions(t *testing.T) {
582582
env := liquid.NewEnvironment()
583583
RegisterStandardTags(env)
584-
585-
tests := []struct{
584+
585+
tests := []struct {
586586
name string
587587
template string
588588
assigns map[string]interface{}

liquid/tags/render.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (r *RenderTag) RenderToOutputBuffer(context liquid.TagContext, output *stri
117117
contextVariableName = name.Name()
118118
}
119119
}
120-
120+
121121
// Parse the body as a template
122122
parsedTemplate, err := liquid.ParseTemplate(body, &liquid.TemplateOptions{
123123
Environment: r.ParseContext().Environment(),

liquid/tags/snippet.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package tags
22

33
import (
4+
"strings"
5+
46
"github.com/Notifuse/liquidgo/liquid"
57
)
68

@@ -17,6 +19,7 @@ func NewSnippetTag(tagName, markup string, parseContext liquid.ParseContextInter
1719
// Parse markup - should be just a variable name
1820
// Ruby: p.consume(:id)
1921
// For now, use simple parsing - expect just an identifier
22+
markup = strings.TrimSpace(markup)
2023
if markup == "" {
2124
return nil, liquid.NewSyntaxError("snippet tag requires a variable name")
2225
}
@@ -51,17 +54,11 @@ func (s *SnippetTag) RenderToOutputBuffer(context liquid.TagContext, output *str
5154
// Get template name
5255
templateName := ctx.TemplateName()
5356

54-
// Create snippet drop
57+
// Create snippet drop (body is the rendered content, not the BlockBody)
5558
snippetDrop := liquid.NewSnippetDrop(bodyOutput, s.to, templateName)
5659

5760
// Assign to variable in last scope (matching Ruby's context.scopes.last[@to])
58-
// Use direct scope access like the test does
59-
scopes := ctx.Scopes()
60-
if len(scopes) == 0 {
61-
scopes = []map[string]interface{}{make(map[string]interface{})}
62-
}
63-
// Set in the last scope
64-
scopes[len(scopes)-1][s.to] = snippetDrop
61+
ctx.SetLast(s.to, snippetDrop)
6562

6663
// Increment assign score in resource limits
6764
rl := context.ResourceLimits()

0 commit comments

Comments
 (0)