Sha256: 051b1c3c65525e371f8a6a2b9cbe7beef4f6074042fd201e29ae3ddb7136a7ad

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require File.dirname(__FILE__) + "/../util"
module FN
  module Node
    def self.Base(name, attributes = {})
      n = XML::Node.new(name)
      attributes.each {|k, v| n[k.to_s] = Base.value(v) }
      n.extend(Base)
      return n
    end
    
    module Base
      
      CURRENT_PAGE_WIDTH  = "__current_page_width"
      CURRENT_PAGE_HEIGHT = "__current_page_height"
    
      def visit(struct)
        visit_children(struct)
      end
      
      def has_no_children
        @logger = Logger.new("#{RAILS_ROOT}/log/pdf_writer_logs/#{Time.now.strftime('pdf_writer_log_%Y_%m_%d')}.log")
        if children.any?{|c| !c.cdata?}
          # @logger.info "HAS NO CHILDREN "*88
          raise "should have no children" 
        else
          # @logger.info "This should not have any children and it does not"
        end
      end
      
      def visit_children(struct)
        children.each do |c| 
          if c.element?
            mixin(c)
            c.visit(struct)
          end
        end
        return struct
      end
      
      def mixin(node)
        name = classify(node.name)
        mod = FN::SWF::Node.const_get(name) rescue 
              FN::PDF::Node.const_get(name)
        node.extend(mod)
      end
      
      def classify(name)
        name.split("_").map{|s| s.capitalize}.join("")
      end
      
      def with_attributes_like(node)
        node.attributes.each do |attr|
          self[attr.name] = attr.value
        end
        self
      end
      
      def value(v)
        case v
        when Array: v.map{|e| value(e)}.join(" ")
        else
          v.to_s
        end
      end
      
      extend self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fn_document-0.9.2 lib/fn/node/base.rb