Skip to content

Commit

Permalink
Add --output-dir option
Browse files Browse the repository at this point in the history
  • Loading branch information
apjanke committed Dec 25, 2018
1 parent f19130e commit 0813a43
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Version 0.8.0 (???? ??? ??)

* Added tables support. (apjanke)
* Lint & Rubocop fixes. (apjanke)
* Added --output-dir option. (apjanke)

Version 0.7.4 (2018 Dec 22)
---------------------------
Expand Down
4 changes: 4 additions & 0 deletions bin/ronn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# / --pipe write to standard output instead of generating files
# / -m, --man show manual like with man(1)
# / -S, --server serve <file>s at http://localhost:1207/
# / -o, --output-dir <dir> write generated files to specified directory
# /
# / Format options control which files / formats are generated:
# / -r, --roff generate roff output
Expand Down Expand Up @@ -75,6 +76,7 @@ write_index = false
styles = %w[man]
groff = 'groff -Wall -mtty-char -mandoc -Tascii -t'
pager = ENV['MANPAGER'] || ENV['PAGER'] || 'more'
output_dir = nil

##
# Environment variables
Expand All @@ -95,6 +97,7 @@ ARGV.options do |argv|
argv.on('-m', '--man') { build = server = false; view = true }
argv.on('-S', '--server') { build = view = false; server = true }
argv.on('-i', '--index') { write_index = true }
argv.on('-o', '--output-dir=V') { |val| output_dir = val }

# format options
argv.on('-r', '--roff') { (formats ||= []) << 'roff' }
Expand Down Expand Up @@ -148,6 +151,7 @@ formats.delete('html') if formats.include?('html_fragment')

options['date'] &&= Date.strptime(options['date'], '%Y-%m-%d')
options['styles'] = styles
options['outdir'] = output_dir

##
# Server
Expand Down
15 changes: 13 additions & 2 deletions lib/ronn/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Document
# Array of style modules to apply to the document.
attr_reader :styles

# Output directory to write files to
attr_accessor :outdir

# Create a Ronn::Document given a path or with the data returned by
# calling the block. The document is loaded and preprocessed before
# the intialize method returns. The attributes hash may contain values
Expand Down Expand Up @@ -100,9 +103,17 @@ def basename(type = nil)
# appends it to the dirname of the source document.
def path_for(type = nil)
if @basename
File.join(File.dirname(path), basename(type))
if @outdir
File.join(@outdir, basename(type))
else
File.join(File.dirname(path), basename(type))
end
else
basename(type)
if @outdir
File.join(@outdir, basename(type))
else
basename(type)
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions man/ronn.1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ The server respects the \fB\-\-style\fR and document attribute options (\fB\-\-m
\fB\-\-pipe\fR
Don\'t generate files, write generated output to standard output\. This is the default behavior when ronn source text is piped in on standard input and no \fIfile\fR arguments are provided\.
.
.TP
\fB\-o\fR=\fIdirectory\fR, \fB\-\-output\-dir\fR=\fIdirectory\fR
Write generated files to the specified directory instead of the default location\.
.
.P
Format options control the files \fBronn\fR generates, or the output format when the \fB\-\-pipe\fR argument is specified\. When no format options are given, both \fB\-\-roff\fR and \fB\-\-html\fR are assumed\.
.
Expand Down
4 changes: 4 additions & 0 deletions man/ronn.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ directly to a man pager.
default behavior when ronn source text is piped in on standard input and no
<file> arguments are provided.

* `-o`=<directory>, `--output-dir`=<directory>:
Write generated files to the specified directory instead of the default
location.

Format options control the files `ronn` generates, or the output format when the
`--pipe` argument is specified. When no format options are given, both `--roff`
and `--html` are assumed.
Expand Down

0 comments on commit 0813a43

Please sign in to comment.