class Asciidoctor::Stylesheets

A utility class for working with the built-in stylesheets.

Constants

DEFAULT_PYGMENTS_STYLE

DEFAULT_CODERAY_STYLE = 'asciidoctor'

DEFAULT_STYLESHEET_NAME
STYLESHEETS_DATA_PATH

Public Class Methods

instance() click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 14
def self.instance
  @__instance__
end

Public Instance Methods

coderay_stylesheet_data() click to toggle source

Public: Read the contents of the default CodeRay stylesheet

returns the [String] CodeRay stylesheet data

# File lib/asciidoctor/stylesheets.rb, line 46
def coderay_stylesheet_data
  # NOTE use the following two lines to load a built-in theme instead
  # Helpers.require_library 'coderay'
  # ::CodeRay::Encoders[:html]::CSS.new(:default).stylesheet
  @coderay_stylesheet_data ||= ::IO.read(::File.join(STYLESHEETS_DATA_PATH, 'coderay-asciidoctor.css')).chomp
end
coderay_stylesheet_name() click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 39
def coderay_stylesheet_name
  'coderay-asciidoctor.css'
end
embed_coderay_stylesheet() click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 53
  def embed_coderay_stylesheet
    %Q(<style>
#{coderay_stylesheet_data}
</style>)
  end
embed_primary_stylesheet() click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 29
  def embed_primary_stylesheet
    %Q(<style>
#{primary_stylesheet_data}
</style>)
  end
embed_pygments_stylesheet(style = nil) click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 76
  def embed_pygments_stylesheet style = nil
    %Q(<style>
#{pygments_stylesheet_data style}
</style>)
  end
load_pygments() click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 86
def load_pygments
  Helpers.require_library 'pygments', 'pygments.rb' unless defined? ::Pygments
  {}
end
primary_stylesheet_data() click to toggle source

Public: Read the contents of the default Asciidoctor stylesheet

returns the [String] Asciidoctor stylesheet data

# File lib/asciidoctor/stylesheets.rb, line 25
def primary_stylesheet_data
  @primary_stylesheet_data ||= ::IO.read(::File.join(STYLESHEETS_DATA_PATH, 'asciidoctor-default.css')).chomp
end
primary_stylesheet_name() click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 18
def primary_stylesheet_name
  DEFAULT_STYLESHEET_NAME
end
pygments_stylesheet_data(style = nil) click to toggle source

Public: Generate the Pygments stylesheet with the specified style.

returns the [String] Pygments stylesheet data

# File lib/asciidoctor/stylesheets.rb, line 71
def pygments_stylesheet_data style = nil
  style ||= DEFAULT_PYGMENTS_STYLE
  (@pygments_stylesheet_data ||= load_pygments)[style] ||= ::Pygments.css '.listingblock .pygments', :classprefix => 'tok-', :style => style
end
pygments_stylesheet_name(style = nil) click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 63
def pygments_stylesheet_name style = nil
  style ||= DEFAULT_PYGMENTS_STYLE
  %Q(pygments-#{style}.css)
end
write_coderay_stylesheet(target_dir) click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 59
def write_coderay_stylesheet target_dir
  ::File.open(::File.join(target_dir, coderay_stylesheet_name), 'w') {|f| f.write coderay_stylesheet_data }
end
write_primary_stylesheet(target_dir) click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 35
def write_primary_stylesheet target_dir
  ::File.open(::File.join(target_dir, primary_stylesheet_name), 'w') {|f| f.write primary_stylesheet_data }
end
write_pygments_stylesheet(target_dir, style = nil) click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 82
def write_pygments_stylesheet target_dir, style = nil
  ::File.open(::File.join(target_dir, pygments_stylesheet_name(style)), 'w') {|f| f.write pygments_stylesheet_data(style) }
end