Пример #1
0
        private void UpdateEditor(SnippetDescriptor descriptor, ElementEditorContext context) {
            var viewModel = new SnippetViewModel {
                Descriptor = descriptor
            };
            
            if (context.Updater != null) {
                foreach (var fieldDescriptor in descriptor.Fields) {
                    var name = fieldDescriptor.Name;
                    var result = context.ValueProvider.GetValue(name);

                    if (result == null)
                        continue;

                    context.Element.Data[name] = result.AttemptedValue;
                }
            }

            viewModel.FieldEditors = descriptor.Fields.Select(x => {
                var fieldEditorTemplateName = String.Format("Elements.Snippet.Field.{0}", x.Type ?? "Text");
                var fieldDescriptorViewModel = new SnippetFieldViewModel {
                    Descriptor = x,
                    Value = context.Element.Data.Get(x.Name)
                };
                var fieldEditor = context.ShapeFactory.EditorTemplate(TemplateName: fieldEditorTemplateName, Model: fieldDescriptorViewModel, Prefix: context.Prefix);

                return fieldEditor;
            }).ToList();

            var snippetEditorShape = context.ShapeFactory.EditorTemplate(TemplateName: "Elements.Snippet", Model: viewModel, Prefix: context.Prefix);
            snippetEditorShape.Metadata.Position = "Fields:0";
            
            context.EditorResult.Add(snippetEditorShape);
        }
Пример #2
0
 private void Editor(SnippetDescriptor descriptor, ElementEditorContext context) {
     UpdateEditor(descriptor, context);
 }
Пример #3
0
        private SnippetDescriptor DescribeSnippet(dynamic shape) {
            // Execute the shape and intercept calls to the Html.SnippetField method.
            var descriptor = new SnippetDescriptor();
            shape.DescriptorRegistrationCallback = (Action<SnippetFieldDescriptor>) (fieldDescriptor => {
                var existingDescriptor = descriptor.Fields.SingleOrDefault(x => x.Name == fieldDescriptor.Name); // Not using Dictionary, as that will break rendering the view for some obscure reason.
                
                if (existingDescriptor == null)
                    descriptor.Fields.Add(fieldDescriptor);

                if (fieldDescriptor.DisplayName == null)
                    fieldDescriptor.DisplayName = new LocalizedString(fieldDescriptor.Name);
            });

            using (_currentThemeShapeBindingResolver.Value.Enable()) {
                _shapeDisplay.Value.Display(shape);
            }

            shape.SnippetDescriptor = descriptor;
            return descriptor;
        }
Пример #4
0
        private void Displaying(ElementDisplayingContext context, ShapeDescriptor shapeDescriptor, SnippetDescriptor snippetDescriptor) {
            var shapeType = shapeDescriptor.ShapeType;
            var shape = (dynamic)_shapeFactory.Value.Create(shapeType);

            shape.Element = context.Element;
            shape.SnippetDescriptor = snippetDescriptor;

            ElementShapes.AddTokenizers(shape, _tokenizer.Value);
            context.ElementShape.Snippet = shape;
            context.ElementShape.SnippetDescriptor = snippetDescriptor;
        }
Пример #5
0
        private SnippetDescriptor ParseSnippetDescriptor(string bindingSource)
        {
            var physicalSourcePath = _wca.GetContext().HttpContext.Server.MapPath(bindingSource);
            var paramsFileName = Path.Combine(Path.GetDirectoryName(physicalSourcePath) ?? "", Path.GetFileNameWithoutExtension(physicalSourcePath) + ".txt");

            if (!File.Exists(paramsFileName))
                return null;

            var yaml = File.ReadAllText(paramsFileName);
            var snippetConfig = Deserialize(yaml);
            var fieldsConfig = snippetConfig.Fields != null ? snippetConfig.Fields.Children : new dynamic[0];
            var descriptor = new SnippetDescriptor();

            foreach (var fieldConfig in fieldsConfig) {
                descriptor.Fields.Add(new SnippetFieldDescriptor {
                    Name = (string)fieldConfig.Name,
                    Type = (string)fieldConfig.Type,
                    DisplayName = new LocalizedString((string)fieldConfig.DisplayName),
                    Description = new LocalizedString((string)fieldConfig.Description)
                });
            }

            return descriptor;
        }
Пример #6
0
        private void Displaying(ElementDisplayingContext context, ShapeDescriptor shapeDescriptor, SnippetDescriptor snippetDescriptor)
        {
            var shapeType = shapeDescriptor.ShapeType;
            var shape = (dynamic)_shapeFactory.Value.Create(shapeType);

            shape.Element = context.Element;

            if (snippetDescriptor != null) {
                foreach (var fieldDescriptor in snippetDescriptor.Fields) {
                    var value = context.Element.Data.Get(fieldDescriptor.Name);
                    shape.Properties[fieldDescriptor.Name] = value;
                }
            }

            ElementShapes.AddTokenizers(shape, _tokenizer.Value);
            context.ElementShape.Snippet = shape;
        }