diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-10-22 03:11:36 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2022-10-24 02:03:12 -0600 |
| commit | f3468f43361a2d1e2ecb5bb35d89612f28ae8126 (patch) | |
| tree | de5684ffbbd9b61eed783a2e46a673cb9e2bdf0a /lib | |
| parent | 55450b1459208622c972e40688f4257cf16f6f3c (diff) | |
enable GuardClause lint rule for method bodies >= 15 lines and reformat code
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 94 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb | 2 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/theme_loader.rb | 7 |
3 files changed, 48 insertions, 55 deletions
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 99386484..6fecd738 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -3171,27 +3171,26 @@ module Asciidoctor def ink_cover_page doc, face image_path, image_opts = resolve_background_image doc, @theme, %(#{face}-cover-image), theme_key: %(cover_#{face}_image).to_sym, symbolic_paths: ['', '~'] - if image_path - if image_path.empty? - go_to_page page_count if face == :back - start_new_page_discretely - # NOTE: open graphics state to prevent page from being reused - open_graphics_state if face == :front - return - elsif image_path == '~' - @page_margin[:cover] = @page_margin[page.layout][:recto] if @media == 'prepress' - return - end - + return unless image_path + if image_path.empty? go_to_page page_count if face == :back - if image_opts[:format] == 'pdf' - import_page image_path, (image_opts.merge advance: face != :back, advance_if_missing: false) - else - begin - image_page image_path, image_opts - rescue - log :warn, %(could not embed #{face} cover image: #{image_path}; #{$!.message}) - end + start_new_page_discretely + # NOTE: open graphics state to prevent page from being reused + open_graphics_state if face == :front + return + elsif image_path == '~' + @page_margin[:cover] = @page_margin[page.layout][:recto] if @media == 'prepress' + return + end + + go_to_page page_count if face == :back + if image_opts[:format] == 'pdf' + import_page image_path, (image_opts.merge advance: face != :back, advance_if_missing: false) + else + begin + image_page image_path, image_opts + rescue + log :warn, %(could not embed #{face} cover image: #{image_path}; #{$!.message}) end end end @@ -4095,36 +4094,33 @@ module Asciidoctor image_path = from_theme = theme[key] end symbolic_paths = opts.delete :symbolic_paths - if image_path - if symbolic_paths&.include? image_path - return [image_path, {}] - elsif image_path == 'none' || image_path == '' - return [] - elsif (image_path.include? ':') && image_path =~ ImageAttributeValueRx - image_attrs = (AttributeList.new $2).parse %w(alt width) - image_path = $1 - image_relative_to = true - end - if from_theme - image_path = apply_subs_discretely doc, image_path, subs: [:attributes], imagesdir: (image_relative_to = @themesdir), page_layout: page.layout.to_s - elsif image_path.include? '{page-layout}' - image_path = image_path.sub '{page-layout}', page.layout.to_s - end - image_path, image_format = ::Asciidoctor::Image.target_and_format image_path, image_attrs - image_path = resolve_image_path doc, image_path, image_format, image_relative_to - - return unless image_path - - unless ::File.readable? image_path - log :warn, %(#{key.to_s.tr '-_', ' '} not found or readable: #{image_path}) - return - end + return unless image_path + return [image_path, {}] if symbolic_paths&.include? image_path + return [] if image_path == 'none' || image_path == '' + if (image_path.include? ':') && image_path =~ ImageAttributeValueRx + image_attrs = (AttributeList.new $2).parse %w(alt width) + image_path = $1 + image_relative_to = true + end + if from_theme + image_path = apply_subs_discretely doc, image_path, subs: [:attributes], imagesdir: (image_relative_to = @themesdir), page_layout: page.layout.to_s + elsif image_path.include? '{page-layout}' + image_path = image_path.sub '{page-layout}', page.layout.to_s + end + image_path, image_format = ::Asciidoctor::Image.target_and_format image_path, image_attrs + image_path = resolve_image_path doc, image_path, image_format, image_relative_to + + return unless image_path + + unless ::File.readable? image_path + log :warn, %(#{key.to_s.tr '-_', ' '} not found or readable: #{image_path}) + return + end - if image_format == 'pdf' - [image_path, page: [image_attrs&.[]('page').to_i, 1].max, format: image_format] - else - [image_path, (resolve_image_options image_path, image_format, image_attrs, (({ background: true, container_size: [page_width, page_height] }.merge opts)))] - end + if image_format == 'pdf' + [image_path, page: [image_attrs&.[]('page').to_i, 1].max, format: image_format] + else + [image_path, (resolve_image_options image_path, image_format, image_attrs, (({ background: true, container_size: [page_width, page_height] }.merge opts)))] end end diff --git a/lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb b/lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb index aa73ccac..e2b2640a 100644 --- a/lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb +++ b/lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb @@ -34,7 +34,7 @@ class Prawn::Table::Cell::Text placeholder_width = styled_width_of 'M' text = text.gsub ImageTagRx do if (pctidx = $1.index '%') - if pctidx == $1.length - 1 + if pctidx == $1.length - 1 # rubocop:disable Style/GuardClause # TODO: look up the intrinsic image width in pixels #width_of_images += (<image width> - placeholder_width) next '' diff --git a/lib/asciidoctor/pdf/theme_loader.rb b/lib/asciidoctor/pdf/theme_loader.rb index 7bcf4676..eed1ac2f 100644 --- a/lib/asciidoctor/pdf/theme_loader.rb +++ b/lib/asciidoctor/pdf/theme_loader.rb @@ -296,11 +296,8 @@ module Asciidoctor value = value.join end when ::String - if value == 'transparent' - return TransparentColorValue.new value - elsif value.length == 6 - return HexColorValue.new value.upcase - end + return TransparentColorValue.new value if value == 'transparent' + return HexColorValue.new value.upcase if value.length == 6 when ::NilClass return else |
