From 7803102d4da53025b3111ecf995ddb0225e02a5a Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Sat, 20 Aug 2022 22:54:32 +0700 Subject: [PATCH 01/11] delete default css --- framework/view/ssr/svelte.js | 288 ---------------------------------- framework/view/ssr/svelte.ts | 291 ----------------------------------- 2 files changed, 579 deletions(-) diff --git a/framework/view/ssr/svelte.js b/framework/view/ssr/svelte.js index 0242f6c6..6ffc1616 100644 --- a/framework/view/ssr/svelte.js +++ b/framework/view/ssr/svelte.js @@ -327,7 +327,6 @@ var defaultLayout = { - ${slots.head(props)} ${slots.default(props)} @@ -336,293 +335,6 @@ var defaultLayout = { }; } }; -var defaultCSS = ` -/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */ - -/* -Document -======== -*/ - -/** -Use a better box model (opinionated). -*/ - -*, -::before, -::after { - box-sizing: border-box; -} - -/** -1. Correct the line height in all browsers. -2. Prevent adjustments of font size after orientation changes in iOS. -3. Use a more readable tab size (opinionated). -*/ - -html { - line-height: 1.15; /* 1 */ - -webkit-text-size-adjust: 100%; /* 2 */ - -moz-tab-size: 4; /* 3 */ - tab-size: 4; /* 3 */ -} - -/* -Sections -======== -*/ - -/** -1. Remove the margin in all browsers. -2. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) -*/ - -body { - margin: 0; /* 1 */ - font-family: - system-ui, - -apple-system, /* Firefox supports this but not yet system-ui */ - 'Segoe UI', - Roboto, - Helvetica, - Arial, - sans-serif, - 'Apple Color Emoji', - 'Segoe UI Emoji'; /* 2 */ -} - -/* -Grouping content -================ -*/ - -/** -1. Add the correct height in Firefox. -2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) -*/ - -hr { - height: 0; /* 1 */ - color: inherit; /* 2 */ -} - -/* -Text-level semantics -==================== -*/ - -/** -Add the correct text decoration in Chrome, Edge, and Safari. -*/ - -abbr[title] { - text-decoration: underline dotted; -} - -/** -Add the correct font weight in Edge and Safari. -*/ - -b, -strong { - font-weight: bolder; -} - -/** -1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) -2. Correct the odd 'em' font sizing in all browsers. -*/ - -code, -kbd, -samp, -pre { - font-family: - ui-monospace, - SFMono-Regular, - Consolas, - 'Liberation Mono', - Menlo, - monospace; /* 1 */ - font-size: 1em; /* 2 */ -} - -/** -Add the correct font size in all browsers. -*/ - -small { - font-size: 80%; -} - -/** -Prevent 'sub' and 'sup' elements from affecting the line height in all browsers. -*/ - -sub, -sup { - font-size: 75%; - line-height: 0; - position: relative; - vertical-align: baseline; -} - -sub { - bottom: -0.25em; -} - -sup { - top: -0.5em; -} - -/* -Tabular data -============ -*/ - -/** -1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) -2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) -*/ - -table { - text-indent: 0; /* 1 */ - border-color: inherit; /* 2 */ -} - -/* -Forms -===== -*/ - -/** -1. Change the font styles in all browsers. -2. Remove the margin in Firefox and Safari. -*/ - -button, -input, -optgroup, -select, -textarea { - font-family: inherit; /* 1 */ - font-size: 100%; /* 1 */ - line-height: 1.15; /* 1 */ - margin: 0; /* 2 */ -} - -/** -Remove the inheritance of text transform in Edge and Firefox. -*/ - -button, -select { - text-transform: none; -} - -/** -Correct the inability to style clickable types in iOS and Safari. -*/ - -button, -[type='button'], -[type='reset'], -[type='submit'] { - -webkit-appearance: button; -} - -/** -Remove the inner border and padding in Firefox. -*/ - -::-moz-focus-inner { - border-style: none; - padding: 0; -} - -/** -Restore the focus styles unset by the previous rule. -*/ - -:-moz-focusring { - outline: 1px dotted ButtonText; -} - -/** -Remove the additional ':invalid' styles in Firefox. -See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737 -*/ - -:-moz-ui-invalid { - box-shadow: none; -} - -/** -Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers. -*/ - -legend { - padding: 0; -} - -/** -Add the correct vertical alignment in Chrome and Firefox. -*/ - -progress { - vertical-align: baseline; -} - -/** -Correct the cursor style of increment and decrement buttons in Safari. -*/ - -::-webkit-inner-spin-button, -::-webkit-outer-spin-button { - height: auto; -} - -/** -1. Correct the odd appearance in Chrome and Safari. -2. Correct the outline style in Safari. -*/ - -[type='search'] { - -webkit-appearance: textfield; /* 1 */ - outline-offset: -2px; /* 2 */ -} - -/** -Remove the inner padding in Chrome and Safari on macOS. -*/ - -::-webkit-search-decoration { - -webkit-appearance: none; -} - -/** -1. Correct the inability to style clickable types in iOS and Safari. -2. Change font properties to 'inherit' in Safari. -*/ - -::-webkit-file-upload-button { - -webkit-appearance: button; /* 1 */ - font: inherit; /* 2 */ -} - -/* -Interactive -=========== -*/ - -/* -Add the correct display in Chrome and Safari. -*/ - -summary { - display: list-item; -} -`; export { createView }; diff --git a/framework/view/ssr/svelte.ts b/framework/view/ssr/svelte.ts index 9104a6c4..8dbfa7f5 100644 --- a/framework/view/ssr/svelte.ts +++ b/framework/view/ssr/svelte.ts @@ -58,7 +58,6 @@ const defaultLayout = { - ${slots.head(props)} ${slots.default(props)} @@ -67,293 +66,3 @@ const defaultLayout = { } }, } - -// Default CSS is modern-normalize by Sindre Sorhus -// https://raw.githubusercontent.com/sindresorhus/modern-normalize/v1.1.0/modern-normalize.css -const defaultCSS = ` -/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */ - -/* -Document -======== -*/ - -/** -Use a better box model (opinionated). -*/ - -*, -::before, -::after { - box-sizing: border-box; -} - -/** -1. Correct the line height in all browsers. -2. Prevent adjustments of font size after orientation changes in iOS. -3. Use a more readable tab size (opinionated). -*/ - -html { - line-height: 1.15; /* 1 */ - -webkit-text-size-adjust: 100%; /* 2 */ - -moz-tab-size: 4; /* 3 */ - tab-size: 4; /* 3 */ -} - -/* -Sections -======== -*/ - -/** -1. Remove the margin in all browsers. -2. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) -*/ - -body { - margin: 0; /* 1 */ - font-family: - system-ui, - -apple-system, /* Firefox supports this but not yet system-ui */ - 'Segoe UI', - Roboto, - Helvetica, - Arial, - sans-serif, - 'Apple Color Emoji', - 'Segoe UI Emoji'; /* 2 */ -} - -/* -Grouping content -================ -*/ - -/** -1. Add the correct height in Firefox. -2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) -*/ - -hr { - height: 0; /* 1 */ - color: inherit; /* 2 */ -} - -/* -Text-level semantics -==================== -*/ - -/** -Add the correct text decoration in Chrome, Edge, and Safari. -*/ - -abbr[title] { - text-decoration: underline dotted; -} - -/** -Add the correct font weight in Edge and Safari. -*/ - -b, -strong { - font-weight: bolder; -} - -/** -1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) -2. Correct the odd 'em' font sizing in all browsers. -*/ - -code, -kbd, -samp, -pre { - font-family: - ui-monospace, - SFMono-Regular, - Consolas, - 'Liberation Mono', - Menlo, - monospace; /* 1 */ - font-size: 1em; /* 2 */ -} - -/** -Add the correct font size in all browsers. -*/ - -small { - font-size: 80%; -} - -/** -Prevent 'sub' and 'sup' elements from affecting the line height in all browsers. -*/ - -sub, -sup { - font-size: 75%; - line-height: 0; - position: relative; - vertical-align: baseline; -} - -sub { - bottom: -0.25em; -} - -sup { - top: -0.5em; -} - -/* -Tabular data -============ -*/ - -/** -1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) -2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) -*/ - -table { - text-indent: 0; /* 1 */ - border-color: inherit; /* 2 */ -} - -/* -Forms -===== -*/ - -/** -1. Change the font styles in all browsers. -2. Remove the margin in Firefox and Safari. -*/ - -button, -input, -optgroup, -select, -textarea { - font-family: inherit; /* 1 */ - font-size: 100%; /* 1 */ - line-height: 1.15; /* 1 */ - margin: 0; /* 2 */ -} - -/** -Remove the inheritance of text transform in Edge and Firefox. -*/ - -button, -select { - text-transform: none; -} - -/** -Correct the inability to style clickable types in iOS and Safari. -*/ - -button, -[type='button'], -[type='reset'], -[type='submit'] { - -webkit-appearance: button; -} - -/** -Remove the inner border and padding in Firefox. -*/ - -::-moz-focus-inner { - border-style: none; - padding: 0; -} - -/** -Restore the focus styles unset by the previous rule. -*/ - -:-moz-focusring { - outline: 1px dotted ButtonText; -} - -/** -Remove the additional ':invalid' styles in Firefox. -See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737 -*/ - -:-moz-ui-invalid { - box-shadow: none; -} - -/** -Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers. -*/ - -legend { - padding: 0; -} - -/** -Add the correct vertical alignment in Chrome and Firefox. -*/ - -progress { - vertical-align: baseline; -} - -/** -Correct the cursor style of increment and decrement buttons in Safari. -*/ - -::-webkit-inner-spin-button, -::-webkit-outer-spin-button { - height: auto; -} - -/** -1. Correct the odd appearance in Chrome and Safari. -2. Correct the outline style in Safari. -*/ - -[type='search'] { - -webkit-appearance: textfield; /* 1 */ - outline-offset: -2px; /* 2 */ -} - -/** -Remove the inner padding in Chrome and Safari on macOS. -*/ - -::-webkit-search-decoration { - -webkit-appearance: none; -} - -/** -1. Correct the inability to style clickable types in iOS and Safari. -2. Change font properties to 'inherit' in Safari. -*/ - -::-webkit-file-upload-button { - -webkit-appearance: button; /* 1 */ - font: inherit; /* 2 */ -} - -/* -Interactive -=========== -*/ - -/* -Add the correct display in Chrome and Safari. -*/ - -summary { - display: list-item; -} -` From 481da95d29fbefbe61efd2d1dc743623940998ce Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Sun, 28 Aug 2022 04:39:00 +0700 Subject: [PATCH 02/11] add default css in render default layout --- framework/view/ssr/svelte.js | 1 + framework/view/ssr/svelte.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/framework/view/ssr/svelte.js b/framework/view/ssr/svelte.js index 6ffc1616..617c6396 100644 --- a/framework/view/ssr/svelte.js +++ b/framework/view/ssr/svelte.js @@ -327,6 +327,7 @@ var defaultLayout = { + ${slots.head(props)} ${slots.default(props)} diff --git a/framework/view/ssr/svelte.ts b/framework/view/ssr/svelte.ts index 8dbfa7f5..1f5e8452 100644 --- a/framework/view/ssr/svelte.ts +++ b/framework/view/ssr/svelte.ts @@ -58,6 +58,7 @@ const defaultLayout = { + ${slots.head(props)} ${slots.default(props)} From 5b8253f2e461036ad6d2923a686db39f0611fd3d Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Sun, 28 Aug 2022 04:41:11 +0700 Subject: [PATCH 03/11] add normalize.css to embedded file --- framework/public/loader.go | 11 ++ internal/embedded/embedded.go | 12 ++ internal/embedded/normalize.css | 285 ++++++++++++++++++++++++++++++++ 3 files changed, 308 insertions(+) create mode 100644 internal/embedded/normalize.css diff --git a/framework/public/loader.go b/framework/public/loader.go index 5cb2e42f..a9177188 100644 --- a/framework/public/loader.go +++ b/framework/public/loader.go @@ -97,5 +97,16 @@ func (l *loader) loadDefaults() (files []*embed.File) { Data: embedded.Favicon(), }) } + + // Add a empty default.css if it doesn't exist + if err := vfs.Exist(l.fsys, "public/default.css"); err != nil { + if !errors.Is(err, fs.ErrNotExist) { + l.Bail(err) + } + files = append(files, &embed.File{ + Path: "public/default.css", + Data: []byte(embedded.DefaultCss("")), + }) + } return files } diff --git a/internal/embedded/embedded.go b/internal/embedded/embedded.go index b0196d83..94b8c14a 100644 --- a/internal/embedded/embedded.go +++ b/internal/embedded/embedded.go @@ -7,7 +7,19 @@ import ( //go:embed favicon.ico var favicon []byte +//go:embed normalize.css +var normalize string + // Favicon returns the favicon data func Favicon() []byte { return favicon } + +// DefaultCss returns the default css data +func DefaultCss(css string) string { + switch css { + case "normalize": + return normalize + } + return "/* No Default CSS Loaded */" +} diff --git a/internal/embedded/normalize.css b/internal/embedded/normalize.css new file mode 100644 index 00000000..a57c2225 --- /dev/null +++ b/internal/embedded/normalize.css @@ -0,0 +1,285 @@ +/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */ + +/* +Document +======== +*/ + +/** +Use a better box model (opinionated). +*/ + +*, +::before, +::after { + box-sizing: border-box; +} + +/** +1. Correct the line height in all browsers. +2. Prevent adjustments of font size after orientation changes in iOS. +3. Use a more readable tab size (opinionated). +*/ + +html { + line-height: 1.15; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ + -moz-tab-size: 4; /* 3 */ + tab-size: 4; /* 3 */ +} + +/* +Sections +======== +*/ + +/** +1. Remove the margin in all browsers. +2. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) +*/ + +body { + margin: 0; /* 1 */ + font-family: + system-ui, + -apple-system, /* Firefox supports this but not yet system-ui */ + 'Segoe UI', + Roboto, + Helvetica, + Arial, + sans-serif, + 'Apple Color Emoji', + 'Segoe UI Emoji'; /* 2 */ +} + +/* +Grouping content +================ +*/ + +/** +1. Add the correct height in Firefox. +2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) +*/ + +hr { + height: 0; /* 1 */ + color: inherit; /* 2 */ +} + +/* +Text-level semantics +==================== +*/ + +/** +Add the correct text decoration in Chrome, Edge, and Safari. +*/ + +abbr[title] { + text-decoration: underline dotted; +} + +/** +Add the correct font weight in Edge and Safari. +*/ + +b, +strong { + font-weight: bolder; +} + +/** +1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) +2. Correct the odd 'em' font sizing in all browsers. +*/ + +code, +kbd, +samp, +pre { + font-family: + ui-monospace, + SFMono-Regular, + Consolas, + 'Liberation Mono', + Menlo, + monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/** +Add the correct font size in all browsers. +*/ + +small { + font-size: 80%; +} + +/** +Prevent 'sub' and 'sup' elements from affecting the line height in all browsers. +*/ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* +Tabular data +============ +*/ + +/** +1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) +2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) +*/ + +table { + text-indent: 0; /* 1 */ + border-color: inherit; /* 2 */ +} + +/* +Forms +===== +*/ + +/** +1. Change the font styles in all browsers. +2. Remove the margin in Firefox and Safari. +*/ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ +} + +/** +Remove the inheritance of text transform in Edge and Firefox. +*/ + +button, +select { + text-transform: none; +} + +/** +Correct the inability to style clickable types in iOS and Safari. +*/ + +button, +[type='button'], +[type='reset'], +[type='submit'] { + -webkit-appearance: button; +} + +/** +Remove the inner border and padding in Firefox. +*/ + +::-moz-focus-inner { + border-style: none; + padding: 0; +} + +/** +Restore the focus styles unset by the previous rule. +*/ + +:-moz-focusring { + outline: 1px dotted ButtonText; +} + +/** +Remove the additional ':invalid' styles in Firefox. +See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737 +*/ + +:-moz-ui-invalid { + box-shadow: none; +} + +/** +Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers. +*/ + +legend { + padding: 0; +} + +/** +Add the correct vertical alignment in Chrome and Firefox. +*/ + +progress { + vertical-align: baseline; +} + +/** +Correct the cursor style of increment and decrement buttons in Safari. +*/ + +::-webkit-inner-spin-button, +::-webkit-outer-spin-button { + height: auto; +} + +/** +1. Correct the odd appearance in Chrome and Safari. +2. Correct the outline style in Safari. +*/ + +[type='search'] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ +} + +/** +Remove the inner padding in Chrome and Safari on macOS. +*/ + +::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** +1. Correct the inability to style clickable types in iOS and Safari. +2. Change font properties to 'inherit' in Safari. +*/ + +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ +} + +/* +Interactive +=========== +*/ + +/* +Add the correct display in Chrome and Safari. +*/ + +summary { + display: list-item; +} \ No newline at end of file From be8ad1903156f5d517ff32cd4d49770b3f0ab401 Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Sun, 28 Aug 2022 04:42:21 +0700 Subject: [PATCH 04/11] update scaffolding to add public/default.css --- internal/cli/bud/bud.go | 1 + internal/cli/cli.go | 1 + internal/cli/create/create.go | 3 +++ internal/cli/create/create_test.go | 1 + 4 files changed, 6 insertions(+) diff --git a/internal/cli/bud/bud.go b/internal/cli/bud/bud.go index 89ae7876..2d9999e7 100644 --- a/internal/cli/bud/bud.go +++ b/internal/cli/bud/bud.go @@ -43,6 +43,7 @@ type Input struct { Env []string // Currently passed in only for testing + Css string // Can be empty Dir string // Can be empty BudLn socket.Listener // Can be nil WebLn socket.Listener // Can be nil diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 9b01e73b..6b7c8353 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -49,6 +49,7 @@ func (c *CLI) Run(ctx context.Context, args ...string) error { cmd := create.New(cmd, c.in) cli := cli.Command("create", "create a new app") cli.Arg("dir").String(&cmd.Dir) + cli.Flag("css", "add a css").String(&cmd.Css).Default("normalize") cli.Flag("dev", "link to the development version").Short('D').Bool(&cmd.Dev).Default(versions.Bud == "latest") cli.Flag("log", "filter logs with this pattern").Short('L').String(&cmd.Log).Default("info") cli.Flag("module", "module path for go.mod").String(&cmd.Module).Optional() diff --git a/internal/cli/create/create.go b/internal/cli/create/create.go index f12f9cbe..1173c5dd 100644 --- a/internal/cli/create/create.go +++ b/internal/cli/create/create.go @@ -9,6 +9,7 @@ import ( "github.com/livebud/bud/internal/bail" "github.com/livebud/bud/internal/cli/bud" + "github.com/livebud/bud/internal/embedded" "github.com/livebud/bud/internal/scaffold" "github.com/livebud/bud/internal/versions" mod "github.com/livebud/bud/package/gomod" @@ -22,6 +23,7 @@ func New(bud *bud.Command, in *bud.Input) *Command { type Command struct { Log string Dir string + Css string Module string Dev bool @@ -159,6 +161,7 @@ func (c *Command) Scaffold(state *State) error { if err := scaffold.Scaffold(scaffold.OSFS(c.absDir), scaffold.Template("go.mod", gomod, state.Module), scaffold.Template(".gitignore", gitignore, nil), + scaffold.Template("public/default.css", embedded.DefaultCss(c.Css), nil), scaffold.JSON("package.json", state.Package), ); err != nil { return err diff --git a/internal/cli/create/create_test.go b/internal/cli/create/create_test.go index 1ee4913c..5d153724 100644 --- a/internal/cli/create/create_test.go +++ b/internal/cli/create/create_test.go @@ -39,6 +39,7 @@ func TestCreateOutsideGoPath(t *testing.T) { is.NoErr(td.Exists("go.sum")) is.NoErr(td.Exists("package.json")) is.NoErr(td.Exists("package-lock.json")) + is.NoErr(td.Exists("public/default.css")) } func TestCreateOutsideGoPathModulePath(t *testing.T) { From 609196589847e80a867fe46dd701dafed4bca609 Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Thu, 1 Sep 2022 00:27:55 +0700 Subject: [PATCH 05/11] Change func name for clearly in embedded --- framework/public/loader.go | 2 +- framework/view/ssr/svelte.js | 2 +- framework/view/ssr/svelte.ts | 2 +- internal/cli/create/create.go | 2 +- internal/embedded/embedded.go | 17 +++++++++-------- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/framework/public/loader.go b/framework/public/loader.go index a9177188..d573b672 100644 --- a/framework/public/loader.go +++ b/framework/public/loader.go @@ -105,7 +105,7 @@ func (l *loader) loadDefaults() (files []*embed.File) { } files = append(files, &embed.File{ Path: "public/default.css", - Data: []byte(embedded.DefaultCss("")), + Data: embedded.EmptyCss(), }) } return files diff --git a/framework/view/ssr/svelte.js b/framework/view/ssr/svelte.js index 617c6396..07644668 100644 --- a/framework/view/ssr/svelte.js +++ b/framework/view/ssr/svelte.js @@ -327,7 +327,7 @@ var defaultLayout = { - + ${slots.head(props)} ${slots.default(props)} diff --git a/framework/view/ssr/svelte.ts b/framework/view/ssr/svelte.ts index 1f5e8452..5d54fd77 100644 --- a/framework/view/ssr/svelte.ts +++ b/framework/view/ssr/svelte.ts @@ -58,7 +58,7 @@ const defaultLayout = { - + ${slots.head(props)} ${slots.default(props)} diff --git a/internal/cli/create/create.go b/internal/cli/create/create.go index 1173c5dd..4dce64c7 100644 --- a/internal/cli/create/create.go +++ b/internal/cli/create/create.go @@ -161,7 +161,7 @@ func (c *Command) Scaffold(state *State) error { if err := scaffold.Scaffold(scaffold.OSFS(c.absDir), scaffold.Template("go.mod", gomod, state.Module), scaffold.Template(".gitignore", gitignore, nil), - scaffold.Template("public/default.css", embedded.DefaultCss(c.Css), nil), + scaffold.Template("public/default.css", string(embedded.NormalizeCss()), nil), scaffold.JSON("package.json", state.Package), ); err != nil { return err diff --git a/internal/embedded/embedded.go b/internal/embedded/embedded.go index 94b8c14a..107f9b23 100644 --- a/internal/embedded/embedded.go +++ b/internal/embedded/embedded.go @@ -8,18 +8,19 @@ import ( var favicon []byte //go:embed normalize.css -var normalize string +var normalize []byte // Favicon returns the favicon data func Favicon() []byte { return favicon } -// DefaultCss returns the default css data -func DefaultCss(css string) string { - switch css { - case "normalize": - return normalize - } - return "/* No Default CSS Loaded */" +// NormalizeCss returns the normalize css data +func NormalizeCss() []byte { + return normalize +} + +// EmptyCss reset the default css data +func EmptyCss() []byte { + return []byte("/* No Default CSS Loaded */") } From 61afb450c787aaa11b635ecf21d63e27fdd34ca2 Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Thu, 1 Sep 2022 22:05:07 +0700 Subject: [PATCH 06/11] add test case for default.css scaffolding --- framework/controller/controller_test.go | 13 -------- framework/public/public_test.go | 43 +++++++++++++++++++------ framework/view/view_test.go | 10 ------ internal/cli/create/create_test.go | 1 + 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/framework/controller/controller_test.go b/framework/controller/controller_test.go index 93fc59c5..e176ec8a 100644 --- a/framework/controller/controller_test.go +++ b/framework/controller/controller_test.go @@ -1286,7 +1286,6 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err := res.Query("#bud_target") @@ -1308,7 +1307,6 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1330,7 +1328,6 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1352,7 +1349,6 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1435,7 +1431,6 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err := res.Query("#bud_target") @@ -1457,7 +1452,6 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1479,7 +1473,6 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1501,7 +1494,6 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1587,7 +1579,6 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err := res.Query("#bud_target") @@ -1609,7 +1600,6 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1631,7 +1621,6 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1653,7 +1642,6 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1774,7 +1762,6 @@ func TestEmptyActionWithView(t *testing.T) { // HTML response is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), `

