Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Move mux and server main inside each examples group
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfmin committed Jun 1, 2024
1 parent 77e5d2d commit 972c7e7
Show file tree
Hide file tree
Showing 25 changed files with 253 additions and 262 deletions.
48 changes: 24 additions & 24 deletions docs/appendix/all-demo-examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,24 @@ <h1 class='mb-8'>All Demo Examples</h1>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_web/web-scope.go#L61-L178' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/composite-component-sample-1-page' target='_blank'>Composite New Component With Go</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_web/composite-components.go#L3-L154' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/hello-world-tip-tap' target='_blank'>Integrate a Heavy Vue Component</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_web/use-tiptap-editor.go#L3-L64' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/hello-world' target='_blank'>Hello World</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/server/main.go#L43-L49' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/vuetify-basic-inputs' target='_blank'>Vuetify Basic Inputs</a>
|
Expand Down Expand Up @@ -475,7 +493,7 @@ <h1 class='mb-8'>All Demo Examples</h1>
<li>
<a href='/samples/presets-hello-world/customers' target='_blank'>Presets Hello World</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L1-L64' target='_blank'>Source</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L1-L66' target='_blank'>Source</a>
</li>

<li>
Expand All @@ -493,31 +511,31 @@ <h1 class='mb-8'>All Demo Examples</h1>
<li>
<a href='/samples/presets-listing-customization-fields/customers' target='_blank'>Presets Listing Customization Fields</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L66-L171' target='_blank'>Source</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L68-L173' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/presets-listing-customization-filters/customers' target='_blank'>Presets Listing Filters</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L173-L224' target='_blank'>Source</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L175-L226' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/presets-listing-customization-tabs/customers' target='_blank'>Presets Listing Filter Tabs</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L226-L261' target='_blank'>Source</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L228-L263' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/presets-listing-customization-bulk-actions/customers' target='_blank'>Presets Listing Bulk Actions</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L263-L313' target='_blank'>Source</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L265-L315' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/presets-listing-customization-searcher/customers' target='_blank'>Search Func</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L315-L333' target='_blank'>Source</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L317-L335' target='_blank'>Source</a>
</li>

<li>
Expand Down Expand Up @@ -579,24 +597,6 @@ <h1 class='mb-8'>All Demo Examples</h1>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_admin/action_worker.go#L3-L163' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/composite-component-sample-1-page' target='_blank'>Composite New Component With Go</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_web/composite-components.go#L3-L154' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/hello-world-tip-tap' target='_blank'>Integrate a Heavy Vue Component</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_web/use-tiptap-editor.go#L3-L64' target='_blank'>Source</a>
</li>

<li>
<a href='/samples/hello-world' target='_blank'>Hello World</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/server/main.go#L33-L39' target='_blank'>Source</a>
</li>
</ul>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions docs/basics/listing-customizations.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ <h2 id='change-list-columns-and-component-of-field'>Change List Columns and Comp
<div class='demo'>
<a href='/samples/presets-listing-customization-fields/customers' target='_blank'>Check the demo</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L66-L171' target='_blank'>Source on GitHub</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L68-L173' target='_blank'>Source on GitHub</a>
</div>
</div>
<p>What we did with above code:</p>
Expand All @@ -257,7 +257,7 @@ <h2 id='filters-panel'>Filters Panel
<div class='demo'>
<a href='/samples/presets-listing-customization-filters/customers' target='_blank'>Check the demo</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L173-L224' target='_blank'>Source on GitHub</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L175-L226' target='_blank'>Source on GitHub</a>
</div>
</div>
<p><code>FilterDataFunc</code> of <code>presets.ListingBuilder</code> setup to have the filter menu or not.<br />
Expand All @@ -284,7 +284,7 @@ <h2 id='filter-tabs'>Filter Tabs
<div class='demo'>
<a href='/samples/presets-listing-customization-tabs/customers' target='_blank'>Check the demo</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L226-L261' target='_blank'>Source on GitHub</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L228-L263' target='_blank'>Source on GitHub</a>
</div>
</div>
<p><code>Query</code> string name must be from the Filter's item configuration key field.</p>
Expand All @@ -302,7 +302,7 @@ <h2 id='bulk-actions'>Bulk Actions
<div class='demo'>
<a href='/samples/presets-listing-customization-bulk-actions/customers' target='_blank'>Check the demo</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L263-L313' target='_blank'>Source on GitHub</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L265-L315' target='_blank'>Source on GitHub</a>
</div>
</div>
<ul>
Expand All @@ -325,7 +325,7 @@ <h2 id='search-func'>Search Func
<div class='demo'>
<a href='/samples/presets-listing-customization-searcher/customers' target='_blank'>Check the demo</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L315-L333' target='_blank'>Source on GitHub</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L317-L335' target='_blank'>Source on GitHub</a>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/basics/presets-instant-crud.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ <h1 class='mb-8'>presets, Instant CRUD</h1>
It's not a scaffolding to generate source code. But provide more abstract and<br />
flexible API to enrich features along the way.</p>

