作者:DuoSoftwar
项目:v6engine-dep
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))
}
作者:DimShadoWW
项目:hug
// 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
}
作者:hugodunca
项目:hug
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
}
作者:GuoJin
项目:hug
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
}
作者:orive
项目:git-compos
func plural(qty int, singular string) string {
s := singular
if qty != 1 {
s = inflect.Pluralize(s)
}
return fmt.Sprintf("%d %s", qty, s)
}
作者:johnst
项目:hug
// 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
}
作者:haage
项目:forc
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
}
作者:yauhen-
项目:go-json-schema-tool
//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
}
作者:RoyRu
项目:hug
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
}
作者:cdwilhel
项目:self-service-plugin
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
}
作者:jade
项目:hug
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
}
作者:marue
项目:hug
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
}
作者:derekperkin
项目:gorm
// 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
}
}
}
作者:ChaitanyaRanad
项目:forc
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")
}
作者:derekperkin
项目:gorm
// 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
}
}
}
作者:h12
项目:xs
func (e Element) Field(plural bool) *ast.Field {
omitempty := false
if e.MinOccurs == "0" {
omitempty = true
}
if e.MaxOccurs == "unbounded" {
plural = true
}
if e.GoType() == "" {
e.Type = e.Name
defer func() { e.Type = "" }()
}
doc := ""
if e.Annotation.Documentation != "" {
doc = e.Annotation.Documentation
}
if plural {
pluralName := inflect.Pluralize(e.GoName())
pluralType := "[]" + e.GoType()
return &ast.Field{
Names: []*ast.Ident{{Name: pluralName}},
Type: &ast.Ident{Name: pluralType},
Tag: tag(XMLTag{Name: e.Name, Omitempty: omitempty}.String()),
Doc: comment(doc),
}
}
typ := e.GoType()
if e.MinOccurs == "0" {
typ = omitType(typ)
}
return &ast.Field{
Names: []*ast.Ident{{Name: e.GoName()}},
Type: &ast.Ident{Name: typ},
Tag: tag(XMLTag{Name: e.Name, Omitempty: omitempty}.String()),
Doc: comment(doc),
}
}
作者:johnvilsac
项目:golang-stuf
func (s *Site) RenderLists() {
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+"/index.xml")))
n.Date = data[0].Date
n.Data["Pages"] = data
layout := "indexes/" + section + ".html"
x := s.RenderThing(n, layout)
s.WritePublic(section, "index.html", x.Bytes())
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
// XML Feed
n.Url = Urlize(section + "/index.xml")
n.Permalink = template.HTML(string(n.Site.BaseUrl) + section + "/index.xml")
y := s.NewXMLBuffer()
s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
s.WritePublic(section, "index.xml", y.Bytes())
}
}
}
作者:jmptrade
项目:dbmetamode
func (proc *postgresqlSchemaProcessor) RetrieveTableMetaData(databaseName string, schemaName string) ([]Table, error) {
// fetch the schema tables
dbTables, err := proc.schemaLoader.GetTables(databaseName, schemaName)
if err != nil {
log.Fatalln(err)
return nil, err
}
tables := []Table{}
for _, dbTable := range dbTables {
sanitisedModelName := toCapitalCase(dbTable.TableName)
sanitisedModelNameLowerCase := strings.ToLower(sanitisedModelName)
pluralisedModelName := inflect.Pluralize(sanitisedModelNameLowerCase)
table := Table{
DatabaseName: dbTable.TableCatalog,
SchemaName: dbTable.TableSchema,
TableName: dbTable.TableName,
ModelName: sanitisedModelName,
ModelNameLowerCase: sanitisedModelNameLowerCase, // sanitised tableName
ModelNameLowerCasePlural: pluralisedModelName, // pluralised sanitised tableName
Columns: []*Column{},
ForeignKeys: []*ForeignKey{},
InsertColumns: []*Column{},
UpdateColumns: []*Column{},
PrimaryKeyColumns: []*Column{},
}
// fetch the schema columns
dbColumns, err := proc.schemaLoader.GetColumns(databaseName, schemaName, dbTable.TableName)
if err != nil {
log.Fatalln(err)
return nil, err
}
// get the foreign key information
var currentFk *ForeignKey
dbForeignKeys, err := proc.schemaLoader.GetForeignKeys(databaseName, schemaName, dbTable.TableName)
for _, fk := range dbForeignKeys {
if currentFk == nil {
currentFk = proc.populateFk(&table, fk)
table.ForeignKeys = append(table.ForeignKeys, currentFk)
} else {
if currentFk.DatabaseName == fk.UqTableCatalog && currentFk.SchemaName == fk.UqTableSchema && currentFk.TableName == fk.UqTableName {
currentFk.FkColumns = append(currentFk.FkColumns, fk.FkColumnName)
currentFk.UkColumns = append(currentFk.UkColumns, fk.UqColumnName)
} else {
currentFk = proc.populateFk(&table, fk)
table.ForeignKeys = append(table.ForeignKeys, currentFk)
}
}
}
for _, dbColumn := range dbColumns {
// get the primay and unique key column usage
keyColumns, err := proc.schemaLoader.GetColumnKeyUsage(databaseName, schemaName, dbTable.TableName, dbColumn.ColumnName)
if err != nil {
log.Fatalln(err)
return nil, err
}
sanitisedColumnName := toCapitalCase(dbColumn.ColumnName)
sanitisedColumnNameLowerCase := strings.ToLower(sanitisedColumnName)
column := Column{
ColumnName: dbColumn.ColumnName,
FieldName: sanitisedColumnName,
FieldNameLowerCase: sanitisedColumnNameLowerCase,
FieldType: dataType(dbColumn.DataType),
DataType: dbColumn.DataType,
IsNullable: false,
IsPrimaryKeyColumn: false,
HasDefault: false,
}
if dbColumn.CharacterMaximumLength.Valid {
column.DataTypeSize = dbColumn.CharacterMaximumLength.Int64
}
if dbColumn.IsNullable.Valid && dbColumn.IsNullable.String == "YES" {
column.IsNullable = true
}
if dbColumn.ColumnDefault.Valid {
column.HasDefault = true
}
for _, colKey := range keyColumns {
if colKey.ConstraintType == "PRIMARY KEY" {
column.IsPrimaryKeyColumn = true
table.PrimaryKeyColumns = append(table.PrimaryKeyColumns, &column)
}
if colKey.ConstraintType == "UNIQUE" {
column.IsUnique = true
}
//.........这里部分代码省略.........
作者:goadesig
项目:gorm
// RightNamePlural returns the pluralized version
// of the "child" of the m2m relationship.
func (m *ManyToManyDefinition) RightNamePlural() string {
return inflect.Pluralize(m.Right.ModelName)
}
作者:derekperkin
项目:gorm
func (m *ManyToManyDefinition) LeftNamePlural() string {
return inflect.Pluralize(m.Left.Name)
}