hello

`) diff --git a/framework/public/public_test.go b/framework/public/public_test.go index d0654d51..58b8834b 100644 --- a/framework/public/public_test.go +++ b/framework/public/public_test.go @@ -57,12 +57,15 @@ var gif = []byte{ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x3b, } +var defaultCss = embedded.NormalizeCss() + func TestPublic(t *testing.T) { is := is.New(t) ctx := context.Background() dir := t.TempDir() td := testdir.New(dir) td.BFiles["public/favicon.ico"] = favicon + td.BFiles["public/default.css"] = defaultCss ga := `function ga(track){}` td.Files["public/ga.js"] = ga css := `* { box-sizing: border-box; }` @@ -87,19 +90,20 @@ func TestPublic(t *testing.T) { is.Equal(200, res.Status()) is.Equal(res.Body().String(), ga) is.In(res.Header("Content-Type"), "/javascript") - // /normalize/normalize.css - res, err = app.Get("/normalize/normalize.css") - is.NoErr(err) - is.Equal(200, res.Status()) - is.Equal(res.Body().String(), css) - is.In(res.Header("Content-Type"), "css") - // /normalize/normalize.css + // check gif file res, err = app.Get("/lol.gif") is.NoErr(err) is.Equal(200, res.Status()) is.Equal(res.Body().Bytes(), gif) is.In(res.Header("Content-Type"), "image/") is.In(res.Header("Content-Type"), "gif") + + // default.css has in public folder + res, err = app.Get("/default.css") + is.NoErr(err) + is.Equal(200, res.Status()) + is.Equal(res.Body().Bytes(), defaultCss) + is.In(res.Header("Content-Type"), "css") } func TestPlugin(t *testing.T) { @@ -126,6 +130,7 @@ func TestGetChangeGet(t *testing.T) { dir := t.TempDir() td := testdir.New(dir) td.BFiles["public/favicon.ico"] = favicon + td.BFiles["public/default.css"] = defaultCss is.NoErr(td.Write(ctx)) cli := testcli.New(dir) app, err := cli.Start(ctx, "run") @@ -145,8 +150,20 @@ func TestGetChangeGet(t *testing.T) { is.NoErr(err) is.Equal(200, res.Status()) is.Equal(res.Body().Bytes(), favicon2) - // is.Equal(result.Stdout(), "") - // is.Equal(result.Stderr(), "") + + res, err = app.Get("/default.css") + is.NoErr(err) + is.Equal(200, res.Status()) + is.Equal(res.Body().Bytes(), defaultCss) + + // default.css changed + defaultCss2 := []byte("/* changed default.css */") + td.BFiles["public/default.css"] = defaultCss2 + is.NoErr(td.Write(ctx)) + res, err = app.Get("/default.css") + is.NoErr(err) + is.Equal(200, res.Status()) + is.Equal(res.Body().Bytes(), defaultCss2) } func TestEmbedFavicon(t *testing.T) { @@ -201,5 +218,11 @@ func TestDefaults(t *testing.T) { is.Equal(200, res.Status()) is.Equal(len(res.Body().Bytes()), len(embedded.Favicon())) is.Equal(res.Body().Bytes(), embedded.Favicon()) - is.NoErr(app.Close()) + + // default.css load as empty if not exist + res, err = app.Get("/default.css") + is.NoErr(err) + is.Equal(200, res.Status()) + is.Equal(res.Body().Bytes(), embedded.EmptyCss()) + is.In(res.Header("Content-Type"), "css") } diff --git a/framework/view/view_test.go b/framework/view/view_test.go index a21cf810..99f36225 100644 --- a/framework/view/view_test.go +++ b/framework/view/view_test.go @@ -41,7 +41,6 @@ func TestHello(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -63,7 +62,6 @@ func TestHello(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hi

") @@ -117,7 +115,6 @@ func TestHelloEmbed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -138,7 +135,6 @@ func TestHelloEmbed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -189,7 +185,6 @@ func TestChunks(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

index

") @@ -207,7 +202,6 @@ func TestChunks(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

show

") @@ -261,7 +255,6 @@ func TestConsoleLog(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -306,7 +299,6 @@ func TestRenameView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

10

") @@ -383,7 +375,6 @@ func TestAddView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

10

") @@ -416,7 +407,6 @@ func TestSvelteImportFromNodeModule(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "") diff --git a/internal/cli/create/create_test.go b/internal/cli/create/create_test.go index 5d153724..3cf88216 100644 --- a/internal/cli/create/create_test.go +++ b/internal/cli/create/create_test.go @@ -58,6 +58,7 @@ func TestCreateOutsideGoPathModulePath(t *testing.T) { is.NoErr(td.Exists("go.sum")) is.NoErr(td.Exists("package.json")) is.NoErr(td.Exists("package-lock.json")) + is.NoErr(td.Exists("public/default.css")) } func TestAutoQuote(t *testing.T) { From d35f4e1d8c4fb9df47efd892cc0c215c0f1435a8 Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Mon, 19 Sep 2022 00:40:20 +0700 Subject: [PATCH 07/11] remove emptyCss --- framework/public/loader.go | 11 ----------- framework/public/public_test.go | 7 ------- 2 files changed, 18 deletions(-) diff --git a/framework/public/loader.go b/framework/public/loader.go index d573b672..5cb2e42f 100644 --- a/framework/public/loader.go +++ b/framework/public/loader.go @@ -97,16 +97,5 @@ func (l *loader) loadDefaults() (files []*embed.File) { Data: embedded.Favicon(), }) } - - // Add a empty default.css if it doesn't exist - if err := vfs.Exist(l.fsys, "public/default.css"); err != nil { - if !errors.Is(err, fs.ErrNotExist) { - l.Bail(err) - } - files = append(files, &embed.File{ - Path: "public/default.css", - Data: embedded.EmptyCss(), - }) - } return files } diff --git a/framework/public/public_test.go b/framework/public/public_test.go index 58b8834b..f09a62fb 100644 --- a/framework/public/public_test.go +++ b/framework/public/public_test.go @@ -218,11 +218,4 @@ func TestDefaults(t *testing.T) { is.Equal(200, res.Status()) is.Equal(len(res.Body().Bytes()), len(embedded.Favicon())) is.Equal(res.Body().Bytes(), embedded.Favicon()) - - // default.css load as empty if not exist - res, err = app.Get("/default.css") - is.NoErr(err) - is.Equal(200, res.Status()) - is.Equal(res.Body().Bytes(), embedded.EmptyCss()) - is.In(res.Header("Content-Type"), "css") } From f721555919f870a9d3cebaa13060dea27f009ee9 Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Mon, 19 Sep 2022 00:42:38 +0700 Subject: [PATCH 08/11] linked default css to svelte runtime when added revert the header with chunked change overlay fs to bud fs --- framework/controller/controller_test.go | 13 +++++ framework/view/ssr/ssr.go | 6 ++ framework/view/ssr/ssr_test.go | 75 +++++++++++++++++++++++++ framework/view/ssr/svelte.js | 4 +- framework/view/ssr/svelte.ts | 4 +- framework/view/view_test.go | 10 ++++ internal/embedded/embedded.go | 5 -- 7 files changed, 108 insertions(+), 9 deletions(-) diff --git a/framework/controller/controller_test.go b/framework/controller/controller_test.go index e176ec8a..93fc59c5 100644 --- a/framework/controller/controller_test.go +++ b/framework/controller/controller_test.go @@ -1286,6 +1286,7 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err := res.Query("#bud_target") @@ -1307,6 +1308,7 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1328,6 +1330,7 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1349,6 +1352,7 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1431,6 +1435,7 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err := res.Query("#bud_target") @@ -1452,6 +1457,7 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1473,6 +1479,7 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1494,6 +1501,7 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1579,6 +1587,7 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err := res.Query("#bud_target") @@ -1600,6 +1609,7 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1621,6 +1631,7 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1642,6 +1653,7 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1762,6 +1774,7 @@ func TestEmptyActionWithView(t *testing.T) { // HTML response is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), `

