- Timestamp:
- Apr 21, 2023, 8:25:31 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cmd/aya/main.go
r59 r60 17 17 "marisa.chaotic.ninja/aya" 18 18 log "github.com/sirupsen/logrus" 19 "github.com/eknkc/amber" 20 "github.com/yosssi/gcss" 19 21 ) 20 22 … … 222 224 } 223 225 226 // Renders .amber file into .html 227 func buildAmber(path string, w io.Writer, vars Vars) error { 228 v, body, err := getVars(path, vars) 229 if err != nil { 230 return err 231 } 232 a := amber.New() 233 if err := a.Parse(body); err != nil { 234 fmt.Println(body) 235 return err 236 } 237 238 t, err := a.Compile() 239 if err != nil { 240 return err 241 } 242 243 htmlBuf := &bytes.Buffer{} 244 if err := t.Execute(htmlBuf, v); err != nil { 245 return err 246 } 247 248 if body, err = render(string(htmlBuf.Bytes()), v); err != nil { 249 return err 250 } 251 252 if w == nil { 253 f, err := os.Create(filepath.Join(PUBDIR, renameExt(path, ".amber", ".html"))) 254 if err != nil { 255 return err 256 } 257 defer f.Close() 258 w = f 259 } 260 _, err = io.WriteString(w, body) 261 return err 262 } 263 // Compiles .gcss into .css 264 func buildGCSS(path string, w io.Writer) error { 265 f, err := os.Open(path) 266 if err != nil { 267 return err 268 } 269 defer f.Close() 270 271 if w == nil { 272 s := strings.TrimSuffix(path, ".gcss") + ".css" 273 css, err := os.Create(filepath.Join(PUBDIR, s)) 274 if err != nil { 275 return err 276 } 277 defer css.Close() 278 w = css 279 } 280 _, err = gcss.Compile(w, f) 281 return err 282 } 283 224 284 // Copies file as is from path to writer 225 285 func buildRaw(path string, w io.Writer) error { … … 247 307 } else if ext == ".html" || ext == ".xml" { 248 308 return buildHTML(path, w, vars) 309 } else if ext == ".amber" { 310 return buildAmber(path, w, vars) 311 } else if ext == ".gcss" { 312 return buildGCSS(path, w) 249 313 } else { 250 314 return buildRaw(path, w)
Note:
See TracChangeset
for help on using the changeset viewer.