2015-09-20 08:15:21 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/mholt/caddy/config/setup"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the add-on configuration set on Caddyfile
|
|
|
|
type Config struct {
|
2015-09-27 19:33:36 +00:00
|
|
|
Styles string
|
|
|
|
Args []string
|
2015-09-27 12:20:05 +00:00
|
|
|
Command string
|
2015-09-27 18:49:58 +00:00
|
|
|
Content string
|
2015-09-20 08:15:21 +00:00
|
|
|
}
|
|
|
|
|
2015-09-27 12:20:05 +00:00
|
|
|
// ParseCMS parses the configuration file
|
|
|
|
func ParseCMS(c *setup.Controller) (*Config, error) {
|
2015-09-27 19:33:36 +00:00
|
|
|
conf := &Config{Content: "content"}
|
2015-09-20 08:15:21 +00:00
|
|
|
|
|
|
|
for c.Next() {
|
|
|
|
for c.NextBlock() {
|
|
|
|
switch c.Val() {
|
|
|
|
case "styles":
|
|
|
|
if !c.NextArg() {
|
|
|
|
return nil, c.ArgErr()
|
|
|
|
}
|
|
|
|
conf.Styles = c.Val()
|
|
|
|
// Remove the beginning slash if it exists or not
|
|
|
|
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
|
|
|
|
// Add a beginning slash to make a
|
|
|
|
conf.Styles = "/" + conf.Styles
|
2015-09-27 18:49:58 +00:00
|
|
|
case "content":
|
|
|
|
if !c.NextArg() {
|
|
|
|
return nil, c.ArgErr()
|
|
|
|
}
|
|
|
|
conf.Content = c.Val()
|
|
|
|
conf.Content = strings.TrimPrefix(conf.Content, "/")
|
|
|
|
conf.Content = strings.TrimSuffix(conf.Content, "/")
|
2015-09-27 12:20:05 +00:00
|
|
|
case "command":
|
|
|
|
if !c.NextArg() {
|
|
|
|
return nil, c.ArgErr()
|
|
|
|
}
|
|
|
|
conf.Command = c.Val()
|
|
|
|
case "args":
|
|
|
|
conf.Args = c.RemainingArgs()
|
|
|
|
if len(conf.Args) == 0 {
|
2015-09-20 21:00:25 +00:00
|
|
|
return conf, c.ArgErr()
|
|
|
|
}
|
2015-09-20 08:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-27 19:50:17 +00:00
|
|
|
conf.parseArgs()
|
2015-09-20 08:15:21 +00:00
|
|
|
return conf, nil
|
|
|
|
}
|
2015-09-20 21:00:25 +00:00
|
|
|
|
2015-09-27 19:50:17 +00:00
|
|
|
func (c *Config) parseArgs() {
|
2015-09-27 12:20:05 +00:00
|
|
|
for index, element := range c.Args {
|
|
|
|
c.Args[index] = strings.Replace(element, "\"", "", -1)
|
2015-09-20 21:00:25 +00:00
|
|
|
}
|
|
|
|
}
|