//Page does the work of turning a path plus a PBundle into a ComponentResult. That
//ComponentResult might have Status==CONTINUE for a url like /plural/index.css.
424950
func (self *IndexOnlyComponent) Page(pb PBundle, path []string, trailingSlash bool) ComponentResult {
	//allow singular to be used as synonym for plural
	if len(path) == 0 {
		return ComponentResult{
			Path:   "/" + self.indexPath,
			Status: http.StatusOK,
		}
	}

	if len(path) == 1 && path[0] == "index.html" {
		return ComponentResult{
			Path:   "/" + self.indexPath,
			Status: http.StatusOK,
		}
	}

	continuePoint := self.plural
	if self.singular != "" {
		continuePoint = self.singular
	}

	//just try to serve up the content
	return ComponentResult{
		Status:           CONTINUE,
		ContinueAt:       continuePoint,
		ContinueConsumed: 1,
	}

}
500540
func (exp *explorerUI) AddressPage(w http.ResponseWriter, r *http.Request) {
	// AddressPageData is the data structure passed to the HTML template

	type AddressPageData struct {
		*CommonPageData
		Data         *dbtypes.AddressInfo
		CRLFDownload bool
		FiatBalance  *exchanges.Conversion
	}

	// Grab the URL query parameters
	address, txnType, limitN, offsetAddrOuts, err := parseAddressParams(r)
	if err != nil {
		exp.StatusPage(w, defaultErrorCode, err.Error(), address, ExpStatusError)
		return
	}

	// Validate the address.
	addr, addrType, addrErr := txhelpers.AddressValidation(address, exp.ChainParams)
	isZeroAddress := addrErr == txhelpers.AddressErrorZeroAddress
	if addrErr != nil && !isZeroAddress {
		var status expStatus
		var message string
		code := defaultErrorCode
		switch addrErr {
		case txhelpers.AddressErrorDecodeFailed, txhelpers.AddressErrorUnknown:
			status = ExpStatusError
			message = "Unexpected issue validating this address."
		case txhelpers.AddressErrorWrongNet:
			status = ExpStatusWrongNetwork
			message = fmt.Sprintf("The address %v is valid on %s, not %s.",
				addr, addr.Net().Name, exp.NetName)
			code = wrongNetwork
		default:
			status = ExpStatusError
			message = "Unknown error."
		}

		exp.StatusPage(w, code, message, address, status)
		return
	}

	// Handle valid but unsupported address types.
	switch addrType {
	case txhelpers.AddressTypeP2PKH, txhelpers.AddressTypeP2SH:
		// All good.
	case txhelpers.AddressTypeP2PK:
		message := "Looks like you are searching for an address of type P2PK."
		exp.StatusPage(w, defaultErrorCode, message, address, ExpStatusP2PKAddress)
		return
	default:
		message := "Unsupported address type."
		exp.StatusPage(w, defaultErrorCode, message, address, ExpStatusNotSupported)
		return
	}

	// Retrieve address information from the DB and/or RPC.
	var addrData *dbtypes.AddressInfo
	if isZeroAddress {
		// For the zero address (e.g. DsQxuVRvS4eaJ42dhQEsCXauMWjvopWgrVg),
		// short-circuit any queries.
		addrData = &dbtypes.AddressInfo{
			Address:         address,
			Net:             addr.Net().Name,
			IsDummyAddress:  true,
			Balance:         new(dbtypes.AddressBalance),
			UnconfirmedTxns: new(dbtypes.AddressTransactions),
		}
	} else {
		addrData, err = exp.AddressListData(address, txnType, limitN, offsetAddrOuts)
		if exp.timeoutErrorPage(w, err, "TicketsPriceByHeight") {
			return
		} else if err != nil {
			exp.StatusPage(w, defaultErrorCode, err.Error(), address, ExpStatusError)
			return
		}
	}

	// Set page parameters.
	addrData.IsDummyAddress = isZeroAddress // may be redundant
	addrData.Path = r.URL.Path

	// If exchange monitoring is active, prepare a fiat balance conversion
	conversion := exp.xcBot.Conversion(dcrutil.Amount(addrData.Balance.TotalUnspent).ToCoin())

	// For Windows clients only, link to downloads with CRLF (\r\n) line
	// endings.
	UseCRLF := strings.Contains(r.UserAgent(), "Windows")

	// Execute the HTML template.
	pageData := AddressPageData{
		CommonPageData: exp.commonData(r),
		Data:           addrData,
		CRLFDownload:   UseCRLF,
		FiatBalance:    conversion,
	}
	str, err := exp.templates.execTemplateToString("address", pageData)
	if err != nil {
		log.Errorf("Template execute failure: %v", err)
		exp.StatusPage(w, defaultErrorCode, defaultErrorMessage, "", ExpStatusError)
		return
	}

	w.Header().Set("Content-Type", "text/html")
	w.Header().Set("Turbolinks-Location", r.URL.RequestURI())
	w.WriteHeader(http.StatusOK)
	io.WriteString(w, str)
}
1257953
func (p *PathObserver) NotifyPage(pg *Pages) {
	p.React(func(r pub.Publisher, _ error, d interface{}) {
		if ps, ok := d.(PathSpec); ok {
			pg.All(ps.Sequence)
		}
	}, true)
}
1264540
func (l *BasicLayout) MovePage(state *Peco, p PagingRequest) (moved bool) {
	switch p.Type() {
	case ToScrollLeft, ToScrollRight:
		moved = horizontalScroll(state, l, p)
	default:
		moved = verticalScroll(state, l, p)
	}
	return
}
1105123
func (db *DB) page(id pgid) *page {
	pos := id * pgid(db.pageSize)
	return (*page)(unsafe.Pointer(&db.data[pos]))
}
364497
func (p *page) leafPageElement(index uint16) *leafPageElement {
	n := &((*[0x7FFFFFF]leafPageElement)(unsafe.Pointer(&p.ptr)))[index]
	return n
}
129360
func (s *IPServiceList) FirstPage() (*IPServiceList, error) {
	return s.getPage(s.Meta.FirstPageUri)
}
264846
func (p Pages) Next(cur Page) Page {
	for x, c := range p {
		if c.Eq(cur) {
			if x < len(p)-1 {
				return p[x+1]
			}
			// TODO(bep) consider return nil here to get it line with the other Nexts
			return p[0]
		}
	}
	return nil
}
106081
func (p *WebPage) Pages() ([]*WebPage, error) {
	var resp struct {
		Refs []refJSON `json:"refs"`
	}
	if err := p.ref.process.doJSON("POST", "/webpage/Pages", map[string]interface{}{"ref": p.ref.id}, &resp); err != nil {
		return nil, err
	}

	// Convert reference IDs to web pages.
	a := make([]*WebPage, len(resp.Refs))
	for i, ref := range resp.Refs {
		a[i] = &WebPage{ref: newRef(p.ref.process, ref.ID)}
	}
	return a, nil
}
328797
func (p *Pager) page(index int) (Page, error) {

	if pages, ok := p.element().(Pages); ok {
		if pages != nil && len(pages) > index {
			return pages[index], nil
		}
		return nil, nil
	}

	// must be PagesGroup
	// this construction looks clumsy, but ...
	// ... it is the difference between 99.5% and 100% test coverage :-)
	groups := p.element().(PagesGroup)

	i := 0
	for _, v := range groups {
		for _, page := range v.Pages {
			if i == index {
				return page, nil
			}
			i++
		}
	}
	return nil, nil
}
351069
func (g *PagesService) PageBuilds(uri *Hyperlink, uriParams M) (builds []PageBuild,
	result *Result) {
	url, err := ExpandWithDefault(uri, &PagesBuildsURL, uriParams)
	if err != nil {
		return nil, &Result{Err: err}
	}
	result = g.client.get(url, &builds)
	return
}
1271830
func (r *PaginationResult) NextPage() *Pagination {
	if r.PageNumber*r.PageSize >= r.TotalCount {
		return nil
	}
	return &Pagination{PageNumber: r.PageNumber + 1, PageSize: r.PageSize}
}
718395
func (s *IPUserList) LastPage() (*IPUserList, error) {
	return s.getPage(s.Meta.LastPageUri)
}
1180697
func (self *SimplePageMapper) ErrorPage(conn OauthConnector, errorText string) string {
	v := url.Values{
		"service": []string{conn.Name()},
		"error":   []string{errorText},
	}
	return fmt.Sprintf("%s?%s", self.errorPage, v.Encode())
}
874229
func (p *PaginationResponseMeta) nextPage(originalQuery *PaginationMeta) (next *PaginationMeta) {
	nextOffset := p.Offset + p.Length

	if nextOffset >= p.Found {
		return nil
	}

	next = &PaginationMeta{}
	next.Offset = nextOffset
	next.Length = p.Length

	if originalQuery != nil {
		next.OrderBy = originalQuery.OrderBy
		next.Sort = originalQuery.Sort
	}

	return next
}
338788
func (l Links) CurrentPage() (int, error) {
	switch {
	case l.Previous == "" && l.Next != "":
		return 1, nil
	case l.Previous != "":
		prevPage, err := pageForURL(l.Previous)
		if err != nil {
			return 0, err
		}

		return prevPage + 1, nil
	}
	return 0, nil
}
472758
func recoverSymlinkPath(p string) string {
	// A/.cipd/pkgs/<name>/<id>/b/c/d => A/b/c/d. (at least 5 components)
	chunks := strings.Split(p, string(filepath.Separator))
	if len(chunks) < 5 {
		return ""
	}
	// Search for .cipd to find site root.
	var i int
	for i = len(chunks) - 1; i >= 0; i-- {
		if chunks[i] == ".cipd" {
			break
		}
	}
	if i == -1 {
		return ""
	}
	// Must have at least ".cipd/pkgs/<name>/<id>/...".
	if len(chunks)-i <= 4 {
		return ""
	}
	// Cut out .cipd/pkgs/<name>/<id> to get A/b/c/d.
	return strings.Join(append(chunks[:i], chunks[i+4:]...), string(filepath.Separator))
}