dynarex-blog 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/dynarex-blog.rb +53 -37
- metadata +1 -1
data/lib/dynarex-blog.rb
CHANGED
@@ -63,40 +63,58 @@ class DynarexBlog
|
|
63
63
|
file = lookup.records[id][:body][:file]
|
64
64
|
|
65
65
|
dynarex = Dynarex.new(@file_path + file)
|
66
|
-
dynarex.
|
66
|
+
prev_tags = dynarex.record(id).tags
|
67
|
+
cur_tags = h[:tags]
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
if cur_tags.length > 0 then
|
70
|
+
|
71
|
+
a = cur_tags.split(/\s/)
|
72
|
+
|
73
|
+
if prev_tags and prev_tags.length > 0 then
|
74
|
+
|
75
|
+
b = prev_tags.split(/\s/)
|
76
|
+
old_list = a - b # tags to be deleted
|
77
|
+
new_list = b - a # tags to be inserted
|
78
|
+
|
79
|
+
old.each {|x| delete_entry(doc_tag, node_entry, tag_name, id) }
|
80
|
+
common = a.to_set.intersection(b).to_a # tags to be updated
|
81
|
+
common.each {|name| update_entry(name, id, h) } if dynarex.record(id).tags
|
82
|
+
else
|
83
|
+
new_list = a
|
84
|
+
end
|
85
|
+
|
86
|
+
new_list.each {|tag| create_record(h, id, name=tag, type='tags') }
|
87
|
+
|
88
|
+
dynarex.update(id, h)
|
89
|
+
dynarex.save
|
90
|
+
end
|
71
91
|
|
72
|
-
|
92
|
+
lookup.update(lookup_id, uri: h[:title].gsub(/\s/,'-')).save
|
93
|
+
@hc_lookup.write(@current_lookup) { Document.new File.open(@file_path + @current_lookup,'r').read }
|
94
|
+
|
73
95
|
end
|
74
96
|
|
75
|
-
def delete(id=
|
97
|
+
def delete(id='')
|
76
98
|
|
77
99
|
# delete from the tags files (entry and lookup), the entry file and lookup
|
78
100
|
# look the id up in lookup.xml
|
79
101
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
tags =
|
86
|
-
|
87
|
-
dynarex_entry.parent.delete dynarex_entry
|
88
|
-
File.open(dynarex_file,'w'){|f| dynarex.write f}
|
102
|
+
lookup = Dynarex.new @file_path + @current_lookup
|
103
|
+
lookup_id = lookup.records[id][:id]
|
104
|
+
file = lookup.records[id][:body][:file]
|
105
|
+
|
106
|
+
dynarex = Dynarex.new(@file_path + file)
|
107
|
+
tags = dynarex.record(id).tags.split(/\s/)
|
108
|
+
dynarex.delete(id).save
|
89
109
|
|
90
|
-
|
91
|
-
lookup = "%s%s" % [@file_path, '_entry_lookup.xml']
|
92
|
-
File.open(lookup,'w'){|f| doc_entry.write f}
|
110
|
+
lookup.delete(lookup_id).save
|
93
111
|
|
94
112
|
tags.each do |tag_name|
|
95
113
|
# find the lookup
|
96
|
-
|
97
|
-
delete_entry(doc_tag, node_entry, tag_name, id)
|
114
|
+
delete_entry(tag_name, id)
|
98
115
|
end
|
99
116
|
|
117
|
+
# start of reindexing
|
100
118
|
doc = Document.new File.open(@file_path + 'index.xml','r').read
|
101
119
|
node = XPath.first(doc.root, "records/entry[@id='#{id}']")
|
102
120
|
|
@@ -194,34 +212,32 @@ class DynarexBlog
|
|
194
212
|
|
195
213
|
private
|
196
214
|
|
197
|
-
def delete_entry(
|
198
|
-
|
199
|
-
|
215
|
+
def delete_entry(lookup_filename, id)
|
216
|
+
|
217
|
+
lookup_path = "%s%s_lookup.xml" % [@file_path, lookup_filename]
|
218
|
+
lookup = Dynarex.new lookup_path
|
219
|
+
|
220
|
+
lookup_id = lookup.records[id][:id]
|
221
|
+
file = lookup.records[id][:body][:file]
|
222
|
+
lookup.delete(lookup_id).save
|
223
|
+
|
224
|
+
Dynarex.new(file).delete(id).save
|
200
225
|
|
201
|
-
node.parent.delete node
|
202
|
-
lookup = "%s%s_lookup.xml" % [@file_path, lookup_filename]
|
203
|
-
File.open(lookup,'w'){|f| doc.write f}
|
204
226
|
end
|
205
227
|
|
206
228
|
def update_entry(lookup_filename, id, h)
|
207
229
|
|
208
|
-
lookup_path = "%s%s_lookup.xml" % [@file_path, lookup_filename]
|
209
|
-
|
230
|
+
lookup_path = "%s%s_lookup.xml" % [@file_path, lookup_filename]
|
210
231
|
lookup = Dynarex.new lookup_path
|
211
232
|
lookup_id = lookup.records[id][:id]
|
233
|
+
|
212
234
|
file = lookup.records[id][:body][:file]
|
235
|
+
lookup.update(lookup_id, uri: h[:title].gsub(/\s/,'-')).save
|
236
|
+
|
237
|
+
Dynarex.new(@file_path + file).update(id, h).save
|
213
238
|
|
214
|
-
Dynarex.new(@file_path + file).update(id, h).save
|
215
|
-
|
216
|
-
uri = h[:title].gsub(/\s/,'-')
|
217
|
-
lookup.update(lookup_id, uri: uri).save
|
218
239
|
end
|
219
240
|
|
220
|
-
def open_lookup_record(name, id)
|
221
|
-
lookup_path = "%s%s_lookup.xml" % [@file_path, name]
|
222
|
-
lookup = Document.new File.open(lookup_path,'r').read
|
223
|
-
[lookup, XPath.first(lookup.root, "records/entry[id='#{id}']")]
|
224
|
-
end
|
225
241
|
|
226
242
|
def select_page(doc, number)
|
227
243
|
|