render

package
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnswersToCSV

func AnswersToCSV(survey *surveygo.Survey, answers surveygo.Answers, checkMark ...*CheckMark) ([]byte, error)

AnswersToCSV generates a CSV from survey answers. An optional CheckMark controls the strings used for selected/not-selected marks in multi-select, checkbox, and toggle columns. Defaults to "true"/"false".

func DefinitionTreeHTML

func DefinitionTreeHTML(survey *surveygo.Survey) ([]byte, error)

DefinitionTreeHTML renders the survey group hierarchy as interactive HTML bytes.

Types

type AnswersResult

type AnswersResult struct {
	CSV    []byte      `json:"csv,omitempty"`
	JSON   *SurveyCard `json:"json,omitempty"`
	HTML   *HTMLResult `json:"html,omitempty"`
	TipTap *TipTapNode `json:"tiptap,omitempty"`
}

AnswersResult contains the requested output formats. Fields are nil when not requested via OutputOptions.

func AnswersTo

func AnswersTo(survey *surveygo.Survey, answers surveygo.Answers, opts OutputOptions) (*AnswersResult, error)

AnswersTo generates multiple output formats in a single pass. Only the formats enabled in opts are computed.

type CheckMark

type CheckMark struct {
	Selected    string
	NotSelected string
}

CheckMark defines the strings used for selected/not-selected marks in CSV output for multi-select, checkbox, and toggle columns. When nil, defaults to "true"/"false".

type Column

type Column struct {
	NameId    string      `json:"nameId"`
	Label     string      `json:"label"`
	FieldType string      `json:"fieldType"`
	Options   []OptionRef `json:"options,omitempty"`
}

Column describes a column in a "repeat-table" section.

type Field

type Field struct {
	Type   string `json:"type"`
	NameId string `json:"nameId"`
	Label  string `json:"label"`
	Value  any    `json:"value"`
}

Field represents a single question rendered inside a "group" section.

type GroupNode

type GroupNode struct {
	NameId            string       `json:"nameId"`
	AllowRepeat       bool         `json:"allowRepeat,omitempty"`
	RepeatDescendants int          `json:"repeatDescendants"`
	Children          []*GroupNode `json:"children,omitempty"`
}

GroupNode represents a node in the group hierarchy tree.

type GroupQuestions

type GroupQuestions struct {
	GroupNameId string         `json:"groupNameId"`
	Questions   []QuestionInfo `json:"questions"`
}

GroupQuestions maps a group to its direct questions.

type GroupTree

type GroupTree struct {
	Roots []*GroupNode          `json:"roots"`
	Index map[string]*GroupNode `json:"-"`
}

GroupTree holds the hierarchical tree and a flat index for O(1) lookup.

func DefinitionTreeJSON

func DefinitionTreeJSON(survey *surveygo.Survey) (*GroupTree, error)

DefinitionTreeJSON builds the hierarchical group tree with cycle detection.

type HTMLResult

type HTMLResult struct {
	HTML []byte `json:"html"`
	CSS  []byte `json:"css"`
}

HTMLResult contains HTML body and CSS as separate byte slices.

func AnswersToHTML

func AnswersToHTML(survey *surveygo.Survey, answers surveygo.Answers) (*HTMLResult, error)

AnswersToHTML renders survey answers as HTML and CSS independently.

func (*HTMLResult) WithCSSPath

func (r *HTMLResult) WithCSSPath(cssPath string) *HTMLResult

WithCSSPath returns a copy of HTMLResult with the CSS link href replaced in the HTML.

type Instance

type Instance struct {
	Sections []Section `json:"sections"`
}

Instance is a single entry in a "repeat-list" section.

type OptionInfo

type OptionInfo struct {
	NameId string `json:"nameId"`
	Label  string `json:"label"`
	Value  any    `json:"value,omitempty"`
}

OptionInfo is the processed output for a select/choice option.

type OptionRef

type OptionRef struct {
	NameId   string `json:"nameId"`
	Label    string `json:"label"`
	Selected bool   `json:"selected"`
}

OptionRef represents an option in a multi-select column or field.

type OutputOptions

type OutputOptions struct {
	CSV    bool
	JSON   bool
	HTML   bool
	TipTap bool

	CheckMark *CheckMark // CSV boolean columns; nil = "true"/"false"
}

OutputOptions specifies which output formats to generate.

type QuestionInfo

type QuestionInfo struct {
	NameId       string       `json:"nameId"`
	Label        string       `json:"label,omitempty"`
	QuestionType string       `json:"questionType"`
	Format       string       `json:"format,omitempty"`
	ExternalType string       `json:"externalType,omitempty"`
	Options      []OptionInfo `json:"options,omitempty"`
	AnswerExpr   string       `json:"answerExpr,omitempty"`
}

QuestionInfo is the processed output for a question.

type Row

type Row = map[string]any

Row is a single row in a "repeat-table" section, keyed by column nameId.

type Section

type Section struct {
	Type      string     `json:"type"`
	NameId    string     `json:"nameId"`
	Title     string     `json:"title"`
	Fields    []Field    `json:"fields,omitempty"`
	Columns   []Column   `json:"columns,omitempty"`
	Rows      []Row      `json:"rows,omitempty"`
	Instances []Instance `json:"instances,omitempty"`
	Sections  []Section  `json:"sections,omitempty"`
}

Section represents a group rendered as a card section. Type determines which fields are populated: "group" uses Fields, "repeat-table" uses Columns+Rows, "repeat-list" uses Instances.

type SurveyCard

type SurveyCard struct {
	SurveyId string    `json:"surveyId"`
	Title    string    `json:"title"`
	Sections []Section `json:"sections"`
}

SurveyCard is the JSON-renderable card output for a survey response.

func AnswersToJSON

func AnswersToJSON(survey *surveygo.Survey, answers surveygo.Answers) (*SurveyCard, error)

AnswersToJSON builds a structured SurveyCard from survey answers.

type TipTapMark

type TipTapMark struct {
	Type  string         `json:"type"`
	Attrs map[string]any `json:"attrs,omitempty"`
}

TipTapMark represents an inline mark (bold, italic, etc.) on a text node.

type TipTapNode

type TipTapNode struct {
	Type    string         `json:"type"`
	Attrs   map[string]any `json:"attrs,omitempty"`
	Content []TipTapNode   `json:"content,omitempty"`
	Text    string         `json:"text,omitempty"`
	Marks   []TipTapMark   `json:"marks,omitempty"`
}

TipTapNode represents a node in a TipTap/ProseMirror document tree.

func AnswersToTipTap

func AnswersToTipTap(survey *surveygo.Survey, answers surveygo.Answers) (*TipTapNode, error)

AnswersToTipTap builds a TipTap-compatible document from survey answers.

type TreeResult

type TreeResult struct {
	HTML []byte     `json:"html,omitempty"`
	JSON *GroupTree `json:"json,omitempty"`
}

TreeResult contains both representations of the group tree.

func DefinitionTree

func DefinitionTree(survey *surveygo.Survey) (*TreeResult, error)

DefinitionTree returns both HTML and JSON representations of the group tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL