Skip to content

Commit

Permalink
fix(lint): rubocop linting
Browse files Browse the repository at this point in the history
  • Loading branch information
as-op committed Apr 25, 2024
1 parent 72603e4 commit b4d3609
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ Style/HashTransformValues:
RSpec/ExampleLength:
Enabled: false

RSpec/AnyInstance:
Enabled: false

Naming/VariableNumber:
Enabled: false

Expand Down
32 changes: 15 additions & 17 deletions lib/md_to_pdf/elements/codeblock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def mermaid_cli_available?
begin
_, status = Open3.capture2e("mmdc", "-V")
status.success?
rescue StandardError => e
rescue StandardError
false
end
end
Expand All @@ -57,7 +57,7 @@ def build_mermaid_block(node, _opts)
}
@pdf.embed_image(image_obj, image_info, options)
true
rescue StandardError => e
rescue StandardError
false
ensure
image_file.unlink
Expand All @@ -66,21 +66,19 @@ def build_mermaid_block(node, _opts)

def run_mermaid_cli(mmdc, destination, format, options = {})
tmp_file('mermaid', 'mmdc', mmdc) do |filename|
begin
args = ["-i", filename, '-e', format, '-o', destination]
args << '-C' << options[:css_file] if options[:css_file]
args << '-t' << options[:theme] if options[:theme]
args << '-w' << options[:width] if options[:width]
args << '-H' << options[:height] if options[:height]
args << '-s' << options[:scale] if options[:scale]
args << '-b' << options[:background] if options[:background]
args << '-p' << options[:puppeteer_config_file] if options[:puppeteer_config_file]
args << '-c' << options[:config_file] if options[:config_file]
_, status = Open3.capture2e("mmdc", *args)
status.success?
rescue StandardError => e
false
end
args = ["-i", filename, '-e', format, '-o', destination]
args << '-C' << options[:css_file] if options[:css_file]
args << '-t' << options[:theme] if options[:theme]
args << '-w' << options[:width] if options[:width]
args << '-H' << options[:height] if options[:height]
args << '-s' << options[:scale] if options[:scale]
args << '-b' << options[:background] if options[:background]
args << '-p' << options[:puppeteer_config_file] if options[:puppeteer_config_file]
args << '-c' << options[:config_file] if options[:config_file]
_, status = Open3.capture2e("mmdc", *args)
status.success?
rescue StandardError
false
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include_context 'with pdf'

it 'keeps using the code block if mermaid cli is not available' do
allow_any_instance_of(MarkdownToPDF::Codeblock)
allow_any_instance_of(described_class)
.to receive(:mermaid_cli_available?)
.and_return(false)
generator.parse_file('mermaid/mermaid.md')
Expand Down Expand Up @@ -36,11 +36,11 @@
end

it 'replaces mermaid diagram code block with images' do
allow_any_instance_of(MarkdownToPDF::Codeblock)
allow_any_instance_of(described_class)
.to receive(:mermaid_cli_available?)
.and_return(true)
allow_any_instance_of(MarkdownToPDF::Codeblock)
.to receive(:run_mermaid_cli) do |caller, mmdc, destination, format, options|
allow_any_instance_of(described_class)
.to receive(:run_mermaid_cli) do |_caller, _mmdc, destination, _format, _options|
png = Base64.decode64("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==")
File.write(destination, png)
true
Expand Down

0 comments on commit b4d3609

Please sign in to comment.