-
Notifications
You must be signed in to change notification settings - Fork 46
Support original PDF #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Support original PDF #180
Conversation
`: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.
| markup_language = :markdown if markup_language == :pdf | ||
| generator = Rabbit::SourceGenerator.find(markup_language) |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
rabbit/lib/rabbit/task/slide.rb
Lines 203 to 205 in 01885b2
| def pdf_base_path | |
| "#{@slide.id}-#{@slide.base_name}.pdf" | |
| end |
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
kou
left a comment
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
| 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 |
There was a problem hiding this comment.
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
:pdfmarkup language already exists, but we couldn't use it to use original PDF.This fix allows us to use
:pdfmarkup language to use original PDF.Points:
pdf/{id}-{base-name}.pdf.pdftask to avoid unexpected PDF rebuild.How to use:
rabbit-slide new --id=foo --base_name=bar --markup-language=pdf ...pdf/foo-bar.pdfwith the actual PDF file.README.md.config.yamlif necessary.raketo show it orrake publishto publish it now.