hello

`) diff --git a/framework/view/ssr/ssr.go b/framework/view/ssr/ssr.go index f4165be2..8be33a6b 100644 --- a/framework/view/ssr/ssr.go +++ b/framework/view/ssr/ssr.go @@ -20,6 +20,7 @@ import ( "github.com/livebud/bud/internal/gotemplate" "github.com/livebud/bud/package/budfs" "github.com/livebud/bud/package/gomod" + "github.com/livebud/bud/package/vfs" ) // Response from evaluating SSR files @@ -49,6 +50,11 @@ type Compiler struct { func (c *Compiler) Compile(ctx context.Context, fsys budfs.FS) ([]byte, error) { dir := c.module.Directory() + + if existCss := vfs.Exist(fsys, "public/default.css"); nil == existCss { + svelteRuntime = strings.Replace(svelteRuntime, ``, ``, 1) + } + result := esbuild.Build(esbuild.BuildOptions{ EntryPointsAdvanced: []esbuild.EntryPoint{ { diff --git a/framework/view/ssr/ssr_test.go b/framework/view/ssr/ssr_test.go index 0d7cacf1..e3f0c018 100644 --- a/framework/view/ssr/ssr_test.go +++ b/framework/view/ssr/ssr_test.go @@ -63,6 +63,81 @@ func TestSvelteHello(t *testing.T) { is.True(strings.Contains(res.Body, `

