Browse Source

Fixes, tests, checkbox sizes to px

Vova Tkach 6 years ago
parent
commit
4e67c42508
8 changed files with 224 additions and 18 deletions
  1. 1 1
      README.md
  2. 11 11
      assets/cp.styles.css
  3. 0 0
      assets/cp.styles.css.go
  4. 1 1
      consts/consts.go
  5. 5 1
      hosts/localhost/htdocs/styles.css
  6. 1 1
      modules/module_index.go
  7. 16 3
      utils/utils.go
  8. 189 0
      utils/utils_test.go

+ 1 - 1
README.md

@@ -1,5 +1,5 @@
 # golang-fave
-CMS written in Go with MySQL as database. Dynamical, splitted by modules, user friendly and thanks bootstrap is fully adaptive for mobile devices and tablets. Thanks Go language it's fastern, all in one binary file, no need to install additional web servers. Go native template with vars allow to do almost all what are need.
+CMS written on Go with MySQL as database. Dynamical, splitted by modules, user friendly and thanks bootstrap is fully adaptive for mobile devices and tablets. Thanks Go language it's fastern, all in one binary file, no need to install additional web servers. Go native template with vars allow to do almost all what are need.
 
 ![](testdata/screenshots.gif)
 

+ 11 - 11
assets/cp.styles.css

@@ -35,7 +35,7 @@ body.cp-first-user {
 	align-items: center;
 	-webkit-box-pack: center;
 	justify-content: center;
-	background-color: #f5f5f5;
+	background-color: #eee;
 }
 
 .cp-login .form-signin,
