Skip to content

Commit

Permalink
Merge branch 'master' into hh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel authored Nov 10, 2023
2 parents 5307dd9 + 837039a commit 97d9d54
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Stipple"
uuid = "4acbeb90-81a0-11ea-1966-bdaff8155998"
authors = ["Adrian <[email protected]>"]
version = "0.27.14"
version = "0.27.16"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -27,7 +27,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
DataFrames = "1"
Dates = "1.6"
FilePathsBase = "0.9"
Genie = "5.20"
Genie = "5.21.1"
GenieSession = "1"
GenieSessionFileSession = "1"
JSON = "0.20, 0.21"
Expand Down
44 changes: 43 additions & 1 deletion src/Layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Layout

using Genie, Stipple

export layout
export layout, add_css, remove_css
export page, app, row, column, cell, container, flexgrid_kwargs

export theme
Expand Down Expand Up @@ -300,5 +300,47 @@ function theme(; core_theme::Bool = true) :: Vector{String}
output
end

"""
add_css(css::Function; update = true)
Add a css function to the `THEMES`.
### Params
* `css::Function` - a function that results in a vector of style elements
* `update` - determines, whether existing style sheets with the same name shall be removed
### Example
```julia
# css to remove the stipple-core color format of q-table rows
# (this will enable font color setting by the attribute `table-class`)
function mycss()
[
style(\"\"\"
.stipple-core .q-table tbody tr { color: inherit; }
\"\"\")
]
end
add_css(mycss)
```
`
"""
function add_css(css::Function; update = true)
# removal can only be done by name, as the old function has already been overwritten
update && remove_css(css::Function, byname = true)
push!(Stipple.Layout.THEMES, css)
end

"""
remove_css(css::Function, byname::Bool = false)
Remove a stylesheet function from the stack (`Stipple.Layout.THEMES`)
If called with `byname = true`, the function will be identified by name rather than by the function itself.
"""
function remove_css(css::Function; byname::Bool = false)
inds = byname ? nameof.(Stipple.Layout.THEMES) .== nameof(css) : Stipple.Layout.THEMES .== css
deleteat!(Stipple.Layout.THEMES, inds)
end

end
2 changes: 1 addition & 1 deletion src/Stipple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ using Logging, Mixers, Random, Reexport, Dates, Tables
@reexport using Observables
@reexport @using_except Genie: download
import Genie.Router.download
@reexport @using_except Genie.Renderer.Html: mark, div, time, view, render, Headers
@reexport @using_except Genie.Renderers.Html: mark, div, time, view, render, Headers, menu
const htmldiv = Html.div
export render, htmldiv, js_attr
@reexport using JSON3
Expand Down
3 changes: 3 additions & 0 deletions src/stipple/reactivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ end
import Base.map!
@inline Base.map!(f::F, r::Reactive, os...; update::Bool=true) where F = Base.map!(f::F, getfield(r, :o), os...; update=update)

Base.axes(r::Reactive, args...) = Base.axes(getfield(getfield(r, :o), :val), args...)
Base.lastindex(r::Reactive, args...) = Base.lastindex(getfield(getfield(r, :o), :val), args...)

const R = Reactive
const PUBLIC = 1
const PRIVATE = 2
Expand Down
37 changes: 37 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,40 @@ end

down()
end

@testset "Indexing with `end`" begin
r = R([1, 2, 3])
on(r) do r
r[end - 1] += 1
end
@test r[end] == 3
r[end] = 4
@test r[end - 1] == 3
@test r[end] == 4

df = DataFrame(:a => 1:3, :b => 12:14)
@test df[end, 1] == 3
@test df[end, end] == 14
@test df[:, end] == 12:14
end

@testset "adding and removing stylesheets" begin
function my_css()
[style("""
.stipple-core .q-table tbody tr { color: inherit; }
""")]
end

add_css(my_css)
@test Stipple.Layout.THEMES[end] == my_css

n = length(Stipple.Layout.THEMES)
remove_css(my_css)
@test length(Stipple.Layout.THEMES) == n - 1
@test findfirst(==(my_css), Stipple.Layout.THEMES) === nothing

add_css(my_css)
@test Stipple.Layout.THEMES[end] == my_css
remove_css(my_css, byname = true)
@test findfirst(==(my_css), Stipple.Layout.THEMES) === nothing
end

0 comments on commit 97d9d54

Please sign in to comment.