iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 7
2
自我挑戰組

中年失業大叔的耍廢日記系列 第 7

第七天:平淡無奇的週二

今天筆電有充電,所以就到家附近的咖啡店寫作業。

今天的作業是開始把雛形修改成正式版。之前的雛形其實只是一個概念驗證,確認這樣處理是可行的,所以完全沒考慮架構問題。回頭看了一下,發現很多地方還無法測試,就一步一步調整。第一步是把對變數的依賴移到函數參數,需要的話做一下currying,以便bind到函數的scope中。然後把使用的一些函數抽出到模組,因為本來是一個內部的函數,這樣會無法測試。一些程式的執行步驟也拆開成函數,方便作單元測試。最後讓程式的進入點index.js只留下明確而不需要測試的幾個函數呼叫。

ㄝ,怎麼飄來奇怪的味道?好像排水有問題,然後有人來修理?(不會是廁所吧)...好吧,等一等就過去了,反正已經在修理...

繼續寫作業,如果根據規格,是要用mocha搭配chai來做單元測試,用istanbul做測試覆蓋率報告,就先把依賴加進來。等架構調整好,就開始寫測試。

寫了兩個鐘頭,冷氣冷得受不了,還是先轉移陣地...回家繼續奮鬥好了。

下午聽到太太傳來新聞:重磅!微軟耗資2170億台幣收購Bethesda母公司ZeniMax,拿下《上古卷軸》《異塵餘生》等IP...唉呀,難怪沒買下抖音,這樣是否可以期待TES6早一點出現呢?

晚上去成吉思汗蒙古烤肉聚餐,在座有幾位OP,然後就開始聊綠色乖乖傳奇...有些管理乖乖很嚴格的,一定先進先出,還要維持固定的水位。然後還有許多案例...不信邪的後果之類/images/emoticon/emoticon37.gif

吃完已經九點多,還是回頭看一下之前做的pptx viewer的json結構,先從第一個property relations開始。在pptx archive中,有許多_rels目錄,裡面會放[xml檔名].rels檔案,格式也是xml,用來描述xml檔中使用的Id與其他xml檔案的關係。之前做好的parser,處理完的結果像這樣:

{
    "relations": {
        "ppt/presentation.xml": {
            "rId11": "ppt/notesMasters/notesMaster1.xml",
            "ppt/notesMasters/notesMaster1.xml": "rId11",
            "rId12": "ppt/handoutMasters/handoutMaster1.xml",
            "ppt/handoutMasters/handoutMaster1.xml": "rId12",
            "rId13": "ppt/printerSettings/printerSettings1.bin",
            "ppt/printerSettings/printerSettings1.bin": "rId13",
            "rId14": "ppt/presProps.xml",
            ...
        },
        ...
    },
    ...
}

跟原本的xml對比一下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId11" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster" Target="notesMasters/notesMaster1.xml" />
    <Relationship Id="rId12" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/handoutMaster" Target="handoutMasters/handoutMaster1.xml" />
    <Relationship Id="rId13" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings" Target="printerSettings/printerSettings1.bin" />
    <Relationship Id="rId14" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps" Target="presProps.xml" />
...

可以看出,就是把Id跟Target屬性取出後,做一個雙向的索引。

其他的xml,處理方式不太一樣,例如ppt/presentation.xml轉成javascript object:

...
    "presentation": {
        "slideMasterIdList": [{
            "id": 2147483648,
            "rid": "rId1",
            "target": "ppt/slideMasters/slideMaster1.xml"
        }, {
            "id": 2147483780,
            "rid": "rId2",
            "target": "ppt/slideMasters/slideMaster2.xml"
        }],
...

原本的xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" saveSubsetFonts="1">
    <p:sldMasterIdLst>
        <p:sldMasterId id="2147483648" r:id="rId1" />
        <p:sldMasterId id="2147483780" r:id="rId2" />
    </p:sldMasterIdLst>
...

看起來除了原本的屬性,還透過relations把target指向的xml檔放進來,然後r:id被改成rid,這樣好像也怪怪的。

其他檔案可能還有各自的轉換問題,當初還為了節省檔案大小,刪掉一些不想處理的資料,這些可能都要考慮。總之,今天先觀察到這裡吧。明天繼續!


上一篇
第六天:筆電沒電,手機也沒電,只好出門充電
下一篇
第八天:臃腫的週三
系列文
中年失業大叔的耍廢日記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

1
海綿寶寶
iT邦大神 1 級 ‧ 2020-09-22 22:47:30

如果根據規格,是要用mocha搭配chai來做單元測試,用istanbul做測試覆蓋率報告

報告,三個名詞我都沒聽過
/images/emoticon/emoticon25.gif

fillano iT邦超人 1 級 ‧ 2020-09-23 09:28:41 檢舉

去伊斯坦堡喝茶喝咖啡...很觀光的意思

/images/emoticon/emoticon07.gif

我要留言

立即登入留言