Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add js_attr(x) for setting julia expressions as js attributes, fix JSONText in Plots #230

Merged
merged 4 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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.11"
version = "0.27.12"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
2 changes: 1 addition & 1 deletion ext/StippleJSONExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ isdefined(Base, :get_extension) ? using JSON : using ..JSON

JSON.JSONText(json::Stipple.JSONText) = JSON.JSONText(json.s)
JSON.show_json(io::JSON.Writer.CompactContext, ::JSON.Writer.CS, json::Stipple.JSONText) = write(io, json.s)
JSON.Writer.lower(json::Stipple.JSONText) = json.s
JSON.Writer.lower(json::Stipple.JSONText) = json

Stipple.JSONText(json::JSON.JSONText) = Stipple.JSONText(json.s)
@inline StructTypes.StructType(::Type{JSON.JSONText}) = JSON3.RawType()
Expand Down
2 changes: 1 addition & 1 deletion src/Stipple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ using Logging, Mixers, Random, Reexport, Dates, Tables
import Genie.Router.download
@reexport @using_except Genie.Renderer.Html: mark, div, time, view, render, Headers
const htmldiv = Html.div
export render, htmldiv
export render, htmldiv, js_attr
@reexport using JSON3
@reexport using StructTypes
@reexport using Parameters
Expand Down
23 changes: 22 additions & 1 deletion src/stipple/rendering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,25 @@ Default rendering of `Reactive` values. Specialize `Stipple.render` to define cu
"""
function Stipple.render(o::Reactive{T}, fieldname::Union{Symbol,Nothing} = nothing) where {T}
Stipple.render(o[], fieldname)
end
end

"""
js_attr(x)

Renders a Julia expression as Javascript Expression that can be passed as an attribute value in html elements.
### Example
```
using StippleUI

quasar(
:btn__toggle,
fieldname = :btn_value,
options = js_attr([opts(label = "Off", value = false), opts(label = "On", value = true)])
)

# "<q-btn-toggle v-model=\\"btn_value\\" :options=\\"[{'value':false,'label':'Off'}, {'value':true,'label':'On'}]\\"></q-btn-toggle>"
```
"""
function js_attr(x)
Symbol(replace(json(render(x)), "'" => raw"\'", '"' => '''))
end
Loading