urbit/lib/write.hoon

144 lines
3.7 KiB
Plaintext
Raw Normal View History

2015-12-08 04:46:18 +03:00
:: File writer module
::
:::: /hoon/write/lib
::
2016-02-18 02:36:43 +03:00
/? 310
/- plan-diff, plan-acct
2016-12-02 02:59:17 +03:00
=, format
=, space:userlib
2015-12-08 04:46:18 +03:00
|%
2016-02-01 09:16:26 +03:00
++ part {$write $0 pith} :: no state
++ pith $~
2015-12-08 04:46:18 +03:00
--
::
::::
::
|%
++ data $%({$json json} {$mime mime})
2016-11-08 04:40:00 +03:00
++ card $% {$exec wire @p $~ {beak silk:^ford}}
{$info wire @p toro:^clay}
2015-12-08 04:46:18 +03:00
==
--
2016-11-17 04:42:58 +03:00
::
2015-12-08 04:46:18 +03:00
::::
::
2016-11-08 04:40:00 +03:00
|= {bowl:^gall part}
2015-12-08 04:46:18 +03:00
=* par +<+
2016-02-01 09:16:26 +03:00
|_ moz/(list {bone card})
2015-12-08 04:46:18 +03:00
++ abet [(flop moz) `part`par]
2016-02-01 09:16:26 +03:00
++ emit |=(a/card %_(+> moz :_(moz [ost a])))
2015-12-08 04:46:18 +03:00
++ beak-now byk(r [%da now])
2015-12-11 01:04:59 +03:00
++ poke-wipe
2016-11-08 04:40:00 +03:00
|= sup/path ^+ abet :: XX determine extension, beak
2015-12-11 01:04:59 +03:00
=+ ext=%md
2016-12-02 02:59:17 +03:00
?~ (file (en-beam beak-now [ext sup]))
2016-02-12 02:29:52 +03:00
~|(not-found+[ext `path`(flop sup)] !!)
=- abet:(emit %info write+~ our -)
2016-12-02 02:59:17 +03:00
(fray (en-beam beak-now [ext sup]))
2015-12-11 01:04:59 +03:00
::
2015-12-10 01:12:59 +03:00
++ poke-tree
|= {sup/path mim/mime} ^+ abet :: XX determine extension, beak
2015-12-11 01:04:59 +03:00
(poke--data [`%md (flop sup)] %mime mim)
2015-12-08 04:46:18 +03:00
::
++ poke-plan-account
|= {sev/knot usr/plan-acct} ^+ abet
(poke-plan-diff [~ ~ [[sev usr] ~ ~]])
::
++ poke-plan-info
|= {who/@t loc/@t}
(poke-plan-diff [[~ who loc] ~ ~])
::
++ poke-plan-diff
|= dif/plan-diff ^+ abet
?. =(our src)
~|(foreign-write+[our=our src=src] !!)
2016-11-08 04:40:00 +03:00
=; sob/soba:^clay
?~(sob abet abet:(emit %info write+~ our `toro:^clay`[q.byk %& sob]))
2016-03-25 03:15:12 +03:00
=+ pax=`path`/web/plan
2016-12-02 02:59:17 +03:00
=+ paf=(en-beam beak-now (flop pax))
2016-03-31 03:27:18 +03:00
?~ [fil:.^(arch %cy paf)]
=+ ins=(pact-plan [['' ''] ~] dif)
2016-03-31 03:27:18 +03:00
[pax %ins plan+!>(ins)]~
2016-11-08 04:40:00 +03:00
=+ ole=.^({{@t @t} (map knot plan-acct)} %cx paf)
2016-03-31 03:27:18 +03:00
=+ neu=(pact-plan ole dif)
?: =(ole neu) ~
[pax %dif plan-diff+!>(dif)]~
2016-03-25 02:31:37 +03:00
::
2016-03-31 03:27:18 +03:00
++ pact-plan :: XX clay should handle fused insert+diff
2016-11-08 04:40:00 +03:00
|= {all/{{who/@t loc/@t} acc/(map knot plan-acct)} dif/plan-diff}
2016-03-31 03:27:18 +03:00
^+ all
:- (fall inf.dif -.all)
=; neu (~(uni by neu) put.dif)
=+ del=(~(tap by del.dif)) :: XXX map functions
|- ^+ acc.all
?~ del acc.all
$(del t.del, acc.all (~(del by acc.all) p.i.del))
::
2015-12-08 04:46:18 +03:00
++ poke-paste
2016-02-01 09:16:26 +03:00
|= {typ/?($hoon $md $txt) txt/@t} ^+ abet
2016-11-01 03:12:56 +03:00
(poke--data [`typ /web/paste/(scot %da now)] %mime / (taco:bytes:eyre txt))
2015-12-08 04:46:18 +03:00
::
++ poke-comment
2016-11-08 04:40:00 +03:00
|= {sup/path him/ship txt/@t} ^+ abet
=+ pax=(welp (flop sup) /comments/(scot %da now))
2016-03-04 03:36:39 +03:00
=. txt
%+ rap 3 :~
'## `' (scot %p him) '`'
'\0a' txt
==
2016-11-01 03:12:56 +03:00
(poke--data [`%md pax] %mime / (taco:bytes:eyre txt))
::
++ poke-fora-post
2016-11-08 04:40:00 +03:00
|= {sup/path him/ship hed/@t txt/@t} ^+ abet
=+ pax=(welp (flop sup) /posts/(cat 3 (scot %da now) '~'))
=. txt
%- crip
"""
---
type: post
date: {<now>}
title: {(trip hed)}
author: {<him>}
navsort: bump
navuptwo: true
2016-07-29 22:41:16 +03:00
comments: reverse
---
{(trip txt)}
"""
2016-11-01 03:12:56 +03:00
(poke--data [`%md pax] %mime / (taco:bytes:eyre txt))
::
++ ames-secret
^- @t
=- (crip +:<.^(@p %a pax)>)
pax=/(scot %p our)/code/(scot %da now)/(scot %p our)
::
2016-02-05 02:03:51 +03:00
++ poke-sec-atom
2016-11-08 04:40:00 +03:00
|= {hot/host:^eyre dat/@}
2016-02-19 23:33:56 +03:00
?> ?=($& -.hot)
=. p.hot (scag 2 p.hot) :: ignore subdomain
=. dat (scot %uw (en:crua:crypto ames-secret dat))
2016-11-01 03:12:56 +03:00
(poke--data [`%atom [%sec p.hot]] %mime / (taco:bytes:eyre dat))
2016-02-05 02:03:51 +03:00
::
2015-12-08 04:46:18 +03:00
++ poke--data
2016-02-01 09:16:26 +03:00
|= {{ext/(unit @t) pax/path} dat/data} ^+ abet
2015-12-08 04:46:18 +03:00
?~ ext $(ext [~ -.dat])
2016-02-01 09:16:26 +03:00
=+ cay=?-(-.dat $json [-.dat !>(+.dat)], $mime [-.dat !>(+.dat)])
?: =(u.ext -.dat)
2016-02-12 02:29:52 +03:00
(made pax ~ &+cay)
2015-12-08 04:46:18 +03:00
=< abet
2016-02-01 09:16:26 +03:00
%^ emit %exec write+pax :: XX defer %nice
2016-02-12 02:29:52 +03:00
[our ~ beak-now %cast u.ext $+cay]
2015-12-08 04:46:18 +03:00
::
++ made
2016-11-08 04:40:00 +03:00
|= {pax/wire @ res/gage:^ford} ^+ abet
:: ?. =(our src)
:: ~|(foreign-write/[our=our src=src] !!)
2016-02-12 02:29:52 +03:00
?+ -.res ~|(gage+-.res !!)
2016-02-01 09:16:26 +03:00
$| (mean p.res)
$& =- abet:(emit %info write+~ our -)
2016-12-02 02:59:17 +03:00
(foal :(welp (en-beam beak-now ~) pax /[-.p.res]) p.res)
2015-12-08 04:46:18 +03:00
==
--
2016-02-12 02:29:52 +03:00