<highlightjs :language='"go"' :code='"package examples_presets\n\nimport (\n\t\"fmt\"\n\t\"net/url\"\n\t\"time\"\n\n\t\"github.com/qor5/admin/v3/presets\"\n\t\"github.com/qor5/admin/v3/presets/actions\"\n\t\"github.com/qor5/admin/v3/presets/gorm2op\"\n\tv \"github.com/qor5/ui/v3/vuetify\"\n\t\"github.com/qor5/ui/v3/vuetifyx\"\n\t\"github.com/qor5/web/v3\"\n\t\"github.com/qor5/x/v3/i18n\"\n\th \"github.com/theplant/htmlgo\"\n\t\"golang.org/x/text/language\"\n\t\"gorm.io/gorm\"\n)\n\ntype Customer struct {\n\tID int\n\tName string\n\tEmail string\n\tDescription string\n\tCompanyID int\n\tCreatedAt time.Time\n\tUpdatedAt time.Time\n\tApprovedAt *time.Time\n\tTermAgreedAt *time.Time\n\tApprovalComment string\n\tCreditCards []*CreditCard `gorm:\"-\"`\n\tNotes []*Note `gorm:\"-\"`\n}\n\ntype Address struct {\n\tID int\n\tProvince string\n\tCity string\n\tDistrict string\n}\n\nfunc PresetsHelloWorld(b *presets.Builder, db *gorm.DB) (\n\tmb *presets.ModelBuilder,\n\tcl *presets.ListingBuilder,\n\tce *presets.EditingBuilder,\n\tdp *presets.DetailingBuilder,\n) {\n\terr := db.AutoMigrate(\n\t\t\u0026Customer{},\n\t\t\u0026Company{},\n\t\t\u0026Address{},\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tb.DataOperator(gorm2op.DataOperator(db))\n\tmb = b.Model(\u0026Customer{})\n\n\treturn\n}\n"'></highlightjs>
<highlightjs :language='"go"' :code='"package examples_presets\n\nimport (\n\t\"fmt\"\n\t\"net/url\"\n\t\"time\"\n\n\t\"github.com/qor5/admin/v3/media/media_library\"\n\t\"github.com/qor5/admin/v3/presets\"\n\t\"github.com/qor5/admin/v3/presets/actions\"\n\t\"github.com/qor5/admin/v3/presets/gorm2op\"\n\tv \"github.com/qor5/ui/v3/vuetify\"\n\t\"github.com/qor5/ui/v3/vuetifyx\"\n\t\"github.com/qor5/web/v3\"\n\t\"github.com/qor5/x/v3/i18n\"\n\th \"github.com/theplant/htmlgo\"\n\t\"golang.org/x/text/language\"\n\t\"gorm.io/gorm\"\n)\n\ntype Customer struct {\n\tID int\n\tName string\n\tEmail string\n\tDescription string\n\tCompanyID int\n\tCreatedAt time.Time\n\tUpdatedAt time.Time\n\tApprovedAt *time.Time\n\tTermAgreedAt *time.Time\n\tApprovalComment string\n\tAvatar media_library.MediaBox\n\tCreditCards []*CreditCard `gorm:\"-\"`\n\tNotes []*Note `gorm:\"-\"`\n}\n\ntype Address struct {\n\tID int\n\tProvince string\n\tCity string\n\tDistrict string\n}\n\nfunc PresetsHelloWorld(b *presets.Builder, db *gorm.DB) (\n\tmb *presets.ModelBuilder,\n\tcl *presets.ListingBuilder,\n\tce *presets.EditingBuilder,\n\tdp *presets.DetailingBuilder,\n) {\n\terr := db.AutoMigrate(\n\t\t\u0026Customer{},\n\t\t\u0026Company{},\n\t\t\u0026Address{},\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tb.DataOperator(gorm2op.DataOperator(db))\n\tmb = b.Model(\u0026Customer{})\n\n\treturn\n}\n"'></highlightjs>

