infod 0.0.3.2 → 0.0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  #watch __FILE__
2
- class E
2
+ class R
3
3
 
4
4
  # sprintf() formats in <https://github.com/infodaemon/www/blob/60a9b5f51cf15d5723afd9172767843d97190d8f/css/i/lotek.theme>
5
5
  def triplrIRC &f
@@ -17,27 +17,27 @@ class E
17
17
  yield s, SIOCt+'ChatChannel', channel
18
18
  yield s, Creator, m[2]
19
19
  yield s, Content, m[3].hrefs(true)
20
- yield s, Type, E[SIOCt+'InstantMessage']
21
- yield s, Type, E[SIOC+'Post']
20
+ yield s, Type, R[SIOCt+'InstantMessage']
21
+ yield s, Type, R[SIOC+'Post']
22
22
  yield s, SIOC+'link', (m[3].match(/http:\//) ? 'true' : 'false')
23
23
  } rescue nil
24
24
  }
25
25
  end
26
26
 
27
27
  def tw g
28
- no.readlines.shuffle.each_slice(22){|s|
29
- E['https://twitter.com/search/realtime?q='+s.map{|u|'from:'+u.chomp}.intersperse('+OR+').join].addDocs :triplrTweets, g, nil, FeedArchiver}
28
+ node.readlines.shuffle.each_slice(22){|s|
29
+ R['https://twitter.com/search/realtime?q='+s.map{|u|'from:'+u.chomp}.intersperse('+OR+').join].addDocs :triplrTweets, g, nil, FeedArchiver}
30
30
  end
31
31
 
32
32
  def triplrTweets
33
33
  base = 'http://twitter.com'
34
34
  nokogiri.css('div.tweet').map{|t|
35
35
  s = base + t.css('a.details').attr('href') # subject URI
36
- yield s, Type, E[SIOCt+'MicroblogPost']
37
- yield s, Type, E[SIOC+'Post']
38
- yield s, Creator, E(base+'/'+t.css('.username b')[0].inner_text)
36
+ yield s, Type, R[SIOCt+'MicroblogPost']
37
+ yield s, Type, R[SIOC+'Post']
38
+ yield s, Creator, R(base+'/'+t.css('.username b')[0].inner_text)
39
39
  yield s, Name,t.css('.fullname')[0].inner_text
40
- yield s, Atom+"/link/image", E(t.css('.avatar')[0].attr('src'))
40
+ yield s, Atom+"/link/image", R(t.css('.avatar')[0].attr('src'))
41
41
  yield s, Date, Time.at(t.css('[data-time]')[0].attr('data-time').to_i).iso8601
42
42
  content = t.css('.tweet-text')[0]
43
43
  content.css('a').map{|a|
@@ -48,10 +48,10 @@ class E
48
48
  end
49
49
 
50
50
  fn 'view/chat',->d,e{
51
- Fn'baseview/chat',d,e,->{d.map{|u,r|Fn 'itemview/chat',r,e}}}
51
+ F['baseview/chat'][d, e, ->{d.map{|u,r|F['itemview/chat'][r,e]}}]}
52
52
 
53
53
  fn 'itemview/chat',->r,e{
54
- r[Type] && [*r[Type]].map{|t|t.respond_to?(:uri) && t.uri}.include?(SIOCt+'MailMessage') && r[:mail]=true
54
+ r[Type] && [*r[Type]].map(&:maybeURI).include?(SIOCt+'MailMessage') && r[:mail]=true
55
55
  r[Content] && r[Date] && r[Date][0] &&
56
56
  [r[Date][0].match(/T([0-9:]{5})/).do{|m|m[1]},
57
57
  {_: :span, :class => :nick, c: {_: :a, href: r[Atom+'/link/alternate'].do{|a|a[0].uri}||r.url,
@@ -69,7 +69,7 @@ class E
69
69
  c: F['itemview/chat'][r,e]}}}
70
70
 
71
71
  fn 'baseview/chat',->d,e,c{
72
- [(H.once e,'chat.head',(H.css '/css/tw'),{_: :style, c: "body {background-color: #{E.c}}\n"}),c.()]}
72
+ [(H.once e,'chat.head',(H.css '/css/tw'),{_: :style, c: "body {background-color: #{R.c}}\n"}),c.()]}
73
73
 
74
74
  F['view/'+SIOCt+'InstantMessage']=F['view/chat']
75
75
  F['view/'+SIOCt+'MicroblogPost']=F['view/chat']
@@ -1,5 +1,5 @@
1
1
  #watch __FILE__
2
- class E
2
+ class R
3
3
 
4
4
  # no link-follow
5
5
  def mime
@@ -10,12 +10,12 @@ class E
10
10
  "inode/symlink"
11
11
  elsif d?
12
12
  "inode/directory"
13
+ elsif base.index('msg.')==0 # how to make procmail append a non-gibberish extension?
14
+ "message/rfc822"
13
15
  elsif MIME[t]
14
16
  MIME[t]
15
17
  elsif Rack::Mime::MIME_TYPES[t='.'+t.to_s]
16
18
  Rack::Mime::MIME_TYPES[t]
17
- elsif base.index('msg.')==0
18
- "message/rfc822"
19
19
  elsif e
20
20
  `file --mime-type -b #{sh}`.chomp
21
21
  else
@@ -33,12 +33,12 @@ class E
33
33
  t = ((File.extname p).tail || '').downcase.to_sym
34
34
  if p.directory?
35
35
  "inode/directory"
36
+ elsif (File.basename p).index('msg.')==0
37
+ "message/rfc822"
36
38
  elsif MIME[t]
37
39
  MIME[t]
38
40
  elsif Rack::Mime::MIME_TYPES[t='.'+t.to_s]
39
41
  Rack::Mime::MIME_TYPES[t]
40
- elsif (File.basename p).index('msg.')==0
41
- "message/rfc822"
42
42
  else
43
43
  `file --mime-type -b #{Shellwords.escape p.to_s}`.chomp
44
44
  end
@@ -155,25 +155,18 @@ class E
155
155
  'text/x-tex'=>true,
156
156
  }
