Sha256: 224e84671c095efbf7210d9a8d5733aa628af2daf6ebabedf58ffad75273e044

Contents?: true

Size: 1.55 KB

Versions: 13

Compression:

Stored size: 1.55 KB

Contents

require 'asciidoctor'

require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'

include ::Asciidoctor


# The following docinfo processor permits the converter to
# read an additional style file (extras.css in the data directory).
# The docinfo extension is registered in the converter.rb:
#
#   Asciidoctor::Extensions.register do
#     docinfo_processor CSSDocinfoProcessor
#     ..
#   end
#

class CSSDocinfoProcessor < Asciidoctor::Extensions::DocinfoProcessor

  use_dsl
  at_location :header


  def process doc
    extdir = File.expand_path("../../../../data", __FILE__)
    stylesheet_name = 'extras.css'
    if doc.attr? 'linkcss'
      stylesheet_href = handle_stylesheet doc, extdir, stylesheet_name
      %(<link rel="stylesheet" href="#{stylesheet_href}">)
    else
      content = doc.read_asset %(#{extdir}/#{stylesheet_name})
      ['<style>', content.chomp, '</style>'] * "\n"
    end
  end

  def handle_stylesheet doc, extdir, stylesheet_name
    outdir = (doc.attr? 'outdir') ? (doc.attr 'outdir') : (doc.attr 'docdir')
    stylesoutdir = doc.normalize_system_path((doc.attr 'stylesdir'), outdir, (doc.safe >= SafeMode::SAFE ? outdir : nil))
    if stylesoutdir != extdir && doc.safe < SafeMode::SECURE && (doc.attr? 'copycss')
      destination = doc.normalize_system_path stylesheet_name, stylesoutdir, (doc.safe >= SafeMode::SAFE ? outdir : nil)
      content = doc.read_asset %(#{extdir}/#{stylesheet_name})
      ::File.open(destination, 'w') {|f|
        f.write content
      }
      destination
    else
      %(./#{stylesheet_name})
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
asciidoctor-latex-1.5.0.17.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.16.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.15.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.14.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.13.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.12.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.11.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.10.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.9.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.8b.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.7.dev lib/asciidoctor/latex/css_doc_info.rb
asciidoctor-latex-1.5.0.5.dev lib/asciidoctor/latex/css.rb
asciidoctor-latex-1.5.0.4.dev lib/asciidoctor/latex/css.rb