<div>
<div class='demo'>
<a href='/samples/presets-hello-world/customers' target='_blank'>Check the demo</a>
|
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L1-L64' target='_blank'>Source on GitHub</a>
<a href='https://github.com/qor5/docs/tree/vue3/docsrc/examples/examples_presets/listing.go#L1-L66' target='_blank'>Source on GitHub</a>
</div>
</div>
<p>And this <code>*presets.Builder</code> instance is actually also a <code>http.Handler</code>, So that we can mount it<br />
Expand Down
2 changes: 1 addition & 1 deletion docs/search_indexes.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docsrc/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ rm ../docs/assets.go
function docsRestart() {
echo "=================>"
killall docgodocs
go build -o /tmp/docgodocs ./examples/server/main.go && /tmp/docgodocs
go build -o /tmp/docgodocs ./server/main.go && /tmp/docgodocs
}

export -f docsRestart
Expand Down
7 changes: 3 additions & 4 deletions docsrc/examples/examples_admin/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package examples_admin
import (
"context"

"github.com/qor5/web/v3"
. "github.com/theplant/htmlgo"
"gorm.io/gorm"

"github.com/qor5/admin/v3/activity"
"github.com/qor5/admin/v3/presets"
"github.com/qor5/admin/v3/presets/gorm2op"
"github.com/qor5/web/v3"
. "github.com/theplant/htmlgo"
"gorm.io/gorm"
)

