dynarex-blog 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dynarex-blog.rb +36 -7
- metadata +2 -2
data/lib/dynarex-blog.rb
CHANGED
@@ -30,6 +30,15 @@ class DynarexBlog
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def create_entry(record={})
|
33
|
+
|
34
|
+
if record.has_key? :title then
|
35
|
+
lookup = '_entry_lookup.xml'
|
36
|
+
doc = Rexle.new File.open(@file_path + lookup,'r').read
|
37
|
+
if doc.element("records/entry[uri='#{format_uri(record[:title])}']") then
|
38
|
+
raise "err: create_entry: Duplicate title found"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
33
42
|
@hc_result.reset
|
34
43
|
@id += 1
|
35
44
|
# create a new record
|
@@ -65,7 +74,11 @@ class DynarexBlog
|
|
65
74
|
|
66
75
|
def update(id, h)
|
67
76
|
|
77
|
+
puts '@current_looup ' + @current_lookup
|
78
|
+
puts 'id : ' + id.to_s
|
79
|
+
|
68
80
|
lookup = Dynarex.new @file_path + @current_lookup
|
81
|
+
puts 'records : ' + lookup.records.inspect
|
69
82
|
lookup_id = lookup.records[id][:id]
|
70
83
|
file = lookup.records[id][:body][:file]
|
71
84
|
|
@@ -73,11 +86,10 @@ class DynarexBlog
|
|
73
86
|
|
74
87
|
dynarex = Dynarex.new(@file_path + file)
|
75
88
|
prev_tags = dynarex.record(id).tags
|
76
|
-
cur_tags = h[:tags]
|
77
89
|
|
78
|
-
if
|
90
|
+
if h[:tags] and h[:tags].length > 0 then
|
79
91
|
|
80
|
-
a =
|
92
|
+
a = h[:tags].split(/\s/)
|
81
93
|
|
82
94
|
if prev_tags and prev_tags.length > 0 then
|
83
95
|
|
@@ -94,6 +106,8 @@ class DynarexBlog
|
|
94
106
|
|
95
107
|
new_list.each {|tag| create_record(h, id, name=tag, type='tags') }
|
96
108
|
dynarex.update(id, h)
|
109
|
+
puts 'dynarex : ' + dynarex.to_xml
|
110
|
+
puts 'saving: ' + @file_path + file
|
97
111
|
dynarex.save
|
98
112
|
end
|
99
113
|
|
@@ -101,7 +115,7 @@ class DynarexBlog
|
|
101
115
|
|
102
116
|
@hc_lookup.write(@current_lookup) { Rexle.new File.open(@file_path + @current_lookup,'r').read }
|
103
117
|
|
104
|
-
refresh_index if index_include? id
|
118
|
+
(puts "rebuilding index #@file_path} ... "; refresh_index) if index_include? id
|
105
119
|
|
106
120
|
end
|
107
121
|
|
@@ -155,6 +169,15 @@ class DynarexBlog
|
|
155
169
|
@entities.create.section({name: 'tags'}, id='tags')
|
156
170
|
@entities.save @file_path + ENTITIES
|
157
171
|
@lookup = new_lookup_file '_entry_lookup.xml'
|
172
|
+
|
173
|
+
# add the _404.xml
|
174
|
+
dynarex = Dynarex.new('entries/entry(id,file,year,month,uri)')
|
175
|
+
year, month = [:year, :month].map{|x| "%02d" % Time.now.method(x).call}
|
176
|
+
dynarex.create id: '1', file: '_4041.xml', year: year, month: month
|
177
|
+
dynarex.save '_404_lookup.xml'
|
178
|
+
|
179
|
+
Dynarex.new('entries/entry(title,body,tags,user)').save '_4041.xml'
|
180
|
+
|
158
181
|
end
|
159
182
|
|
160
183
|
def open(file_path='./')
|
@@ -252,7 +275,7 @@ class DynarexBlog
|
|
252
275
|
lookup_id = lookup.records[id][:id]
|
253
276
|
|
254
277
|
file = lookup.records[id][:body][:file]
|
255
|
-
lookup.update(lookup_id, uri: h[:title]
|
278
|
+
lookup.update(lookup_id, uri: format_uri(h[:title])).save
|
256
279
|
|
257
280
|
Dynarex.new(@file_path + file).update(id, h).save
|
258
281
|
delete_cache_entry(lookup_filename, file)
|
@@ -271,6 +294,10 @@ class DynarexBlog
|
|
271
294
|
@hc_lookup.delete(lookup_filename)
|
272
295
|
end
|
273
296
|
|
297
|
+
def format_uri(s)
|
298
|
+
s.gsub(/\s/,'-')
|
299
|
+
end
|
300
|
+
|
274
301
|
def reset_cache_entry(lookup_filename, file)
|
275
302
|
|
276
303
|
@hc_entry_file.delete(file)
|
@@ -285,14 +312,15 @@ class DynarexBlog
|
|
285
312
|
x1 = (number - 1) * 10
|
286
313
|
x2 = x1 + 9
|
287
314
|
|
288
|
-
lookup_a = doc.xpath('records/entry') do |entry|
|
315
|
+
lookup_a = doc.xpath('records/entry').map do |entry|
|
289
316
|
%w(file id).map{|x| entry.text(x)}
|
290
317
|
end
|
291
318
|
|
292
319
|
threads = lookup_a.reverse[x1..x2].group_by(&:first).map do |filename,raw_ids|
|
293
320
|
Thread.new do
|
294
321
|
xpath = raw_ids.map{|x| "@id='%s'" % x[-1]}.join(' or ')
|
295
|
-
|
322
|
+
|
323
|
+
Thread.current[:records] = Rexle.new(File.open(@file_path + filename,'r').read)\
|
296
324
|
.xpath("records/entry[#{xpath}]")
|
297
325
|
end
|
298
326
|
end
|
@@ -378,6 +406,7 @@ class DynarexBlog
|
|
378
406
|
@hc_lookup_a.delete(lookup + '1')
|
379
407
|
|
380
408
|
page = select_page(doc, 1)
|
409
|
+
puts 'page : ' + page.xml(pretty: true)
|
381
410
|
@index.add page.element('records')
|
382
411
|
@index.save
|
383
412
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynarex-blog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors: []
|
7
7
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-02-06 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|