Home Download Docs Code Community
     1	/*
     2	Copyright 2013 The Perkeep Authors.
     3	
     4	Licensed under the Apache License, Version 2.0 (the "License");
     5	you may not use this file except in compliance with the License.
     6	You may obtain a copy of the License at
     7	
     8	     http://www.apache.org/licenses/LICENSE-2.0
     9	
    10	Unless required by applicable law or agreed to in writing, software
    11	distributed under the License is distributed on an "AS IS" BASIS,
    12	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13	See the License for the specific language governing permissions and
    14	limitations under the License.
    15	*/
    16	
    17	// Package publish exposes the types and functions that can be used
    18	// from a Go template, for publishing.
    19	package publish // import "perkeep.org/pkg/publish"
    20	
    21	import (
    22		"html/template"
    23	
    24		"perkeep.org/pkg/blob"
    25		"perkeep.org/pkg/search"
    26	)
    27	
    28	// SubjectPage is the data structure used when serving a
    29	// publishing template. It contains the functions that can be called
    30	// from the template.
    31	type SubjectPage struct {
    32		Header  func() *PageHeader
    33		File    func() *PageFile
    34		Members func() *PageMembers
    35	}
    36	
    37	// PageHeader contains the data available to the template,
    38	// and relevant to the page header.
    39	type PageHeader struct {
    40		Title         string      // Page title.
    41		CSSFiles      []string    // Available CSS files.
    42		JSDeps        []string    // Dependencies (for e.g closure) that can/should be included as javascript files.
    43		CamliClosure  template.JS // Closure namespace defined in the provided js. e.g camlistore.GalleryPage from pics.js
    44		Subject       blob.Ref    // Subject of this page (i.e the object which is described and published).
    45		ViewerIsOwner bool        // Whether the viewer of the page is also the owner of the displayed subject. (localhost check for now.)
    46		PublishedRoot blob.Ref    // Root permanode for this publisher. On camliRoot, camliPath:somePath = publishedRoot
    47		// SubjectBasePath is the URL path up to the digest prefix of the
    48		// subject. e.g. "/pics/foo/-/h341b133369" or "/pics/foo/-" if the subject
    49		// is the published root itself.
    50		SubjectBasePath string
    51		// PathPrefix is the publisher app handler prefix on Perkeep, e.g.
    52		// "/pics/", or "/" if the request was not proxied through Perkeep.
    53		PathPrefix string
    54		Host       string
    55	}
    56	
    57	// PageFile contains the file related data available to the subject template,
    58	// if the page describes some file contents.
    59	type PageFile struct {
    60		FileName     string
    61		Size         int64
    62		MIMEType     string
    63		IsImage      bool
    64		DownloadURL  string
    65		ThumbnailURL string
    66		DomID        string
    67		Nav          func() *Nav
    68	}
    69	
    70	// Nav holds links to the previous, next, and parent elements,
    71	// when displaying members.
    72	type Nav struct {
    73		ParentPath string
    74		PrevPath   string
    75		NextPath   string
    76	}
    77	
    78	// PageMembers contains the data relevant to the members if the published subject
    79	// is a permanode with members.
    80	type PageMembers struct {
    81		SubjectPath string                                      // URL prefix path to the subject (i.e the permanode).
    82		ZipName     string                                      // Name of the downloadable zip file which contains all the members.
    83		Members     []*search.DescribedBlob                     // List of the members.
    84		Description func(*search.DescribedBlob) string          // Returns the description of the given member.
    85		Title       func(*search.DescribedBlob) string          // Returns the title for the given member.
    86		Path        func(*search.DescribedBlob) string          // Returns the url prefix path to the given the member.
    87		DomID       func(*search.DescribedBlob) string          // Returns the Dom ID of the given member.
    88		FileInfo    func(*search.DescribedBlob) *MemberFileInfo // Returns some file info if the given member is a file permanode.
    89	}
    90	
    91	// MemberFileInfo contains the file related data available for each member,
    92	// if the member is the permanode for a file.
    93	type MemberFileInfo struct {
    94		FileName         string
    95		FileDomID        string
    96		FilePath         string
    97		FileThumbnailURL string
    98	}
Website layout inspired by memcached.
Content by the authors.