From 617e36bc52127f7412de16fb1f1df21d25336038 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 19 Apr 2018 22:01:28 +0200 Subject: [PATCH] Refactor search and stringutils into separate modules --- mixins/Japanese.pixy | 2 +- mixins/Postable.pixy | 2 +- mixins/Rating.pixy | 4 ++-- pages/anime/anime.pixy | 2 +- pages/editor/editor.pixy | 6 +++--- pages/popular/animetitles.go | 3 ++- pages/profile/profile.pixy | 4 ++-- pages/search/search.go | 17 +++++++++-------- pages/shop/shop.pixy | 2 +- pages/statistics/anime.go | 4 +++- pages/statistics/statistics.go | 2 +- patches/add-song-titles/add-song-titles.go | 2 +- 12 files changed, 27 insertions(+), 23 deletions(-) diff --git a/mixins/Japanese.pixy b/mixins/Japanese.pixy index 9ebe2bbd..4945e16a 100644 --- a/mixins/Japanese.pixy +++ b/mixins/Japanese.pixy @@ -1,5 +1,5 @@ component Japanese(text string) - if arn.ContainsUnicodeLetters(text) + if stringutils.ContainsUnicodeLetters(text) for _, token := range arn.JapaneseTokenizer.Tokenize(text) if token.Furigana a.japanese(href="http://jisho.org/search/" + token.Original, target="_blank", rel="noopener") diff --git a/mixins/Postable.pixy b/mixins/Postable.pixy index 61c31ba7..2349c1db 100644 --- a/mixins/Postable.pixy +++ b/mixins/Postable.pixy @@ -27,7 +27,7 @@ component Postable(post arn.Postable, user *arn.User, highlightAuthorID string) .post-toolbar(id="toolbar-" + post.ID()) .spacer - .post-likes.tip(id="likes-" + post.ID(), aria-label=arn.Plural(len(post.Likes()), "like"))= "+" + strconv.Itoa(len(post.Likes())) + .post-likes.tip(id="likes-" + post.ID(), aria-label=stringutils.Plural(len(post.Likes()), "like"))= "+" + strconv.Itoa(len(post.Likes())) if user != nil if user.ID != post.Creator().ID diff --git a/mixins/Rating.pixy b/mixins/Rating.pixy index 71cb0016..59ab724a 100644 --- a/mixins/Rating.pixy +++ b/mixins/Rating.pixy @@ -1,5 +1,5 @@ component Rating(value float64, userCount int, user *arn.User) if user == nil - .anime-rating.tip(aria-label="Rated by " + arn.Plural(userCount, "user"))= fmt.Sprintf("%.1f", value) + .anime-rating.tip(aria-label="Rated by " + stringutils.Plural(userCount, "user"))= fmt.Sprintf("%.1f", value) else - .anime-rating.tip(aria-label="Rated by " + arn.Plural(userCount, "user"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value) \ No newline at end of file + .anime-rating.tip(aria-label="Rated by " + stringutils.Plural(userCount, "user"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value) \ No newline at end of file diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index dcf9607b..674b67c4 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -214,7 +214,7 @@ component AnimeInformation(anime *arn.Anime) tr.mountable(data-mountable-type="info") td.anime-info-key Season: td.anime-info-value - a(href="/explore/anime/" + anime.StartDate[:4] + "/" + strings.ToLower(anime.Season()) + "/any/" + anime.Type)= arn.Capitalize(anime.Season()) + " " + anime.StartDate[:4] + a(href="/explore/anime/" + anime.StartDate[:4] + "/" + strings.ToLower(anime.Season()) + "/any/" + anime.Type)= stringutils.Capitalize(anime.Season()) + " " + anime.StartDate[:4] if anime.Source != "" && arn.AnimeSourceHumanReadable[anime.Source] != "" tr.mountable(data-mountable-type="info") diff --git a/pages/editor/editor.pixy b/pages/editor/editor.pixy index 544ebfde..dab19e2b 100644 --- a/pages/editor/editor.pixy +++ b/pages/editor/editor.pixy @@ -7,21 +7,21 @@ component Editor(url string, score int, scoreTitle string, scoreTypes map[string RawIcon("tv") .feature-card-text p Anime - p.editor-score= arn.Plural(scoreTypes["Anime"], "contribution") + p.editor-score= stringutils.Plural(scoreTypes["Anime"], "contribution") a.feature-card.mountable(href="/editor/soundtracks/links") .feature-card-icon.feature-card-color-soundtrack RawIcon("music") .feature-card-text p SoundTracks - p.editor-score= arn.Plural(scoreTypes["SoundTrack"], "contribution") + p.editor-score= stringutils.Plural(scoreTypes["SoundTrack"], "contribution") a.feature-card.mountable(href="/editor/companies/description") .feature-card-icon.feature-card-color-company RawIcon("building-o") .feature-card-text p Companies - p.editor-score= arn.Plural(scoreTypes["Company"], "contribution") + p.editor-score= stringutils.Plural(scoreTypes["Company"], "contribution") .footer.mountable a.footer-element(href="/editor/mal/diff/anime" + user.Settings().Editor.Filter.Suffix()) MALdiff diff --git a/pages/popular/animetitles.go b/pages/popular/animetitles.go index 5acb6da3..4e8c4803 100644 --- a/pages/popular/animetitles.go +++ b/pages/popular/animetitles.go @@ -5,6 +5,7 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" + "github.com/animenotifier/arn/stringutils" ) // AnimeTitles returns a list of the 500 most popular anime titles. @@ -26,7 +27,7 @@ func AnimeTitles(ctx *aero.Context) string { for _, anime := range popularAnime { popularAnimeTitles = append(popularAnimeTitles, anime.Title.Canonical) - if arn.ContainsUnicodeLetters(anime.Title.Japanese) { + if stringutils.ContainsUnicodeLetters(anime.Title.Japanese) { popularAnimeTitles = append(popularAnimeTitles, anime.Title.Japanese) } } diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 781baffd..020471aa 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -71,7 +71,7 @@ component ProfileHead(viewUser *arn.User, user *arn.User, uri string) a(href="https://osu.ppy.sh/u/" + viewUser.Accounts.Osu.Nick, target="_blank", rel="noopener")= toString(int(viewUser.Accounts.Osu.PP)) + " pp" if viewUser.Accounts.Overwatch.BattleTag != "" && viewUser.Accounts.Overwatch.SkillRating >= 1000 - p.profile-field.overwatch(title=arn.Capitalize(viewUser.Accounts.Overwatch.Tier) + " (Overwatch)") + p.profile-field.overwatch(title=stringutils.Capitalize(viewUser.Accounts.Overwatch.Tier) + " (Overwatch)") Icon("overwatch") a(href="https://playoverwatch.com/en-us/career/pc/" + strings.Replace(viewUser.Accounts.Overwatch.BattleTag, "#", "-", 1), target="_blank", rel="noopener")= toString(viewUser.Accounts.Overwatch.SkillRating) + " SR" @@ -90,7 +90,7 @@ component ProfileHead(viewUser *arn.User, user *arn.User, uri string) if viewUser.Role != "" p.profile-field.role Icon("rocket") - span= arn.Capitalize(viewUser.Role) + span= stringutils.Capitalize(viewUser.Role) if viewUser.IsPro() p.profile-field.profile-pro-status diff --git a/pages/search/search.go b/pages/search/search.go index 6696ef27..be796e93 100644 --- a/pages/search/search.go +++ b/pages/search/search.go @@ -7,6 +7,7 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" + "github.com/animenotifier/arn/search" "github.com/animenotifier/notify.moe/components" ) @@ -25,7 +26,7 @@ func Get(ctx *aero.Context) string { term := ctx.Get("term") term = strings.TrimPrefix(term, "/") - users, animes, posts, threads, tracks, characters, companies := arn.Search( + users, animes, posts, threads, tracks, characters, companies := search.All( term, maxUsers, maxAnime, @@ -49,7 +50,7 @@ func Anime(ctx *aero.Context) string { term := ctx.Get("term") term = strings.TrimPrefix(term, "/") - animes := arn.SearchAnime(term, maxAnime) + animes := search.Anime(term, maxAnime) return ctx.HTML(components.AnimeSearchResults(animes)) } @@ -58,7 +59,7 @@ func Characters(ctx *aero.Context) string { term := ctx.Get("term") term = strings.TrimPrefix(term, "/") - characters := arn.SearchCharacters(term, maxCharacters) + characters := search.Characters(term, maxCharacters) return ctx.HTML(components.CharacterSearchResults(characters)) } @@ -71,9 +72,9 @@ func Forum(ctx *aero.Context) string { var threads []*arn.Thread flow.Parallel(func() { - posts = arn.SearchPosts(term, maxPosts) + posts = search.Posts(term, maxPosts) }, func() { - threads = arn.SearchThreads(term, maxThreads) + threads = search.Threads(term, maxThreads) }) return ctx.HTML(components.ForumSearchResults(posts, threads)) @@ -84,7 +85,7 @@ func SoundTracks(ctx *aero.Context) string { term := ctx.Get("term") term = strings.TrimPrefix(term, "/") - tracks := arn.SearchSoundTracks(term, maxSoundTracks) + tracks := search.SoundTracks(term, maxSoundTracks) return ctx.HTML(components.SoundTrackSearchResults(tracks)) } @@ -93,7 +94,7 @@ func Users(ctx *aero.Context) string { term := ctx.Get("term") term = strings.TrimPrefix(term, "/") - users := arn.SearchUsers(term, maxUsers) + users := search.Users(term, maxUsers) return ctx.HTML(components.UserSearchResults(users)) } @@ -102,6 +103,6 @@ func Companies(ctx *aero.Context) string { term := ctx.Get("term") term = strings.TrimPrefix(term, "/") - companies := arn.SearchCompanies(term, maxCompanies) + companies := search.Companies(term, maxCompanies) return ctx.HTML(components.CompanySearchResults(companies)) } diff --git a/pages/shop/shop.pixy b/pages/shop/shop.pixy index 5eef38a8..cdcc0548 100644 --- a/pages/shop/shop.pixy +++ b/pages/shop/shop.pixy @@ -24,7 +24,7 @@ component ShopItem(item *arn.ShopItem, popularity int) .shop-item-info-column h3.shop-item-name= item.Name - .shop-item-popularity= arn.Plural(popularity, "user") + " bought this" + .shop-item-popularity= stringutils.Plural(popularity, "user") + " bought this" //- span.shop-item-duration= " " + duration //- .shop-item-description!= markdown.Render(item.Description) diff --git a/pages/statistics/anime.go b/pages/statistics/anime.go index b8814a4a..1a1d3457 100644 --- a/pages/statistics/anime.go +++ b/pages/statistics/anime.go @@ -1,6 +1,8 @@ package statistics import ( + "fmt" + "github.com/aerogo/aero" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" @@ -47,7 +49,7 @@ func getAnimeStats() []*arn.PieChart { anidb["Not connected with AniDB"]++ } - rating[arn.ToString(int(anime.Rating.Overall+0.5))]++ + rating[fmt.Sprint(int(anime.Rating.Overall+0.5))]++ found := false for _, episode := range anime.Episodes().Items { diff --git a/pages/statistics/statistics.go b/pages/statistics/statistics.go index 346d03c3..a95d6992 100644 --- a/pages/statistics/statistics.go +++ b/pages/statistics/statistics.go @@ -42,7 +42,7 @@ func getUserStats() []*arn.PieChart { pixelRatio[fmt.Sprintf("%.0f", info.Screen.PixelRatio)]++ - size := arn.ToString(info.Screen.Width) + " x " + arn.ToString(info.Screen.Height) + size := fmt.Sprint(info.Screen.Width) + " x " + fmt.Sprint(info.Screen.Height) screenSize[size]++ if info.Connection.EffectiveType != "" { diff --git a/patches/add-song-titles/add-song-titles.go b/patches/add-song-titles/add-song-titles.go index 5f14bc54..e7c10dda 100644 --- a/patches/add-song-titles/add-song-titles.go +++ b/patches/add-song-titles/add-song-titles.go @@ -4,7 +4,7 @@ func main() { // defer arn.Node.Close() // for track := range arn.StreamSoundTracks() { - // if arn.ContainsUnicodeLetters(track.Title) { + // if stringutils.ContainsUnicodeLetters(track.Title) { // track.Title.Native = track.Title // } else { // track.Title.Canonical = track.Title