Skip to content

Commit a03c293

Browse files
major fixes
1 parent 17cfd55 commit a03c293

File tree

3 files changed

+78
-53
lines changed

3 files changed

+78
-53
lines changed

README.md

Lines changed: 74 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
DocumentFunction
22
================
33

4+
A module for documenting functions.
5+
It also provides methods to get function methods, arguments and keywords.
6+
47
[![DocumentFunction](http://pkg.julialang.org/badges/DocumentFunction_0.5.svg)](http://pkg.julialang.org/?pkg=DocumentFunction&ver=0.5)
58
[![DocumentFunction](http://pkg.julialang.org/badges/DocumentFunction_0.6.svg)](http://pkg.julialang.org/?pkg=DocumentFunction&ver=0.6)
69
[![DocumentFunction](http://pkg.julialang.org/badges/DocumentFunction_0.7.svg)](http://pkg.julialang.org/?pkg=DocumentFunction&ver=0.7)
@@ -13,83 +16,103 @@ Installation:
1316
------------
1417

1518
```julia
16-
Pkg.add("DocumentFunction")
19+
import Pkg; Pkg.add("DocumentFunction")
20+
21+
using DocumentFunction
1722
```
1823

19-
Example:
24+
Examples:
2025
------------
2126

27+
```
28+
print(documentfunction(documentfunction))
29+
```
30+
31+
```
32+
Methods:
33+
- `DocumentFunction.documentfunction(f::Function; location, maintext, argtext, keytext) in DocumentFunction` : /Users/monty/.julia/dev/DocumentFunction/src/DocumentFunction.jl:56
34+
Arguments:
35+
- `f::Function`
36+
Keywords:
37+
- `argtext`
38+
- `keytext`
39+
- `location`
40+
- `maintext`
41+
```
42+
43+
```
44+
print(documentfunction(occursin))
45+
```
46+
47+
```
48+
Methods:
49+
- `Base.occursin(delim::UInt8, buf::Base.GenericIOBuffer{Array{UInt8,1}}) in Base` : iobuffer.jl:464
50+
- `Base.occursin(delim::UInt8, buf::Base.GenericIOBuffer) in Base` : iobuffer.jl:470
51+
- `Base.occursin(needle::Union{AbstractChar, AbstractString}, haystack::AbstractString) in Base` : strings/search.jl:452
52+
- `Base.occursin(r::Regex, s::SubString; offset) in Base` : regex.jl:172
53+
- `Base.occursin(r::Regex, s::AbstractString; offset) in Base` : regex.jl:166
54+
- `Base.occursin(pattern::Tuple, r::Test.LogRecord) in Test` : /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/Test/src/logging.jl:211
55+
Arguments:
56+
- `buf::Base.GenericIOBuffer`
57+
- `buf::Base.GenericIOBuffer{Array{UInt8,1}}`
58+
- `delim::UInt8`
59+
- `haystack::AbstractString`
60+
- `needle::Union{AbstractChar, AbstractString}`
61+
- `pattern::Tuple`
62+
- `r::Regex`
63+
- `r::Test.LogRecord`
64+
- `s::AbstractString`
65+
- `s::SubString`
66+
Keywords:
67+
- `offset`
68+
```
69+
70+
Documentation Examples:
71+
---------
72+
2273
```julia
2374
import DocumentFunction
2475

25-
function getfunctionarguments(f::Function)
26-
m = methods(f)
27-
getfunctionarguments(f, string.(collect(m.ms)))
76+
function foobar(f::Function)
77+
return nothing
2878
end
29-
function getfunctionarguments(f::Function, m::Vector{String})
30-
l = length(m)
31-
mp = Array{Symbol}(0)
32-
for i in 1:l
33-
r = match(r"(.*)\(([^;]*);(.*)\)", m[i])
34-
if typeof(r) == Void
35-
r = match(r"(.*)\((.*)\)", m[i])
36-
end
37-
if typeof(r) != Void && length(r.captures) > 1
38-
fargs = strip.(split(r.captures[2], ", "))
39-
for j in 1:length(fargs)
40-
if !contains(string(fargs[j]), "...") && fargs[j] != ""
41-
push!(mp, fargs[j])
42-
end
43-
end
44-
end
45-
end
46-
return sort(unique(mp))
79+
function foobar(f::Function, m::Vector{String})
80+
return nothing
4781
end
4882

4983
@doc """
50-
$(DocumentFunction.documentfunction(getfunctionarguments;
84+
$(DocumentFunction.documentfunction(foobar;
5185
location=false,
52-
maintext="Get function arguments",
53-
argtext=Dict("f"=>"Function to be documented",
54-
"m"=>"Function methods")))
55-
""" getfunctionarguments
86+
maintext="Foobar function to do amazing stuff",
87+
argtext=Dict("f"=>"Input function ...",
88+
"m"=>"Input string array ...")))
89+
""" foobar
5690
```
5791

58-
Execution of
59-
60-
`?getfunctionarguments`
61-
62-
produces the following output:
92+
Getting the help for the function type "?foobar" which will produces the following output:
6393

6494
```
65-
DocumentFunction.getfunctionarguments
66-
67-
Get function arguments
95+
foobar
6896
69-
Methods
97+
Foobar function to do amazing stuff
7098
71-
• DocumentFunction.getfunctionarguments(f::Function)
99+
Methods:
72100
73-
DocumentFunction.getfunctionarguments(f::Function, m::Array{String,1})
101+
Main.foobar(f::Function) in Main
74102
103+
• Main.foobar(f::Function, m::Array{String,1}) in Main
75104
76-
Arguments
105+
Arguments:
77106
78-
• f::Function : Function to be documented
79-
80-
• m::Array{String,1} : Function methods
107+
• f::Function : Input function ...
81108
109+
• m::Array{String,1} : Input string array ...
82110
```
83111

84-
Developers
85-
==========
86-
87-
* [Velimir (monty) Vesselinov](http://www.lanl.gov/orgs/ees/staff/monty) [(publications)](http://scholar.google.com/citations?user=sIFHVvwAAAAJ)
88-
* [Daniel O'Malley](http://www.lanl.gov/expertise/profiles/view/daniel-o'malley) [(publications)](http://scholar.google.com/citations?user=rPzCVjEAAAAJ)
89-
* [see also](https://github.com/madsjulia/DocumentFunction.jl/graphs/contributors)
90112

91113
Publications, Presentations, Projects
92114
=====================================
93115

94-
* [mads.lanl.gov/](http://mads.lanl.gov/)
95-
* [ees.lanl.gov/monty](http://ees.lanl.gov/monty)
116+
* [mads.gitlab.io](http://mads.gitlab.io)
117+
* [monty.gitlab.io](http://monty.gitlab.io)
118+
* [ees.lanl.gov/monty](https://www.lanl.gov/orgs/ees/staff/monty)

src/DocumentFunction.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Licensing: GPLv3: http://www.gnu.org/licenses/gpl-3.0.html
1212
"""
1313
module DocumentFunction
1414

15+
export documentfunction, getfunctionmethods, getfunctionarguments, getfunctionkeywords
16+
1517
"""
1618
Redirect STDOUT to a reader
1719
"""

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import DocumentFunction
22

3-
expected = "**DocumentFunction.documentfunction**\n\nCreate function documentation\n\nMethods\n - `DocumentFunction.documentfunction(f::Function; location, maintext, argtext, keytext) in DocumentFunction`\nArguments\n - `f::Function` : Function to be documented\nKeywords\n - `argtext` : Dictionary with text for each argument\n - `keytext` : Dictionary with text for each keyword\n - `location` : Boolean to show/hide function location on the disk\n - `maintext` : Function description\n"
3+
expected = "**DocumentFunction.documentfunction**\n\nCreate function documentation\n\nMethods:\n - `DocumentFunction.documentfunction(f::Function; location, maintext, argtext, keytext) in DocumentFunction`\nArguments:\n - `f::Function` : Function to be documented\nKeywords:\n - `argtext` : Dictionary with text for each argument\n - `keytext` : Dictionary with text for each keyword\n - `location` : Boolean to show/hide function location on the disk\n - `maintext` : General function description\n"
44

55
import Test
66

77
output = DocumentFunction.documentfunction(DocumentFunction.documentfunction;
88
location=false,
99
maintext="Create function documentation",
1010
argtext=Dict("f"=>"Function to be documented"),
11-
keytext=Dict("maintext"=>"Function description",
11+
keytext=Dict("maintext"=>"General function description",
1212
"argtext"=>"Dictionary with text for each argument",
1313
"keytext"=>"Dictionary with text for each keyword",
1414
"location"=>"Boolean to show/hide function location on the disk"))

0 commit comments

Comments
 (0)