summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-03-30 21:29:39 +0200
committerhukl <contact@smyck.org>2009-03-30 21:29:39 +0200
commit6150357ded46ab20dc73095c89eda64c008c3be5 (patch)
treeb519c50e2612d14f6a6c5413db0291a697ee9b5d /lib
parent85b60ee48a4c9973d4bc52aacddaa62491ab16ed (diff)
next level - events to go
Diffstat (limited to 'lib')
-rw-r--r--lib/chaos_xml.rb60
1 files changed, 49 insertions, 11 deletions
diff --git a/lib/chaos_xml.rb b/lib/chaos_xml.rb
index f36708a..f06d750 100644
--- a/lib/chaos_xml.rb
+++ b/lib/chaos_xml.rb
@@ -13,7 +13,7 @@ class ChaosXml
13 @years = {} 13 @years = {}
14 end 14 end
15 15
16 def import_xml 16 def import_updates
17 unless @updates = Node.find_by_unique_name('updates') 17 unless @updates = Node.find_by_unique_name('updates')
18 @updates = Node.create!( :slug => 'updates' ) 18 @updates = Node.create!( :slug => 'updates' )
19 @updates.move_to_child_of Node.root 19 @updates.move_to_child_of Node.root
@@ -23,6 +23,11 @@ class ChaosXml
23 node = find_or_create_node( chaospage, chaos_id ) 23 node = find_or_create_node( chaospage, chaos_id )
24 html = convert_to_html( chaospage ) 24 html = convert_to_html( chaospage )
25 page = fill_draft_with_content(node.draft, html, lang) 25 page = fill_draft_with_content(node.draft, html, lang)
26
27 add_tags_to_page page, chaospage, "update"
28 add_events_to_page page, chaospage
29
30 puts node.unique_name
26 end 31 end
27 end 32 end
28 33
@@ -73,29 +78,62 @@ class ChaosXml
73 node 78 node
74 end 79 end
75 80
76 def fill_draft_with_content draft, chaospage, lang 81 def fill_draft_with_content draft, html, lang
77 I18n.locale = lang 82 I18n.locale = lang
78 83
79 options = { 84 options = {
80 :title => chaospage.xpath("//title")[0].content, 85 :title => html.xpath("//title")[0].content,
81 :abstract => chaospage.xpath("//abstract")[0].content, 86 :abstract => html.xpath("//abstract")[0].content,
82 :body => extract_body(chaospage) 87 :body => extract_body(html)
83 } 88 }
84 89
85 puts options.inspect 90 draft.update_attributes options
86 #draft.update_attributes options 91 draft
87 end 92 end
88 93
89 def extract_body chaospage 94 def extract_body html, excluded_tags=[]
95 default_excluded_tags = [
96 "DTSTART",
97 "DTEND",
98 "DURATION",
99 "LOCATION",
100 "GEO",
101 "SUMMARY",
102 "URL"
103 ]
104
105 excluded_tags = (default_excluded_tags + excluded_tags).uniq
106
90 body = "" 107 body = ""
91 element = chaospage.xpath("//abstract")[0].next_sibling 108 element = html.xpath("//abstract")[0].next_sibling
92 109
93 while element do 110 while element do
94 body << element.to_s 111 body << element.to_s unless excluded_tags.include? element.name
95 element = element.next_sibling 112 element = element.next_sibling
96 end 113 end
114
115 body
116 end
117
118 def add_tags_to_page page, xml, *custom_tags
119 tag_list = custom_tags
120
121 xml.xpath("//flags").each do |node|
122 node.each do |k,v|
123 case k
124 when "calendar"
125 tag_list << "event"
126 when "pm"
127 tag_list << "pressemitteilung"
128 end
129 end
130 end
131
132 # Getting rid of duplicate flags
133 tag_list.uniq!
97 134
98 puts body 135 page.tag_list = tag_list.join(",")
136 page.save
99 end 137 end
100 138
101 def convert_to_html chaospage 139 def convert_to_html chaospage