"Fossies" - the Fresh Open Source Software Archive

Member "asciidoctor-2.0.10/lib/asciidoctor/stylesheets.rb" (1 Jun 2019, 2694 Bytes) of package /linux/www/asciidoctor-2.0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # frozen_string_literal: true
    2 module Asciidoctor
    3 # A utility class for working with the built-in stylesheets.
    4 #--
    5 # QUESTION create methods for link_*_stylesheet?
    6 # QUESTION create method for user stylesheet?
    7 class Stylesheets
    8   DEFAULT_STYLESHEET_NAME = 'asciidoctor.css'
    9   STYLESHEETS_DIR = ::File.join DATA_DIR, 'stylesheets'
   10 
   11   @__instance__ = new
   12 
   13   def self.instance
   14     @__instance__
   15   end
   16 
   17   def primary_stylesheet_name
   18     DEFAULT_STYLESHEET_NAME
   19   end
   20 
   21   # Public: Read the contents of the default Asciidoctor stylesheet
   22   #
   23   # returns the [String] Asciidoctor stylesheet data
   24   def primary_stylesheet_data
   25     @primary_stylesheet_data ||= (::File.read (::File.join STYLESHEETS_DIR, 'asciidoctor-default.css'), mode: FILE_READ_MODE).rstrip
   26   end
   27 
   28   # Deprecated: Generate code to embed the primary stylesheet
   29   #
   30   # Returns the [String] primary stylesheet data wrapped in a <style> tag
   31   def embed_primary_stylesheet
   32     %(<style>
   33 #{primary_stylesheet_data}
   34 </style>)
   35   end
   36 
   37   def write_primary_stylesheet target_dir = '.'
   38     ::File.write (::File.join target_dir, primary_stylesheet_name), primary_stylesheet_data, mode: FILE_WRITE_MODE
   39   end
   40 
   41   def coderay_stylesheet_name
   42     (SyntaxHighlighter.for 'coderay').stylesheet_basename
   43   end
   44 
   45   # Public: Read the contents of the default CodeRay stylesheet
   46   #
   47   # returns the [String] CodeRay stylesheet data
   48   def coderay_stylesheet_data
   49     (SyntaxHighlighter.for 'coderay').read_stylesheet
   50   end
   51 
   52   # Deprecated: Generate code to embed the CodeRay stylesheet
   53   #
   54   # Returns the [String] CodeRay stylesheet data wrapped in a <style> tag
   55   def embed_coderay_stylesheet
   56     %(<style>
   57 #{coderay_stylesheet_data}
   58 </style>)
   59   end
   60 
   61   def write_coderay_stylesheet target_dir = '.'
   62     ::File.write (::File.join target_dir, coderay_stylesheet_name), coderay_stylesheet_data, mode: FILE_WRITE_MODE
   63   end
   64 
   65   def pygments_stylesheet_name style = nil
   66     (SyntaxHighlighter.for 'pygments').stylesheet_basename style
   67   end
   68 
   69   # Public: Generate the Pygments stylesheet with the specified style.
   70   #
   71   # returns the [String] Pygments stylesheet data
   72   def pygments_stylesheet_data style = nil
   73     (SyntaxHighlighter.for 'pygments').read_stylesheet style
   74   end
   75 
   76   # Deprecated: Generate code to embed the Pygments stylesheet
   77   #
   78   # Returns the [String] Pygments stylesheet data for the specified style wrapped in a <style> tag
   79   def embed_pygments_stylesheet style = nil
   80     %(<style>
   81 #{pygments_stylesheet_data style}
   82 </style>)
   83   end
   84 
   85   def write_pygments_stylesheet target_dir = '.', style = nil
   86     ::File.write (::File.join target_dir, (pygments_stylesheet_name style)), (pygments_stylesheet_data style), mode: FILE_WRITE_MODE
   87   end
   88 end
   89 end