func initBlog(settings *settings, session *service.Session, sessions *service.SessionPool, logger *log.Logger, renderer *mtemplate.Renderer) error { G := func(in string) string { return in } nodeType := service.NodeType{ Id: "core.Blog", AddableTo: []string{"."}, Name: i18n.GenLanguageMap(G("Blog"), availableLocales), Fields: []*service.FieldConfig{ {Id: "core.Title"}, }, } if err := session.Monsti().RegisterNodeType(&nodeType); err != nil { return fmt.Errorf("Could not register blog node type: %v", err) } nodeType = service.NodeType{ Id: "core.BlogPost", AddableTo: []string{"core.Blog"}, Name: i18n.GenLanguageMap(G("Blog Post"), availableLocales), Fields: []*service.FieldConfig{ {Id: "core.Title"}, {Id: "core.Body"}, }, Hide: true, PathPrefix: "$year/$month", } if err := session.Monsti().RegisterNodeType(&nodeType); err != nil { return fmt.Errorf("Could not register blog post node type: %v", err) } // Add a signal handler handler := service.NewNodeContextHandler(sessions, func(req uint, session *service.Session, nodeType string, embedNode *service.EmbedNode) ( map[string][]byte, *service.CacheMods, error) { switch nodeType { case "core.Blog": ctx, mods, err := getBlogContext(req, embedNode, session, settings, renderer) if err != nil { return nil, nil, fmt.Errorf("Could not get blog context: %v", err) } return ctx, mods, nil default: return nil, nil, nil } }) if err := session.Monsti().AddSignalHandler(handler); err != nil { logger.Fatalf("Could not add signal handler: %v", err) } return nil }
func setup(c *module.ModuleContext) error { gettext.DefaultLocales.Domain = "monsti-daemon" G := func(in string) string { return in } m := c.Session.Monsti() nodeType := &service.NodeType{ Id: "core.ContactForm", AddableTo: []string{"."}, Name: i18n.GenLanguageMap(G("Contact form"), availableLocales), Fields: append(service.CoreFields, []*service.FieldConfig{ { Id: "core.ContactFormFields", Hidden: true, Type: &service.ListFieldType{ ElementType: &service.CombinedFieldType{map[string]service.FieldConfig{ "Name": {Type: new(service.TextFieldType)}, "Required": {Type: new(service.BoolFieldType)}, "Field": {Type: &service.DynamicTypeFieldType{ Fields: []service.FieldConfig{ { Id: "text", Type: new(service.DummyFieldType), }, { Id: "textarea", Type: new(service.DummyFieldType), }, }}}}}}}}...)} if err := m.RegisterNodeType(nodeType); err != nil { c.Logger.Fatalf("Could not register %q node type: %v", nodeType.Id, err) } handler := service.NewRenderNodeHandler(c.Sessions, func(args *service.RenderNodeArgs, session *service.Session) ( *service.RenderNodeRet, error) { if args.NodeType == "core.ContactForm" { req, err := session.Monsti().GetRequest(args.Request) if err != nil || req == nil { return nil, fmt.Errorf("Could not get request: %v", err) } return renderContactForm(req, session) } return nil, nil }) if err := m.AddSignalHandler(handler); err != nil { c.Logger.Fatalf("Could not add signal handler: %v", err) } return nil }
func setup(c *module.ModuleContext) error { G := func(in string) string { return in } m := c.Session.Monsti() // Register a new node type nodeType := service.NodeType{ Id: "example.ExampleType", Name: i18n.GenLanguageMap(G("Example node type"), availableLocales), Fields: []*service.FieldConfig{ // core.Title and core.Body are already known to the system, // just specify their IDs to include them. {Id: "core.Title"}, {Id: "core.Body"}, { Id: "example.Foo", Name: i18n.GenLanguageMap(G("Foo"), availableLocales), Type: new(service.TextFieldType), }, { Id: "example.Bar", Name: i18n.GenLanguageMap(G("Bar"), availableLocales), Type: new(service.DateTimeFieldType), }, }, } if err := m.RegisterNodeType(&nodeType); err != nil { c.Logger.Fatalf("Could not register %q node type: %v", nodeType.Id, err) } nodeType = service.NodeType{ Id: "example.Embed", Name: i18n.GenLanguageMap(G("Embed example"), availableLocales), Fields: []*service.FieldConfig{ // core.Title and core.Body are already known to the system, // just specify their IDs to include them. {Id: "core.Title"}, {Id: "core.Body"}, }, } if err := m.RegisterNodeType(&nodeType); err != nil { c.Logger.Fatalf("Could not register %q node type: %v", nodeType.Id, err) } nodeType = service.NodeType{ Id: "example.Fields", Name: i18n.GenLanguageMap(G("Fields example"), availableLocales), Fields: []*service.FieldConfig{ // core.Title and core.Body are already known to the system, // just specify their IDs to include them. {Id: "core.Title"}, {Id: "core.Body"}, { Id: "example.Bool", Name: i18n.GenLanguageMap(G("Bool"), availableLocales), Type: new(service.BoolFieldType), }, { Id: "example.DateTime", Name: i18n.GenLanguageMap(G("DateTime"), availableLocales), Type: new(service.DateTimeFieldType), }, { Id: "example.HTMLArea", Name: i18n.GenLanguageMap(G("HTML"), availableLocales), Type: new(service.HTMLFieldType), }, { Id: "example.Hidden", Name: i18n.GenLanguageMap(G("Hidden"), availableLocales), Hidden: true, Type: new(service.TextFieldType), }, { Id: "example.Text", Name: i18n.GenLanguageMap(G("Text"), availableLocales), Type: new(service.TextFieldType), }, { Id: "example.TextList", Name: i18n.GenLanguageMap(G("Text list"), availableLocales), Type: &service.ListFieldType{new(service.TextFieldType)}, }, { Id: "example.Map", Name: i18n.GenLanguageMap(G("Map"), availableLocales), Type: &service.MapFieldType{new(service.TextFieldType)}, }, { Id: "example.Combined", Name: i18n.GenLanguageMap(G("Combined"), availableLocales), Type: &service.CombinedFieldType{ map[string]service.FieldConfig{ "Text": { Name: i18n.GenLanguageMap(G("Text"), availableLocales), Type: new(service.TextFieldType), }, "Bool": { Name: i18n.GenLanguageMap(G("Bool"), availableLocales), Type: new(service.BoolFieldType), }, }}, }, }, } if err := m.RegisterNodeType(&nodeType); err != nil { c.Logger.Fatalf("Could not register %q node type: %v", nodeType.Id, err) } // Add a signal handler handler := service.NewNodeContextHandler(c.Sessions, func(id uint, session *service.Session, nodeType string, embedNode *service.EmbedNode) ( map[string][]byte, *service.CacheMods, error) { if nodeType == "example.ExampleType" { req, err := session.Monsti().GetRequest(id) if err != nil || req == nil { return nil, nil, fmt.Errorf("Could not get request: %v", err) } return map[string][]byte{ "SignalFoo": []byte(fmt.Sprintf("Hello Signal! Site name: %v", req.Site)), }, nil, nil } return nil, nil, nil }) if err := m.AddSignalHandler(handler); err != nil { c.Logger.Fatalf("Could not add signal handler: %v", err) } return nil }
// LoadSiteSettings loads settings for the given site. func (s *MonstiClient) LoadSiteSettings(site string) (*Settings, error) { if s.Error != nil { return nil, s.Error } var reply []byte err := s.RPCClient.Call("Monsti.LoadSiteSettings", site, &reply) if err != nil { return nil, fmt.Errorf("service: LoadSiteSettings error: %v", err) } G := func(in string) string { return in } types := []*FieldConfig{ { Id: "core.Title", Required: true, Name: i18n.GenLanguageMap(G("Title"), []string{"de", "en"}), Type: new(TextFieldType), }, { Id: "core.BaseURL", Required: true, Name: i18n.GenLanguageMap(G("Base URL"), []string{"de", "en"}), Type: new(TextFieldType), }, { Id: "core.Locale", Required: true, Name: i18n.GenLanguageMap(G("Locale"), []string{"de", "en"}), Type: new(TextFieldType), }, { Id: "core.Timezone", Required: true, Name: i18n.GenLanguageMap(G("Timezone"), []string{"de", "en"}), Type: new(TextFieldType), }, { Id: "core.EmailName", Required: true, Name: i18n.GenLanguageMap(G("Email name"), []string{"de", "en"}), Type: new(TextFieldType), }, { Id: "core.EmailAddress", Required: true, Name: i18n.GenLanguageMap(G("Email address"), []string{"de", "en"}), Type: new(TextFieldType), }, { Id: "core.OwnerName", Required: true, Name: i18n.GenLanguageMap(G("Owner name"), []string{"de", "en"}), Type: new(TextFieldType), }, { Id: "core.OwnerEmail", Required: true, Name: i18n.GenLanguageMap(G("Owner email address"), []string{"de", "en"}), Type: new(TextFieldType), }, { Id: "core.SessionAuthKey", Required: true, Name: i18n.GenLanguageMap(G("Session auth key"), []string{"de", "en"}), Type: new(TextFieldType), Hidden: true, }, { Id: "core.PasswordTokenKey", Required: true, Name: i18n.GenLanguageMap(G("Password token key"), []string{"de", "en"}), Type: new(TextFieldType), Hidden: true, }, { Id: "core.CacheDisabled", Hidden: true, Type: new(BoolFieldType), }, { Id: "core.Navigations", Name: i18n.GenLanguageMap(G("Navigations"), []string{"de", "en"}), Hidden: true, Type: &MapFieldType{ &CombinedFieldType{ map[string]FieldConfig{ "depth": { Type: new(IntegerFieldType), }, }}, }, }, { Id: "core.ImageStyles", Hidden: true, Type: &MapFieldType{ &CombinedFieldType{ map[string]FieldConfig{ "width": { Type: new(IntegerFieldType), }, "height": { Type: new(IntegerFieldType), }, }}, }, }, { // EXPERIMENTAL Id: "core.RegionBlocks", Hidden: true, Type: &MapFieldType{ &ListFieldType{ ElementType: &CombinedFieldType{map[string]FieldConfig{ "id": {Type: new(TextFieldType)}}}}}, }, } settings, err := newSettingsFromData(reply, types, s, site) if err != nil { return nil, fmt.Errorf("service: Could not convert node: %v", err) } return settings, nil }
func initNodeTypes(settings *settings, session *service.Session, logger *log.Logger) error { G := func(in string) string { return in } pathType := service.NodeType{ Id: "core.Path", Hide: true, Name: i18n.GenLanguageMap(G("Path"), availableLocales), } if err := session.Monsti().RegisterNodeType(&pathType); err != nil { return fmt.Errorf("Could not register path node type: %v", err) } documentType := service.NodeType{ Id: "core.Document", AddableTo: []string{"."}, Name: i18n.GenLanguageMap(G("Document"), availableLocales), Fields: []*service.FieldConfig{ { Id: "core.Title", Required: true, Name: i18n.GenLanguageMap(G("Title"), availableLocales), Type: new(service.TextFieldType), }, { Id: "core.Description", Name: i18n.GenLanguageMap(G("Description"), availableLocales), Type: new(service.TextFieldType), }, { Id: "core.Thumbnail", Name: i18n.GenLanguageMap(G("Thumbnail"), availableLocales), Type: new(service.RefFieldType), }, { Id: "core.Body", Required: true, Name: i18n.GenLanguageMap(G("Body"), availableLocales), Type: new(service.HTMLFieldType), }, }, } if err := session.Monsti().RegisterNodeType(&documentType); err != nil { return fmt.Errorf("Could not register document node type: %v", err) } fileType := service.NodeType{ Id: "core.File", AddableTo: []string{"."}, Name: i18n.GenLanguageMap(G("File"), availableLocales), Fields: []*service.FieldConfig{ {Id: "core.Title"}, { Id: "core.File", Required: true, Name: i18n.GenLanguageMap(G("File"), availableLocales), Type: new(service.FileFieldType), }, }, } if err := session.Monsti().RegisterNodeType(&fileType); err != nil { return fmt.Errorf("Could not register file node type: %v", err) } imageType := service.NodeType{ Id: "core.Image", Hide: true, AddableTo: []string{"."}, Name: i18n.GenLanguageMap(G("Image"), availableLocales), Fields: []*service.FieldConfig{ {Id: "core.Title"}, {Id: "core.File"}, }, } if err := session.Monsti().RegisterNodeType(&imageType); err != nil { return fmt.Errorf("Could not register image node type: %v", err) } contactFormType := service.NodeType{ Id: "core.ContactForm", AddableTo: []string{"."}, Name: i18n.GenLanguageMap(G("Contact form"), availableLocales), Fields: service.CoreFields, } if err := session.Monsti().RegisterNodeType(&contactFormType); err != nil { return fmt.Errorf("Could not register contactform node type: %v", err) } return nil }