Represents a scope of keys.
        public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope context)
        {
            int width;
            if (arguments["width"] is decimal)
                width = Convert.ToInt32((decimal) arguments["width"]);
            else
                width = (int) arguments["width"];

            int height;
            if (arguments["height"] is decimal)
                height = Convert.ToInt32((decimal) arguments["height"]);
            else
                height = (int) arguments["height"];

            var imageFormat = new ImageFormat
            {
                Width = width,
                Height = height,
                Type = (string) arguments["format"]
            };

            var baseUrl = (string) arguments["baseUrl"];
            var url = _imageService.GetURL(new Uri(baseUrl), imageFormat);
            writer.Write(url.ToString());
        }
 void IGenerator.GetText(Scope keyScope, TextWriter writer, Scope contextScope)
 {
     Dictionary<string, object> arguments = _arguments.GetArguments(keyScope, contextScope);
     IEnumerable<NestedContext> contexts = _definition.GetChildContext(writer, keyScope, arguments, contextScope);
     List<IGenerator> generators;
     if (_definition.ShouldGeneratePrimaryGroup(arguments))
     {
         generators = _primaryGenerators;
     }
     else
     {
         generators = new List<IGenerator>();
         if (_subGenerator != null)
         {
             generators.Add(_subGenerator);
         }
     }
     foreach (NestedContext context in contexts)
     {
         foreach (IGenerator generator in generators)
         {
             generator.GetText(context.KeyScope ?? keyScope, context.Writer ?? writer, context.ContextScope);
             if (context.WriterNeedsConsidated)
             {
                 writer.Write(_definition.ConsolidateWriter(context.Writer ?? writer, arguments));
             }
         }
     }
 }
 /// <summary>
 /// Gets the context to use when building the inner text of the tag.
 /// </summary>
 /// <param name="writer">The text writer passed</param>
 /// <param name="keyScope">The current scope.</param>
 /// <param name="arguments">The arguments passed to the tag.</param>
 /// <returns>The scope to use when building the inner text of the tag.</returns>
 public override IEnumerable<NestedContext> GetChildContext(
     TextWriter writer, 
     Scope keyScope, 
     Dictionary<string, object> arguments,
     Scope contextScope)
 {
     object value = arguments[collectionParameter];
     IEnumerable enumerable = value as IEnumerable;
     if (enumerable == null)
     {
         yield break;
     }
     int index = 0;
     foreach (object item in enumerable)
     {
         NestedContext childContext = new NestedContext() 
         { 
             KeyScope = keyScope.CreateChildScope(item), 
             Writer = writer, 
             ContextScope = contextScope.CreateChildScope(),
         };
         childContext.ContextScope.Set("index", index);
         yield return childContext;
         ++index;
     }
 }
 public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope context)
 {
     var partial = (string)arguments["partial"];
     var source = arguments["source"];
     
     var rendered = _engine.RenderPartial(partial, source);
     writer.Write(rendered);
 }
 /// <summary>
 /// Gets the text to output.
 /// </summary>
 /// <param name="writer">The writer to write the output to.</param>
 /// <param name="arguments">The arguments passed to the tag.</param>
 /// <param name="contextScope">Extra data passed along with the context.</param>
 public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope contextScope)
 {
     object index;
     if (contextScope.TryFind("index", out index))
     {
         writer.Write(Convert.ToInt32(index) % 2 == 0? "even" : "odd");
     }
 }
 /// <summary>
 /// Gets the text to output.
 /// </summary>
 /// <param name="writer">The writer to write the output to.</param>
 /// <param name="arguments">The arguments passed to the tag.</param>
 /// <param name="contextScope">Extra data passed along with the context.</param>
 public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope contextScope)
 {
     object index;
     if (contextScope.TryFind("index", out index))
     {
         writer.Write(index);
     }
 }
        public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope context)
        {
            var str = (string) arguments["string"];

            if (string.IsNullOrWhiteSpace(str)) return;

            writer.Write(str.CamelCase());
        }
