Skip to content
Snippets Groups Projects
Select Git revision
  • 16f1439e7353a5afb9ebbc6d22288dd47061ac29
  • master default protected
  • commit-alias
  • editor-modeline
  • commit-abbreviation
  • make-hooks-work-as-advertised
  • lyda-home-version
  • feature-aliases
  • git-version-bsd-fix
  • hook-changes
  • v1.20151229-1
  • v1.20151229
  • v1.20150502-1
  • v1.20150502
  • v1.20141026-manpage-static
  • v1.20141026-1
  • v1.20141026
  • v1.20141025-1
  • v1.20141025
  • v1.20141009-manpage-static
  • v1.20141009-1
  • v1.20141009
  • v1.20140508-1-bpo70+1
  • v1.20140508-1
  • v1.20140508-manpage-static
  • v1.20140508
  • v1.20140507
  • v1.20140313
  • v1.20131229-homebrew
  • v1.20131229-1-bpo60+1
30 results

hooks

Blame
  • modules.go 1.09 KiB
    package modules
    
    import (
    	"fmt"
    
    	"gopkg.in/yaml.v3"
    )
    
    // ParamsInterface is the interface for module paramaters.
    type ParamsInterface interface {
    	Name() string
    	OnClick() string
    	Render() string
    }
    
    // Module defines a module.
    type Module struct {
    	Module  string          `yaml:"module"`
    	Name    string          `yaml:"name"`
    	OnClick string          `yaml:"on-click"`
    	Params  ParamsInterface `yaml:"-"`
    }
    
    // M is an intermidiate type to avoid name collisions.
    type M Module
    
    // Params is the structure for module specific params.
    type Params struct {
    	*M     `yaml:",inline"`
    	Params yaml.Node `yaml:"params"`
    }
    
    // UnmarshalYAML is a helper program to unmarshall the specific params.
    func (m *Module) UnmarshalYAML(node *yaml.Node) error {
    	params := &Params{M: (*M)(m)}
    	if err := node.Decode(params); err != nil {
    		return err
    	}
    
    	switch params.Module {
    	case "date":
    		m.Params = NewDate(m)
    	case "text":
    		m.Params = NewText(m)
    	default:
    		return fmt.Errorf("module '%s' is unknown", params.Module)
    	}
    	return params.Params.Decode(m.Params)
    }
    
    func (m *Module) Render() string {
    	return m.Params.Render()
    }