Class: OdtText

Inherits:
Object
  • Object
show all
Defined in:
lib/documenter/ooo/odt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ OdtText

Returns a new instance of OdtText.



7
8
9
# File 'lib/documenter/ooo/odt.rb', line 7

def initialize xml
	@xml = Hpricot.parse(xml)
end

Instance Attribute Details

#xmlObject

Returns the value of attribute xml.



5
6
7
# File 'lib/documenter/ooo/odt.rb', line 5

def xml
  @xml
end

Instance Method Details

#edit_table(params) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/documenter/ooo/odt.rb', line 55

def edit_table params
@name = params[:name]
@rows = params[:data]
raise 'cannot edit table rows without datarows' if !@rows || @rows.size==0
@start_row = (params[:no_header]) ? 0 : 1
  
  table = nil
@xml.search("table:table").each {|t| table = t if t['table:name'] == @name }
  raise "no such table '#{@name.to_s}'" if !table
  
  table['table:name'] = params[:new_name] if params[:new_name]
  puts table
  row =  (table/'table:table-row')[@start_row]
template = row.to_html
row.inner_html=''
  
@rows.each do |row|
    puts 'inside'
    table.inner_html += (yield OdtText.new(template), row).to_html
end
  
  #puts @xml
end

#fill_form(data) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/documenter/ooo/odt.rb', line 11

def fill_form  data 
	(@xml/'text:user-field-decl').each do |decl|
		name = decl['text:name']
		decl['office:string-value']  = data[name] if data[name]
	end
	@xml
end

#fill_table(params) ⇒ Object



47
48
49
50
51
52
# File 'lib/documenter/ooo/odt.rb', line 47

def fill_table params
  edit_table(params) do |row, content|
    row.replace_form content
    row
  end
end

#find_table(name) ⇒ Object



32
33
# File 'lib/documenter/ooo/odt.rb', line 32

def  find_table name
end

#rename_table(oldname, newname) ⇒ Object



36
37
# File 'lib/documenter/ooo/odt.rb', line 36

def rename_table oldname, newname
end

#replace_form(data) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/documenter/ooo/odt.rb', line 19

def replace_form data
	(@xml/'text:user-field-get').each do |decl|
		name = decl['text:name']
		if data && data[name]
			parent_html = decl.parent.inner_html 
       decl.parent.inner_html = parent_html.gsub(/#{decl.to_html}/,"#{data[name].to_s}")
		end
	end
   puts @xml
	@xml
end

#to_htmlObject



39
40
41
# File 'lib/documenter/ooo/odt.rb', line 39

def to_html
  @xml.to_html
end

#to_xmlObject



43
44
45
# File 'lib/documenter/ooo/odt.rb', line 43

def to_xml
  @xml.to_html
end