hv

package
v0.0.0-...-cd27406 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2014 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package Hacker View provides APIs to analyze Go projects and generate AST-based source code view.

Index

Constants

View Source
const PACKAGE_VER = 1

PACKAGE_VER is modified when previously stored packages are invalid.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	Pos, End   int16
	Kind       AnnotationKind
	ImportPath string
}

type AnnotationKind

type AnnotationKind int16
const (
	ExportLinkAnnotation AnnotationKind = iota
	AnchorAnnotation
	CommentAnnotation
	PackageLinkAnnotation
	BuiltinAnnotation
)

type Code

type Code struct {
	Text        string
	Annotations []Annotation
}

type Example

type Example struct {
	Name string
	Doc  string
	Code string
	//Play   string
	Output string
	IsUsed bool // Indicates if it's used by any kind object.
}

Example represents function or method examples.

type File

type File struct {
	// Top-level declarations.
	Consts []*Value
	Funcs  []*Func
	Types  []*Type
	Vars   []*Value

	// Internal declarations.
	Ifuncs []*Func
	Itypes []*Type
}

A File describles declaration of file.

type Func

type Func struct {
	Name, FullName string
	Doc            string
	Decl, FmtDecl  string
	URL            string // VCS URL.
	Code           string // Included field 'Decl', formatted.
	Examples       []*Example
}

Func represents functions

type Gist

type Gist struct {
	ImportPath string     `xorm:"index VARCHAR(150)"`
	Gist       string     // Gist path.
	Examples   []*Example // Examples.
}

Gist represents a Gist.

type Link struct {
	Path, Name, Comment string
}

A link describes the (HTML) link information for an identifier. The zero value of a link represents "no link".

func GetLinks(prefix string, imports []string, files map[string]File) []*Link

GetLinks returns objects with its jump link.

type Package

type Package struct {
	*PkgInfo

	Readme map[string][]byte

	*PkgDecl

	IsNeedRender bool

	IsHasExport bool

	// Top-level declarations.
	IsHasConst, IsHasVar bool

	IsHasExample bool

	IsHasFile   bool
	IsHasSubdir bool
}

A Package describles the full documentation and declaration of a project or package.

type PkgDecl

type PkgDecl struct {
	Tag string // Current tag of project.
	Doc string // Package documentation(doc.go).

	File

	Examples, UserExamples []*Example // Function or method example.
	Imports, TestImports   []string   // Imports.
	Files, TestFiles       []*Source  // Source files.

	Notes []string // Source code notes.
	Dirs  []string // Subdirectories

	// Indicate how many JS should be downloaded(JsNum=total num - 1)
	JsNum int
}

PkgDecl is package declaration in database acceptable form.

type PkgInfo

type PkgInfo struct {
	Id         int64  `json:"id"`
	ImportPath string `xorm:"index VARCHAR(150)" json:"import_path"`

	ProjectName string `xorm:"VARCHAR(50)" json:"project_name"`
	ProjectPath string `xorm:"VARCHAR(120)" json:"project_path"`
	ViewDirPath string `xorm:"VARCHAR(120)" json:"-"`
	Synopsis    string `xorm:"VARCHAR(300)" json:"synopsis"`

	/*
		- Indicates whether it's a command line tool or package.
		- Indicates whether it uses cgo / os/user or not.
		- Indicates whether it belongs to Go standard library.
		- Indicates whether it's developed by Go team.
	*/
	IsCmd       bool `json:"cmd"`
	IsCgo       bool `json:"cgo"`
	IsGoRepo    bool `json:"go_repo"`
	IsGoSubrepo bool `json:"go_subrepo"`

	/*
		- All tags of project.
		eg.
			master|||v0.6.2.0718
		- Views of projects.
		- User viewed time(Unix-timestamp).
		eg.
			1374127619
		- Time when information last updated(UTC).
		eg.
			2013-07-16 21:09:27.48932087
	*/
	Tags       string `xorm:"-" json:"tags"`
	Views      int64  `xorm:"index" json:"-"`
	ViewedTime int64  `json:"-"`
	Created    int64  `xorm:"index" json:"created"`

	/*
		- Rank is the benchmark of projects, it's based on BaseRank and views.
	*/
	Rank int64 `xorm:"index" json:"-"`

	/*
		- Package (structure) version.
		eg.
			9
		- Project revision.
		eg.
			8976ce8b2848
		- Project labels.
		eg.
			$tool|
	*/
	PkgVer int    `json:"-"`
	Ptag   string `xorm:"VARCHAR(50)" json:"ptag"`
	Labels string `xorm:"TEXT" json:"-"`

	/*
		- Number of projects that import this project.
		- Ids of projects that import this project.
		eg.
			$47|$89|$5464|$8586|$8595|$8787|$8789|$8790|$8918|$9134|$9139|
	*/
	RefNum  int    `json:"-"`
	RefPids string `xorm:"TEXT" json:"-"`

	/*
		- Addtional information.
	*/
	Vcs      string `xorm:"-" json:"-"`
	Homepage string `xorm:"VARCHAR(100)" json:"homepage"`
	ForkUrl  string `xorm:"VARCHAR(150)" json:"-"`

	Issues, Stars, Forks int    `json:"-"`
	Note                 string `xorm:"TEXT" json:"-"`

	SourceSize int64 `json:"-"`
}

