Sha256: 4a321dff9ed3ff16117d4b16f863f60a59614d3d85db55098cee87cc8ca1b476

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

# coding: utf-8

module ThinReports
  module Generator
    
    # @private
    class Pxd::ListRenderer
      include Pxd::Helper
      
      def initialize
        @renderers = {}
        @list      = nil
      end

      # @param [ThinReports::Core::Shape::List::PageState] list
      def render(list)
        @list = list
        
        result = String.new
        render_section(result, list.header) if list.header
        
        list.rows.each do |row|
          render_section(result, row)
        end
        result
      end
      
    private

      # @param [String] result
      # @param [ThinReports::Core::Shape::List::SectionInterface] section
      def render_section(result, section)
        internal   = section.internal
        attributes = internal.attributes
        contents   = renderer(internal.section_name).render(section.manager)
        
        # Only for when older than Ver 0.6.0.pre2.
        # Since 0.6.0.pre3, ignore this.
        if internal.relative_top
          attributes['transform'] =
              "translate(#{internal.relative_position.join(',')})"
        end
        
        result << content_tag(internal.svg_tag, contents, attributes,
                              :escape => false)
      end
      
      # @param [Symbol] section_name
      # @return [ThinReports::Generator::Pxd::PageRenderer]
      def renderer(section_name)
        @renderers[section_name] ||=
          Pxd::PageRenderer.new(@list.format.sections[section_name])
      end
      
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinreports-0.6.0.pre3 lib/thinreports/generator/pxd/list_renderer.rb