Skip to content

Commit

Permalink
Merge pull request #300 from jonathanhefner/render_template-dry_run
Browse files Browse the repository at this point in the history
Use `@options.dry_run` in `render_template`
  • Loading branch information
jonathanhefner authored Sep 9, 2023
2 parents 521b8c5 + 07f8d60 commit f2d2369
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 4 additions & 4 deletions lib/sdoc/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def generate_index_file
templatefile = @template_dir + 'index.rhtml'
outfile = @outputdir + 'index.html'

self.render_template( templatefile, binding(), outfile ) unless @options.dry_run
render_template(templatefile, binding, outfile)
end

### Generate a documentation file for each class
Expand All @@ -152,7 +152,7 @@ def generate_class_files
outfile = @outputdir + klass.path

debug_msg " rendering #{outfile}"
self.render_template( templatefile, binding(), outfile ) unless @options.dry_run
render_template(templatefile, binding, outfile)
end
end

Expand All @@ -166,7 +166,7 @@ def generate_file_files
debug_msg " working on %s (%s)" % [ file.full_name, outfile ]

debug_msg " rendering #{outfile}"
self.render_template( templatefile, binding(), outfile ) unless @options.dry_run
render_template(templatefile, binding, outfile)
end
end

Expand All @@ -176,7 +176,7 @@ def generate_file_links
templatefile = @template_dir + 'file_links.rhtml'
outfile = @outputdir + 'panel/file_links.html'

self.render_template( templatefile, binding(), outfile ) unless @options.dry_run
render_template(templatefile, binding, outfile)
end

### Create class tree structure and write it as json
Expand Down
15 changes: 4 additions & 11 deletions lib/sdoc/templatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,10 @@ def include_template(template_name, local_assigns = {})
### Load and render the erb template in the given +templatefile+ within the
### specified +context+ (a Binding object) and write it out to +outfile+.
### Both +templatefile+ and +outfile+ should be Pathname-like objects.
def render_template( templatefile, context, outfile )
def render_template(templatefile, context, outfile)
return if @options.dry_run
output = SDoc::Postprocessor.process(eval_template(templatefile, context))

unless $dryrun
outfile.dirname.mkpath
outfile.open( 'w', 0644 ) do |file|
file.print( output )
end
else
debug_msg " would have written %d bytes to %s" %
[ output.length, outfile ]
end
outfile.dirname.mkpath
outfile.write(output)
end
end
13 changes: 13 additions & 0 deletions spec/rdoc_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ def parse_options(*options)
_(`./bin/sdoc -v`.strip).must_equal SDoc::VERSION
end

describe "options.dry_run" do
it "prevents files from being rendered" do
Dir.mktmpdir do |dir|
rdoc_dry_run(
"--files", "#{__dir__}/../README.md", "#{__dir__}/../lib/sdoc/version.rb",
"--output", dir
)

_(Dir.glob("**/*", base: dir)).must_be_empty
end
end
end

describe "options.github" do
it "is disabled by default" do
_(parse_options().github).must_be_nil
Expand Down

0 comments on commit f2d2369

Please sign in to comment.