157
157
 
158
- # cache triplr output
159
- MIMEcache={
160
- 'audio' => true,
161
- 'image' => true,
162
- # '' =>
163
- }
164
-
165
158
  %w{c c++ fortran haskell makefile pascal perl php python ruby}.map{|t|
166
159
  %w{application/ text/x-}.map{|m|
167
160
  MIMEcook[m+t] = true
168
161
  }}
169
162
 
170
- def render mime, graph, e
171
- E[Render+ mime].y graph, e
163
+ def render mime, graph, e
164
+ F[Render+mime][graph, e]
172
165
  end
173
166
 
174
167
  def triplrMIME &b
175
168
  mimeP.do{|mime|
176
- yield uri, E::Type, (E MIMEtype+mimeP)
169
+ yield uri, R::Type, (R MIMEtype+mimeP)
177
170
  (MIMEsource[mimeP]||
178
171
  MIMEsource[mimeP.split(/\//)[0]]).do{|s|
179
172
  send *s,&b }}
@@ -1,75 +1,65 @@
1
- %w{cgi shellwords}.each{|r|require(r)}
1
+ class R
2
+
3
+ def appendURI u; R uri + u.to_s end
4
+ def appendSlashURI u; R uri.t + u.to_s end
5
+ def basename; File.basename path end
6
+ def barename; basename.sub(/\.#{ext}$/,'') rescue basename end
7
+ def cascade; [self].concat parents end
8
+ def children; node.c.map &:R end
9
+ def container; @u ||= R[f ? dirname + '/.' + (File.basename path) : path] end
10
+ def d; node.to_s end
11
+ def delete; node.deleteNode if e; self end
12
+ def dirname; node.dirname.do{|d| d.to_s.size <= BaseLen ? '/' : d }.R end
13
+ def docBase; uri.split(/#/)[0].R.do{|d| d.dirname.as d.bare } end
14
+ def d?; node.directory? end
15
+ def env r=nil;r ? (@r = r; self) : @r end
16
+ def exist?; node.exist? end
17
+ def expand; uri.expand.R end
18
+ def ext; File.extname(uri).tail||'' end
19
+ def file?; node.file? end
20
+ def frag; uri.frag end
21
+ def get; open(uri).read end
22
+ def glob p=""; (Pathname.glob d + p).map &:R end
23
+ def hostURL e; host='http://'+e['SERVER_NAME']; (uri.index('/') == 0 ? host : '') + uri end
24
+ def inside; node.expand_path.to_s.index(FSbase) == 0 end
25
+ def label; uri.label end
26
+ def mk; e || FileUtils.mkdir_p(d); self end
27
+ def mtime; node.stat.mtime if e end
28
+ def node; Pathname.new FSbase + path end
29
+ def parent; R Pathname.new(uri).parent end
30
+ def parents; parent.do{|p|p.uri.match(/^[.\/]+$/) ? [p] : [p].concat(p.parents)} end
31
+ def path; uri.match(/^\//) ? uri : ('/'+uri) end
32
+ def pathSegment; uri.match(/^([a-z]+:\/\/[^\/]+)?(\/.*)/).do{|p|p[2]&&p[2].R}||nil end
33
+ def predicatePath p,s=true; container.as s ? p.R.shorten : p end
34
+ def predicates; container.c.map{|c|c.base.expand.R} end
35
+ def prependURI u; R u.to_s + uri end
36
+ def read; f ? readFile : get end
37
+ def readFile; File.open(d).read end
38
+ def realpath; node.realpath rescue Errno::ENOENT end
39
+ def shorten; uri.shorten.R end
40
+ def siblings; parent.c end
41
+ def size; node.size end
42
+ def == u; to_s == u.to_s end
43
+ def <=> c; to_s <=> c.to_s end
44
+ def sh; d.force_encoding('UTF-8').sh end
45
+ def to_s; uri end
46
+ def to_h; {'uri' => uri} end
47
+ def touch; FileUtils.touch node; self end
48
+ def writeFile c; File.open(d,'w'){|f|f << c} end
2
49
 
3
- class E
4
-
5
- attr_reader :uri
6
- alias_method :url, :uri
7
- alias_method :maybeURI, :uri
8
-
9
- def env r=nil
10
- r ? (@r = r
11
- self) : @r
12
- end
13
-
14
- def == u
15
- to_s == u.to_s
16
- end
17
-
18
- def basename
19
- File.basename path
20
- end
50
+ alias_method :+, :appendURI
51
+ alias_method :a, :appendURI
52
+ alias_method :as, :appendSlashURI
21
53
  alias_method :base, :basename
22
-
23
- def barename
24
- basename.sub(/\.#{ext}$/,'')
25
- rescue
26
- basename
27
- end
28
54
  alias_method :bare, :barename
29
-
30
- def ef; @ef ||= docBase.a('.e') end
31
- def nt; @nt ||= docBase.a('.nt') end
32
- def ttl; @ttl||= docBase.a('.ttl') end
33
-
34
- def docBase
35
- !uri.empty? && uri.split(/#/)[0].do{|u|u.E.do{|d| d.dirname.as d.bare }} || E['']
36
- end
37
-
38
- def frag
39
- uri.frag
40
- end
41
-
42
- def parent
43
- E Pathname.new(uri).parent
44
- end
45
-
46
- def parents
47
- parent.do{|p|
48
- p.uri.match(/^[.\/]+$/) ? [p] : [p].concat(p.parents)}
49
- end
50
-
51
- def cascade
52
- [self].concat parents
53
- end
54
-
55
- def dirname
56
- n = node.dirname
57
- n = '/' if n.to_s.size <= BaseLen
58
- n.E
59
- end
55
+ alias_method :c, :children
60
56
  alias_method :dir, :dirname
57
+ alias_method :e, :exist?
58
+ alias_method :f, :file?
59
+ alias_method :m, :mtime
60
+ alias_method :maybeURI, :uri
61
+ alias_method :url, :uri
61
62
 
62
- # add hostname to URI (if missing)
63
- def hostURL e
64
- host = 'http://'+e['SERVER_NAME']
65
- if uri.index('/') == 0
66
- host + uri
67
- else
68
- uri
69
- end
70
- end
71
-
72
- # pointer to local data about global URI
73
63
  def localURL e
74
64
  if uri.index('/') == 0
75
65
  uri # already a local path
@@ -80,203 +70,67 @@ class E
80
70
  end
81
71
  end
82
72
 
83
- def pathSegment
84
- m = uri.match(/^([a-z]+:\/\/[^\/]+)?(\/.*)/)
85
- m && m[2] && m[2].E || nil
86
- end
87
-
88
- def ext
89
- File.extname(uri).tail||''
90
- end
91
-
92
- def label
93
- uri.label
94
- end
95
-
96
- def expand
97
- uri.expand.E
98
- end
99
-
100
- def shorten
101
- uri.shorten.E
102
- end
103
-
104
- def prependURI u
105
- E u.to_s + uri
106
- end
107
-
108
- def appendURI u
109
- E uri + u.to_s
110
- end
111
-
112
- def appendSlashURI u
113
- E uri.t + u.to_s
114
- end
115
-
116
- def concatURI b
117
- u.appendURI b.E.shortPath
118
- end
119
-
120
- alias_method :a, :appendURI
121
- alias_method :+, :appendURI
122
- alias_method :as, :appendSlashURI
123
-
124
- def shortPath
125
- @shortPath ||=
126
- (if uri.match /^\//
127
- uri
128
- else
129
- '/' + uri.shorten
130
- end)
131
- end
132
-
133
- def path
134
- if uri.match /^\//
135
- uri
136
- else
137
- '/' + uri
138
- end
139
- end
140
-
141
- def u
142
- # path for data about this resource
143
- @u ||= E (f ? dirname + '/.' + (File.basename path) : path.t + '._')
144
- end
145
-
146
- # (_ _ o) -> o
147
- def innerPath
148
- (uri.split S)[-1].unpath
149
- end
150
- alias_method :ro, :innerPath
151
-
152
- def sh
153
- d.force_encoding('UTF-8').sh
154
- end
155
-
156
- def E.literal o
157
- ''.E.literal o
158
- end
159
-
160
- def literal o
161
- return o if o.class == E
162
- u = (if o.class == String
163
- E "/E/blob/"+o.h.dive
73
+ def objectPath o
74
+ p,v=(if o.class == R
75
+ [o.path, nil]
164
76
  else
165
- E "/E/json/"+[o].to_json.h.dive
77
+ literal o
166
78
  end)
167
- u.w o, !o.class == String unless u.f
168
- u
79
+ [(a p), v]
169
80
  end
170
81
 
171
- # spaceship comparison-operator
172
- def <=> c
173
- to_s <=> c.to_s
174
- end
175
-
176
- def to_s
177
- uri
178
- end
179
-
180
- def to_h
181
- {'uri' => uri}
82
+ def literal o
83
+ str = nil
84
+ ext = nil
85
+ if o.class == String
86
+ str = o; ext='.txt'
87
+ else
88
+ str = o.to_json; ext='.json'
89
+ end
90
+ ['/'+str.h+ext, str]
182
91
  end
183
92
 
184
- # internal pathnames not on the web (cached representations, index databases)
185
- F['/E/GET'] = F[E404]
186
-
187
93
  end
188
94
 
189
95
  class Hash
190
- def uri
191
- self["uri"]||""
192
- end
96
+ def R; R.new uri end
97
+ def uri; self["uri"]||"" end
98
+ def label; uri.label end
193
99
  alias_method :url, :uri
194
100
  alias_method :maybeURI, :uri
195
- def label
196
- self[E::Label] || uri.label
197
- end
198
- def E
199
- E.new uri
200
- end
201
- end
202
-
203
- class Array
204
- def E
205
- self[0].E if self[0].class==Hash
206
- end
207
101
  end
208
102
 
209
103
  class String
210
- def dive
211
- self[0..1]+'/'+
212
- self[2..3]+'/'+
213
- self[4..-1]
214
- end
215
104
 
216
- # expand qname/CURIE-style identifier to URI
105
+ def dive; self[0..2]+'/'+self[3..-1] end
106
+
107
+ # expand possibly CURIE entryname
217
108
  Expand={}
218
109
  def expand
219
110
  (Expand.has_key? self) ?
220
111
  Expand[self] :
221
112
  (Expand[self] =
222
113
  match(/([^:]+):([^\/].*)/).do{|e|
223
- ( E::Prefix[e[1]] || e[1]+':' )+e[2]} ||
224
- self )
114
+ ( R::Prefix[e[1]] || e[1]+':' )+e[2]} ||
115
+ gsub('|','/'))
225
116
  end
226
117
 
227
- # shrink URI to qname/CURIE/prefixed identifier
118
+ # shrink to entryname, CURIE if possible
228
119
  def shorten
229
- E::Prefix.map{|p,f|
120
+ R::Prefix.map{|p,f|
230
121
  return p + ':' + self[f.size..-1] if (index f) == 0
231
122
  }
232
- self
233
- end
234
-
235
- def sh
236
- Shellwords.escape self
237
- end
238
-
239
- def unpathFs
240
- self[E::BaseLen..-1].do{|p|
241
- (p.match(/^\/([a-z]+:)\/+(.*)/).do{|m|m[1]+'//'+m[2]}||p).E}
123
+ gsub('/','|')
242
124
  end
243
125
 
244
- # path -> URI || literal
245
- def unpath
246
-
247
- # HTTP URI
248
- if m = (match /^\/([a-z]+:)\/+(.*)/)
249
- (m[1] + '//' + m[2]).E
250
-
251
- # prefix-shortened URI
252
- elsif m = (match /^\/([^\/:]+:[^\/]+)/)
253
- m[1].expand.E
254
-
255
- # String literal
256
- elsif match /^\/E\/blob/
257
- self.E.r
258
-
259
- # JSON literal
260
- elsif match /^\/E\/json/
261
- self.E.r true
262
-
263
- # plain path
264
- else
265
- self.E
266
- end
267
-
268
- end
269
-
270
- def E
271
- E.new self
126
+ def unpath skip = R::BaseLen
127
+ self[skip..-1].do{|p|
128
+ (p.match(/^\/([a-z]+:)\/+(.*)/).do{|m|m[1]+'//'+m[2]}||p).R}
272
129
  end
273
130
 
274
- def frag
275
- split(/#/).pop()
276
- end
277
-
278
- def label
279
- split(/[\/#]/)[-1]
280
- end
131
+ def R; R.new self end
132
+ def frag; split(/#/).pop() end
133
+ def label; split(/[\/#]/)[-1] end
134
+ def sh; Shellwords.escape self end
281
135
 
282
136
  end