embedme

package
v0.0.0-...-01a91d6 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Magenta ...
	Magenta = color.New(color.FgMagenta).FprintfFunc()
	// Success ...
	Success = color.New(color.FgGreen).FprintfFunc()
	// Info ...
	Info = color.New(color.FgBlue).FprintfFunc()
	// Warning ...
	Warning = color.New(color.FgYellow).FprintfFunc()
	// Error ...
	Error = color.New(color.FgRed).FprintfFunc()
	// Log ...
	Log = color.New(color.FgWhite).FprintfFunc()
)
View Source
var (
	// PlainText file extensions
	PlainText = []LanguageID{"txt", "embedme"}
	// None contains no text file extensions
	None = []LanguageID{""}
	// Typescript file extensions
	Typescript = []LanguageID{"ts"}
	// Javascript file extensions
	Javascript = []LanguageID{"js"}
	// Reason file extensions
	Reason = []LanguageID{"re"}
	// Scss file extensions
	Scss = []LanguageID{"scss"}
	// Rust file extensions
	Rust = []LanguageID{"rust"}
	// Java file extensions
	Java = []LanguageID{"java"}
	// Cpp file extensions
	Cpp = []LanguageID{"cpp"}
	// C file extensions
	C = []LanguageID{"c"}
	// HTML file extensions
	HTML = []LanguageID{"html"}
	// XML file extensions
	XML = []LanguageID{"xml"}
	// Markdown file extensions
	Markdown = []LanguageID{"md"}
	// TOML file extensions
	TOML = []LanguageID{"toml"}
	// YAML file extensions
	YAML = []LanguageID{"yaml"}
	// JSON file extensions
	JSON = []LanguageID{"json"}
	// JSON5 file extensions
	JSON5 = []LanguageID{"json5"}
	// Python file extensions
	Python = []LanguageID{"py", "python"}
	// Bash file extensions
	Bash = []LanguageID{"bash"}
	// Shell file extensions
	Shell = []LanguageID{"sh", "shell"}
	// Golang file extensions
	Golang = []LanguageID{"go", "golang"}
	// ObjectiveC file extensions
	ObjectiveC = []LanguageID{"objectivec", "objc"}
	// PHP file extensions
	PHP = []LanguageID{"php"}
	// CSharp file extensions
	CSharp = []LanguageID{"cs"}
	// Swift file extensions
	Swift = []LanguageID{"swift"}
	// Ruby file extensions
	Ruby = []LanguageID{"rb"}
	// Kotlin file extensions
	Kotlin = []LanguageID{"kotlin"}
	// Scala file extensions
	Scala = []LanguageID{"scala"}
	// Crystal file extensions
	Crystal = []LanguageID{"cr"}
	// PlantUML file extensions
	PlantUML = []LanguageID{"puml"}
	// Mermaid file extensions
	Mermaid = []LanguageID{"mermaid"}
	// Cmake file extensions
	Cmake = []LanguageID{"cmake"}
	// Protobuf file extensions
	Protobuf = []LanguageID{"proto"}
	// SQL file extensions
	SQL = []LanguageID{"sql"}
	// Haskell file extensions
	Haskell = []LanguageID{"hs"}
	// Arduino file extensions
	Arduino = []LanguageID{"ino"}
	// Jsx file extensions
	Jsx = []LanguageID{"jsx"}
	// Tsx file extensions
	Tsx = []LanguageID{"tsx"}
)
View Source
var (
	// LanguageComments ...
	LanguageComments = map[CommentType][]LanguageID{
		CommentNone: concat(JSON),
		CommentDoubleSlash: concat(
			None,
			PlainText,
			C,
			Typescript,
			Reason,
			Javascript,
			Rust,
			Cpp,
			Java,
			Golang,
			ObjectiveC,
			Scss,
			PHP,
			CSharp,
			Swift,
			Kotlin,
			Scala,
			JSON5,
			Protobuf,
			Arduino,
			Jsx,
			Tsx,
		),
		CommentXML: concat(
			HTML,
			Markdown,
			XML,
		),
		CommentHash: concat(
			Python,
			Bash,
			Shell,
			YAML,
			TOML,
			Ruby,
			Crystal,
			Cmake,
		),
		CommentSingleQuote: concat(
			PlantUML,
		),
		CommentDoublePercent: concat(
			Mermaid,
		),
		CommentDoubleHyphens: concat(
			SQL,
			Haskell,
		),
	}
	// SupportedLanguages ...
	SupportedLanguages = buildSupportedLanguages(LanguageComments)
	// CommentForLanguage ...
	CommentForLanguage = buildCommentForLanguage(LanguageComments)
)