@@ -333,8 +333,8 @@ ul.pagination {
 	box-shadow: inset 0 0 0 1px #ced4da;
 	background: #ced4da;
 	text-indent: -5000px;
-	height: 1.8rem;
-	width: 3.5rem;
+	height: 30px;
+	width: 60px;
 	border-radius: 1.5rem;
 	cursor: pointer;
 	margin-top: 0px;
@@ -345,8 +345,8 @@ ul.pagination {
 	content: "";
 	position: absolute;
 	display: block;
-	height: 1.8rem;
-	width: 1.8rem;
+	height: 30px;
+	width: 30px;
 	top: 0px;
 	left: 0px;
 	border-radius: 1.5rem;
@@ -360,10 +360,10 @@ ul.pagination {
 	content: "";
 	position: absolute;
 	display: block;
-	height: 1.6rem;
-	width: 1.6rem;
-	top: 0.1rem;
-	left: 0.13rem;
+	height: 28px;
+	width: 28px;
+	top: 1px;
+	left: 1px;
 	border-radius: 1.5rem;
 	background: #fff;
 	-moz-transition: .20s ease-in-out;
@@ -372,12 +372,12 @@ ul.pagination {
 }
 
 .checkbox-ios input[type=checkbox]:checked + label:before {
-	width: 3.5rem;
+	width: 60px;
 	background: #007bff;
 }
 
 .checkbox-ios input[type=checkbox]:checked + label:after {
-	left: 1.77rem;
+	left: 31px;
 }
 
 /* Bootstrap fixes */

File diff suppressed because it is too large
+ 0 - 0
assets/cp.styles.css.go


+ 1 - 1
consts/consts.go

@@ -5,7 +5,7 @@ import (
 )
 
 const ServerVersion = "1.0.0"
-const AssetsVersion = "12"
+const AssetsVersion = "14"
 const AssetsPath = "assets"
 const DirIndexFile = "index.html"
 

+ 5 - 1
hosts/localhost/htdocs/styles.css

@@ -25,7 +25,7 @@
 /* Base font and colors */
 body {
 	color: #444;
-	font-size: 1.2rem;
+	font-size: 1.0rem;
 	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
 }
 
@@ -49,6 +49,10 @@ footer {
 	font-weight: bold;
 }
 
+h1 {
+	font-size: 250%;
+}
+
 /* Nice sticky footer */
 html,
 body {

+ 1 - 1
modules/module_index.go

@@ -242,7 +242,7 @@ func (this *Modules) RegisterModule_Index() *Module {
 					Caption: "Page alias",
 					Name:    "alias",
 					Value:   data.A_alias,
-					Hint:    "Example: /about-us/ or /about-us.html or /about/team.html",
+					Hint:    "Example: /about-us/ or /about-us.html",
 				},
 				{
 					Kind:    builder.DFKTextArea,

+ 16 - 3
utils/utils.go

@@ -11,6 +11,7 @@ import (
 	"strconv"
 	"strings"
 	"time"
+	"unicode/utf16"
 
 	"golang-fave/assets"
 	"golang-fave/consts"
@@ -67,7 +68,7 @@ func FixPath(path string) string {
 		return newPath
 	}
 	if newPath[len(newPath)-1] == '/' || newPath[len(newPath)-1] == '\\' {
-		newPath = newPath[0 : len(newPath)-2]
+		newPath = newPath[0 : len(newPath)-1]
 	}
 	return newPath
 }
@@ -187,12 +188,22 @@ func SystemErrorPage404(w http.ResponseWriter) {
 
 func UrlToArray(url string) []string {
 	url_buff := url
+
+	// Remove GET parameters
+	i := strings.Index(url_buff, "?")
+	if i > -1 {
+		url_buff = url_buff[:i]
+	}
+
+	// Cut slashes
 	if len(url_buff) >= 1 && url_buff[:1] == "/" {
 		url_buff = url_buff[1:]
 	}
 	if len(url_buff) >= 1 && url_buff[len(url_buff)-1:] == "/" {
 		url_buff = url_buff[:len(url_buff)-1]
 	}
+
+	// Explode
 	if url_buff == "" {
 		return []string{}
 	} else {
@@ -217,13 +228,15 @@ func GenerateAlias(str string) string {
 		return ""
 	}
 
+	strc := utf16.Encode([]rune(str))
+
 	lat := []string{"EH", "I", "i", "#", "eh", "A", "B", "V", "G", "D", "E", "JO", "ZH", "Z", "I", "JJ", "K", "L", "M", "N", "O", "P", "R", "S", "T", "U", "F", "KH", "C", "CH", "SH", "SHH", "'", "Y", "", "EH", "YU", "YA", "a", "b", "v", "g", "d", "e", "jo", "zh", "z", "i", "jj", "k", "l", "m", "n", "o", "p", "r", "s", "t", "u", "f", "kh", "c", "ch", "sh", "shh", "", "y", "", "eh", "yu", "ya", "", "", "-", "-", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "-", "-", ":", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M"}
 	cyr := []string{"Є", "І", "і", "№", "є", "А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И", "Й", "К", "Л", "М", "Н", "О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ы", "Ь", "Э", "Ю", "Я", "а", "б", "в", "г", "д", "е", "ё", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы", "ь", "э", "ю", "я", "«", "»", "—", " ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "", "", "a", "s", "d", "f", "g", "h", "j", "k", "l", "", "", "z", "x", "c", "v", "b", "n", "m", "", "", "", "(", ")", "", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M"}
 
 	var alias string = ""
-	for i := 0; i < len(str); i++ {
+	for i := 0; i < len(strc); i++ {
 		for j := 0; j < len(cyr); j++ {
-			if string(str[i]) == cyr[j] {
+			if string(strc[i]) == cyr[j] {
 				alias += lat[j]
 			}
 		}

+ 189 - 0
utils/utils_test.go

@@ -0,0 +1,189 @@
+package utils
+
+import (
+	"errors"
+	"testing"
+	"time"
+
+	"golang-fave/consts"
+)
+
+func Expect(t *testing.T, actual, expect interface{}) {
+	if actual != expect {
+		t.Fatalf("\033[0;33mExpected \033[0;32m`%v`\033[0;33m but got \033[0;31m`%v`\033[0m",
+			expect, actual)
+	}
+}
+
+func TestIsFileExists(t *testing.T) {
+	Expect(t, IsFileExists("./../testdata/screenshots.gif"), true)
+	Expect(t, IsFileExists("./../testdata/no-existed-file"), false)
+}
+
+func TestIsDir(t *testing.T) {
+	Expect(t, IsDir("./../testdata"), true)
+	Expect(t, IsDir("./../testdata/screenshots.gif"), false)
+	Expect(t, IsDir("./../testdata/no-existed-dir"), false)
+}
+
+func TestIsDirExists(t *testing.T) {
+	Expect(t, IsDirExists("./../testdata"), true)
+	Expect(t, IsDirExists("./../testdata/screenshots.gif"), false)
+	Expect(t, IsDirExists("./../testdata/no-existed-dir"), false)
+}
+
+func TestIsNumeric(t *testing.T) {
+	Expect(t, IsNumeric("12345"), true)
+	Expect(t, IsNumeric("string"), false)
+}
+
+func TestIsValidEmail(t *testing.T) {
+	Expect(t, IsValidEmail("test@gmail.com"), true)
+	Expect(t, IsValidEmail("test@yandex.ru"), true)
+	Expect(t, IsValidEmail("test@ya.ru"), true)
+	Expect(t, IsValidEmail("test@test"), false)
+}
+
+func TestIsValidAlias(t *testing.T) {
+	Expect(t, IsValidAlias("/"), true)
+	Expect(t, IsValidAlias("/some-page/"), true)
+	Expect(t, IsValidAlias("/some-page.html"), true)
+	Expect(t, IsValidAlias("/some-page.html/"), true)
+	Expect(t, IsValidAlias(""), false)
+	Expect(t, IsValidAlias("some-page"), false)
+	Expect(t, IsValidAlias("/some page/"), false)
+}
+
+func TestFixPath(t *testing.T) {
+	Expect(t, FixPath(""), "")
+	Expect(t, FixPath("/"), "")
+	Expect(t, FixPath("./dir"), "./dir")
+	Expect(t, FixPath("./dir/"), "./dir")
+	Expect(t, FixPath("\\dir"), "\\dir")
+	Expect(t, FixPath("\\dir\\"), "\\dir")
+}
+
+func TestExtractHostPort(t *testing.T) {
+	h, p := ExtractHostPort("localhost:8080", false)
+	Expect(t, h, "localhost")
+	Expect(t, p, "8080")
+
+	h, p = ExtractHostPort("localhost:80", false)
+	Expect(t, h, "localhost")
+	Expect(t, p, "80")
+
+	h, p = ExtractHostPort("localhost", false)
+	Expect(t, h, "localhost")
+	Expect(t, p, "80")
+
+	h, p = ExtractHostPort("localhost", true)
+	Expect(t, h, "localhost")
+	Expect(t, p, "443")
+}
+
+func TestGetAssetsUrl(t *testing.T) {
+	Expect(t, GetAssetsUrl("style.css"), "/style.css?v="+consts.AssetsVersion)
+}
+
+func TestGetTmplSystemData(t *testing.T) {
+	Expect(t, GetTmplSystemData(), consts.TmplSystem{
+		PathIcoFav:       "/assets/sys/fave.ico?v=" + consts.AssetsVersion,
+		PathSvgLogo:      "/assets/sys/logo.svg?v=" + consts.AssetsVersion,
+		PathCssStyles:    "/assets/sys/styles.css?v=" + consts.AssetsVersion,
+		PathCssCpStyles:  "/assets/cp/styles.css?v=" + consts.AssetsVersion,
+		PathCssBootstrap: "/assets/bootstrap.css?v=" + consts.AssetsVersion,
+		PathJsJquery:     "/assets/jquery.js?v=" + consts.AssetsVersion,
+		PathJsPopper:     "/assets/popper.js?v=" + consts.AssetsVersion,
+		PathJsBootstrap:  "/assets/bootstrap.js?v=" + consts.AssetsVersion,
+		PathJsCpScripts:  "/assets/cp/scripts.js?v=" + consts.AssetsVersion,
+	})
+}
+
+func TestGetTmplError(t *testing.T) {
+	Expect(t, GetTmplError(errors.New("some error")), consts.TmplError{
+		ErrorMessage: "some error",
+	})
+}
+
+func TestGetMd5(t *testing.T) {
+	Expect(t, GetMd5("some string"), "5ac749fbeec93607fc28d666be85e73a")
+}
+
+func TestGetCurrentUnixTimestamp(t *testing.T) {
+	Expect(t, GetCurrentUnixTimestamp(), int64(time.Now().Unix()))
+}
+
+func TestSystemRenderTemplate(t *testing.T) {
+	//
+}
+
+func TestSystemErrorPageEngine(t *testing.T) {
+	//
+}
+
+func TestSystemErrorPageTemplate(t *testing.T) {
+	//
+}
+
+func TestSystemErrorPage404(t *testing.T) {
+	//
+}
+
+func TestUrlToArray(t *testing.T) {
+	a := UrlToArray("/some/url")
+	Expect(t, len(a), 2)
+	Expect(t, a[0], "some")
+	Expect(t, a[1], "url")
+
+	a = UrlToArray("/some/url/")
+	Expect(t, len(a), 2)
+	Expect(t, a[0], "some")
+	Expect(t, a[1], "url")
+
+	a = UrlToArray("/some/url?a=1&b=2")
+	Expect(t, len(a), 2)
+	Expect(t, a[0], "some")
+	Expect(t, a[1], "url")
+
+	a = UrlToArray("/some/url/?a=1&b=2")
+	Expect(t, len(a), 2)
+	Expect(t, a[0], "some")
+	Expect(t, a[1], "url")
+}
+
+func TestIntToStr(t *testing.T) {
+	Expect(t, IntToStr(2000), "2000")
+}
+
+func TestStrToInt(t *testing.T) {
+	Expect(t, StrToInt("2000"), 2000)
+	Expect(t, StrToInt("string"), 0)
+}
+
+func TestGenerateAlias(t *testing.T) {
+	Expect(t, GenerateAlias(""), "")
+	Expect(t, GenerateAlias("Some page name"), "/some-page-name/")
+	Expect(t, GenerateAlias("Some page name 2"), "/some-page-name-2/")
+	Expect(t, GenerateAlias("Какая то страница"), "/kakaya-to-stranica/")
+	Expect(t, GenerateAlias("Какая то страница 2"), "/kakaya-to-stranica-2/")
+}
+
+func TestUnixTimestampToMySqlDateTime(t *testing.T) {
+	Expect(t, UnixTimestampToMySqlDateTime(1551741275), "2019-03-05 01:14:35")
+}
+
+func TestUnixTimestampToFormat(t *testing.T) {
+	Expect(t, UnixTimestampToFormat(1551741275, "2006/01/02 15:04"), "2019/03/05 01:14")
+}
+
+func TestExtractGetParams(t *testing.T) {
+	Expect(t, ExtractGetParams("/some-url"), "")
+	Expect(t, ExtractGetParams("/some-url/"), "")
+	Expect(t, ExtractGetParams("/some-url?a=1&b=2"), "?a=1&b=2")
+	Expect(t, ExtractGetParams("/some-url/?a=1&b=2"), "?a=1&b=2")
+}
+
+func TestJavaScriptVarValue(t *testing.T) {
+	Expect(t, JavaScriptVarValue(`It's "string"`), "It&rsquo;s &rdquo;string&rdquo;")
+	Expect(t, JavaScriptVarValue(`It is string`), "It is string")
+}

Some files were not shown because too many files changed in this diff