Sha256: ab375146f1c694cf0886a23cd8c0db79d3297357d52d54a5cf51cdf4040bbecf

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8

require 'bade'


module Epuber
  class Compiler
    module FileTypes
      require_relative 'xhtml_file'

      class BadeFile < XHTMLFile
        # @param [Epuber::Compiler::CompilationContext] compilation_context
        #
        def process(compilation_context)
          target = compilation_context.target
          book = compilation_context.book
          file_resolver = compilation_context.file_resolver

          bade_content = load_source(compilation_context)

          variables = {
            __book: book,
            __target: target,
            __file_resolver: file_resolver,
            __file: self,
            __toc_item: toc_item,
            __const: Hash.new { |_hash, key| UI.warning("Undefined constant with key `#{key}`", location: caller_locations[0]) }.merge!(target.constants),
          }

          xhtml_content = Bade::Renderer.from_source(bade_content, source_path)
                                        .with_locals(variables)
                                        .render(new_line: '', indent: '')

          write_compiled(common_process(xhtml_content, compilation_context))
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
epuber-0.3.12 lib/epuber/compiler/file_types/bade_file.rb
epuber-0.3.11 lib/epuber/compiler/file_types/bade_file.rb
epuber-0.3.10 lib/epuber/compiler/file_types/bade_file.rb
epuber-0.3.9 lib/epuber/compiler/file_types/bade_file.rb
epuber-0.3.7 lib/epuber/compiler/file_types/bade_file.rb
epuber-0.3.6 lib/epuber/compiler/file_types/bade_file.rb
epuber-0.3.5 lib/epuber/compiler/file_types/bade_file.rb