Sha256: 21eb02293d0813dbdf247f6786052a96f321960c8ac024656484568434937b0e

Contents?: true

Size: 845 Bytes

Versions: 5

Compression:

Stored size: 845 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'uri'

module Genit

  # A base class for all builders.
  class BuilderBase
  
    # Public: Constructor.
    #
    # doc - A Nokogiri::XML::Document
    def initialize doc
      raise RuntimeError if doc.nil?
      @document = doc
    end
    
    # Define me in child
    def build_for_page page_name
      raise NotImplementedError
    end
    
    def build page_name, elements
      @page_name = page_name
      elements.each {|elem| update elem }
      @document
    end
    
    def BuilderBase.get_number_of_base_dirs filename
      return 0 if filename =~ URI::regexp
      
      dirs = File.dirname filename
      return 0 if dirs == '.'
      
      return dirs.split('/').size
    end
    
    private
    
    def make_relative nb
      nb.times { @path = '../' + @path }
    end
  
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
genit-1.0.1 lib/genit/builders/builder_base.rb
genit-1.0 lib/genit/builders/builder_base.rb
genit-0.99 lib/genit/builders/builder_base.rb
genit-0.9 lib/genit/builders/builder_base.rb
genit-0.5 lib/genit/builder_base.rb