-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
92 lines (83 loc) · 2.87 KB
/
Copy pathinit.lua
File metadata and controls
92 lines (83 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
local version = [[Evernote/0.1-alpha1]]
local require, io, assert, table = require, io, assert, table
local theme, date, seawolf, arg, url = theme, os.date, seawolf, arg, url
local settings, tonumber, print = settings, tonumber, print
require [[seawolf.contrib]]
local table_concat, l = seawolf.contrib.table_concat, l
local path_register_alias, page_set_title = path_register_alias, page_set_title
module [[ophal.modules.evernote]]
--[[
Implementation of hook_menu().
]]
function menu()
local items = {}
items.evernote = {
title = [[Evernote]],
page_callback = [[page]],
}
return items
end
function page()
local file = settings.evernote.file
local note, r, s
local ID = tonumber(arg(1) or [[]])
local result = {}
-- Parse .nnex file
local xmlreader = require [[xmlreader]]
r = assert(xmlreader.from_file(file))
while r:read() do
if r:node_type() == [[element]] then
if r:name() == [[Note]] then
note = {src = r:read_outer_xml()}
-- Parse NNEX
if note.src then
s = xmlreader.from_string(note.src)
s:read() -- skip container
while s:read() do
if s:name() == [[UpdateSequenceNumber]] and note.id == nil then
note.id = tonumber(s:read_string())
elseif s:name() == [[Title]] and note.Title == nil then
note.Title = s:read_string()
elseif s:name() == [[Created]] and note.Created == nil then
note.Created = s:read_string()
elseif s:name() == [[Updated]] and note.Updated == nil then
note.Updated = s:read_string()
elseif s:name() == [[NoteAttributes]] then
while s:read() do
if s:name() == [[Author]] and note.Author == nil then
note.Author = s:read_string()
end
if s:name() == [[NoteAttributes]] then break end
end
elseif s:name() == [[Content]] and note.Content == nil then
note.Content = s:read_string()
end
end
end
-- Note page view
if ID == tonumber(note.id) then
ID = tonumber(ID)
page_set_title(note.Title)
return theme{[[evernote]], note, true}
-- Notes list view
else
table.insert(result, tonumber(note.id), theme{[[evernote]], note})
r:next_node()
end
end
end
end
page_set_title(settings.evernote.title)
return table_concat(result)
end
function theme.evernote(note, page)
local title, path = [[]]
if not page then
path = url(([[evernote/%d]]):format(note.id))
title = ([[<h2 class="title">%s</h2>]]):format(l(note.Title, path))
end
return ([[
%s
<div class="submitted">Submitted by %s on %s</div>
<div class="content">%s</div>]]):format(title, note.Author, date([[!%a, %Y-%m-%d %H:%M:%S]], note.Created/1000), note.Content)
end