Documentation
¶
Index ¶
- func AnswersToCSV(survey *surveygo.Survey, answers surveygo.Answers, checkMark ...*CheckMark) ([]byte, error)
- func DefinitionTreeHTML(survey *surveygo.Survey) ([]byte, error)
- type AnswersResult
- type CheckMark
- type Column
- type Field
- type GroupNode
- type GroupQuestions
- type GroupTree
- type HTMLResult
- type Instance
- type OptionInfo
- type OptionRef
- type OutputOptions
- type QuestionInfo
- type Row
- type Section
- type SurveyCard
- type TipTapMark
- type TipTapNode
- type TreeResult
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".
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 ¶
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 HTMLResult ¶
HTMLResult contains HTML body and CSS as separate byte slices.
func AnswersToHTML ¶
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 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 ¶
AnswersToJSON builds a structured SurveyCard from survey answers.
type TipTapMark ¶
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 ¶
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.