本文整理匯總了Golang中bitbucket/org/pkg/inflect.Pluralize函數的典型用法代碼示例。如果您正苦於以下問題:Golang Pluralize函數的具體用法?Golang Pluralize怎麽用?Golang Pluralize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Pluralize函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: pluralize
func pluralize(c int, s string, format bool) string {
if c == 1 {
if format {
return fmt.Sprintf("1 %s", inflect.Singularize(s))
}
return fmt.Sprintf("%s", inflect.Singularize(s))
}
if format {
return fmt.Sprintf("%d %s", c, inflect.Pluralize(s))
}
return fmt.Sprintf("%s", inflect.Pluralize(s))
}
示例2: pluralize
// pluralize returns the plural form of a single word.
func pluralize(in interface{}) (string, error) {
word, err := cast.ToStringE(in)
if err != nil {
return "", err
}
return inflect.Pluralize(word), nil
}
示例3: RenderLists
func (s *Site) RenderLists() error {
for section, data := range s.Sections {
n := s.NewNode()
n.Title = strings.Title(inflect.Pluralize(section))
n.Url = Urlize(section + "/" + "index.html")
n.Permalink = template.HTML(MakePermalink(string(n.Site.BaseUrl), string(n.Url)))
n.RSSlink = template.HTML(MakePermalink(string(n.Site.BaseUrl), string(section+".xml")))
n.Date = data[0].Date
n.Data["Pages"] = data
layout := "indexes" + slash + section + ".html"
x, err := s.RenderThing(n, layout)
if err != nil {
return err
}
s.WritePublic(section+slash+"index.html", x.Bytes())
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
// XML Feed
if s.Config.UglyUrls {
n.Url = Urlize(section + ".xml")
} else {
n.Url = Urlize(section + "/" + "index.xml")
}
n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url)
y := s.NewXMLBuffer()
s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
s.WritePublic(section+slash+"index.xml", y.Bytes())
}
}
return nil
}
示例4: RenderLists
func (s *Site) RenderLists() error {
for section, data := range s.Sections {
n := s.NewNode()
n.Title = strings.Title(inflect.Pluralize(section))
s.setUrls(n, section)
n.Date = data[0].Page.Date
n.Data["Pages"] = data.Pages()
layout := "indexes/" + section + ".html"
err := s.render(n, section, layout, "_default/indexes.html")
if err != nil {
return err
}
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
// XML Feed
s.setUrls(n, section+".xml")
err = s.render(n, section+".xml", "rss.xml")
if err != nil {
return err
}
}
}
return nil
}
示例5: plural
func plural(qty int, singular string) string {
s := singular
if qty != 1 {
s = inflect.Pluralize(s)
}
return fmt.Sprintf("%d %s", qty, s)
}
示例6: RenderSectionLists
// Render a page for each section
func (s *Site) RenderSectionLists() error {
for section, data := range s.Sections {
n := s.NewNode()
if viper.GetBool("PluralizeListTitles") {
n.Title = strings.Title(inflect.Pluralize(section))
} else {
n.Title = strings.Title(section)
}
s.setUrls(n, section)
n.Date = data[0].Page.Date
n.Data["Pages"] = data.Pages()
layouts := []string{"section/" + section + ".html", "_default/section.html", "_default/list.html", "indexes/" + section + ".html", "_default/indexes.html"}
err := s.render(n, section, s.appendThemeTemplates(layouts)...)
if err != nil {
return err
}
if !viper.GetBool("DisableRSS") {
// XML Feed
rssLayouts := []string{"section/" + section + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}
s.setUrls(n, section+".xml")
err = s.render(n, section+".xml", s.appendThemeTemplates(rssLayouts)...)
if err != nil {
return err
}
}
}
return nil
}
示例7: CreateCustomObject
func (fm *ForceMetadata) CreateCustomObject(object string) (err error) {
fld := ""
fld = strings.ToUpper(object)
fld = fld[0:1]
soap := `
<metadata xsi:type="CustomObject" xmlns:cmd="http://soap.sforce.com/2006/04/metadata">
<fullName>%s__c</fullName>
<label>%s</label>
<pluralLabel>%s</pluralLabel>
<deploymentStatus>Deployed</deploymentStatus>
<sharingModel>ReadWrite</sharingModel>
<nameField>
<label>%s Name</label>
<type>AutoNumber</type>
<displayFormat>%s-{00000}</displayFormat>
<startingNumber>1</startingNumber>
</nameField>
</metadata>
`
body, err := fm.soapExecute("create", fmt.Sprintf(soap, object, object, inflect.Pluralize(object), object, fld))
if err != nil {
return err
}
var status struct {
Id string `xml:"Body>createResponse>result>id"`
}
if err = xml.Unmarshal(body, &status); err != nil {
return
}
if err = fm.CheckStatus(status.Id); err != nil {
return
}
return
}
示例8: NewBuilder
//NewBuilder creates a build instance using the JSON schema data from the given filename. If modelName and/or pkgName
//are left empty the title-attribute of the JSON schema is used for:
// => struct-name (singular, camelcase e.g contact => Contact)
// => package name (pluralize, lowercased e.g. payment_reminder => paymentreminders)
func NewBuilder(inputFile string, modelName string, pkgName string) (builder Builder) {
builder = Builder{}
// try to read input file
raw, err := ioutil.ReadFile(inputFile)
if err != nil {
msg := fmt.Sprintf("File error: %s", err)
builder.Errors = append(builder.Errors, msg)
return
}
builder.InputFile = inputFile
builder.SchemaRaw = raw
// try parsing json
if err := json.Unmarshal(builder.SchemaRaw, &builder.SchemaJSON); err != nil {
msg := fmt.Sprintf("JSON error: %s", err)
builder.Errors = append(builder.Errors, msg)
return
}
// defer model name from schema.title if not given as argument, schema['title'] MUST be set
if len(modelName) > 0 {
builder.ModelName = modelName
} else {
builder.ModelName = inflect.Typeify(builder.SchemaJSON["title"].(string))
}
// defer package name from schema.title if not given as argument
if len(pkgName) > 0 {
builder.PkgName = pkgName
} else {
//Pluralize no underscores
builder.PkgName = strings.ToLower(inflect.Camelize(inflect.Pluralize(builder.SchemaJSON["title"].(string))))
}
return
}
示例9: RenderLists
func (s *Site) RenderLists() error {
for section, data := range s.Sections {
n := s.NewNode()
n.Title = strings.Title(inflect.Pluralize(section))
n.Url = helpers.Urlize(section + "/" + "index.html")
n.Permalink = permalink(s, n.Url)
n.RSSlink = permalink(s, section+".xml")
n.Date = data[0].Page.Date
n.Data["Pages"] = data.Pages()
layout := "indexes/" + section + ".html"
err := s.render(n, section, layout, "_default/indexes.html")
if err != nil {
return err
}
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
// XML Feed
n.Url = helpers.Urlize(section + ".xml")
n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url)
err = s.render(n, section+".xml", "rss.xml")
if err != nil {
return err
}
}
}
return nil
}
示例10: ResourceNames
func (s *Service) ResourceNames() []string {
l := make([]string, len(s.Resources))
i := 0
for _, r := range s.Resources {
l[i] = inflect.Pluralize(r.Name)
i++
}
sort.Strings(l)
return l
}
示例11: newSectionListNode
func (s *Site) newSectionListNode(section string, data WeightedPages) *Node {
n := s.NewNode()
if viper.GetBool("PluralizeListTitles") {
n.Title = strings.Title(inflect.Pluralize(section))
} else {
n.Title = strings.Title(section)
}
s.setUrls(n, section)
n.Date = data[0].Page.Date
n.Data["Pages"] = data.Pages()
return n
}
示例12: newSectionListNode
func (s *Site) newSectionListNode(sectionName, section string, data WeightedPages) *Node {
n := s.NewNode()
sectionName = helpers.FirstUpper(sectionName)
if viper.GetBool("PluralizeListTitles") {
n.Title = inflect.Pluralize(sectionName)
} else {
n.Title = sectionName
}
s.setURLs(n, section)
n.Date = data[0].Page.Date
n.Lastmod = data[0].Page.Lastmod
n.Data["Pages"] = data.Pages()
return n
}
示例13: HasMany
// HasMany signifies a relationship between this model and a
// set of Children. The Parent has the children, and the Children belong
// to the Parent. The first parameter becomes the name of the
// field in the model struct, the second parameter is the name
// of the child model. The Child model will have a ParentID field
// appended to the field list. The Parent model definition will use
// the first parameter as the field name in the struct definition.
// Usage: HasMany("Orders", "Order")
// Struct field definition: Children []Child
func HasMany(name, child string) {
if r, ok := relationalModelDefinition(false); ok {
field := &gorma.RelationalFieldDefinition{
Name: codegen.Goify(name, true),
HasMany: child,
Description: "has many " + inflect.Pluralize(child),
Datatype: gorma.HasMany,
Parent: r,
}
r.RelationalFields[field.Name] = field
var model *gorma.RelationalModelDefinition
model, ok := r.Parent.RelationalModels[child]
if ok {
r.HasMany[child] = model
// create the fk field
f := &gorma.RelationalFieldDefinition{
Name: codegen.Goify(inflect.Singularize(r.Name), true) + "ID",
HasMany: child,
Description: "has many " + child,
Datatype: gorma.HasManyKey,
Parent: model,
DatabaseFieldName: SanitizeDBFieldName(codegen.Goify(inflect.Singularize(r.Name), true) + "ID"),
}
model.RelationalFields[f.Name] = f
} else {
model = &gorma.RelationalModelDefinition{
Name: child,
Parent: r.Parent,
RelationalFields: make(map[string]*gorma.RelationalFieldDefinition),
BelongsTo: make(map[string]*gorma.RelationalModelDefinition),
HasMany: make(map[string]*gorma.RelationalModelDefinition),
HasOne: make(map[string]*gorma.RelationalModelDefinition),
ManyToMany: make(map[string]*gorma.ManyToManyDefinition),
}
r.HasMany[child] = model
// create the fk field
f := &gorma.RelationalFieldDefinition{
Name: codegen.Goify(inflect.Singularize(r.Name), true) + "ID",
HasMany: child,
Description: "has many " + child,
Datatype: gorma.HasManyKey,
Parent: model,
DatabaseFieldName: SanitizeDBFieldName(codegen.Goify(inflect.Singularize(r.Name), true) + "ID"),
}
model.RelationalFields[f.Name] = f
}
}
}
示例14: runBigObjectCreate
func runBigObjectCreate(args []string) {
var fieldObjects = make([]BigObjectField, len(fields))
for i, field := range fields {
fieldObjects[i] = parseField(field)
}
var object = BigObject{deploymentStatus, objectLabel, pluralLabel, fieldObjects}
if len(object.Label) == 0 {
ErrorAndExit("Please provide a label for your big object using the -l flag.")
}
if len(object.PluralLabel) == 0 {
object.PluralLabel = inflect.Pluralize(object.Label)
}
force, _ := ActiveForce()
if err := force.Metadata.CreateBigObject(object); err != nil {
ErrorAndExit(err.Error())
}
fmt.Println("Big object created")
}
示例15: ManyToMany
// ManyToMany creates a join table to store the intersection relationship
// between this model and another model. For example, in retail an Order can
// contain many products, and a product can belong to many orders. To express
// this relationship use the following syntax:
// Model("Order", func(){
// ManyToMany("Product", "order_lines")
// })
// This specifies that the Order and Product tables have a "junction" table
// called `order_lines` that contains the order and product information.
// The generated model will have a field called `Products` that will
// be an array of type `product.Product`.
func ManyToMany(other, tablename string) {
if r, ok := relationalModelDefinition(false); ok {
field := &gorma.RelationalFieldDefinition{
Name: inflect.Pluralize(other),
Many2Many: other,
Description: "many to many " + r.Name + "/" + strings.Title(other),
Parent: r,
}
r.RelationalFields[field.Name] = field
var model *gorma.RelationalModelDefinition
model, ok := r.Parent.RelationalModels[other]
var m2m *gorma.ManyToManyDefinition
if ok {
m2m = &gorma.ManyToManyDefinition{
Left: r,
Right: model,
DatabaseField: tablename,
}
r.ManyToMany[other] = m2m
} else {
model = &gorma.RelationalModelDefinition{
Name: other,
Parent: r.Parent,
RelationalFields: make(map[string]*gorma.RelationalFieldDefinition),
BelongsTo: make(map[string]*gorma.RelationalModelDefinition),
HasMany: make(map[string]*gorma.RelationalModelDefinition),
HasOne: make(map[string]*gorma.RelationalModelDefinition),
ManyToMany: make(map[string]*gorma.ManyToManyDefinition),
}
m2m = &gorma.ManyToManyDefinition{
Left: r,
Right: model,
DatabaseField: tablename,
}
r.ManyToMany[other] = m2m
}
}
}