func ActivityExample(b *presets.Builder, db *gorm.DB) {
Expand Down
41 changes: 41 additions & 0 deletions docsrc/examples/examples_admin/mux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package examples_admin

import (
"net/http"

"github.com/go-chi/chi/v5/middleware"
"github.com/qor5/docs/v3/docsrc/examples"
"github.com/qor5/docs/v3/docsrc/examples/examples_presets"
"github.com/qor5/docs/v3/docsrc/examples/examples_vuetify"
)

func Mux(mux *http.ServeMux, prefix string) http.Handler {
examples_vuetify.Mux(mux, prefix)

im := &examples_vuetify.IndexMux{Mux: http.NewServeMux()}
SamplesHandler(im, prefix)

mux.Handle("/samples/",
middleware.Logger(
middleware.RequestID(
im.Mux,
),
),
)

return mux
}

func SamplesHandler(mux examples.Muxer, prefix string) {
examples_vuetify.SamplesHandler(mux, prefix)
examples_presets.SamplesHandler(mux, prefix)

examples.AddPresetExample(mux, ListingExample)
examples.AddPresetExample(mux, WorkerExample)
examples.AddPresetExample(mux, ActionWorkerExample)
examples.AddPresetExample(mux, InternationalizationExample)
examples.AddPresetExample(mux, LocalizationExample)
examples.AddPresetExample(mux, PublishExample)
examples.AddPresetExample(mux, SEOExampleBasic)
examples.AddPresetExample(mux, ActivityExample)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"

"github.com/go-chi/chi/v5/middleware"
"github.com/qor5/docs/v3/docsrc/examples/mux_admin"
"github.com/qor5/docs/v3/docsrc/examples/mux_web_vuetify"
"github.com/qor5/docs/v3/docsrc/examples/examples_admin"
"github.com/qor5/docs/v3/docsrc/examples/examples_vuetify"
"github.com/qor5/web/v3"
"github.com/theplant/osenv"
)
Expand All @@ -16,10 +16,10 @@ var port = osenv.Get("PORT", "The port to serve on", "7800")
func main() {
fmt.Println("Starting docs at :" + port)
mux := http.NewServeMux()
mux_web_vuetify.Mux(mux, "")
examples_vuetify.Mux(mux, "")

im := &mux_web_vuetify.IndexMux{Mux: http.NewServeMux()}
mux_admin.SamplesHandler(im, "/samples")
im := &examples_vuetify.IndexMux{Mux: http.NewServeMux()}
examples_admin.SamplesHandler(im, "/samples")
mux.Handle("/samples/",
middleware.Logger(
middleware.RequestID(
Expand Down
6 changes: 4 additions & 2 deletions docsrc/examples/examples_presets/detailing_inline_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package examples_presets
import (
"fmt"

"github.com/qor5/admin/v3/media"
"github.com/qor5/admin/v3/presets"
"github.com/qor5/admin/v3/presets/gorm2op"
"github.com/qor5/docs/v3/docsrc/examples"
Expand All @@ -22,7 +23,8 @@ func PresetsDetailInlineEditDetails(b *presets.Builder, db *gorm.DB) (
if err != nil {
panic(err)
}
b.DataOperator(gorm2op.DataOperator(db))
mediaBuilder := media.New(db)
b.DataOperator(gorm2op.DataOperator(db)).Use(mediaBuilder)

cust = b.Model(&Customer{})
dp = cust.Detailing("Details").Drawer(true)
Expand Down Expand Up @@ -51,7 +53,7 @@ func PresetsDetailInlineEditDetails(b *presets.Builder, db *gorm.DB) (
)
return detail
}).
Editing("Name", "Email", "Description")
Editing("Name", "Email", "Description", "Avatar")

return
}
Expand Down
2 changes: 2 additions & 0 deletions docsrc/examples/examples_presets/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"
"time"

"github.com/qor5/admin/v3/media/media_library"
"github.com/qor5/admin/v3/presets"
"github.com/qor5/admin/v3/presets/actions"
"github.com/qor5/admin/v3/presets/gorm2op"
Expand All @@ -29,6 +30,7 @@ type Customer struct {
ApprovedAt *time.Time
TermAgreedAt *time.Time
ApprovalComment string
Avatar media_library.MediaBox
CreditCards []*CreditCard `gorm:"-"`
Notes []*Note `gorm:"-"`
}
Expand Down
58 changes: 58 additions & 0 deletions docsrc/examples/examples_presets/mux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package examples_presets

import (
"fmt"

"github.com/qor5/admin/v3/presets"
"github.com/qor5/docs/v3/docsrc/examples"
"gorm.io/gorm"
)

func SamplesHandler(mux examples.Muxer, prefix string) {
db := examples.ExampleDB()
addExample(mux, db, PresetsHelloWorld)
addExample(mux, db, PresetsListingCustomizationFields)
addExample(mux, db, PresetsListingCustomizationFilters)
addExample(mux, db, PresetsListingCustomizationTabs)
addExample(mux, db, PresetsListingCustomizationBulkActions)
addExample(mux, db, PresetsEditingCustomizationDescription)
addExample(mux, db, PresetsEditingCustomizationFileType)
addExample(mux, db, PresetsEditingCustomizationValidation)
addExample(mux, db, PresetsDetailPageTopNotes)
addExample(mux, db, PresetsDetailPageDetails)
addExample(mux, db, PresetsDetailPageCards)
addExample(mux, db, PresetsPermissions)
addExample(mux, db, PresetsModelBuilderExtensions)
addExample(mux, db, PresetsBasicFilter)
addExample(mux, db, PresetsNotificationCenterSample)
addExample(mux, db, PresetsLinkageSelectFilterItem)
addExample(mux, db, PresetsBrandTitle)
addExample(mux, db, PresetsBrandFunc)
addExample(mux, db, PresetsProfile)
addExample(mux, db, PresetsOrderMenu)
addExample(mux, db, PresetsGroupMenu)
addExample(mux, db, PresetsConfirmDialog)
addExample(mux, db, PresetsEditingCustomizationTabs)
addExample(mux, db, PresetsListingCustomizationSearcher)
addExample(mux, db, PresetsDetailInlineEditDetails)
addExample(mux, db, PresetsDetailInlineEditInspectTables)
return
}

type exampleFunc func(b *presets.Builder, db *gorm.DB) (
cust *presets.ModelBuilder,
cl *presets.ListingBuilder,
ce *presets.EditingBuilder,
dp *presets.DetailingBuilder,
)

func addExample(mux examples.Muxer, db *gorm.DB, f exampleFunc) {
path := examples.URLPathByFunc(f)
p := presets.New().AssetFunc(examples.AddGA).URIPrefix(path)
f(p, db)
fmt.Println("Example mounting at: ", path)
mux.Handle(
path,
p,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"

"github.com/go-chi/chi/v5/middleware"
"github.com/qor5/docs/v3/docsrc/examples/mux_presets"
"github.com/qor5/docs/v3/docsrc/examples/mux_web_vuetify"
"github.com/qor5/docs/v3/docsrc/examples/examples_presets"
"github.com/qor5/docs/v3/docsrc/examples/examples_vuetify"
"github.com/qor5/web/v3"
"github.com/theplant/osenv"
)
Expand All @@ -16,8 +16,8 @@ var port = osenv.Get("PORT", "The port to serve on", "7800")
func main() {
fmt.Println("Starting docs at :" + port)
mux := http.NewServeMux()
im := &mux_web_vuetify.IndexMux{Mux: http.NewServeMux()}
mux_presets.SamplesHandler(im, "/samples")
im := &examples_vuetify.IndexMux{Mux: http.NewServeMux()}
examples_presets.SamplesHandler(im, "/samples")
mux.Handle("/samples/",
middleware.Logger(
middleware.RequestID(
Expand Down
Loading

0 comments on commit 972c7e7

Please sign in to comment.