Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
goloop committed Apr 29, 2022
0 parents commit 78a68e2
Show file tree
Hide file tree
Showing 15 changed files with 964 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories
# vendor/
.vscode/
cmd/
49 changes: 49 additions & 0 deletions .godocdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[//]: # (!!!Don't modify the README.md, use `make readme` to generate it!!!)


[![Go Report Card](https://goreportcard.com/badge/github.com/goloop/slug)](https://goreportcard.com/report/github.com/goloop/slug) [![License](https://img.shields.io/badge/license-BSD-blue)](https://github.com/goloop/slug/blob/master/LICENSE) [![License](https://img.shields.io/badge/godoc-YES-green)](https://godoc.org/github.com/goloop/slug)

*Version: .ModuleVersion*

# slug

{{.EmitSynopsis}}


## Installation

To install this module use `go get` as:

$ go get -u github.com/goloop/slug

## Quick Start

To use this module import it as: `github.com/goloop/slug`

### Conversion functions

#### Fast conversion.

Use the `Make` method to convert a string to slug.

```go
package main

import (
"fmt"

"github.com/goloop/slug"
)

func main() {
// Simple generate slug from the string.
s := slug.Make("Hello 世界")
h := "https://example.com/"
fmt.Printf("%s%s\n", h, s)

// Output:
// hello-shi-jie
}
```

{{ .EmitUsage }}
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2022, GoLoop.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the GoLoop nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER AND CONTRIBUTORS ''AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER AND CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# GOLOOP
#
# Load data about the package:
# NAME
# Name of the GoLang's module;
# VERSION
# Current version.
# REPOSITORY
# The name of the repository where the package is stored,
# for example: github.com/goloop;
MODULE_NAME:=$(shell cat go.mod | grep module | awk '{split($$2,v,"/"); print v[3]}')
MODULE_VERSION:=$(shell cat doc.go | grep "const version" | awk '{gsub(/"/, "", $$4); print $$4}')
MODULE_MAJOR_VERSION:=$(shell cat doc.go | grep "const version" | awk '{gsub(/"/, "", $$4); print $$4}' | awk '{split($$0,r,"."); print r[1]}')
REPOSITORY_NAME:=$(shell cat go.mod | grep module | awk '{split($$2,v,"/"); print v[1] "/" v[2]}')

# Help information.
define MSG_HELP
Go-package's manager of
${MODULE_NAME} v${MODULE_VERSION}

Commands:
help
Show this help information
test
Run tests
cover
Check test coverage
readme
Create readme from the GoLang code

Requires `godocdown`, install as:
go get github.com/robertkrimen/godocdown/godocdown
tag
Create git-tag with current version of package
endef

# Constants.
export MSG_HELP
REPOSITORY_PATH=${REPOSITORY_NAME}/${MODULE_NAME}

all: help
help:
@echo "$$MSG_HELP"
test:
@go clean -testcache; \
go test ${REPOSITORY_PATH}
cover:
@go test -cover ${REPOSITORY_PATH} && \
go test -coverprofile=/tmp/coverage.out ${REPOSITORY_PATH} && \
go tool cover -func=/tmp/coverage.out && \
go tool cover -html=/tmp/coverage.out
readme:
ifeq (, $(shell which godocdown))
@go get github.com/robertkrimen/godocdown/godocdown
endif
@godocdown -plain=true -template=.godocdown.md ./ | \
sed -e 's/\.ModuleVersion/v${MODULE_VERSION}/g' > README.md
tag:
@bash -c 'read -p "Do you want to create v${MODULE_VERSION} tag [y/n]?: " yn; case $${yn} in "y") git tag "v${MODULE_VERSION}"; exit 0;; *) exit 0;; esac'
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
[//]: # (!!!Don't modify the README.md, use `make readme` to generate it!!!)


[![Go Report Card](https://goreportcard.com/badge/github.com/goloop/slug)](https://goreportcard.com/report/github.com/goloop/slug) [![License](https://img.shields.io/badge/license-BSD-blue)](https://github.com/goloop/slug/blob/master/LICENSE) [![License](https://img.shields.io/badge/godoc-YES-green)](https://godoc.org/github.com/goloop/slug)

*Version: v0.0.1-alpha*

# slug

Package slug generate slug from Unicode string, URL-friendly slugify with
multiple languages support.


## Installation

To install this module use `go get` as:

$ go get -u github.com/goloop/slug

## Quick Start

To use this module import it as: `github.com/goloop/slug`

### Conversion functions

#### Fast conversion.

Use the `Make` method to convert a string to slug.

```go
package main

import (
"fmt"

"github.com/goloop/slug"
)

func main() {
// Simple generate slug from the string.
s := slug.Make("Hello 世界")
h := "https://example.com/"
fmt.Printf("%s%s\n", h, s)

// Output:
// hello-shi-jie
}
```

## Usage

#### func Lower

func Lower(t string) string

Lower returns slug in lowercase.

#### func Make

func Make(t string) string

Make returns slug from string.

#### func Version

func Version() string

Version returns the version of the module.

#### type Slug

type Slug struct {
}


Slug is the slug constructor.

#### func New

func New() *Slug

New retursn pointer to Slug.

#### func (*Slug) Lang

func (s *Slug) Lang(l string) *Slug

Lang sets the type of language features to use during slugify.

#### func (*Slug) Lower

func (s *Slug) Lower(t string) string

Lower returns slug in lowercase.

#### func (*Slug) Make

func (s *Slug) Make(t string) string

Make returns slug from string.
10 changes: 10 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Package slug generate slug from Unicode string,
// URL-friendly slugify with multiple languages support.
package slug

const version = "0.0.1-alpha"

// Version returns the version of the module.
func Version() string {
return "v" + version
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/goloop/slug

go 1.17

require github.com/goloop/t13n v1.0.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/goloop/t13n v1.0.0 h1:FaX8xLhJ1MR+Ua1jc+WNcFFFqQgkzTcFWKAOwLmlPZ8=
github.com/goloop/t13n v1.0.0/go.mod h1:1A8l9eGVc905TSEVbUS36ctQSEFtW7n5FBOc1Tp32r8=
Loading

0 comments on commit 78a68e2

Please sign in to comment.