# File lib/asciidoctor/stylesheets.rb, line 26 def primary_stylesheet_data @primary_stylesheet_data ||= ::IO.read(::File.join(STYLESHEETS_DATA_PATH, 'asciidoctor-default.css')).rstrip end
class Asciidoctor::Stylesheets
A utility class for working with the built-in stylesheets.
Constants
- DEFAULT_PYGMENTS_STYLE
- DEFAULT_STYLESHEET_NAME
- PygmentsBgColorRx
- STYLESHEETS_DATA_PATH
Public Class Methods
instance()
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 15 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 47 def coderay_stylesheet_data # NOTE use the following lines to load a built-in theme instead # unless load_coderay.nil? # ::CodeRay::Encoders[:html]::CSS.new(:default).stylesheet # end @coderay_stylesheet_data ||= ::IO.read(::File.join(STYLESHEETS_DATA_PATH, 'coderay-asciidoctor.css')).rstrip end
coderay_stylesheet_name()
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 40 def coderay_stylesheet_name 'coderay-asciidoctor.css' end
embed_coderay_stylesheet()
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 55 def embed_coderay_stylesheet %(<style> #{coderay_stylesheet_data} </style>) end
embed_primary_stylesheet()
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 30 def embed_primary_stylesheet %(<style> #{primary_stylesheet_data} </style>) end
embed_pygments_stylesheet(style = nil)
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 89 def embed_pygments_stylesheet style = nil %(<style> #{pygments_stylesheet_data style} </style>) end
load_pygments()
click to toggle source
def load_coderay
(defined? ::CodeRay) ? true : !(Helpers.require_library 'coderay', true, :ignore).nil?
end
# File lib/asciidoctor/stylesheets.rb, line 103 def load_pygments (defined? ::Pygments) ? true : !(Helpers.require_library 'pygments', 'pygments.rb', :ignore).nil? end
primary_stylesheet_data()
click to toggle source
Public: Read the contents of the default Asciidoctor stylesheet
returns the [String] Asciidoctor stylesheet data
primary_stylesheet_name()
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 19 def primary_stylesheet_name DEFAULT_STYLESHEET_NAME end
pygments_background(style = nil)
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 69 def pygments_background style = nil if load_pygments && PygmentsBgColorRx =~ (::Pygments.css '.pygments', :style => style || DEFAULT_PYGMENTS_STYLE) $1 end 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 78 def pygments_stylesheet_data style = nil if load_pygments style ||= DEFAULT_PYGMENTS_STYLE (@pygments_stylesheet_data ||= {})[style] ||= ((::Pygments.css '.listingblock .pygments', :classprefix => 'tok-', :style => style) || '/* Failed to load Pygments CSS. */'). sub('.listingblock .pygments {', '.listingblock .pygments, .listingblock .pygments code {') else '/* Pygments CSS disabled. Pygments is not available. */' end end
pygments_stylesheet_name(style = nil)
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 65 def pygments_stylesheet_name style = nil %(pygments-#{style || DEFAULT_PYGMENTS_STYLE}.css) end
write_coderay_stylesheet(target_dir = '.')
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 61 def write_coderay_stylesheet target_dir = '.' ::IO.write(::File.join(target_dir, coderay_stylesheet_name), coderay_stylesheet_data) end
write_primary_stylesheet(target_dir = '.')
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 36 def write_primary_stylesheet target_dir = '.' ::IO.write(::File.join(target_dir, primary_stylesheet_name), primary_stylesheet_data) end
write_pygments_stylesheet(target_dir = '.', style = nil)
click to toggle source
# File lib/asciidoctor/stylesheets.rb, line 95 def write_pygments_stylesheet target_dir = '.', style = nil ::IO.write(::File.join(target_dir, pygments_stylesheet_name(style)), pygments_stylesheet_data(style)) end