lib/caracal/renderers/document_renderer.rb in caracal-1.2.0 vs lib/caracal/renderers/document_renderer.rb in caracal-1.3.0

- old
+ new

@@ -80,10 +80,11 @@ xml['w'].sz( { 'w:val' => attrs[:size] }) unless attrs[:size].nil? xml['w'].b( { 'w:val' => (attrs[:bold] ? '1' : '0') }) unless attrs[:bold].nil? xml['w'].i( { 'w:val' => (attrs[:italic] ? '1' : '0') }) unless attrs[:italic].nil? xml['w'].u( { 'w:val' => (attrs[:underline] ? 'single' : 'none') }) unless attrs[:underline].nil? xml['w'].shd( { 'w:fill' => attrs[:bgcolor], 'w:val' => 'clear' }) unless attrs[:bgcolor].nil? + xml['w'].highlight( { 'w:val' => attrs[:highlight_color] }) unless attrs[:highlight_color].nil? xml['w'].vertAlign( { 'w:val' => attrs[:vertical_align] }) unless attrs[:vertical_align].nil? unless attrs[:font].nil? f = attrs[:font] xml['w'].rFonts( { 'w:ascii' => f, 'w:hAnsi' => f, 'w:eastAsia' => f, 'w:cs' => f }) end @@ -95,10 +96,18 @@ end #============= MODEL RENDERERS =========================== + def render_bookmark(xml, model) + if model.start? + xml['w'].bookmarkStart({ 'w:id' => model.bookmark_id, 'w:name' => model.bookmark_name }) + else + xml['w'].bookmarkEnd({ 'w:id' => model.bookmark_id }) + end + end + def render_iframe(xml, model) ::Zip::File.open(model.file) do |zip| a_href = 'http://schemas.openxmlformats.org/drawingml/2006/main' pic_href = 'http://schemas.openxmlformats.org/drawingml/2006/picture' r_href = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships' @@ -193,12 +202,17 @@ xml['w'].br end end def render_link(xml, model) - rel = document.relationship({ target: model.link_href, type: :link }) + if model.external? + rel = document.relationship({ target: model.link_href, type: :link }) + hyperlink_options = { 'r:id' => rel.formatted_id } + else + hyperlink_options = { 'w:anchor' => model.link_href } + end - xml['w'].hyperlink({ 'r:id' => rel.formatted_id }) do + xml['w'].hyperlink(hyperlink_options) do xml['w'].r run_options do render_run_attributes(xml, model, false) xml['w'].t({ 'xml:space' => 'preserve' }, model.link_content) end end