Sha256: 1b7078d58c9c08b8584ae58e41eb8f4a7cf01a65fbed5b272547317d536bf1ad

Contents?: true

Size: 1.9 KB

Versions: 9

Compression:

Stored size: 1.9 KB

Contents

require 'awestruct/util/exception_helper'
require 'awestruct/handler_chain'
require 'awestruct/handlers/base_handler'
require 'awestruct/handlers/file_handler'
require 'awestruct/handlers/front_matter_handler'
require 'awestruct/handlers/interpolation_handler'
require 'awestruct/handlers/layout_handler'

require 'nokogiri'

module Awestruct
  module Handlers
    class RestructuredtextHandler < BaseHandler

      CHAIN = Awestruct::HandlerChain.new( /\.(rst)$/,
        Awestruct::Handlers::FileHandler,
        Awestruct::Handlers::FrontMatterHandler,
        Awestruct::Handlers::InterpolationHandler,
        Awestruct::Handlers::RestructuredtextHandler,
        Awestruct::Handlers::LayoutHandler
      )

      def initialize(site, delegate)
        super( site, delegate )
      end

      def simple_name
        File.basename( relative_source_path, '.rst' )
      end

      def output_filename
        simple_name + output_extension
      end

      def output_extension
        '.html' 
      end

      def content_syntax
        :rst
      end

      def rendered_content(context, with_layouts=true)
        content = delegate.rendered_content( context, with_layouts )

        hl = 1
        if front_matter['initial_header_level'].to_s =~ /^[1-6]$/
          hl = front_matter['initial_header_level']
        end
        begin
          doc = execute_shell( [ "rst2html",
                                 "--strip-comments",
                                 "--no-doc-title",
                                 " --initial-header-level=#{hl}" ].join(' '), 
                                 content )
          content = Nokogiri::HTML( doc ).at( '/html/body/div[@class="document"]' ).inner_html.strip
          content.gsub( "\r", '' )
        rescue => e
          ExceptionHelper.log_building_error e, relative_source_path
          ExceptionHelper.html_error_report e, relative_source_path
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
awestruct-0.5.6.beta3 lib/awestruct/handlers/restructuredtext_handler.rb
awestruct-0.5.6.beta2 lib/awestruct/handlers/restructuredtext_handler.rb
awestruct-0.5.6.beta lib/awestruct/handlers/restructuredtext_handler.rb
awestruct-0.5.5 lib/awestruct/handlers/restructuredtext_handler.rb
awestruct-0.5.4.2 lib/awestruct/handlers/restructuredtext_handler.rb
awestruct-0.5.4.1 lib/awestruct/handlers/restructuredtext_handler.rb
awestruct-0.5.4 lib/awestruct/handlers/restructuredtext_handler.rb
awestruct-0.5.4.rc3 lib/awestruct/handlers/restructuredtext_handler.rb
awestruct-0.5.4.rc2 lib/awestruct/handlers/restructuredtext_handler.rb