summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/page.rb36
1 files changed, 20 insertions, 16 deletions
diff --git a/app/models/page.rb b/app/models/page.rb
index a4817a3..709fa4f 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -123,24 +123,28 @@ class Page < ActiveRecord::Base
123 private 123 private
124 124
125 def rewrite_links_in_body 125 def rewrite_links_in_body
126 if self.body 126 begin
127 tmp_body = "<div>#{self.body}</div>" 127 if self.body
128 xml_string = XML::Parser.string( tmp_body ) 128 tmp_body = "<div>#{self.body}</div>"
129 xml_doc = xml_string.parse 129 xml_string = XML::Parser.string( tmp_body )
130 links = xml_doc.find("a[not(starts-with(@href, 'http://'))]") 130 xml_doc = xml_string.parse
131 131 links = xml_doc.find("a[not(starts-with(@href, 'http://'))]")
132 locales = I18n.available_locales.reject {|l| l == :root} 132
133 133 locales = I18n.available_locales.reject {|l| l == :root}
134 links.each do |link| 134
135 unless locales.include? link[:href].slice(1,2).to_sym 135 links.each do |link|
136 link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/") 136 unless locales.include? link[:href].slice(1,2).to_sym
137 link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/")
138 end
137 end 139 end
140
141 tmp_body = xml_doc.to_s.gsub(/(\n\<div\>|\<\/div\>\n)/, "")
142 tmp_body.gsub!("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "")
143
144 self.body = tmp_body
138 end 145 end
139 146 rescue
140 tmp_body = xml_doc.to_s.gsub(/(\n\<div\>|\<\/div\>\n)/, "") 147 nil
141 tmp_body.gsub!("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "")
142
143 self.body = tmp_body
144 end 148 end
145 end 149 end
146 150