benbjohnson/ego hiện có 588 sao trên GitHub, viết chủ yếu bằng Go. An ERB-style templating language for Go.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Ego is an ERb style templating language for Go. It works by transpiling templates into pure Go and including them at compile time. These templates are light wrappers around the Go language itself.
Install
You can find a release build of ego for Linux on the Releases page.
To install ego from source, you can run this command outside of the GOPATH:
$ go get github.com/benbjohnson/ego/...
Usage
Run ego on a directory. Recursively traverse the directory structure and generate Go files for all matching .ego files.
$ ego mypkg
How to Write Templates
An ego template lets you write text that you want to print out but gives you some handy tags to let you inject actual Go code.
This means you don't need to learn a new scripting language to write ego templates—you already know Go!
Raw Text
Any text the ego tool encounters that is not wrapped in <% and %> tags is considered raw text.
If you have a template like this:
hello!
goodbye!
Then ego will generate a matching .ego.go file:
io.WriteString(w, "hello!\ngoodbye!")
Unfortunately that file won't run because we're missing a package line at the top.
We can fix that with code blocks.
Code Blocks
A code block is a section of your template wrapped in <% and %> tags.
It is raw Go code that will be inserted into our generate .ego.go file as-is.
Note the context and io packages are automatically imported to your template.These are the only packages that do this.You'll need to import any other packages you use.
Print Blocks
Our template is getting more useful.
We now have actually runnable Go code.
However, our templates typically need output text frequently so there are blocks specifically for this task called print blocks.
These print blocks wrap a Go expression with <%= and %> tags.
We can expand our previous example and add a type and fields to our code:
The <%= %> block will print your text as escaped HTML, however, sometimes you need the raw text such as when you're writing JSON.
To do this, simply wrap your Go expression with <%== and %> tags.
Components
Simple code and print tags work well for simple templates but it can be difficult to make reusable functionality.
You can use the component syntax to print types that implement this Renderer interface:
type Renderer interface {
Render(context.Context, io.Writer)
}
Component syntax look likes HTML.
You specify the type you want to instantiate as the node name and then use attributes to assign values to fields.
The body of your component will be assigned as a closure to a field called Yield on your component type.
For example, let's say you want to make a reusable button that outputs Bootstrap 4.0 code:
We can write this component as an ego template or in pure Go code.
Here we'll write the component in Go:
The Yield is a special instance of a closure, however, you can also specify named closures using the :: syntax.
Given a component type:
type MyView struct {
Header func()
Yield func()
}
We can specify the separate closures like this:
<ego:MyView>
<ego::Header>
This content will go in the Header closure.
</ego::Header>
This content will go in the Yield closure.
</ego:MyView>
Importing components from other packages
You can import components from other packages by using a namespace that matches the package name
The ego namespace is reserved to import types in the current package.
For example, you can import components from a library such as bootstrap-ego:
benbjohnson/ego có 588 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/benbjohnson/ego. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
benbjohnson/ego có những chủ đề gì?
GitHub topics của benbjohnson/ego: "erb", "go", "template-language". TopGit xếp repo vào nhóm Backend.
benbjohnson/ego còn đang phát triển không?
Commit gần nhất trên benbjohnson/ego là 3.7 năm trước (theo timestamp GitHub). Repo có 39 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
benbjohnson/ego là gì?
benbjohnson/ego (benbjohnson/ego) là dự án Go trên GitHub. Theo mô tả gốc: An ERB-style templating language for Go.
benbjohnson/ego so với các dự án Backend khác thế nào?
benbjohnson/ego được TopGit xếp vào nhóm Backend, với 588 sao GitHub và viết bằng Go. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
benbjohnson/ego viết bằng ngôn ngữ gì?
benbjohnson/ego chủ yếu viết bằng Go. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Vì sao benbjohnson/ego được xếp vào nhóm Backend?
TopGit xếp benbjohnson/ego vào nhóm Backend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "erb", "go", "template-language"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc ego có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về ego.