Example #8
0
 /// <summary>
 /// Creates a child scope that searches for keys in the given object.
 /// </summary>
 /// <param name="source">The object to search for keys in.</param>
 /// <returns>The new child scope.</returns>
 public Scope CreateChildScope(object source)
 {
     Scope scope = new Scope(source, this);
     scope.KeyFound = KeyFound;
     scope.KeyNotFound = KeyNotFound;
     scope.ValueRequested = ValueRequested;
     return scope;
 }
 public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope context)
 {
     var filenameToReplace = arguments["filename"] as string;
     if (null != filenameToReplace)
     {
         var relativeFileUrl = DocSet.RelativePathToRootFromFile(
             this.DestinationFile,
             Path.Combine(this.RootDestinationFolder, filenameToReplace),
             true);
         writer.Write(relativeFileUrl);
     }
 }
Example #10
0
 void IGenerator.GetText(Scope scope, TextWriter writer, Scope context)
 {
     Dictionary<string, object> arguments;
     if (_definition.IsSetter)
     {
         arguments = _arguments.GetArgumentKeyNames();   
     }
     else
     {
         arguments = _arguments.GetArguments(scope, context);
     }            
     _definition.GetText(writer, arguments, context);
 }
 /// <summary>
 /// Gets the context to use when building the inner text of the tag.
 /// </summary>
 /// <param name="writer">The text writer passed</param>
 /// <param name="keyScope">The current key scope.</param>
 /// <param name="arguments">The arguments passed to the tag.</param>
 /// <returns>The scope to use when building the inner text of the tag.</returns>
 public override IEnumerable<NestedContext> GetChildContext(
     TextWriter writer, 
     Scope keyScope, 
     Dictionary<string, object> arguments,
     Scope contextScope)
 {
     object contextSource = arguments[contextParameter];
     NestedContext context = new NestedContext() 
     { 
         KeyScope = keyScope.CreateChildScope(contextSource), 
         Writer = writer,
         ContextScope = contextScope.CreateChildScope()
     };
     yield return context;
 }
        public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope context)
        {
            var str = arguments["string"] as string;

            if (str == null) return;

            object indexObj;
            if (!context.TryFind("index", out indexObj)) return;
            
            var index = (int) indexObj;

            if (index > 0)
            {
                writer.Write(str);
            }
        }
 /// <summary>
 /// Substitutes the key placeholders with their respective values.
 /// </summary>
 /// <param name="keyScope">The key/value pairs in the current lexical scope.</param>
 /// <param name="contextScope">The key/value pairs in current context.</param>
 /// <returns>A dictionary associating the parameter name to the associated value.</returns>
 public Dictionary<string, object> GetArguments(Scope keyScope, Scope contextScope)
 {
     Dictionary<string, object> arguments = new Dictionary<string,object>();
     foreach (KeyValuePair<TagParameter, IArgument> pair in _argumentLookup)
     {
         object value;
         if (pair.Value == null)
         {
             value = pair.Key.DefaultValue;
         }
         else
         {
             value = pair.Value.GetValue(keyScope, contextScope);
         }
         arguments.Add(pair.Key.Name, value);
     }
     return arguments;
 }
 /// <summary>
 /// Substitutes the key placeholders with their respective values.
 /// </summary>
 /// <param name="keyScope">The key/value pairs in the current lexical scope.</param>
 /// <param name="contextScope">The key/value pairs in current context.</param>
 /// <returns>A dictionary associating the parameter name to the associated value.</returns>
 public Dictionary<string, object> GetArguments(Scope keyScope, Scope contextScope)
 {
     Dictionary<string, object> arguments = new Dictionary<string,object>();
     foreach (KeyValuePair<TagParameter, string> pair in _argumentLookup)
     {
         object value;
         if (pair.Value == null)
         {
             value = pair.Key.DefaultValue;
         }
         else if (pair.Value.StartsWith("@"))
         {
             value = contextScope.Find(pair.Value.Substring(1));
         }
         else
         {
             value = keyScope.Find(pair.Value);
         }
         arguments.Add(pair.Key.Name, value);
     }
     return arguments;
 }
