當前位置: 首頁>>代碼示例>>Golang>>正文


Golang lib.Page類代碼示例

本文整理匯總了Golang中github.com/piranha/gostatic/lib.Page的典型用法代碼示例。如果您正苦於以下問題:Golang Page類的具體用法?Golang Page怎麽用?Golang Page使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Page類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ProcessExternal

func ProcessExternal(page *gostatic.Page, args []string) error {
	if len(args) < 1 {
		return errors.New("'external' rule needs a command name")
	}
	cmdName := args[0]
	cmdArgs := args[1:]

	path, err := exec.LookPath(cmdName)
	if err != nil {
		path, err = exec.LookPath(filepath.Join(page.Site.Base, cmdName))
		if err != nil {
			return fmt.Errorf("command '%s' not found", cmdName)
		}
	}

	cmd := exec.Command(path, cmdArgs...)
	cmd.Stdin = strings.NewReader(page.Content())
	cmd.Dir = page.Site.Base
	var stderr bytes.Buffer
	cmd.Stderr = &stderr
	data, err := cmd.Output()
	if err != nil {
		return fmt.Errorf("'%s' failed: %s\n%s",
			strings.Join(args, " "), err, stderr.String())
	}

	page.SetContent(string(data))
	return nil
}
開發者ID:mchudgins,項目名稱:gostatic,代碼行數:29,代碼來源:external.go

示例2: ProcessInnerTemplate

func ProcessInnerTemplate(page *gostatic.Page, args []string) error {
	//todo catch
	defer func() {
		if err := recover(); err != nil {
			//return fmt.Sprintf("%s: %s", page.Source, err)
		}
	}()

	t, err := page.Site.Template.Clone()
	if err != nil {
		return err
	}
	t, err = t.New("ad-hoc").Parse(page.Content())
	if err != nil {
		return errors.New(fmt.Sprintf("Page %s: %s", page.Source, err))
	}

	var buffer bytes.Buffer
	err = t.ExecuteTemplate(&buffer, "ad-hoc", page)
	if err != nil {
		return errors.New(fmt.Sprintf("Page %s: %s", page.Source, err))
	}

	page.SetContent(buffer.String())
	return nil
}
開發者ID:mchudgins,項目名稱:gostatic,代碼行數:26,代碼來源:template.go

示例3: ProcessExt

func ProcessExt(page *gostatic.Page, args []string) error {
	if len(args) < 1 {
		return errors.New(
			"'ext' rule requires an extension prefixed with dot")
	}
	newExt := args[0]

	ext := filepath.Ext(page.Path)
	if ext == "" {
		page.Path = page.Path + newExt
	} else {
		page.Path = page.Path[0:len(page.Path)-len(ext)] + newExt
	}
	return nil
}
開發者ID:mchudgins,項目名稱:gostatic,代碼行數:15,代碼來源:ext.go

示例4: ProcessTemplate

func ProcessTemplate(page *gostatic.Page, args []string) error {
	if len(args) < 1 {
		return errors.New("'template' rule needs an argument")
	}
	pagetype := args[0]
	//todo catch thiss
	defer func() {
		if err := recover(); err != nil {
			//return err //errors.New(fmt.Sprintf("%s: %s", page.Source, err))
		}
	}()

	var buffer bytes.Buffer
	err := page.Site.Template.ExecuteTemplate(&buffer, pagetype, page)
	if err != nil {
		return errors.New(fmt.Sprintf("%s: %s", page.Source, err))
	}

	page.SetContent(buffer.String())
	return nil
}
開發者ID:mchudgins,項目名稱:gostatic,代碼行數:21,代碼來源:template.go

示例5: checkPage

// Runs some checks against the parsed page.
func checkPage(t *testing.T, pageText string, page *gostatic.Page) {
	if page.Content() != pageText {
		t.Errorf("expected '%s', got '%s'", pageText, page.Content())
	}

	if len(page.PageHeader.Other) != 2 {
		t.Errorf("expected length of 2, got '%d'", len(page.PageHeader.Other))
	}

	// Note: gostatic lib capitalizes the properties for some reason. So it
	// converted 'salve' to 'Salve' etc.
	salve := page.PageHeader.Other["Salve"]
	if salve != "hello" {
		t.Errorf("expected 'hello', got '%s'", salve)
	}

	munde := page.PageHeader.Other["Munde"]
	if munde != "world" {
		t.Errorf("expected 'world', got '%s'", munde)
	}
}
開發者ID:mchudgins,項目名稱:gostatic,代碼行數:22,代碼來源:config_test.go

示例6: ProcessRelativize

func ProcessRelativize(page *gostatic.Page, args []string) error {
	repl := `$1="` + page.Rel("/") + `$2"`
	rv := RelRe.ReplaceAllStringFunc(page.Content(), func(inp string) string {
		if NonProtoRe.MatchString(inp) {
			return inp
		}
		return RelRe.ReplaceAllString(inp, repl)
	})
	page.SetContent(rv)
	return nil
}
開發者ID:mchudgins,項目名稱:gostatic,代碼行數:11,代碼來源:relativize.go

示例7: ProcessConfig

func ProcessConfig(page *gostatic.Page, args []string) error {
	parts := gostatic.TrimSplitN(page.Content(), "\n----\n", 2)
	if len(parts) != 2 {
		// no configuration, well then...
		page.PageHeader = *gostatic.NewPageHeader()
		return nil
	}

	page.PageHeader = *gostatic.ParseHeader(parts[0])
	page.SetContent(parts[1])
	return nil
}
開發者ID:repos-blogs-static,項目名稱:gostatic,代碼行數:12,代碼來源:config.go

示例8: ProcessMarkdown

func ProcessMarkdown(page *gostatic.Page, args []string) error {
	result := Markdown(page.Content())
	page.SetContent(result)
	return nil
}
開發者ID:mchudgins,項目名稱:gostatic,代碼行數:5,代碼來源:markdown.go

示例9: ProcessDirectorify

func ProcessDirectorify(page *gostatic.Page, args []string) error {
	if filepath.Base(page.Path) != "index.html" {
		page.Path = strings.Replace(page.Path, ".html", "/index.html", 1)
	}
	return nil
}
開發者ID:mchudgins,項目名稱:gostatic,代碼行數:6,代碼來源:directorify.go

示例10: ProcessIgnore

func ProcessIgnore(page *gostatic.Page, args []string) error {
	page.SetState(gostatic.StateIgnored)
	return nil
}
開發者ID:mchudgins,項目名稱:gostatic,代碼行數:4,代碼來源:ignore.go


注:本文中的github.com/piranha/gostatic/lib.Page類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。