Class: SPDocgen::RenderRequest
- Inherits:
-
Object
- Object
- SPDocgen::RenderRequest
- Defined in:
- lib/spdocgen/render_request.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#xml ⇒ Object
Returns the value of attribute xml.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(document_set) ⇒ RenderRequest
constructor
A new instance of RenderRequest.
- #submit ⇒ Object
Constructor Details
#initialize(document_set) ⇒ RenderRequest
Returns a new instance of RenderRequest.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/spdocgen/render_request.rb', line 7 def initialize(document_set) raise "Document set should inherit from #{DocumentSet.name}" unless document_set.is_a? DocumentSet raise "Documents should inherit from #{Document.name}" unless document_set.documents.all?{|doc| doc.is_a? Document} @document_set = document_set @xmlns = { 'xmlns:dgr' => 'http://www.sp.com.au/docgen/schemas/wsh', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' }.merge(document_set.all_xmlns) raise 'XML namespace definitions should start with xmlns:' unless @xmlns.keys.all?{|k| k.start_with? 'xmlns:'} = {} if document_set.respond_to? : = document_set. end end |
Instance Attribute Details
#metadata ⇒ Object
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/spdocgen/render_request.rb', line 5 def end |
#xml ⇒ Object
Returns the value of attribute xml.
5 6 7 |
# File 'lib/spdocgen/render_request.rb', line 5 def xml @xml end |
Instance Method Details
#build ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/spdocgen/render_request.rb', line 25 def build raise 'Already built' if @xml raise 'No data sources' if @document_set.nil? or @document_set.documents.nil? or @document_set.documents.empty? builder = Nokogiri::XML::Builder.new :encoding => 'utf-8' do |xml| # Clients that treat this as a real builder sometimes need to call 'tag!' # That's ok. def xml.tag!(*args, &bl) # Handle reserved names correctly name = args.shift + '_' send name, *args, &bl end xml.DocGenRequest @xmlns do # See http://stackoverflow.com/questions/1829425/creating-an-xml-document-with-a-namespaced-root-element-with-nokogiri-builder xml.parent.namespace = xml.parent.namespace_definitions.find{|ns| ns.prefix == 'dgr'} dgr = xml['dgr'] dgr.MetaData do self..each do |k,v| dgr.MetaDataEntry do dgr.Key k dgr.Value v end end end dgr.SharedXmlDataSources do @document_set.all_data_sources.each do |data_source| dgr.SharedXmlDataSource 'sharedXmlDataSourceId' => data_source.id do data_source.build(xml) end end end dgr.DocumentRequests do @document_set.documents.each do |document| document.build(xml) end end end end @xml = builder.to_xml end |
#submit ⇒ Object
70 71 72 73 74 |
# File 'lib/spdocgen/render_request.rb', line 70 def submit raise 'Request needs to be built first' unless @xml SPDocgen::Protocol.instance.submit @xml end |