Skip to content

Conversation

@daipom
Copy link

@daipom daipom commented Nov 17, 2025

:pdf markup language already exists, but we couldn't use it to use original PDF.
This fix allows us to use :pdf markup language to use original PDF.

Points:

  • Fix issue where README generating fails with a nil error.
    • In addition, use Markdown for README.
  • The source file is pdf/{id}-{base-name}.pdf.
    • Generate a dummy file to know the path.
  • Skip pdf task to avoid unexpected PDF rebuild.

How to use:

  1. rabbit-slide new --id=foo --base_name=bar --markup-language=pdf ...
  2. Replace pdf/foo-bar.pdf with the actual PDF file.
  3. Write README.md.
  4. Edit config.yaml if necessary.
  5. You can run rake to show it or rake publish to publish it now.

`:pdf` markup language already exists, but we couldn't use it.
This fix allows us to use `:pdf` markup language to use
original PDF in Rabbit.

Points:

* Fix issue where README generating fails with a nil error.
  * In addition, use Markdown for README.
* The source file is `pdf/{id}-{base-name}.pdf`.
  * Generate a dummy file to know the path.
* Skip `pdf` task to avoid unexpected PDF rebuild.
Comment on lines +710 to 711
markup_language = :markdown if markup_language == :pdf
generator = Rabbit::SourceGenerator.find(markup_language)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Currently, this generator is nil and causes an error when using :pdf.

Comment on lines 147 to +151
file pdf_path => [options_path, *(spec.files - [pdf_path])] do
if @slide.author.markup_language == :pdf
puts "Skipped pdf task because markup_language is PDF."
next
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: We could also stop the define itself, but then we would have to fix the dependent tasks too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work?

diff --git a/lib/rabbit/task/slide.rb b/lib/rabbit/task/slide.rb
index 2e320532..69b0cac3 100644
--- a/lib/rabbit/task/slide.rb
+++ b/lib/rabbit/task/slide.rb
@@ -144,14 +144,19 @@ module Rabbit
       end
 
       def define_pdf_task
-        file pdf_path => [options_path, *(spec.files - [pdf_path])] do
-          mkdir_p(@pdf_dir)
-          rabbit("--print",
-                 "--output-filename", pdf_path)
-        end
+        if @slide.author.markup_language == :pdf
+          # Does nothing. Not list in "rake -T" but "rake pdf" is accepted..
+          task :pdf
+        else
+          file pdf_path => [options_path, *(spec.files - [pdf_path])] do
+            mkdir_p(@pdf_dir)
+            rabbit("--print",
+                   "--output-filename", pdf_path)
+          end
 
-        desc(_("Generate PDF: %{pdf_path}") % {:pdf_path => pdf_path})
-        task :pdf => pdf_path
+          desc(_("Generate PDF: %{pdf_path}") % {:pdf_path => pdf_path})
+          task :pdf => pdf_path
+        end
       end
 
       def define_publish_task

"#{@data.slide_conf.base_name}.#{slide_source_extension}"
case @data.author_conf.markup_language
when :pdf
File.join("pdf", "#{@data.slide_conf.id}-#{@data.slide_conf.base_name}.pdf")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: It would be better to unify this with the following, but I can't think of a good way to do it.

def pdf_base_path
"#{@slide.id}-#{@slide.base_name}.pdf"
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add Rabbit::SlideConfiuration#pdf_base_name?

def generate_slide
if @data.author_conf.markup_language == :pdf
create_file(slide_path) do |slide|
slide.puts("Replace me.")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This generates a broken PDF, but I can't think of a good way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding --pdf option and copy the PDF path here?

Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that we should move markup_language to SlideConfiguration from AuthorConfiguraiton before this.

We may use different markup languages over slides.


def readme_content
markup_language = @data.markup_language
markup_language = :markdown if markup_language == :pdf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Let's add --readme-markup-language instead of reusing --markup-language. (We can use --markup-language value as the default value of --readme-markup-language.)

def generate_slide
if @data.author_conf.markup_language == :pdf
create_file(slide_path) do |slide|
slide.puts("Replace me.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding --pdf option and copy the PDF path here?

"#{@data.slide_conf.base_name}.#{slide_source_extension}"
case @data.author_conf.markup_language
when :pdf
File.join("pdf", "#{@data.slide_conf.id}-#{@data.slide_conf.base_name}.pdf")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add Rabbit::SlideConfiuration#pdf_base_name?

Comment on lines 147 to +151
file pdf_path => [options_path, *(spec.files - [pdf_path])] do
if @slide.author.markup_language == :pdf
puts "Skipped pdf task because markup_language is PDF."
next
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work?

diff --git a/lib/rabbit/task/slide.rb b/lib/rabbit/task/slide.rb
index 2e320532..69b0cac3 100644
--- a/lib/rabbit/task/slide.rb
+++ b/lib/rabbit/task/slide.rb
@@ -144,14 +144,19 @@ module Rabbit
       end
 
       def define_pdf_task
-        file pdf_path => [options_path, *(spec.files - [pdf_path])] do
-          mkdir_p(@pdf_dir)
-          rabbit("--print",
-                 "--output-filename", pdf_path)
-        end
+        if @slide.author.markup_language == :pdf
+          # Does nothing. Not list in "rake -T" but "rake pdf" is accepted..
+          task :pdf
+        else
+          file pdf_path => [options_path, *(spec.files - [pdf_path])] do
+            mkdir_p(@pdf_dir)
+            rabbit("--print",
+                   "--output-filename", pdf_path)
+          end
 
-        desc(_("Generate PDF: %{pdf_path}") % {:pdf_path => pdf_path})
-        task :pdf => pdf_path
+          desc(_("Generate PDF: %{pdf_path}") % {:pdf_path => pdf_path})
+          task :pdf => pdf_path
+        end
       end
 
       def define_publish_task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants