fix typos in struct names
This commit is contained in:
+11
-11
@@ -219,19 +219,19 @@ func New(opts Opts) (*Application, error) {
|
||||
|
||||
authProviders := makeAuthProviders(jwtService, avatarProxy, dataService, opts)
|
||||
imgProxy := &proxy.Image{Enabled: opts.ImageProxy, RoutePath: "/api/v1/img", RemarkURL: opts.RemarkURL}
|
||||
commentFormater := store.NewCommentFormater(imgProxy)
|
||||
commentFormatter := store.NewCommentFormatter(imgProxy)
|
||||
|
||||
srv := &api.Rest{
|
||||
Version: revision,
|
||||
DataService: dataService,
|
||||
Exporter: exporter,
|
||||
WebRoot: opts.WebRoot,
|
||||
RemarkURL: opts.RemarkURL,
|
||||
ImageProxy: imgProxy,
|
||||
CommentFormater: commentFormater,
|
||||
AvatarProxy: avatarProxy,
|
||||
ReadOnlyAge: opts.ReadOnlyAge,
|
||||
SharedSecret: opts.SharedSecret,
|
||||
Version: revision,
|
||||
DataService: dataService,
|
||||
Exporter: exporter,
|
||||
WebRoot: opts.WebRoot,
|
||||
RemarkURL: opts.RemarkURL,
|
||||
ImageProxy: imgProxy,
|
||||
CommentFormatter: commentFormatter,
|
||||
AvatarProxy: avatarProxy,
|
||||
ReadOnlyAge: opts.ReadOnlyAge,
|
||||
SharedSecret: opts.SharedSecret,
|
||||
Authenticator: auth.Authenticator{
|
||||
JWTService: jwtService,
|
||||
AdminEmail: opts.AdminEmail,
|
||||
|
||||
@@ -34,13 +34,13 @@ import (
|
||||
type Rest struct {
|
||||
Version string
|
||||
|
||||
DataService *service.DataStore
|
||||
Authenticator auth.Authenticator
|
||||
Exporter migrator.Exporter
|
||||
Cache cache.LoadingCache
|
||||
AvatarProxy *proxy.Avatar
|
||||
ImageProxy *proxy.Image
|
||||
CommentFormater *store.CommentFormater
|
||||
DataService *service.DataStore
|
||||
Authenticator auth.Authenticator
|
||||
Exporter migrator.Exporter
|
||||
Cache cache.LoadingCache
|
||||
AvatarProxy *proxy.Avatar
|
||||
ImageProxy *proxy.Image
|
||||
CommentFormatter *store.CommentFormatter
|
||||
|
||||
WebRoot string
|
||||
RemarkURL string
|
||||
|
||||
@@ -43,7 +43,7 @@ func (s *Rest) createCommentCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
rest.SendErrorJSON(w, r, http.StatusBadRequest, err, "invalid comment")
|
||||
return
|
||||
}
|
||||
comment = s.CommentFormater.Format(comment)
|
||||
comment = s.CommentFormatter.Format(comment)
|
||||
|
||||
// check if user blocked
|
||||
if s.adminService.checkBlocked(comment.Locator.SiteID, comment.User) {
|
||||
@@ -109,7 +109,7 @@ func (s *Rest) updateCommentCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
editReq := service.EditRequest{
|
||||
Text: s.CommentFormater.FormatText(edit.Text),
|
||||
Text: s.CommentFormatter.FormatText(edit.Text),
|
||||
Orig: edit.Text,
|
||||
Summary: edit.Summary,
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func (s *Rest) previewCommentCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
comment = s.CommentFormater.Format(comment)
|
||||
comment = s.CommentFormatter.Format(comment)
|
||||
comment.Sanitize()
|
||||
render.HTML(w, r, comment.Text)
|
||||
}
|
||||
|
||||
@@ -91,14 +91,14 @@ func prep(t *testing.T) (srv *Rest, ts *httptest.Server) {
|
||||
AdminEmail: "admin@remark-42.com",
|
||||
JWTService: auth.NewJWT(keys.NewStaticStore("123456"), false, time.Minute, time.Hour),
|
||||
},
|
||||
Exporter: &migrator.Remark{DataStore: dataStore},
|
||||
Cache: &cache.Nop{},
|
||||
WebRoot: "/tmp",
|
||||
RemarkURL: "https://demo.remark42.com",
|
||||
AvatarProxy: &proxy.Avatar{Store: avatar.NewLocalFS("/tmp", 300), RoutePath: "/api/v1/avatar"},
|
||||
ImageProxy: &proxy.Image{},
|
||||
ReadOnlyAge: 10,
|
||||
CommentFormater: store.NewCommentFormater(&proxy.Image{}),
|
||||
Exporter: &migrator.Remark{DataStore: dataStore},
|
||||
Cache: &cache.Nop{},
|
||||
WebRoot: "/tmp",
|
||||
RemarkURL: "https://demo.remark42.com",
|
||||
AvatarProxy: &proxy.Avatar{Store: avatar.NewLocalFS("/tmp", 300), RoutePath: "/api/v1/avatar"},
|
||||
ImageProxy: &proxy.Image{},
|
||||
ReadOnlyAge: 10,
|
||||
CommentFormatter: store.NewCommentFormatter(&proxy.Image{}),
|
||||
}
|
||||
srv.ScoreThresholds.Low, srv.ScoreThresholds.Critical = -5, -10
|
||||
|
||||
|
||||
@@ -8,30 +8,30 @@ import (
|
||||
blackfriday "gopkg.in/russross/blackfriday.v2"
|
||||
)
|
||||
|
||||
// CommentFormater implements all generic formatings ops on comment
|
||||
type CommentFormater struct {
|
||||
// CommentFormatter implements all generic formatting ops on comment
|
||||
type CommentFormatter struct {
|
||||
converters []CommentConverter
|
||||
}
|
||||
|
||||
// CommentConverter defines interface to convert some parts of commentHTML
|
||||
// Passed at creation time and does client-defined convertions, like image proxy link change
|
||||
// Passed at creation time and does client-defined conversions, like image proxy link change
|
||||
type CommentConverter interface {
|
||||
Convert(text string) string
|
||||
}
|
||||
|
||||
// NewCommentFormater makes CommentFormater
|
||||
func NewCommentFormater(converters ...CommentConverter) *CommentFormater {
|
||||
return &CommentFormater{converters: converters}
|
||||
// NewCommentFormatter makes CommentFormatter
|
||||
func NewCommentFormatter(converters ...CommentConverter) *CommentFormatter {
|
||||
return &CommentFormatter{converters: converters}
|
||||
}
|
||||
|
||||
// Format comment fields
|
||||
func (f *CommentFormater) Format(c Comment) Comment {
|
||||
func (f *CommentFormatter) Format(c Comment) Comment {
|
||||
c.Text = f.FormatText(c.Text)
|
||||
return c
|
||||
}
|
||||
|
||||
// FormatText formatting line
|
||||
func (f *CommentFormater) FormatText(txt string) (res string) {
|
||||
func (f *CommentFormatter) FormatText(txt string) (res string) {
|
||||
mdExt := blackfriday.NoIntraEmphasis | blackfriday.Tables | blackfriday.FencedCode |
|
||||
blackfriday.Strikethrough | blackfriday.SpaceHeadings | blackfriday.HardLineBreak |
|
||||
blackfriday.BackslashLineBreak | blackfriday.Autolink
|
||||
@@ -45,7 +45,7 @@ func (f *CommentFormater) FormatText(txt string) (res string) {
|
||||
}
|
||||
|
||||
// Shortens all the automatic links in HTML: auto link has equal "href" and "text" attributes.
|
||||
func (f *CommentFormater) shortenAutoLinks(commentHTML string, max int) (resHTML string) {
|
||||
func (f *CommentFormatter) shortenAutoLinks(commentHTML string, max int) (resHTML string) {
|
||||
doc, err := goquery.NewDocumentFromReader(strings.NewReader(commentHTML))
|
||||
if err != nil {
|
||||
return commentHTML
|
||||
@@ -55,12 +55,12 @@ func (f *CommentFormater) shortenAutoLinks(commentHTML string, max int) (resHTML
|
||||
if href != s.Text() || len(href) < max+3 || max < 3 {
|
||||
return
|
||||
}
|
||||
url, e := url.Parse(href)
|
||||
commentURL, e := url.Parse(href)
|
||||
if e != nil {
|
||||
return
|
||||
}
|
||||
url.Path, url.RawQuery, url.Fragment = "", "", ""
|
||||
host := url.String()
|
||||
commentURL.Path, commentURL.RawQuery, commentURL.Fragment = "", "", ""
|
||||
host := commentURL.String()
|
||||
if host == "" {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type mockConvertor struct{}
|
||||
type mockConverter struct{}
|
||||
|
||||
func (m mockConvertor) Convert(text string) string { return text + "!converted" }
|
||||
func (m mockConverter) Convert(text string) string { return text + "!converted" }
|
||||
|
||||
func TestFormater_FormatText(t *testing.T) {
|
||||
func TestFormatter_FormatText(t *testing.T) {
|
||||
tbl := []struct {
|
||||
in, out string
|
||||
}{
|
||||
@@ -22,18 +22,18 @@ func TestFormater_FormatText(t *testing.T) {
|
||||
"http://127.0.0.1/some-long-link/12345/678901234567890", "<p><a href=\"http://127.0.0.1/some-long-link/12345/678901234567890\">http://127.0.0.1/some-long-link/12345/6789012...</a></p>\n!converted",
|
||||
},
|
||||
}
|
||||
f := NewCommentFormater(mockConvertor{})
|
||||
f := NewCommentFormatter(mockConverter{})
|
||||
for n, tt := range tbl {
|
||||
assert.Equal(t, tt.out, f.FormatText(tt.in), "check #%d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormater_FormatTextNoConvertor(t *testing.T) {
|
||||
f := NewCommentFormater()
|
||||
func TestFormatter_FormatTextNoConvertor(t *testing.T) {
|
||||
f := NewCommentFormatter()
|
||||
assert.Equal(t, "<p>12345</p>\n", f.FormatText("12345"))
|
||||
}
|
||||
|
||||
func TestFormater_FormatComment(t *testing.T) {
|
||||
func TestFormatter_FormatComment(t *testing.T) {
|
||||
comment := Comment{
|
||||
Text: `blah`,
|
||||
User: User{ID: "username"},
|
||||
@@ -47,14 +47,14 @@ func TestFormater_FormatComment(t *testing.T) {
|
||||
Votes: map[string]bool{"uu": true},
|
||||
}
|
||||
|
||||
f := NewCommentFormater(mockConvertor{})
|
||||
f := NewCommentFormatter(mockConverter{})
|
||||
exp := comment
|
||||
exp.Text = "<p>blah</p>\n!converted"
|
||||
assert.Equal(t, exp, f.Format(comment))
|
||||
}
|
||||
|
||||
func TestFormater_ShortenAutoLinks(t *testing.T) {
|
||||
f := NewCommentFormater(nil)
|
||||
func TestFormatter_ShortenAutoLinks(t *testing.T) {
|
||||
f := NewCommentFormatter(nil)
|
||||
tbl := []struct {
|
||||
max int
|
||||
in, out string
|
||||
|
||||
Reference in New Issue
Block a user