From ee6a934f4957b9a906134b8d2d452d67f6944d1a Mon Sep 17 00:00:00 2001 From: Stefano Tortarolo Date: Mon, 25 Jan 2016 14:55:30 +0000 Subject: [PATCH] Generate a different filename when :partial_html is used This patch closes #2 --- lib/doc_my_routes/doc/config.rb | 5 ++++- spec/system/output_spec.rb | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/doc_my_routes/doc/config.rb b/lib/doc_my_routes/doc/config.rb index e442d29..65e551f 100644 --- a/lib/doc_my_routes/doc/config.rb +++ b/lib/doc_my_routes/doc/config.rb @@ -28,6 +28,7 @@ def initialize @destination_dir = File.join(Dir.pwd, 'doc', 'api') @format = :html + @partial = false default_static_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'etc') @@ -45,6 +46,7 @@ def format=(format = :html) fail UnsupportedFormat, "The output format must be :html or :partial_format. It is #{@format}" \ unless %i(html partial_html).include?(@format) + @partial = true end # Calculate the relative path of the CSS used @@ -54,7 +56,8 @@ def destination_css end def index_file - File.join(@destination_dir, 'index.html') + filename = @partial ? 'index_partial.html' : 'index.html' + File.join(@destination_dir, filename) end end end diff --git a/spec/system/output_spec.rb b/spec/system/output_spec.rb index 3be3ada..67a1cef 100644 --- a/spec/system/output_spec.rb +++ b/spec/system/output_spec.rb @@ -32,10 +32,12 @@ def doc_route context 'when I run the generation' do subject do DocMyRoutes::Documentation.generate - Nokogiri::XML(File.open("#{tmp_dir}/index.html")) + Nokogiri::XML(File.open("#{tmp_dir}/#{output_file}.html")) end context 'using the default formatter' do + let(:output_file) { 'index' } + it 'generates a valid HTML file' do expect(subject.children.size).to eq 2 expect(subject.children[1].name).to eq('html') @@ -43,6 +45,8 @@ def doc_route end context 'using the :partial_html formatter' do + let(:output_file) { 'index_partial' } + before do DocMyRoutes.configure do |c| c.format = :partial_html