Пример #1
0
        ContentTypeGroupResponseItem GetItem(ContentTypeGroupDescriptor contentTypeGroup)
        {
            var    name = contentTypeGroup.Type.GetCustomAttribute <DisplayAttribute>()?.Name ?? contentTypeGroup.Type.Name;
            string pluralName;

            if (name.Contains(':') && !contentTypeGroup.Id.Contains(':'))
            {
                var nameSplit = name.Split(':');

                name       = nameSplit.First();
                pluralName = nameSplit.Last();
            }
            else
            {
                if (name.Length >= 2 && name.StartsWith('I') && char.IsUpper(name[1]))
                {
                    name = name.Substring(1);
                }

                name       = Humanizer.Humanize(name);
                pluralName = Pluralizer.Pluralize(name);
            }

            var item = new ContentTypeGroupResponseItem
            {
                Id                  = contentTypeGroup.Id,
                Name                = name,
                LowerCaseName       = name.Substring(0, 1).ToLower() + name.Substring(1),
                PluralName          = pluralName,
                LowerCasePluralName = pluralName.Substring(0, 1).ToLower() + pluralName.Substring(1),
                ContentTypes        = ContentTypeGroupMatcher.GetContentTypesFor(contentTypeGroup.Id).Select(t => t.Id).ToList().AsReadOnly(),
            };

            return(item);
        }
Пример #2
0
 public void Humanize()
 {
     Assert.That(Humanizer.Humanize("foo-bar_baz bazz"),
                 Is.EqualTo("Foo bar baz bazz"));
     Assert.That(Humanizer.Humanize("foo-bar_baz bazz", false),
                 Is.EqualTo("foo bar baz bazz"));
     Assert.That(Humanizer.Humanize("foo_bar_baz bazz", true, true),
                 Is.EqualTo("Foo Bar Baz Bazz"));
 }
Пример #3
0
        public IEnumerable <FieldResponse> GetAllForForm(string id)
        {
            var result = new List <FieldResponse>();

            foreach (var field in FieldProvider.GetAllFor(id))
            {
                if (!field.AutoGenerate)
                {
                    continue;
                }

                var control        = ControlMatcher.GetFor(field.Type, field.UIHints);
                var embeddedFormId = FormProvider.GetAll().FirstOrDefault(f => f.Type == field.Type);

                if (control == null && embeddedFormId == null)
                {
                    Logger.LogInformation($"Could not find control for {id} {field.Id}");
                    continue;
                }

                var label = field.Label;

                if (label == null)
                {
                    label = field.Id;
                    label = Humanizer.Humanize(field.Id);

                    if (label.EndsWith(" ids"))
                    {
                        label = label.Substring(0, label.Length - " ids".Length);
                        label = Pluralizer.Pluralize(label);
                    }
                    else if (label.EndsWith(" id"))
                    {
                        label = label.Substring(0, label.Length - " id".Length);
                    }
                }

                var singularLabel = Singularizer.Singularize(label);

                result.Add(new FieldResponse
                {
                    Id             = field.Id,
                    Label          = label,
                    SingularLabel  = singularLabel,
                    CamelCaseId    = CamelCaseNamingStrategy.GetPropertyName(field.Id, false),
                    Control        = control,
                    EmbeddedFormId = embeddedFormId?.Id,
                    IsSortable     = field.IsSortable,
                    Group          = field.Group,
                });
            }

            return(result);
        }
Пример #4
0
        ContentTypeResponseItem GetItem(ContentTypeDescriptor contentType)
        {
            var    name = contentType.Type.GetCustomAttribute <DisplayAttribute>()?.Name ?? contentType.Type.Name;
            string pluralName;

            if (name.Contains(':') && !contentType.Id.Contains(':'))
            {
                var nameSplit = name.Split(':');

                name       = nameSplit.First();
                pluralName = nameSplit.Last();
            }
            else
            {
                name       = Humanizer.Humanize(name);
                pluralName = Pluralizer.Pluralize(name);
            }

            var singleton = SingletonProvider.Get(contentType.Id);

            var item = new ContentTypeResponseItem
            {
                Id                       = contentType.Id,
                Name                     = name,
                LowerCaseName            = name.Substring(0, 1).ToLower() + name.Substring(1),
                PluralName               = pluralName,
                LowerCasePluralName      = pluralName.Substring(0, 1).ToLower() + pluralName.Substring(1),
                IsNameable               = typeof(INameable).IsAssignableFrom(contentType.Type),
                NameablePropertyName     = typeof(INameable).IsAssignableFrom(contentType.Type) ? CamelCaseNamingStrategy.GetPropertyName(NameExpressionParser.Parse(contentType.Type), false) : null,
                IsImageable              = typeof(IImageable).IsAssignableFrom(contentType.Type),
                ImageablePropertyName    = typeof(IImageable).IsAssignableFrom(contentType.Type) ? CamelCaseNamingStrategy.GetPropertyName(ImageExpressionParser.Parse(contentType.Type), false) : null,
                IsRoutable               = typeof(IRoutable).IsAssignableFrom(contentType.Type),
                IsSingleton              = singleton != null,
                Count                    = -1,
                ContentTypeActionModules = ContentTypeActionModuleProvider.GetContentTypeActionModulesFor(contentType.Id),
                ListActionModules        = ListActionModuleProvider.GetListActionModulesFor(contentType.Id),
                ContentTypeGroups        = ContentTypeGroupMatcher.GetContentTypeGroupsFor(contentType.Id).Select(t => t.Id).ToList().AsReadOnly(),
            };

            return(item);
        }
Пример #5
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var o = new JObject();

            var candidate = PolymorphicCandidateProvider.Get(value.GetType());

            if (candidate == null)
            {
                throw new Exception($"Value (of type {value.GetType()}) must be a [Form] when saving to an interface type property for polymorphic serialization to work");
            }

            o["type"]  = candidate.Id;
            o["name"]  = candidate.Type.GetCustomAttribute <DisplayAttribute>()?.Name ?? Humanizer.Humanize(candidate.Type.Name);
            o["value"] = JObject.FromObject(value, JsonWebSerializer);

            o.WriteTo(writer);
        }