Sha256: 230bae2588d6daa324f2afdfa50401608527e6da8621ad391c4ae144f6cfe890

Contents?: true

Size: 1.43 KB

Versions: 23

Compression:

Stored size: 1.43 KB

Contents

module TaliaCore
  module ActiveSourceParts
    module Xml
      
      # Base class for builders that create source-related XML. This uses a Builder::XmlMarkup object
      # in the background which does the actual XML writing.
      # 
      # All builders will be used through the #open method, which can be passed either a Builder::XmlMarkup
      # object, or the options to create one.
      class BaseBuilder
        
        # Creates a new builder. The options are equivalent for the options of the
        # underlying Xml builder. The builder itself will be passed to the block that
        # is called by this method.
        # If you pass a :builder option instead, it will use the given builder instead
        # of creating a new one
        def self.open(options)
          my_builder = self.new(options)
          my_builder.send(:build_structure) do
            yield(my_builder)
          end
        end
        
        # Quick helper: Returns the xml for one source as a string
        def self.build_source(source)
          xml = ''
          
          open(:target => xml, :indent => 2) do |builder|
            builder.write_source(source)
          end
          
          xml
        end
        
        private
        
        # Create a new builder
        def initialize(options)
          @builder = options[:builder]
          @builder ||= Builder::XmlMarkup.new(options)
        end
        
      end
      
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
talia_core-0.5.0 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.22 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.20 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.19 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.18 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.17 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.16 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.15 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.14 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.13 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.12 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.11 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.10 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.9 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.8 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.7 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.6 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.5 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.4 lib/talia_core/active_source_parts/xml/base_builder.rb
talia_core-0.4.3 lib/talia_core/active_source_parts/xml/base_builder.rb