Example #15
0
 private string render(IFormatProvider provider, object source)
 {
     Scope keyScope = new Scope(source);
     Scope contextScope = new Scope(new Dictionary<string, object>());
     foreach (EventHandler<KeyFoundEventArgs> handler in _foundHandlers)
     {
         keyScope.KeyFound += handler;
         contextScope.KeyFound += handler;
     }
     foreach (EventHandler<KeyNotFoundEventArgs> handler in _notFoundHandlers)
     {
         keyScope.KeyNotFound += handler;
         contextScope.KeyNotFound += handler;
     }
     foreach (EventHandler<ValueRequestEventArgs> handler in _valueRequestedHandlers)
     {
         contextScope.ValueRequested += handler;
     }
     StringWriter writer = new StringWriter(provider);
     _generator.GetText(keyScope, writer, contextScope);
     return writer.ToString();
 }
 public override IEnumerable <NestedContext> GetChildContext(TextWriter writer, Scope keyScope, Dictionary <string, object> arguments, Scope contextScope)
 {
     return(new List <NestedContext>());
 }
 /// <summary>
 /// Gets the text to output.
 /// </summary>
 /// <param name="writer">The writer to write the output to.</param>
 /// <param name="arguments">The arguments passed to the tag.</param>
 /// <param name="context">Extra data passed along with the context.</param>
 public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope context)
 {
     writer.Write(Environment.NewLine);
 }
Example #18
0
 public object GetValue(Scope keyScope, Scope contextScope)
 {
     return contextScope.Find(name);
 }
 void IGenerator.GetText(Scope scope, TextWriter writer, Scope context)
 {
     writer.Write(Value);
 }
Example #20
0
 /// <summary>
 /// Gets the context to use when building the inner text of the tag.
 /// </summary>
 /// <param name="writer">The text writer passed</param>
 /// <param name="keyScope">The current key scope.</param>
 /// <param name="arguments">The arguments passed to the tag.</param>
 /// <returns>The scope to use when building the inner text of the tag.</returns>
 public virtual IEnumerable<NestedContext> GetChildContext(
     TextWriter writer, 
     Scope keyScope, 
     Dictionary<string, object> arguments,
     Scope contextScope)
 {
     NestedContext context = new NestedContext() 
     { 
         KeyScope = keyScope, 
         Writer = writer,
         ContextScope = contextScope.CreateChildScope()
     };
     yield return context;
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of a KeyScope.
 /// </summary>
 /// <param name="source">The object to search for keys in.</param>
 /// <param name="parent">The parent scope to search in if the value is not found.</param>
 internal Scope(object source, Scope parent)
 {
     _parent = parent;
     _source = source;
 }
Example #22
0
 public object GetValue(Scope keyScope, Scope contextScope)
 {
     return value;
 }
Example #23
0
 void IGenerator.GetText(Scope scope, TextWriter writer, Scope context)
 {
     object value = _isVariable ? context.Find(_key) : scope.Find(_key);
     writer.Write(_format, value);
 }
Example #24
0
 /// <summary>
 /// Applies additional formatting to the inner text of the tag.
 /// </summary>
 /// <param name="writer">The text writer to write to.</param>
 /// <param name="arguments">The arguments passed to the tag.</param>
 /// <param name="context">The data associated to the context.</param>
 public virtual void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope context)
 {
 }
 public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope context)
 {
     writer.Write($"{{{Guid.NewGuid()}}}");
 }
Example #26
0
 /// <summary>
 /// Gets the text to output.
 /// </summary>
 /// <param name="writer">The writer to write the output to.</param>
 /// <param name="arguments">The arguments passed to the tag.</param>
 /// <param name="contextScope">Extra data passed along with the context.</param>
 public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope contextScope)
 {
     string name = (string)arguments[nameParameter];
     contextScope.Set(name);
 }
Example #27
0
 void IGenerator.GetText(Scope scope, TextWriter writer, Scope context)
 {
     writer.Write(Value);
 }