Functions

func FirstComment

func FirstComment(source string, typ CommentType) (string, bool)

FirstComment ...

func GlobFiles

func GlobFiles(fs afero.Fs, workingDir string, patterns ...string) ([]string, error)

GlobFiles ...

Types

type CodeBlock

type CodeBlock struct {
	Start        int
	End          int
	StartLine    int
	EndLine      int
	Indent       string
	Code         string
	EmbedComment string
	Ignore       bool
	Language     LanguageID
}

CodeBlock ...

func ExtractCodeBlocks

func ExtractCodeBlocks(source string) []CodeBlock

ExtractCodeBlocks ...

func (*CodeBlock) Comment

func (b *CodeBlock) Comment() string

Comment ...

func (*CodeBlock) CommentType

func (b *CodeBlock) CommentType() (*CommentType, error)

CommentType ...

func (*CodeBlock) EmbedCommand

func (b *CodeBlock) EmbedCommand(fs afero.Fs, options *Options) (string, commands.Command, error)

EmbedCommand ...

type CommentType

type CommentType uint32

CommentType describes the type of comment used by a programming language

const (
	// CommentNone refers to no comment
	CommentNone CommentType = iota
	// CommentDoubleSlash refers to "//" comment
	CommentDoubleSlash
	// CommentXML refers to "<!-- ... -->" comment
	CommentXML
	// CommentHash refers to "#" comment
	CommentHash
	// CommentSingleQuote refers to "'" comment
	CommentSingleQuote
	// CommentDoublePercent refers to "%%" comment
	CommentDoublePercent
	// CommentDoubleHyphens refers to "--" comment
	CommentDoubleHyphens
)

type Embedder

type Embedder struct {
	Options Options
	FS      afero.Fs
}

Embedder is the embedder

It is possible to use a custom filesystem implementation.

func NewEmbedder

func NewEmbedder(options Options) (Embedder, error)

NewEmbedder creates a new embedder

The embedder uses the real file system.

func (*Embedder) Embed

func (e *Embedder) Embed(
	markdown []byte,
	absPath string,
	relPath string,
) (string, error)

Embed embeds a document

func (*Embedder) ProcessSource

func (e *Embedder) ProcessSource(i int, absSource string) error

ProcessSource ...

type LanguageID

type LanguageID string

LanguageID describes a programming language

type Options

type Options struct {
	StripEmbedComment bool
	Stdout            bool
	Verify            bool
	DryRun            bool
	WorkingDir        string
	Base              string
}

Options for embedme

func NewDefaultOptions

func NewDefaultOptions() Options

NewDefaultOptions returns default options for embedme

type SourceFinder

type SourceFinder struct {
	WorkingDir  string
	Glob        bool
	IgnoreFiles []string
}

SourceFinder ...

func NewSourceFinder

func NewSourceFinder() SourceFinder

NewSourceFinder ...

func (*SourceFinder) FindSources

func (f *SourceFinder) FindSources(fs afero.Fs, patterns ...string) (SourceMap, error)

FindSources ...

type SourceMap

type SourceMap map[string]bool

SourceMap is a map that tracks if a source path is valid (non-ignored)

func (SourceMap) Add

func (s SourceMap) Add(sources ...string)

Add adds a source to the soure map

func (SourceMap) Ignore

func (s SourceMap) Ignore(gi *ignore.GitIgnore) int

Ignore ignores all sources that match the entries of the Gitignore

Note: Ignore should be called after all sources were added

func (SourceMap) Valid

func (s SourceMap) Valid() []string

Valid returns all valid (non-ignored) sources

func (SourceMap) ValidCount

func (s SourceMap) ValidCount() int

ValidCount counts the number of valid (non-ignored) sources

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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