~alcinnz/rhapsode

091c7d82762d76096de04e2d3f955f5f28b9ccd8 — Adrian Cochrane 2 years ago 2e03314
Refactor link extraction to match new link dispatch, & defer internationalization to config
1 files changed, 6 insertions(+), 21 deletions(-)

M src/Links.hs
M src/Links.hs => src/Links.hs +6 -21
@@ 13,7 13,7 @@ import Data.Maybe
import Text.Read (readMaybe)

-- FIXME: Expose this API from HURL XML...
-- import Table (splitTable)
import Network.URI.Fetch.XML.Table (splitTable)

import Types
import Foreign.StablePtr


@@ 84,8 84,8 @@ extractEl _ el@(Element (Name "link" _ _) attrs [])
        let Application name _ title _ = mimeInfo "text/css"
        in [Link (pack name) (pack title) uri]
  where attrs' = M.mapKeys nameLocalName attrs
-- extractEl path (Element (Name "table" _ _) _ childs) =
--    extractTable path (splitTable childs) ++ extractNodes (0:path) childs
extractEl path (Element (Name "table" _ _) _ childs) =
    extractTable path (splitTable childs) ++ extractNodes (0:path) childs
extractEl path el@(Element _ _ children) =
    extractElAttr el "href" ++
    extractElAttr el "longdesc" ++


@@ 122,7 122,8 @@ extractTH path count ordering nodes = Link {
        label = nodesText nodes "",
        title = pack $ show count,
        href = nullURI {
            uriFragment = '#': intercalate "." [show n | n <- path] ++ o ordering : show count
            uriFragment = '#':'-':'a':'r':'g':'o':'-':'%':
                intercalate "." [show n | n <- path] ++ o ordering : show count
        }
      }
    where


@@ 150,25 151,9 @@ linksFromPage Page {
        html = html',
        apps = apps',
        backStack = back', forwardStack = forward'
    } = -- TODO internationalize!
        link' "reload" title' url' :
        link' "aggiorna" title' url' : -- Italian
        link' "ladda om" title' url' : -- Swedish (Svenska)
        link' "last på nytt" title' url' : -- Norwegian Bokmål
        link' "reload without cache" "Fetch again from server without checking for a local copy" uncached :
        link' "aggiorna senza cache" "" uncached : -- Italian
        link' "ladda om utan cache" "hämta från servern igen utan att kolla efter en lokal kopia" uncached : -- Swedish (Svenska)
        link' "last på nytt uten mellomlager" "Last siden på nytt uten å bruke lokal kopi" uncached : -- Norwegian Bokmål
        [link' l t u | (t, u) <- head' back', l <- backLabels] ++
        [link' l t u | (t, u) <- head' forward', l <- forwardLabels] ++
    } =
        [link' n desc $ URI "app:" Nothing id "" "" | Application n _ desc id <- apps'] ++
        extractLinks html'
    where
        uncached = url' { uriScheme = "nocache+" ++ uriScheme url' }
        backLabels = ["back", {- Italian -} "indietro", {- Swedish -} "tillbaka",
            {- Norwegian Bokmål -}"tilbake"]
        forwardLabels = ["forward", {- Italian -} "avanti", {- Swedish -} "framåt",
            {- Norwegian Bokmål -} "forover", "videre"]

head' (a:_) = [a]
head' [] = []