-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fixed optional properties being assigned - new propdoclist method - more modular file structure
- Loading branch information
Showing
9 changed files
with
78 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
propconvert(p, v[, context]) | ||
propconvert(p, s, v[, context]) | ||
Ensures the `v` is the appropriate type for property `p` given `x`. If it isn't | ||
then `propconvert` attempts to convert to the "correct type". The "correct type" | ||
is determined by `proptype(p, x)`. | ||
""" | ||
propconvert(p::AbstractProperty, v) = propconvert(p, propname(p), v) | ||
propconvert(p::AbstractProperty, s, v) = _propconvert(p, s, v, proptype(p)) | ||
propconvert(p::AbstractProperty, s, v, x) = _propconvert(p, s, v, proptype(p, x)) | ||
_propconvert(p::AbstractProperty, s, v::V, ::Type{T}) where {T,V<:T} = v | ||
_propconvert(p::AbstractProperty, s, v::V, ::Type{T}) where {T,V} = convert(T, v) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" | ||
propdefault(p[, c]) | ||
Returns the default value for property `p` given the optinal context `c`. | ||
""" | ||
propdefault(p::AbstractProperty) = propdefault(p, not_property) | ||
propdefault(::Type{P}) where {P<:AbstractProperty} = propdefault(P, not_property) | ||
propdefault(p::AbstractProperty, context) = propdefault(typeof(p), context) | ||
propdefault(::Type{<:AbstractProperty}, context) = not_property | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
propdoc(x) -> String | ||
Returns documentation for property `x`. | ||
""" | ||
propdoc(::T) where {T} = propdoc(T) | ||
propdoc(::Type{P}) where {P<:AbstractProperty} = _extract_doc(Base.Docs.doc(P)) | ||
function propdoc(::Type{T}) where {T} | ||
pnames = assigned_fields(T) | ||
return NamedTuple{pnames}(([propdoc(sym2prop(T, p)) for p in pnames]...,)) | ||
end | ||
|
||
_extract_doc(x::Markdown.MD) = _extract_doc(x.content) | ||
_extract_doc(x::AbstractArray) = isempty(x) ? "" : _extract_doc(first(x)) | ||
_extract_doc(x::Markdown.Paragraph) = _extract_doc(x.content) | ||
_extract_doc(x::String) = x | ||
|
||
""" | ||
propdoclist(::T) -> String | ||
Returns a markdown list of properties, where `T` is a type that has been assigned | ||
properties (see [`@assignprops`](@ref)) | ||
""" | ||
function propdoclist(x) | ||
out = "" | ||
for (p, d) in pairs(propdoc(x)) | ||
out = out * "* $p: $d\n" | ||
end | ||
return out | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" | ||
proptype(p[, context]) -> Type | ||
Return the appropriate type for property `p` given `context`. This method allows | ||
unique type restrictions given different types for `context`. | ||
""" | ||
proptype(p::AbstractProperty) = proptype(typeof(p)) | ||
proptype(::Type{P}) where {P<:AbstractProperty} = proptype(P, not_property) | ||
proptype(p::AbstractProperty, context) = proptype(typeof(p), context) | ||
proptype(::Type{<:AbstractProperty}, context) = Any | ||
|
c5cd0c6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
c5cd0c6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/8509
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via: