Skip to content

Commit

Permalink
remove web sockets and add .global.disable.aspect-ratio option
Browse files Browse the repository at this point in the history
  • Loading branch information
oktalz committed Dec 8, 2024
1 parent 417cf75 commit 58d1698
Show file tree
Hide file tree
Showing 21 changed files with 325 additions and 319 deletions.
5 changes: 3 additions & 2 deletions config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (
)

type AspectRatio struct {
AspectRatio string
ValueChanged chan string
AspectRatio string
ValueChanged chan string
DisableAspectRatio bool
}

type Config struct {
Expand Down
26 changes: 22 additions & 4 deletions data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,32 @@ type Message struct {
Data any
}

func Init(server Server, config configuration.Config) { //nolint:funlen,gocognit
func Init(server Server, config *configuration.Config) { //nolint:funlen,gocognit
filesModified := fsnotify.FileWatcher()

// initial read
go func() {
filesModified <- struct{}{}
}()

firstRun := true
var wg sync.WaitGroup
wg.Add(1)

go func() {
for range filesModified {
muPresentation.Lock()
presentation = reader.ReadFiles()
if presentation.Options.AspectRatio != "" {
config.AspectRatio.ValueChanged <- presentation.Options.AspectRatio
go func() {
config.AspectRatio.ValueChanged <- presentation.Options.AspectRatio
}()
}
if presentation.Options.DisableAspectRatio {
config.AspectRatio.DisableAspectRatio = true
go func() {
config.AspectRatio.ValueChanged <- presentation.Options.AspectRatio
}()
}
var err error
for i := range presentation.Slides {
Expand Down Expand Up @@ -156,14 +168,14 @@ func Init(server Server, config configuration.Config) { //nolint:funlen,gocognit

markdown.ResetBlocks()

hTMLNormal, err = regenerateHTML(presentation, config, false)
hTMLNormal, err = regenerateHTML(presentation, *config, false)
if err != nil {
log.Println(err)
} else {
eTagHTMLNormal = ulid.Make().String()
}

hTMLAdmin, err = regenerateHTML(presentation, config, true)
hTMLAdmin, err = regenerateHTML(presentation, *config, true)
if err != nil {
log.Println(err)
} else {
Expand All @@ -174,6 +186,12 @@ func Init(server Server, config configuration.Config) { //nolint:funlen,gocognit
Reload: true,
})
muPresentation.Unlock()
if firstRun {
firstRun = false
wg.Done()
}
}
}()

wg.Wait()
}
5 changes: 4 additions & 1 deletion data/reader/reader-slides.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ReadFiles() types.Presentation { //nolint:funlen,gocognit,gocyclo,cyclop,ma
HidePageNumber: true,
KeepPagePrintOnCut: false,
AspectRatio: "",
ForceAspectRatio: false,
DisableAspectRatio: false,
}
endpoints := map[string]types.TerminalCommand{}

Expand Down Expand Up @@ -60,6 +60,9 @@ func ReadFiles() types.Presentation { //nolint:funlen,gocognit,gocyclo,cyclop,ma
if presentationFile.Options.AspectRatio != "" {
presentationFiles.Options.AspectRatio = presentationFile.Options.AspectRatio
}
if presentationFile.Options.DisableAspectRatio {
presentationFiles.Options.DisableAspectRatio = presentationFile.Options.DisableAspectRatio
}
presentationFiles.Slides = append(presentationFiles.Slides, presentationFile.Slides...)
if presentationFile.Title != "" {
presentationFiles.Title = presentationFile.Title
Expand Down
8 changes: 7 additions & 1 deletion data/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ func processSlides(fileContent string, ro types.ReadOptions) types.Presentation
lines[index] = ""
continue
}
if line == ".global.disable.aspect-ratio" {
ro.DisableAspectRatio = true
lines[index] = ""
continue
}
if strings.HasPrefix(line, ".global.background-color(") && strings.HasSuffix(line, ")") {
currentBackgroundColor = strings.TrimPrefix(line, ".global.background-color(")
currentBackgroundColor = strings.TrimSuffix(currentBackgroundColor, ")")
Expand Down Expand Up @@ -620,7 +625,8 @@ func processSlides(fileContent string, ro types.ReadOptions) types.Presentation
}
return types.Presentation{
Options: types.PresentationOptions{
AspectRatio: ro.AspectRatio,
AspectRatio: ro.AspectRatio,
DisableAspectRatio: ro.DisableAspectRatio,
},
Slides: slides,
Title: title,
Expand Down
83 changes: 41 additions & 42 deletions examples/showcase/1.basic.slide
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
.center
.notes
Hello,
this is a new tool called present written in Go
pages are generated with Go templates and displayed in browser.
this is a new tool called present written in Go.
Pages are generated with Go templates and displayed in browser.
For printing, general idea is to use printing in browser, but unfortunately,
this will only work in chromium like browsers.
Before we start, I need to mention that if you open it in multiple tabs simultaneously
Expand All @@ -29,11 +29,6 @@ Lets show some of the features
#space#

.notes





As is says on the screen, most of examples will show a code block
that will demonstrate how to write the code,
but best way is of course to see the source directly.
Expand Down Expand Up @@ -155,14 +150,17 @@ line two is its own line (github like parsing)
# style

.notes
second one is style, style can be used in tow ways:
first one you see here, where after the keyword
quotation marks are surrounding the HTML style and
everything after the quotation marks is
data on which style will be applied

please note that double quotation mark (") is not mandatory,
but can be used to create more readable source
markdown does not really enable customizing, size, color,
or similar styling, therefore
a second special command is about style,
style can be used in three ways:
first one you see here,
you just use dot and curly brace {} surrounding CSS style
and then in parenthesis () you put markdown.
similar to that dot and div uses same approach,
but the content will be put in div (compared to span on first)
the last option is for data that can span in multiple lines

.notes.end
.global.font-size(4.5svh)

Expand Down Expand Up @@ -203,8 +201,8 @@ this is an example of transitions
.transition
- last line
.notes
where with `cut` you can add content to the screen,
but page does not change
where with `.transition` you can add content to the screen,
but page number does not change
.notes.end

use `.transition` (needs to be on start of the line).
Expand Down Expand Up @@ -232,7 +230,7 @@ instead of adding new content, you can also replace the content
# transitions
- but you can 'reset the state of the screen' - second time
.notes
where with `cut` you can add content to the screen,
where with `transition` you can add content to the screen,
but page does not change
.notes.end

Expand Down Expand Up @@ -262,7 +260,8 @@ copying text you can write it once.
also as I will show soon, this can be used with transitions
to have some kind of dynamic changes on slide

key can be anything, but readability i use hashtag as shown in this example
key can be anything, but for readability
i use hashtag as shown in this example
.notes.end

### one line template
Expand Down Expand Up @@ -301,7 +300,8 @@ we have two options, and we want to show that one is the correct one
`.transition{ORIGINAL}(RESULT)` -> replaces one template with another on transition
`.transition(ORIGINAL){RESULT}` -> alternative
.notes
we can use cut and after that keyword mention what replace command is
we can use transition and after
that keyword mention what replace command is
replaced with new content.
in this case we define two replace blocks,
one that is empty and second one
Expand Down Expand Up @@ -388,7 +388,7 @@ is the same as on most popular implementations
## Tables
.notes
however, additional format was added
that is more HTML like, but this one does not allow formatting
that is more HTML like
.notes.end
.slide.font-size(4.3svh)

Expand Down Expand Up @@ -425,7 +425,7 @@ table row 1 column 2
.notes
images can be defined with keyword image, there is a specific format
where after the image, width and height are specified,
its important to note that size can be define in any html format
its important to note that size can be defined in any html format
like pixels, but due to scaling, units relative to screen are best
.notes.end

Expand Down Expand Up @@ -522,7 +522,7 @@ as seen here, even absolute position is used
.{"font-size: 5svh"}(## {{ . }})
<hr>
.template.end
.MYTITLE Templates - part one
.MYTITLE{Templates - part one}

.notes
we have shown replace directive, that is used to replace part of text
Expand All @@ -533,66 +533,65 @@ this allows you to create more complex solution.
one of the obvious applications is using them with headers of the page
in a way, this allows you to add custom keywords

as seen here, you first define template specify its name and content
as seen here, you first define template specify its name
(in curly braces) and content
to use it, you have to use the newly defined template keyword and
content that will replaced.

standard golang templates can be used here
.notes.end

```txt
#dot#template MYTITLE
#dot#template{MYTITLE}
#dot#{font-size: 5svh}(## {{ . }})
<hr>
#dot#template.end

#dot#MYTITLE Templates - part one
#dot#MYTITLE{Templates - part one}
```

- templates can be defined on start page and used in all others
.================================
.notes
since Go templates also allows using multiple params
we can do that here too,
you define what are they, and then on call,
you can write text separated by space.
this is one limitation of this system, but if space is needed,
HTML non breaking space can be used
you define what are they after template title
in parenthesis separated by comma

and then, when you need to execute template,
you just mention name + markdown for each params
one by one
.notes.end

.template{GOTITLE}(Title,Extra,Last)
.{font-size: 5svh}(## {{ .Title }} - `"{{ .Extra }}"` {{ .Last }})
<hr>
.template.end

.GOTITLE{Title}(Templates Go#space#News \o/)
.GOTITLE{Title}(Templates){Extra}(Go News){Last}(\o/)

```txt
#dot#template GOTITLE .Title .Extra .Last
#dot#template{GOTITLE}(Title,Extra,Last)
#dot#{font-size: 5svh}(## {{ .Title }} - `"{{ .Extra }}"` {{ .Last }})
<hr>
#dot#template.end

#dot#replace.after{-hashtag-space#}(&nbsp;)

#dot#GOTITLE Templates Go-hashtag-space#News \o/
#dot#GOTITLE{Title}(Templates){Extra}(Go News){Last}(\o/)
```

- Go templates can be used
- multiple attributes are separated by `space`
- multiple attributes are separated by `comma`
- when params do not exist, whole line is used for `{{.}}`
- replace can be used to add 'space'
.================================
.notes
when we talk about templates, the most obvious example is title,
because we want to have same look and feel on all pages,
but on same topic, footer and headers are usually mentioned too.
when we talk about templates, the most obvious
examples are headers and footers,

notice, that compared to code we created, that has margins,
for headers and footers we need to specify it.
that can be sees in this example, where header have such margin, but footer does not
that can be seen in this example, where header have such margin, but footer does not

this does not need to specified like, this. we can do that with css settings.
this does not need to specified like this. we can do that with css settings.
but more on that on example that specializes on templates
.notes.end
.FOOTER_TITLE Footers, Headers
Expand Down
24 changes: 6 additions & 18 deletions examples/showcase/1.code.slide
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,14 @@ if x == 1:

.================================
.notes
what is new here though is you can specify additional commands
before the block
we can see here list of all possible options

first of all. we need to start with cast, after cast keyword,
in same line we can specify multiple attributes

as we see, file is here to save code to a file,
some programming languages are sensitive to extensions we need to use.
by default code is executed and just returned
we can use stream that allows you to demonstrate time sensitive operations.
edit is a nice feature that allows you to edit code in browser.
before and after allow you to execute commands before and after code block
(to prepare environment, for example setting right context in k8s)
parallel allows you to run code in parallel to yours,
a good example of that is having server in background
and running client to connect to it.
what is new here though is you can specify
additional commands before the block.
we can see here list of some options.

let's see some examples
all options can be seen in documentation
or with editor extensions.

let's see some examples
.notes.end
.TITLE{Code - Running blocks}
.slide.font-size(3.7svh)
Expand Down
3 changes: 1 addition & 2 deletions examples/showcase/8.customisations.slide
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ additionally
.TITLE{Building a presentation}

- live reloads
- `_.slide` - prepended to all `.slide` files
- `present.css` - used to inject css rules
- `present.js` - used to inject js code
- `present.env` - settings for running application
Expand All @@ -59,7 +58,7 @@ additionally
.TITLE{Presentation sharing}

- best way using `tar.gz`
1. enter folder, run `present zip`, this will create `present.tar.gz`
1. enter folder, run `present -c present.tar.gz`, this will create `present.tar.gz`
2. share file
3. `go install github.com/oktalz/present@latest`
4. `present present.tar.gz`
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/oktalz/present
go 1.23

require (
github.com/coder/websocket v1.8.12
github.com/fsnotify/fsnotify v1.8.0
github.com/go-git/go-git/v5 v5.12.0
github.com/joho/godotenv v1.5.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moA
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo=
github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion handlers/api-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func APICmd(config configuration.Config) http.Handler {
return
}
ch := make(chan string)
go exec.CmdStreamWS(cmd, ch, 10*time.Second, true) //nolint:contextcheck
go exec.CmdStreamWS(cmd, ch, 10*time.Second, true)
lines := []string{}
for line := range ch {
lines = append(lines, line)
Expand Down
Loading

0 comments on commit 58d1698

Please sign in to comment.