summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/mtx-context-hashed.tex
blob: 88de10f3f293a766a55c2043a102a5b5931a05bb (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
%D \module
%D   [       file=mtx-context-hashed,
%D        version=2009.03.21,
%D          title=\CONTEXT\ Extra Trickry,
%D       subtitle=Combine Files,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% begin help
%
% usage: context --extra=hashed [options] list-of-files
%
% --database    : database to create or extend
% --pattern     : file pattern
% --patterns    : pattern file
% --compression : apply compression
%
% end help

% \startluacode
%     if not resolvers.finders.helpers.validhashed("hasheddata") then
%         resolvers.finders.helpers.createhashed {
%             database = "hasheddata",
%             pattern  = "m4all/**.jpg$",
%             compress = false,
%         }
%         resolvers.finders.helpers.createhashed {
%             database = "hasheddata",
%             pattern  = "m4all/**.png$",
%             compress = false,
%         }
%         resolvers.finders.helpers.createhashed {
%             database = "hasheddata",
%             pattern  = "m4all/**.xml$",
%             compress = true,
%         }
%     end
% \stopluacode

% \startluacode
%     if not resolvers.finders.helpers.validhashed("hasheddata") then
%         resolvers.finders.helpers.createhashed {
%             database = "hasheddata",
%             patterns = {
%                 { pattern  = "m4all/**.jpg$", compress = false },
%                 { pattern  = "m4all/**.png$", compress = false },
%                 { pattern  = "m4all/**.xml$", compress = true  },
%             },
%         }
%     end
% \stopluacode

% context --extra=hashed --database=hasheddata --pattern=m4all/**.jpg
% context --extra=hashed --database=hasheddata --pattern=m4all/**.png
% context --extra=hashed --database=hasheddata --pattern=m4all/**.xml --compress
% context --extra=hashed --database=hasheddata --pattern=m4all/**.svg --compress

% -- m4all.lua:
%
% return {
%     { pattern  = "m4all/**.jpg$", compress = false },
%     { pattern  = "m4all/**.png$", compress = false },
%     { pattern  = "m4all/**.svg$", compress = true  },
%     { pattern  = "m4all/**.xml$", compress = true  },
% }
%
% context --extra=hashed --database=hasheddata --patterns=m4all.lua

% \registerhashedfiles[hasheddata]
% \registerfilescheme[hashed]
%
% \externalfigure[hashed:///m4all/books/chapters/h3/h3-if1/images/highres/casino.jpg]      [height=1cm]
% \externalfigure[hashed:///m4all/books/chapters/ha/ha-c4/images/highres/ha-c44-ex2-s1.png][height=1cm]
% \externalfigure[m4all/books/chapters/h3/h3-if1/images/highres/casino.jpg]                [height=1cm]
% \externalfigure[m4all/books/chapters/ha/ha-c4/images/highres/ha-c44-ex2-s1.png]          [height=1cm]

\input mtx-context-common.tex

\noheaderandfooterlines \setupbodyfont[tt]

\starttext

\startluacode

    if CONTEXTLMTXMODE > 0 then

        local database = document.arguments.database

        if database then
            local metadata = false
            if tex.systemmodes["first"] then
                metadata = resolvers.finders.helpers.createhashed {
                    database = database,
                    pattern  = document.arguments.pattern,
                    compress = document.arguments.compress,
                    patterns = document.arguments.patterns and table.load(document.arguments.patterns),
                }
            else
                metadata = resolvers.finders.helpers.validhashed(database)
                if metadata then
                    metadata = metadata.metadata
                end
            end
            if metadata then
                local function show(what)
                    context.NC() context(what)
                    context.EQ() context(metadata[what])
                    context.NC() context.NR()
                end
                context.starttitle { title = "database: " .. database }
                    context.starttabulate { "||r|" }
                        show("nofnames")
                        show("nofpaths")
                        show("nofblobs")
                        show("nofcompressed")
                    context.stoptabulate()
                context.stoptitle()
            else
                context("something went wrong, invalid database")
            end
        else
            context("something went wrong, no database specified")
        end
    else
        context("you need lmtx")
    end

\stopluacode

\stoptext