diff options
| author | hukl <contact@smyck.org> | 2009-03-05 21:57:29 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-03-05 21:57:29 +0100 |
| commit | bbd8f83b7fda6da867510a71a50314c4555dcb92 (patch) | |
| tree | bf52a2c479099fb5da3493f2a12842e5cc064321 /app/models | |
| parent | 5bdafce88264d2cd5870f2382878863afcbc6280 (diff) | |
added begin rescue as too much can go wrong
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/page.rb | 36 |
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 | ||
