improve the page, sections, components
This commit is contained in:
@ -2,13 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"masonry/lang"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Read the example.masonry file
|
||||
content, err := ioutil.ReadFile("example.masonry")
|
||||
content, err := os.ReadFile("example.masonry")
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading example.masonry: %v\n", err)
|
||||
return
|
||||
@ -20,7 +20,7 @@ func main() {
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf("🎉 Successfully parsed complete DSL with pages!\n\n")
|
||||
fmt.Printf("🎉 Successfully parsed enhanced DSL with containers and detailed fields!\n\n")
|
||||
|
||||
for _, def := range ast.Definitions {
|
||||
if def.Server != nil {
|
||||
@ -55,6 +55,27 @@ func main() {
|
||||
if field.Default != nil {
|
||||
fmt.Printf(" default=%s", *field.Default)
|
||||
}
|
||||
if field.Relationship != nil {
|
||||
fmt.Printf(" relates to %s as %s", field.Relationship.Type, field.Relationship.Cardinality)
|
||||
if field.Relationship.ForeignKey != nil {
|
||||
fmt.Printf(" via %s", *field.Relationship.ForeignKey)
|
||||
}
|
||||
if field.Relationship.Through != nil {
|
||||
fmt.Printf(" through %s", *field.Relationship.Through)
|
||||
}
|
||||
}
|
||||
if len(field.Validations) > 0 {
|
||||
fmt.Printf(" validates: ")
|
||||
for i, val := range field.Validations {
|
||||
if i > 0 {
|
||||
fmt.Printf(", ")
|
||||
}
|
||||
fmt.Printf("%s", val.Type)
|
||||
if val.Value != nil {
|
||||
fmt.Printf("(%s)", *val.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
@ -72,7 +93,31 @@ func main() {
|
||||
if endpoint.Auth {
|
||||
fmt.Printf(" [AUTH]")
|
||||
}
|
||||
fmt.Printf("\n\n")
|
||||
fmt.Printf("\n")
|
||||
|
||||
for _, param := range endpoint.Params {
|
||||
fmt.Printf(" param %s: %s from %s", param.Name, param.Type, param.Source)
|
||||
if param.Required {
|
||||
fmt.Printf(" (required)")
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
if endpoint.Response != nil {
|
||||
fmt.Printf(" returns %s", endpoint.Response.Type)
|
||||
if endpoint.Response.Format != nil {
|
||||
fmt.Printf(" as %s", *endpoint.Response.Format)
|
||||
}
|
||||
if len(endpoint.Response.Fields) > 0 {
|
||||
fmt.Printf(" fields: %v", endpoint.Response.Fields)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
if endpoint.CustomLogic != nil {
|
||||
fmt.Printf(" custom logic: %s\n", *endpoint.CustomLogic)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
if def.Page != nil {
|
||||
@ -87,66 +132,91 @@ func main() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf(" Layout: %s\n", page.Layout)
|
||||
|
||||
if page.LayoutType != nil {
|
||||
fmt.Printf(" Layout Type: %s\n", *page.LayoutType)
|
||||
}
|
||||
|
||||
for _, meta := range page.Meta {
|
||||
fmt.Printf(" Meta %s: %s\n", meta.Name, meta.Content)
|
||||
}
|
||||
|
||||
for _, comp := range page.Components {
|
||||
fmt.Printf(" 📦 Component: %s", comp.Type)
|
||||
if comp.Entity != nil {
|
||||
fmt.Printf(" for %s", *comp.Entity)
|
||||
// Display containers
|
||||
for _, container := range page.Containers {
|
||||
fmt.Printf(" 📦 Container: %s", container.Type)
|
||||
if container.Class != nil {
|
||||
fmt.Printf(" class=\"%s\"", *container.Class)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
|
||||
for _, attr := range comp.Config {
|
||||
if attr.Fields != nil {
|
||||
fmt.Printf(" fields: %v\n", attr.Fields.Fields)
|
||||
for _, section := range container.Sections {
|
||||
fmt.Printf(" 📂 Section: %s", section.Name)
|
||||
if section.Class != nil {
|
||||
fmt.Printf(" class=\"%s\"", *section.Class)
|
||||
}
|
||||
if attr.Actions != nil {
|
||||
fmt.Printf(" actions: ")
|
||||
for i, action := range attr.Actions.Actions {
|
||||
if i > 0 {
|
||||
fmt.Printf(", ")
|
||||
}
|
||||
fmt.Printf("%s", action.Name)
|
||||
if action.Endpoint != nil {
|
||||
fmt.Printf(" via %s", *action.Endpoint)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
|
||||
for _, comp := range section.Components {
|
||||
displayComponent(comp, " ")
|
||||
}
|
||||
|
||||
for _, panel := range section.Panels {
|
||||
fmt.Printf(" 🗂️ Panel: %s trigger=\"%s\"", panel.Name, panel.Trigger)
|
||||
if panel.Position != nil {
|
||||
fmt.Printf(" position=\"%s\"", *panel.Position)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
if attr.DataSource != nil {
|
||||
fmt.Printf(" data from: %s\n", attr.DataSource.Endpoint)
|
||||
}
|
||||
if attr.Style != nil {
|
||||
fmt.Printf(" style: %s", *attr.Style.Theme)
|
||||
if len(attr.Style.Classes) > 0 {
|
||||
fmt.Printf(" classes: %v", attr.Style.Classes)
|
||||
for _, comp := range panel.Components {
|
||||
displayComponent(comp, " ")
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
if attr.Pagination != nil {
|
||||
fmt.Printf(" pagination: enabled")
|
||||
if attr.Pagination.PageSize != nil {
|
||||
fmt.Printf(" size %d", *attr.Pagination.PageSize)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
for _, tab := range container.Tabs {
|
||||
fmt.Printf(" 📋 Tab: %s label=\"%s\"", tab.Name, tab.Label)
|
||||
if tab.Active {
|
||||
fmt.Printf(" (active)")
|
||||
}
|
||||
if attr.Filters != nil {
|
||||
fmt.Printf(" filters: ")
|
||||
for i, filter := range attr.Filters.Filters {
|
||||
if i > 0 {
|
||||
fmt.Printf(", ")
|
||||
}
|
||||
fmt.Printf("%s as %s", filter.Field, filter.Type)
|
||||
if filter.Label != nil {
|
||||
fmt.Printf(" (%s)", *filter.Label)
|
||||
}
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("\n")
|
||||
for _, comp := range tab.Components {
|
||||
displayComponent(comp, " ")
|
||||
}
|
||||
if attr.Validation {
|
||||
fmt.Printf(" validation: enabled\n")
|
||||
}
|
||||
|
||||
for _, comp := range container.Components {
|
||||
displayComponent(comp, " ")
|
||||
}
|
||||
}
|
||||
|
||||
// Display direct components
|
||||
for _, comp := range page.Components {
|
||||
displayComponent(comp, " ")
|
||||
}
|
||||
|
||||
// Display modals
|
||||
for _, modal := range page.Modals {
|
||||
fmt.Printf(" 🪟 Modal: %s trigger=\"%s\"\n", modal.Name, modal.Trigger)
|
||||
for _, comp := range modal.Components {
|
||||
displayComponent(comp, " ")
|
||||
}
|
||||
}
|
||||
|
||||
// Display master-detail layout
|
||||
if page.MasterDetail != nil {
|
||||
fmt.Printf(" 🔄 Master-Detail Layout\n")
|
||||
if page.MasterDetail.Master != nil {
|
||||
fmt.Printf(" 📋 Master: %s\n", page.MasterDetail.Master.Name)
|
||||
for _, comp := range page.MasterDetail.Master.Components {
|
||||
displayComponent(comp, " ")
|
||||
}
|
||||
}
|
||||
if page.MasterDetail.Detail != nil {
|
||||
fmt.Printf(" 📄 Detail: %s", page.MasterDetail.Detail.Name)
|
||||
if page.MasterDetail.Detail.Trigger != nil {
|
||||
fmt.Printf(" trigger=\"%s\"", *page.MasterDetail.Detail.Trigger)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
for _, comp := range page.MasterDetail.Detail.Components {
|
||||
displayComponent(comp, " ")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -155,3 +225,247 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func displayComponent(comp lang.Component, indent string) {
|
||||
fmt.Printf("%s🧩 Component: %s", indent, comp.Type)
|
||||
if comp.Entity != nil {
|
||||
fmt.Printf(" for %s", *comp.Entity)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
|
||||
// Process elements to extract fields, config, conditions, sections, and actions
|
||||
var fields []lang.ComponentField
|
||||
var config []lang.ComponentAttr
|
||||
var conditions []lang.WhenCondition
|
||||
var sections []lang.ComponentSection
|
||||
var actions []lang.ComponentButtonAttr
|
||||
|
||||
for _, element := range comp.Elements {
|
||||
if element.Field != nil {
|
||||
fields = append(fields, *element.Field)
|
||||
}
|
||||
if element.Config != nil {
|
||||
config = append(config, *element.Config)
|
||||
}
|
||||
if element.Condition != nil {
|
||||
conditions = append(conditions, *element.Condition)
|
||||
}
|
||||
if element.Section != nil {
|
||||
sections = append(sections, *element.Section)
|
||||
}
|
||||
if element.Action != nil {
|
||||
actions = append(actions, *element.Action)
|
||||
}
|
||||
}
|
||||
|
||||
// Display config attributes
|
||||
for _, attr := range config {
|
||||
if attr.Fields != nil {
|
||||
fmt.Printf("%s fields: %v\n", indent, attr.Fields.Fields)
|
||||
}
|
||||
if attr.Actions != nil {
|
||||
fmt.Printf("%s actions: ", indent)
|
||||
for i, action := range attr.Actions.Actions {
|
||||
if i > 0 {
|
||||
fmt.Printf(", ")
|
||||
}
|
||||
fmt.Printf("%s", action.Name)
|
||||
if action.Endpoint != nil {
|
||||
fmt.Printf(" via %s", *action.Endpoint)
|
||||
}
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
if attr.DataSource != nil {
|
||||
fmt.Printf("%s data from: %s\n", indent, attr.DataSource.Endpoint)
|
||||
}
|
||||
if attr.Style != nil {
|
||||
fmt.Printf("%s style: %s", indent, *attr.Style.Theme)
|
||||
if len(attr.Style.Classes) > 0 {
|
||||
fmt.Printf(" classes: %v", attr.Style.Classes)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
if attr.Pagination != nil {
|
||||
fmt.Printf("%s pagination: enabled", indent)
|
||||
if attr.Pagination.PageSize != nil {
|
||||
fmt.Printf(" size %d", *attr.Pagination.PageSize)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
if attr.Filters != nil {
|
||||
fmt.Printf("%s filters: ", indent)
|
||||
for i, filter := range attr.Filters.Filters {
|
||||
if i > 0 {
|
||||
fmt.Printf(", ")
|
||||
}
|
||||
fmt.Printf("%s as %s", filter.Field, filter.Type)
|
||||
if filter.Label != nil {
|
||||
fmt.Printf(" (%s)", *filter.Label)
|
||||
}
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
if attr.Validation {
|
||||
fmt.Printf("%s validation: enabled\n", indent)
|
||||
}
|
||||
}
|
||||
|
||||
// Display enhanced fields
|
||||
for _, field := range fields {
|
||||
fmt.Printf("%s 📝 Field: %s type %s", indent, field.Name, field.Type)
|
||||
|
||||
// Process attributes
|
||||
for _, attr := range field.Attributes {
|
||||
if attr.Label != nil {
|
||||
fmt.Printf(" label=\"%s\"", *attr.Label)
|
||||
}
|
||||
if attr.Placeholder != nil {
|
||||
fmt.Printf(" placeholder=\"%s\"", *attr.Placeholder)
|
||||
}
|
||||
if attr.Required {
|
||||
fmt.Printf(" (required)")
|
||||
}
|
||||
if attr.Sortable {
|
||||
fmt.Printf(" (sortable)")
|
||||
}
|
||||
if attr.Searchable {
|
||||
fmt.Printf(" (searchable)")
|
||||
}
|
||||
if attr.Thumbnail {
|
||||
fmt.Printf(" (thumbnail)")
|
||||
}
|
||||
if attr.Default != nil {
|
||||
fmt.Printf(" default=\"%s\"", *attr.Default)
|
||||
}
|
||||
if len(attr.Options) > 0 {
|
||||
fmt.Printf(" options=%v", attr.Options)
|
||||
}
|
||||
if attr.Accept != nil {
|
||||
fmt.Printf(" accept=\"%s\"", *attr.Accept)
|
||||
}
|
||||
if attr.Rows != nil {
|
||||
fmt.Printf(" rows=%d", *attr.Rows)
|
||||
}
|
||||
if attr.Format != nil {
|
||||
fmt.Printf(" format=\"%s\"", *attr.Format)
|
||||
}
|
||||
if attr.Size != nil {
|
||||
fmt.Printf(" size=\"%s\"", *attr.Size)
|
||||
}
|
||||
if attr.Source != nil {
|
||||
fmt.Printf(" source=\"%s\"", *attr.Source)
|
||||
}
|
||||
if attr.Display != nil {
|
||||
fmt.Printf(" display=\"%s\"", *attr.Display)
|
||||
}
|
||||
if attr.Value != nil {
|
||||
fmt.Printf(" value=\"%s\"", *attr.Value)
|
||||
}
|
||||
if attr.Relates != nil {
|
||||
fmt.Printf(" relates to %s", attr.Relates.Type)
|
||||
}
|
||||
if attr.Validation != nil {
|
||||
fmt.Printf(" validates: %s", attr.Validation.Type)
|
||||
if attr.Validation.Value != nil {
|
||||
fmt.Printf("(%s)", *attr.Validation.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
// Display conditions
|
||||
for _, condition := range conditions {
|
||||
fmt.Printf("%s 🔀 When %s %s \"%s\":\n", indent, condition.Field, condition.Operator, condition.Value)
|
||||
for _, field := range condition.Fields {
|
||||
fmt.Printf("%s 📝 Field: %s type %s", indent, field.Name, field.Type)
|
||||
// Process attributes for conditional fields
|
||||
for _, attr := range field.Attributes {
|
||||
if attr.Label != nil {
|
||||
fmt.Printf(" label=\"%s\"", *attr.Label)
|
||||
}
|
||||
if len(attr.Options) > 0 {
|
||||
fmt.Printf(" options=%v", attr.Options)
|
||||
}
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
for _, section := range condition.Sections {
|
||||
fmt.Printf("%s 📂 Section: %s\n", indent, section.Name)
|
||||
}
|
||||
for _, button := range condition.Buttons {
|
||||
fmt.Printf("%s 🔘 Button: %s label=\"%s\"", indent, button.Name, button.Label)
|
||||
if button.Style != nil {
|
||||
fmt.Printf(" style=\"%s\"", *button.Style)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
}
|
||||
|
||||
// Display sections
|
||||
for _, section := range sections {
|
||||
fmt.Printf("%s 📂 Section: %s", indent, section.Name)
|
||||
if section.Class != nil {
|
||||
fmt.Printf(" class=\"%s\"", *section.Class)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
for _, field := range section.Fields {
|
||||
fmt.Printf("%s 📝 Field: %s type %s", indent, field.Name, field.Type)
|
||||
// Process attributes for section fields
|
||||
for _, attr := range field.Attributes {
|
||||
if attr.Label != nil {
|
||||
fmt.Printf(" label=\"%s\"", *attr.Label)
|
||||
}
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
for _, button := range section.Buttons {
|
||||
fmt.Printf("%s 🔘 Button: %s label=\"%s\"", indent, button.Name, button.Label)
|
||||
if button.Style != nil {
|
||||
fmt.Printf(" style=\"%s\"", *button.Style)
|
||||
}
|
||||
if button.Via != nil {
|
||||
fmt.Printf(" via=\"%s\"", *button.Via)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
for _, action := range section.Actions {
|
||||
fmt.Printf("%s ⚡ Action: %s label=\"%s\"", indent, action.Name, action.Label)
|
||||
if action.Style != nil {
|
||||
fmt.Printf(" style=\"%s\"", *action.Style)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
}
|
||||
|
||||
// Display direct actions/buttons
|
||||
for _, action := range actions {
|
||||
fmt.Printf("%s 🔘 Button: %s label=\"%s\"", indent, action.Name, action.Label)
|
||||
if action.Style != nil {
|
||||
fmt.Printf(" style=\"%s\"", *action.Style)
|
||||
}
|
||||
if action.Icon != nil {
|
||||
fmt.Printf(" icon=\"%s\"", *action.Icon)
|
||||
}
|
||||
if action.Loading != nil {
|
||||
fmt.Printf(" loading=\"%s\"", *action.Loading)
|
||||
}
|
||||
if action.Disabled != nil {
|
||||
fmt.Printf(" disabled when %s", *action.Disabled)
|
||||
}
|
||||
if action.Confirm != nil {
|
||||
fmt.Printf(" confirm=\"%s\"", *action.Confirm)
|
||||
}
|
||||
if action.Target != nil {
|
||||
fmt.Printf(" target=\"%s\"", *action.Target)
|
||||
}
|
||||
if action.Position != nil {
|
||||
fmt.Printf(" position=\"%s\"", *action.Position)
|
||||
}
|
||||
if action.Via != nil {
|
||||
fmt.Printf(" via=\"%s\"", *action.Via)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user