Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

z1_filetest.gno

2.86 Kb · 145 lines
  1package main
  2
  3import "gno.land/p/moul/template/v0"
  4
  5func main() {
  6	markdownTemplate := `{{ H1 "Welcome to {{ .Name }}'s Page!" }}
  7
  8{{ Bold "Skills" -}}
  9{{- range .Skills }}
 10{{ BulletItem . -}}
 11{{- end }}
 12
 13{{ if .ShowProjects -}}
 14{{ H2 "Projects" }}
 15{{- range .Projects }}
 16{{ H3 .Name }}
 17{{ Paragraph .Description }}
 18{{- if .HasDemo }}
 19{{ Link "View Demo" .DemoURL }}
 20{{- end }}
 21{{- end }}
 22{{- end }}
 23
 24{{ H2 "Contact Information" }}
 25{{- range .Contacts }}
 26{{ BulletItem (printf "%s: %s" .Platform .Value) -}}
 27{{- end }}
 28
 29{{ H2 "Recent Posts" }}
 30{{- if .HasPosts }}
 31{{- range .RecentPosts }}
 32{{ H3 .Title }}
 33{{ Italic .Date }}
 34{{ Paragraph .Summary }}
 35{{- if .HasComments }}
 36{{ Blockquote (printf "Latest comment: %s" (index .Comments 0)) }}
 37{{- end }}
 38{{ HorizontalRule -}}
 39{{- end }}
 40{{- end }}`
 41
 42	data := map[string]interface{}{
 43		"Name": "Alice",
 44		"Skills": []interface{}{
 45			"Go Programming",
 46			"Smart Contracts",
 47			"Blockchain Development",
 48			"System Architecture",
 49		},
 50		"ShowProjects": true,
 51		"Projects": []interface{}{
 52			map[string]interface{}{
 53				"Name":        "Gno Templates",
 54				"Description": "A template engine for Gno",
 55				"HasDemo":     true,
 56				"DemoURL":     "https://example.com/demo",
 57			},
 58			map[string]interface{}{
 59				"Name":        "Blockchain Explorer",
 60				"Description": "A tool for exploring the Gno chain",
 61				"HasDemo":     false,
 62			},
 63		},
 64		"Contacts": []interface{}{
 65			map[string]interface{}{
 66				"Platform": "Email",
 67				"Value":    "alice@gno.land",
 68			},
 69			map[string]interface{}{
 70				"Platform": "GitHub",
 71				"Value":    "@alice",
 72			},
 73		},
 74		"HasPosts": true,
 75		"RecentPosts": []interface{}{
 76			map[string]interface{}{
 77				"Title":       "Getting Started with Gno",
 78				"Date":        "2024-03-20",
 79				"Summary":     "A beginner's guide to Gno development",
 80				"HasComments": true,
 81				"Comments":    []interface{}{"Great article!", "Very helpful"},
 82			},
 83			map[string]interface{}{
 84				"Title":       "Advanced Template Techniques",
 85				"Date":        "2024-03-19",
 86				"Summary":     "Deep dive into Gno templates",
 87				"HasComments": false,
 88			},
 89		},
 90	}
 91
 92	renderer := template.NewRenderer()
 93	output := renderer.Render(markdownTemplate, data)
 94	println(output)
 95}
 96
 97// Output:
 98// # Welcome to Alice's Page!
 99//
100//
101// **Skills**
102// - Go Programming
103//
104// - Smart Contracts
105//
106// - Blockchain Development
107//
108// - System Architecture
109//
110//
111//
112// ## Projects
113// ### Gno Templates
114//
115// A template engine for Gno
116// [View Demo](https://example.com/demo)
117//
118//
119// ### Blockchain Explorer
120//
121// A tool for exploring the Gno chain
122//
123// ## Contact Information
124// - Email: alice@gno.land
125//
126// - GitHub: @alice
127//
128//
129// ## Recent Posts
130// ### Getting Started with Gno
131//
132// *2024-03-20*
133// A beginner's guide to Gno development
134//
135// > Latest comment: Great article!
136//
137//
138//
139// ---
140//
141// ### Advanced Template Techniques
142//
143// *2024-03-19*
144// Deep dive into Gno templates
145// ---