A PkgInfo describles a project information.

type Render

type Render struct {
	Links     []*Link
	FilteList map[string]bool
	// contains filtered or unexported fields
}

A Render describles a code render.

func (*Render) Render

func (r *Render) Render(name string, data []byte) []byte

Render highlights code.

type Source

type Source struct {
	SrcName   string
	BrowseUrl string
	RawSrcUrl string
	SrcData   []byte
}

A Source describles a Source code file.

func (*Source) Data

func (s *Source) Data() []byte

func (*Source) IsDir

func (s *Source) IsDir() bool

func (*Source) ModTime

func (s *Source) ModTime() time.Time

func (*Source) Mode

func (s *Source) Mode() os.FileMode

func (*Source) Name

func (s *Source) Name() string

func (*Source) RawUrl

func (s *Source) RawUrl() string

func (*Source) SetData

func (s *Source) SetData(p []byte)

func (*Source) Size

func (s *Source) Size() int64

func (*Source) Sys

func (s *Source) Sys() interface{}

type Type

type Type struct {
	Name          string // Type name.
	Doc           string
	Decl, FmtDecl string // Normal and formatted form of declaration.
	URL           string // VCS URL.

	Consts, Vars []*Value
	Funcs        []*Func // Exported functions that return this type.
	Methods      []*Func // Exported methods.

	IFuncs   []*Func // Internal functions that return this type.
	IMethods []*Func // Internal methods.

	Examples []*Example
}

Type represents structs and interfaces.

type Value

type Value struct {
	Name          string // Value name.
	Doc           string
	Decl, FmtDecl string // Normal and formatted form of declaration.
	URL           string // VCS URL.
}

Value represents constants and variable

type WalkDepth

type WalkDepth uint

WalkDepth indicates how far the process goes.

const (
	WD_Imports WalkDepth = iota
	WD_All
)

type WalkMode

type WalkMode uint

WalkMode indicates which things to do.

const (
	WM_All WalkMode = 1 << iota
	WM_NoReadme
	WM_NoExample
)

type WalkRes

type WalkRes struct {
	WalkDepth
	WalkType
	WalkMode
	RootPath string    // For WT_Local mode.
	Srcs     []*Source // For WT_Memory mode.
	BuildAll bool
}

type WalkType

type WalkType uint

WalkType indicates which way to get data for walker.

const (
	WT_Local WalkType = iota
	WT_Memory
	WT_Zip
	WT_TarGz
	WT_Http
)

type Walker

type Walker struct {
	LineFmt string
	Pdoc    *Package

	Examples []*doc.Example // Function or method example.
	Fset     *token.FileSet
	SrcLines map[string][]string // Source file line slices.
	SrcFiles map[string]*Source
	Buf      []byte // scratch space for printNode method.
	// contains filtered or unexported fields
}

Walker holds the state used when building the documentation.

func (*Walker) Build

func (w *Walker) Build(wr *WalkRes) (*Package, error)

Build generates documentation from given source files through 'WalkType'.

func (*Walker) Render

func (w *Walker) Render() (map[string][]byte, error)

Render renders source code to HTML. Note that you have to call Build before you call this method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL