lib/asciidoctor_fb2.rb in asciidoctor-fb2-0.3.1 vs lib/asciidoctor_fb2.rb in asciidoctor-fb2-0.4.0

- old
+ new

@@ -42,34 +42,32 @@ (node.attr 'genres', '').split(CSV_DELIMITER_REGEX).each do |s| title_info.genres << s end node.authors.each do |author| title_info.authors << FB2rb::Author.new( - author.firstname, - author.middlename, - author.lastname, - nil, - [], - author.email.nil? ? [] : [author.email] + first_name: author.firstname, + middle_name: author.middlename, + last_name: author.lastname, + emails: author.email.nil? ? [] : [author.email] ) end if node.attr? 'series-name' series_name = node.attr 'series-name' series_volume = node.attr 'series-volume', 1 - title_info.sequences << FB2rb::Sequence.new(series_name, series_volume) + title_info.sequences << FB2rb::Sequence.new(name: series_name, number: series_volume) end date = node.attr('revdate') || node.attr('docdate') - fb2date = FB2rb::FB2Date.new(date, Date.parse(date)) + fb2date = FB2rb::FB2Date.new(display_value: date, value: Date.parse(date)) title_info.date = document_info.date = fb2date unless (cover_image = node.attr('front-cover-image')).nil? cover_image = Regexp.last_match(1) if cover_image =~ IMAGE_ATTRIBUTE_VALUE_RX cover_image_path = node.image_uri(cover_image) register_binary(node, cover_image_path, 'image') - title_info.coverpage = FB2rb::Coverpage.new([%(##{cover_image_path})]) + title_info.coverpage = FB2rb::Coverpage.new(images: [%(##{cover_image_path})]) end document_info.id = node.attr('uuid', '') document_info.version = node.attr('revnumber') document_info.program_used = %(Asciidoctor FB2 #{VERSION} using Asciidoctor #{node.attr('asciidoctor-version')}) @@ -79,20 +77,20 @@ body = %(<section> <title><p>#{node.doctitle}</p></title> #{node.content} </section>) - @book.bodies << FB2rb::Body.new(nil, body) + @book.bodies << FB2rb::Body.new(content: body) unless node.document.footnotes.empty? notes = [] node.document.footnotes.each do |footnote| notes << %(<section id="note-#{footnote.index}"> <title><p>#{footnote.index}</p></title> <p>#{footnote.text}</p> </section>) end - @book.bodies << FB2rb::Body.new('notes', notes * "\n") + @book.bodies << FB2rb::Body.new(name: 'notes', content: notes * "\n") end @book end # @param node [Asciidoctor::Section] @@ -380,33 +378,39 @@ lines << '</table>' lines << '<empty-line/>' unless node.has_role?('last') lines * "\n" end + # @param cell [Asciidoctor::Table::Cell] + def get_cell_content(cell) # rubocop:disable Metrics/MethodLength + case cell.style + when :asciidoc + cell.content + when :emphasis + %(<emphasis>#{cell.text}</emphasis>) + when :literal + %(<code>#{cell.text}</code>) + when :monospaced + %(<code>#{cell.text}</code>) + when :strong + %(<strong>#{cell.text}</strong>) + else + cell.text + end + end + # @param node [Asciidoctor::Table] def convert_table(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity lines = [] lines << %(<subtitle>#{node.captioned_title}</subtitle>) if node.title? lines << '<table>' - node.rows.to_h.each do |tsec, rows| # rubocop:disable Metrics/BlockLength + node.rows.to_h.each do |tsec, rows| next if rows.empty? rows.each do |row| lines << '<tr>' row.each do |cell| - cell_content = if tsec == :head - cell.text - else - case cell.style - when :asciidoc - cell.content - when :literal - %(<p><pre>#{cell.text}</pre></p>) - else - (cell_content = cell.content).empty? ? '' : %(<p>#{cell_content * "</p>\n<p>"}</p>) - end - end - + cell_content = get_cell_content(cell) cell_tag_name = (tsec == :head || cell.style == :header ? 'th' : 'td') cell_attrs = [ %(halign="#{cell.attr 'halign'}"), %(valign="#{cell.attr 'valign'}") ]