Sha256: 59b834ccca22ca1c561d0102a67e6e2301c287e2990e53238762e02aeb281771

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

require "rabbit/utils"

dir = File.join("rabbit", "parser")
Rabbit::Utils.require_files_under_directory_in_load_path(dir)

module Rabbit
  module Parser
    include GetText

    module_function
    def parse(canvas, source)
      parser = Base.find_loader(source)
      if parser.nil?
        format = _("unsupported format. (supported: %s)")
        format_names = Base.loaders.collect do |loader|
          loader.format_name
        end
        message = format % "[#{format_names.join(', ')}]"
        raise UnsupportedFormatError.new(message)
      end
      parser.new(canvas, source).parse
    end

    def normalize_property_name(name)
      name.gsub(/_/, "-").strip
    end

    class SlidePropertySetter
      def initialize(slide)
        @slide = slide
      end

      def apply(element)
        return unless element.is_a?(Element::DescriptionList)
        element.each do |item|
          name = Parser.normalize_property_name(item.term.text)
          @slide[name] = item.content.text.strip
        end
      end
    end

    class NoteSetter
      def initialize(slide)
        @slide = slide
      end

      def apply(element)
        return unless element.is_a?(Element::Paragraph)
        @slide['note'] ||= ""
        @slide['note'] << element.text
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rabbit-2.2.1 lib/rabbit/parser.rb
rabbit-2.2.0 lib/rabbit/parser.rb
rabbit-2.1.9 lib/rabbit/parser.rb
rabbit-2.1.8 lib/rabbit/parser.rb
rabbit-2.1.7 lib/rabbit/parser.rb