hi world

`)) } +func TestSvelteRemoveDefaultCss(t *testing.T) { + is := is.New(t) + log := testlog.New() + ctx := context.Background() + dir := t.TempDir() + td := testdir.New(dir) + td.Files["view/index.svelte"] = `

hi world

` + td.NodeModules["svelte"] = versions.Svelte + is.NoErr(td.Write(ctx)) + vm, err := v8.Load() + is.NoErr(err) + svelteCompiler, err := svelte.Load(vm) + is.NoErr(err) + transformer := transformrt.MustLoad(svelte.NewTransformable(svelteCompiler)) + module, err := gomod.Find(dir) + is.NoErr(err) + bfs := budfs.New(module, log) + is.NoErr(err) + bfs.FileGenerator("bud/view/_ssr.js", ssr.New(module, transformer.SSR)) + // Read the wrapped version of index.svelte with node_modules rewritten + code, err := fs.ReadFile(bfs, "bud/view/_ssr.js") + is.NoErr(err) + is.True(strings.Contains(string(code), `create_ssr_component(`)) + is.True(strings.Contains(string(code), `

hi world

`)) + is.True(strings.Contains(string(code), `views["/"] = `)) + result, err := vm.Eval("render.js", string(code)+`; bud.render("/", {})`) + is.NoErr(err) + var res ssr.Response + err = json.Unmarshal([]byte(result), &res) + is.NoErr(err) + is.Equal(res.Status, 200) + is.Equal(len(res.Headers), 1) + is.Equal(res.Headers["Content-Type"], "text/html") + // svelte must not linked to default.css when removed + is.True(!strings.Contains(res.Body, ``)) + is.True(strings.Contains(res.Body, ``)) +} + +func TestSvelteDefaultCss(t *testing.T) { + is := is.New(t) + log := testlog.New() + ctx := context.Background() + dir := t.TempDir() + td := testdir.New(dir) + td.Files["view/index.svelte"] = `

hi world

` + td.Files["public/default.css"] = `.body{}` + td.NodeModules["svelte"] = versions.Svelte + is.NoErr(td.Write(ctx)) + vm, err := v8.Load() + is.NoErr(err) + svelteCompiler, err := svelte.Load(vm) + is.NoErr(err) + transformer := transformrt.MustLoad(svelte.NewTransformable(svelteCompiler)) + module, err := gomod.Find(dir) + is.NoErr(err) + bfs := budfs.New(module, log) + is.NoErr(err) + bfs.FileGenerator("bud/view/_ssr.js", ssr.New(module, transformer.SSR)) + // Read the wrapped version of index.svelte with node_modules rewritten + code, err := fs.ReadFile(bfs, "bud/view/_ssr.js") + is.NoErr(err) + is.True(strings.Contains(string(code), `create_ssr_component(`)) + is.True(strings.Contains(string(code), `

hi world

`)) + is.True(strings.Contains(string(code), `views["/"] = `)) + result, err := vm.Eval("render.js", string(code)+`; bud.render("/", {})`) + is.NoErr(err) + var res ssr.Response + err = json.Unmarshal([]byte(result), &res) + is.NoErr(err) + is.Equal(res.Status, 200) + is.Equal(len(res.Headers), 1) + is.Equal(res.Headers["Content-Type"], "text/html") + is.True(strings.Contains(res.Body, ``)) +} + func TestSvelteAwait(t *testing.T) { is := is.New(t) log := testlog.New() diff --git a/framework/view/ssr/svelte.js b/framework/view/ssr/svelte.js index 07644668..7e5156fa 100644 --- a/framework/view/ssr/svelte.js +++ b/framework/view/ssr/svelte.js @@ -326,8 +326,8 @@ var defaultLayout = { - - + + ${slots.head(props)} ${slots.default(props)} diff --git a/framework/view/ssr/svelte.ts b/framework/view/ssr/svelte.ts index 5d54fd77..29aee608 100644 --- a/framework/view/ssr/svelte.ts +++ b/framework/view/ssr/svelte.ts @@ -57,8 +57,8 @@ const defaultLayout = { - - + + ${slots.head(props)} ${slots.default(props)} diff --git a/framework/view/view_test.go b/framework/view/view_test.go index 99f36225..a21cf810 100644 --- a/framework/view/view_test.go +++ b/framework/view/view_test.go @@ -41,6 +41,7 @@ func TestHello(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -62,6 +63,7 @@ func TestHello(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hi

") @@ -115,6 +117,7 @@ func TestHelloEmbed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -135,6 +138,7 @@ func TestHelloEmbed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -185,6 +189,7 @@ func TestChunks(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

index

") @@ -202,6 +207,7 @@ func TestChunks(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

show

") @@ -255,6 +261,7 @@ func TestConsoleLog(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -299,6 +306,7 @@ func TestRenameView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

10

") @@ -375,6 +383,7 @@ func TestAddView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

10

") @@ -407,6 +416,7 @@ func TestSvelteImportFromNodeModule(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK + Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "") diff --git a/internal/embedded/embedded.go b/internal/embedded/embedded.go index 107f9b23..03f79291 100644 --- a/internal/embedded/embedded.go +++ b/internal/embedded/embedded.go @@ -19,8 +19,3 @@ func Favicon() []byte { func NormalizeCss() []byte { return normalize } - -// EmptyCss reset the default css data -func EmptyCss() []byte { - return []byte("/* No Default CSS Loaded */") -} From ec8fa7974cd21bdf527f04819da094c51f112b7d Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Thu, 22 Sep 2022 00:10:11 +0700 Subject: [PATCH 09/11] reverted cuz default css is not implemented to public.go --- framework/public/public_test.go | 36 +++++++++------------------------ 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/framework/public/public_test.go b/framework/public/public_test.go index f09a62fb..d0654d51 100644 --- a/framework/public/public_test.go +++ b/framework/public/public_test.go @@ -57,15 +57,12 @@ var gif = []byte{ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x3b, } -var defaultCss = embedded.NormalizeCss() - func TestPublic(t *testing.T) { is := is.New(t) ctx := context.Background() dir := t.TempDir() td := testdir.New(dir) td.BFiles["public/favicon.ico"] = favicon - td.BFiles["public/default.css"] = defaultCss ga := `function ga(track){}` td.Files["public/ga.js"] = ga css := `* { box-sizing: border-box; }` @@ -90,20 +87,19 @@ func TestPublic(t *testing.T) { is.Equal(200, res.Status()) is.Equal(res.Body().String(), ga) is.In(res.Header("Content-Type"), "/javascript") - // check gif file + // /normalize/normalize.css + res, err = app.Get("/normalize/normalize.css") + is.NoErr(err) + is.Equal(200, res.Status()) + is.Equal(res.Body().String(), css) + is.In(res.Header("Content-Type"), "css") + // /normalize/normalize.css res, err = app.Get("/lol.gif") is.NoErr(err) is.Equal(200, res.Status()) is.Equal(res.Body().Bytes(), gif) is.In(res.Header("Content-Type"), "image/") is.In(res.Header("Content-Type"), "gif") - - // default.css has in public folder - res, err = app.Get("/default.css") - is.NoErr(err) - is.Equal(200, res.Status()) - is.Equal(res.Body().Bytes(), defaultCss) - is.In(res.Header("Content-Type"), "css") } func TestPlugin(t *testing.T) { @@ -130,7 +126,6 @@ func TestGetChangeGet(t *testing.T) { dir := t.TempDir() td := testdir.New(dir) td.BFiles["public/favicon.ico"] = favicon - td.BFiles["public/default.css"] = defaultCss is.NoErr(td.Write(ctx)) cli := testcli.New(dir) app, err := cli.Start(ctx, "run") @@ -150,20 +145,8 @@ func TestGetChangeGet(t *testing.T) { is.NoErr(err) is.Equal(200, res.Status()) is.Equal(res.Body().Bytes(), favicon2) - - res, err = app.Get("/default.css") - is.NoErr(err) - is.Equal(200, res.Status()) - is.Equal(res.Body().Bytes(), defaultCss) - - // default.css changed - defaultCss2 := []byte("/* changed default.css */") - td.BFiles["public/default.css"] = defaultCss2 - is.NoErr(td.Write(ctx)) - res, err = app.Get("/default.css") - is.NoErr(err) - is.Equal(200, res.Status()) - is.Equal(res.Body().Bytes(), defaultCss2) + // is.Equal(result.Stdout(), "") + // is.Equal(result.Stderr(), "") } func TestEmbedFavicon(t *testing.T) { @@ -218,4 +201,5 @@ func TestDefaults(t *testing.T) { is.Equal(200, res.Status()) is.Equal(len(res.Body().Bytes()), len(embedded.Favicon())) is.Equal(res.Body().Bytes(), embedded.Favicon()) + is.NoErr(app.Close()) } From d16a93ddc84627d30b567dfb9218463d50161810 Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Thu, 22 Sep 2022 01:14:30 +0700 Subject: [PATCH 10/11] remove css parameter --- internal/cli/bud/bud.go | 1 - internal/cli/cli.go | 1 - internal/cli/create/create.go | 1 - 3 files changed, 3 deletions(-) diff --git a/internal/cli/bud/bud.go b/internal/cli/bud/bud.go index 2d9999e7..89ae7876 100644 --- a/internal/cli/bud/bud.go +++ b/internal/cli/bud/bud.go @@ -43,7 +43,6 @@ type Input struct { Env []string // Currently passed in only for testing - Css string // Can be empty Dir string // Can be empty BudLn socket.Listener // Can be nil WebLn socket.Listener // Can be nil diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 6b7c8353..9b01e73b 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -49,7 +49,6 @@ func (c *CLI) Run(ctx context.Context, args ...string) error { cmd := create.New(cmd, c.in) cli := cli.Command("create", "create a new app") cli.Arg("dir").String(&cmd.Dir) - cli.Flag("css", "add a css").String(&cmd.Css).Default("normalize") cli.Flag("dev", "link to the development version").Short('D').Bool(&cmd.Dev).Default(versions.Bud == "latest") cli.Flag("log", "filter logs with this pattern").Short('L').String(&cmd.Log).Default("info") cli.Flag("module", "module path for go.mod").String(&cmd.Module).Optional() diff --git a/internal/cli/create/create.go b/internal/cli/create/create.go index 4dce64c7..6adb0574 100644 --- a/internal/cli/create/create.go +++ b/internal/cli/create/create.go @@ -23,7 +23,6 @@ func New(bud *bud.Command, in *bud.Input) *Command { type Command struct { Log string Dir string - Css string Module string Dev bool From f3067eeaba3991309674d4f19ee8ce047f9645a7 Mon Sep 17 00:00:00 2001 From: Rizal Alfiannor Date: Sun, 25 Sep 2022 09:20:17 +0700 Subject: [PATCH 11/11] remove chunked header in unit test --- framework/controller/controller_test.go | 17 ----------------- framework/view/view_test.go | 12 ------------ 2 files changed, 29 deletions(-) diff --git a/framework/controller/controller_test.go b/framework/controller/controller_test.go index 93fc59c5..9711f38f 100644 --- a/framework/controller/controller_test.go +++ b/framework/controller/controller_test.go @@ -1286,7 +1286,6 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err := res.Query("#bud_target") @@ -1308,7 +1307,6 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1330,7 +1328,6 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1352,7 +1349,6 @@ func TestViewUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1435,7 +1431,6 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err := res.Query("#bud_target") @@ -1457,7 +1452,6 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1479,7 +1473,6 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1501,7 +1494,6 @@ func TestViewNestedUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1587,7 +1579,6 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err := res.Query("#bud_target") @@ -1609,7 +1600,6 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1631,7 +1621,6 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1653,7 +1642,6 @@ func TestViewDeepUnnamed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) el, err = res.Query("#bud_target") @@ -1774,7 +1762,6 @@ func TestEmptyActionWithView(t *testing.T) { // HTML response is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), `

hello

`) @@ -2834,7 +2821,6 @@ func TestCreateRouteAndControllerAndView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) sel, err := res.Query("#bud_target") @@ -2875,7 +2861,6 @@ func TestCreateRouteAndControllerAndView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) sel, err = res.Query("#bud_target") @@ -2918,7 +2903,6 @@ func TestDeleteRouteAndControllerAndView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) sel, err := res.Query("#bud_target") @@ -2931,7 +2915,6 @@ func TestDeleteRouteAndControllerAndView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) sel, err = res.Query("#bud_target") diff --git a/framework/view/view_test.go b/framework/view/view_test.go index a21cf810..1ffc591b 100644 --- a/framework/view/view_test.go +++ b/framework/view/view_test.go @@ -41,7 +41,6 @@ func TestHello(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -63,7 +62,6 @@ func TestHello(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hi

") @@ -84,7 +82,6 @@ func TestHello(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hola

") @@ -117,7 +114,6 @@ func TestHelloEmbed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -138,7 +134,6 @@ func TestHelloEmbed(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -189,7 +184,6 @@ func TestChunks(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

index

") @@ -207,7 +201,6 @@ func TestChunks(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

show

") @@ -261,7 +254,6 @@ func TestConsoleLog(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

hello

") @@ -306,7 +298,6 @@ func TestRenameView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

10

") @@ -383,7 +374,6 @@ func TestAddView(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

10

") @@ -416,7 +406,6 @@ func TestSvelteImportFromNodeModule(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "") @@ -454,7 +443,6 @@ func TestSvelteImportFromOtherDir(t *testing.T) { is.NoErr(err) is.NoErr(res.DiffHeaders(` HTTP/1.1 200 OK - Transfer-Encoding: chunked Content-Type: text/html `)) is.In(res.Body().String(), "

The Time

")