diff --git a/.gitignore b/.gitignore index 0612bf4..a19682d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ - -test.jl -examples/*/*.png -examples/*.md - -*.*~ + +test.jl +examples/*/*.png +examples/*.md + +*.*~ diff --git a/README.md b/README.md index 321facc..284e58a 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,39 @@ -# JuliaReport - -[![Build Status](https://travis-ci.org/mpastell/JuliaReport.jl.svg?branch=master)](https://travis-ci.org/mpastell/JuliaReport.jl) - -JuliaReport is a scientific report generator/literate programming tool -for Julia. It is based on [Pweave](http://mpastell.com/pweave) and -resembles Knitr and Sweave. Actually JuliaReport relies on Pweave for -document parsing and formatting. - -You'll need latest Pweave from Github: - -**Current features** - -* Noweb syntax for documents. -* Execute code as terminal or "script" chunks. -* Capture PyPlot figures. -* All Pweave output formats supported. Including, Latex, Markdown, Sphinx etc. - -**Not implemented** - -* Script reader -* Inline code -* Caching - -## Chunk options - -You can use the same chunk options as for Pweave, but the format is different. -The syntax needs to be valid for creating a dictionary in Julia -without the `{}`. e.g: - - <<"term"=>true, "fig"=>false>>= - - -## Usage - -Run from julia: - - using JuliaReport - weave(Pkg.dir("JuliaReport","examples","julia_sample.mdw") +# JuliaReport + +[![Build Status](https://travis-ci.org/mpastell/JuliaReport.jl.svg?branch=master)](https://travis-ci.org/mpastell/JuliaReport.jl) + +JuliaReport is a scientific report generator/literate programming tool +for Julia. It is based on [Pweave](http://mpastell.com/pweave) and +resembles Knitr and Sweave. Actually JuliaReport relies on Pweave for +document parsing and formatting. + +You'll need latest Pweave from Github: + +**Current features** + +* Noweb syntax for documents. +* Execute code as terminal or "script" chunks. +* Capture PyPlot figures. +* All Pweave output formats supported. Including, Latex, Markdown, Sphinx etc. + +**Not implemented** + +* Script reader +* Inline code +* Caching + +## Chunk options + +You can use the same chunk options as for Pweave, but the format is different. +The syntax needs to be valid for creating a dictionary in Julia +without the `{}`. e.g: + + <<"term"=>true, "fig"=>false>>= + + +## Usage + +Run from julia: + + using JuliaReport + weave(Pkg.dir("JuliaReport","examples","julia_sample.mdw") diff --git a/REQUIRE b/REQUIRE index f858f97..dcf2e2e 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1 @@ -PyPlot +PyPlot diff --git a/src/config.jl b/src/config.jl index 1e828af..7db868f 100644 --- a/src/config.jl +++ b/src/config.jl @@ -1,26 +1,26 @@ -const rcParams = {"figdir"=> "figures", - "plotlib" => "Winston", - "storeresults"=> false, - "cachedir"=> "cache", - "chunk"=> - {"defaultoptions"=> - { - "echo"=> true, - "results"=> "verbatim", - "fig"=> true, - "include"=> true, - "evaluate"=> true, - "caption"=> false, - "term"=> false, - "name"=> nothing, - "wrap"=> true, - "f_pos"=> "htpb", - "f_size"=> (8, 6), - "f_env"=> nothing, - "f_spines"=> true, - "complete"=> true, - "engine"=> "julia", - "option_string"=> "" - } - } - } +const rcParams = {"figdir"=> "figures", + "plotlib" => "Winston", + "storeresults"=> false, + "cachedir"=> "cache", + "chunk"=> + {"defaultoptions"=> + { + "echo"=> true, + "results"=> "verbatim", + "fig"=> true, + "include"=> true, + "evaluate"=> true, + "caption"=> false, + "term"=> false, + "name"=> nothing, + "wrap"=> true, + "f_pos"=> "htpb", + "f_size"=> (8, 6), + "f_env"=> nothing, + "f_spines"=> true, + "complete"=> true, + "engine"=> "julia", + "option_string"=> "" + } + } + } diff --git a/src/readers.jl b/src/readers.jl index 8be9513..b3af114 100644 --- a/src/readers.jl +++ b/src/readers.jl @@ -1,65 +1,65 @@ -function read_noweb(document) - doctext = readall(open(document)) - #doctext = document #Replace with file... - codestart = r"^<<(.*?)>>=" - codeend = r"^@(\s*)$" - state = "doc" - - docno = 1 - codeno = 1 - content = "" - lineno = 0 - start_line = 0 - - options = Dict() - optionstring = "" - parsed = Dict[] - for (lineno, line) in enumerate(split(doctext, "\n")) - - if ismatch(codestart, line) && state=="doc" - state = "code" - m = match(codestart, line) - optionstring=m.captures[1] - #println(m.captures[1]) - if strip(optionstring)=="" - options = Dict() - else - try - options = eval(parse("{" * optionstring * "}")) - catch - options = Dict() - warn(string("Invalid format for chunk options line: ", lineno)) - end - end - haskey(options, "label") && (options["name"] = options["label"]) - haskey(options, "name") || (options["name"] = nothing) - - chunk = {"type" => "doc", "content"=> content, "number" => docno, "start_line"=>start_line} - docno += 1 - start_line = lineno - push!(parsed, chunk) - content = "" - continue - end - if ismatch(codeend, line) && state=="code" - chunk = {"type" => "code", "content" => content, "number" => codeno, - "options"=>options,"optionstring"=>optionstring, "start_line"=>start_line} - codeno+=1 - start_line = lineno - content = "" - state = "doc" - push!(parsed, chunk) - continue - end - - content *= "\n" * line - end - - #Remember the last chunk - if content != "" - chunk = {"type" => "doc", "content"=> content, "number" => docno, "start_line"=>lineno} - push!(parsed, chunk) - end - - return parsed -end +function read_noweb(document) + doctext = readall(open(document)) + #doctext = document #Replace with file... + codestart = r"^<<(.*?)>>=" + codeend = r"^@(\s*)$" + state = "doc" + + docno = 1 + codeno = 1 + content = "" + lineno = 0 + start_line = 0 + + options = Dict() + optionstring = "" + parsed = Dict[] + for (lineno, line) in enumerate(split(doctext, "\n")) + + if ismatch(codestart, line) && state=="doc" + state = "code" + m = match(codestart, line) + optionstring=m.captures[1] + #println(m.captures[1]) + if strip(optionstring)=="" + options = Dict() + else + try + options = eval(parse("{" * optionstring * "}")) + catch + options = Dict() + warn(string("Invalid format for chunk options line: ", lineno)) + end + end + haskey(options, "label") && (options["name"] = options["label"]) + haskey(options, "name") || (options["name"] = nothing) + + chunk = {"type" => "doc", "content"=> content, "number" => docno, "start_line"=>start_line} + docno += 1 + start_line = lineno + push!(parsed, chunk) + content = "" + continue + end + if ismatch(codeend, line) && state=="code" + chunk = {"type" => "code", "content" => content, "number" => codeno, + "options"=>options,"optionstring"=>optionstring, "start_line"=>start_line} + codeno+=1 + start_line = lineno + content = "" + state = "doc" + push!(parsed, chunk) + continue + end + + content *= "\n" * line + end + + #Remember the last chunk + if content != "" + chunk = {"type" => "doc", "content"=> content, "number" => docno, "start_line"=>lineno} + push!(parsed, chunk) + end + + return parsed +end