transmogrifier

package module
v0.0.0-...-2a8b5d8 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2015 License: MIT Imports: 9 Imported by: 0

README

transmogrifier

Build Status

Transmogrifier is named after one of Calvin's most complex inventions. This one a lot simpler, more reliable, and does not have a dinosaur option.

About

A transmogrifier is something that changes things to a different shape or form. In this case it is for transmogrifying data between formats.

For an example implementation see mog, a cli tool for creating a []GitHub Flavored Markdown](https://github.com/articles/github-flavored-markdown) table out of CSV data.

Supported Transformations

Currently, only one transformation is supported: CSV to GitHub Flavored Markdown Table.

CSV -> MD Table

The input CSV data can start with an optional header row. If this row does not exist, a format file must exist. The separator for the CSV data can be specified if it is something other than a comma. For CSV data that comes from a file and is written to a file. the resulting output file with the MD is saved in the same directory as the source, using the same filename. The orginal extension is replaced with .md.

Format file

A format file can be used to specify both the column names and the formatting to be applied to the column. This includes column justification and column text transformations: italics_, _bold, and strikethrough. If a format file is not used, the first row of the data must be the column names. The format file is expected to be filename.fmt and is expected to be in the same directory as the data.

License

This is licensed under the MIT license. Please view the LICENSE file for more information.

Documentation

Overview

Copyright © 2014, All rights reserved Joel Scoble, https://github.com/mohae/transmogrifier

This is licensed under The MIT License. Please refer to the included LICENSE file for more information. If the LICENSE file has not been included, please refer to the url above.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSource = errors.New("no source was specified")
)

Common errors

Functions

func NewResource

func NewResource(s string, f FormatType, t ResourceType) resource

Types

type CSV

type CSV struct {
	// contains filtered or unexported fields
}

CSV is a struct for representing and working with csv data.

func NewCSV

func NewCSV() *CSV

NewCSV returns an initialize CSV object. It still needs to be configured for use.

func NewCSVSource

func NewCSVSource(s string) *CSV

NewCSVSource creates a new *CSV with its source set,

func (*CSV) HasHeader

func (c *CSV) HasHeader() bool

HasHeader returns the hasHeader bool

func (*CSV) HeaderRow

func (c *CSV) HeaderRow() []string

HeaderRow returns the header row, if it exists.

func (*CSV) Read

func (c *CSV) Read(r io.Reader) error

ReadAll takes a reader, and reads the data connected with it as CSV data. If there is a header row, CSV.hasHeader == true, the headerRow field is populated with the first row of the source. This reads the entire file at once. If an error occurs, it is returned

func (*CSV) ReadFile

func (c *CSV) ReadFile(f string) error

ReadFile takes a path, reads the contents of the file and returns any error encountered. The entire file will be read at once.

func (*CSV) ReadSource

func (c *CSV) ReadSource() error

func (*CSV) Rows

func (c *CSV) Rows() [][]string

Rows returns the csv rows.

func (*CSV) SetHasHeader

func (c *CSV) SetHasHeader(b bool)

func (*CSV) SetSource

func (c *CSV) SetSource(s string)

SetSource sets the source and has the formatFile updated, if applicable. TODO: Currently assumes file, refactor to support other types when needed.

func (*CSV) Source

func (c *CSV) Source() string

Source returns the source string

type FormatType

type FormatType int

FormatType is the format of a resource

const (
	FmtUnsupported FormatType = iota
	FmtCSV
	FmtMD
	FmtMDTable
)

type mogger interface{} {

}

func FormatTypeFromString

func FormatTypeFromString(s string) FormatType

func (FormatType) String

func (f FormatType) String() string

type MDTable

type MDTable struct {
	// contains filtered or unexported fields
}

MDTable is a struct for representing and working with markdown tables

func NewMDTable

func NewMDTable() *MDTable

NewMDTable returns an empty MDTable struct.

func (MDTable) Bytes

func (m MDTable) Bytes() []byte

func (*MDTable) SetColumnAlignment

func (m *MDTable) SetColumnAlignment(cols []string)

func (*MDTable) SetColumnEmphasis

func (m *MDTable) SetColumnEmphasis(cols []string)

func (*MDTable) SetColumnNames

func (m *MDTable) SetColumnNames(cols []string)

SetColumnNames

func (*MDTable) SetDest

func (m *MDTable) SetDest(s string)

SetDest sets the destination of the Write operation. If the destination is an empty string, "", the source name will be concatinated with '.md'. Any non-empty dest string will be used as the destination.

Currently, only write to file is supported.

func (*MDTable) SetFormatSource

func (m *MDTable) SetFormatSource(s string) error

SetFormatSource set's the source of the format information and sets useFormat to 'true'. If the formatSource != "", it will be used as the location of the formatting information for the MD Table. If it isn't set and useFormat == true, the format source is expected to be in the same location as the source, with the same name + an extension of '.fmt'.

func (*MDTable) SetHasColumnNames

func (m *MDTable) SetHasColumnNames(b bool)

SetHasColumnNames

func (*MDTable) SetSource

func (m *MDTable) SetSource(s string) error

SetSource set's the Source to the passed value. The source's extension is checked to see if it is a supported format. An error is returned if it isn't.

func (*MDTable) SetUseFormat

func (m *MDTable) SetUseFormat(b bool)

SetUseFormat: whether or not a format should be applied to the MD table.

func (MDTable) String

func (m MDTable) String() string

func (*MDTable) TransmogrifyStringTable

func (m *MDTable) TransmogrifyStringTable(t [][]string) error

Transmogrify transomgrifies the source into a MD table. The result is held in md and can be obtained by m.MD(). Any error encountered is returned. SetHasHeader needs to be called prior to calling this method.

func (*MDTable) WriteToFile

func (m *MDTable) WriteToFile() (name string, n int, err error)

Write saves the md table as a markdown file.

type ResourceType

type ResourceType int

ResourceType is the type of a resource

const (
	UnsupportedResource ResourceType = iota
	File
)

func ResourceTypeFromString

func ResourceTypeFromString(s string) ResourceType

ResourceTypeFromString returns the ResourceType constant

func (ResourceType) String

func (r ResourceType) String() string

Jump to

Keyboard shortcuts

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