package halleck.webserver.renderers;

import com.google.common.collect.ImmutableSet;
import halleck.webserver.MustacheRenderer;
import halleck.webserver.Renderer;

public class CourseRenderer {

    private MustacheRenderer mustacheRenderer = new MustacheRenderer();

    private static final Renderer STANDARD_RENDERER = new StandardRenderer();
    private static final ImmutableSet<Renderer> RENDERERS = ImmutableSet.<Renderer>of(new YouTubeRenderer(),
                                                                                      new EmbeddedVideoRenderer());



    public String render(String standardLink) {
        Renderer renderer = getRenderer(standardLink);
        return mustacheRenderer.renderTemplate(renderer.mustacheTemplate(), renderer.formatUrl(standardLink));
    }

    private Renderer getRenderer(String standardLink) {
        return RENDERERS.stream()
                .filter(r -> r.canRender(standardLink))
                .findFirst()
                .orElseGet(() -> STANDARD_RENDERER);
    }




}

@@ -78,16 +78,56 @@
 bleSet;%0A
+import com.google.common.collect.Lists;%0A
 import h
@@ -244,64 +244,79 @@
 ate 
-MustacheRenderer mustacheRenderer = new Mustache
+ImmutableSet%3CRenderer%3E renderers;%0A    private Renderer standard
 Renderer
 ();%0A
@@ -315,13 +315,10 @@
 erer
-()
 ;%0A
-%0A
     
@@ -329,49 +329,170 @@
 ate 
+Mu
 sta
-tic final Renderer STANDARD_RENDERER =
+cheRenderer mustacheRenderer;%0A%0A%0A    public CourseRenderer()%7B%0A        this(Lists.newArrayList(new YouTubeRenderer(),new EmbeddedVideoRenderer()),%0A            
  new
@@ -514,115 +514,113 @@
 er()
-;
+,
 %0A    
-private static final ImmutableSet%3CRenderer%3E RENDERERS = ImmutableSet.%3CRenderer%3Eof(new YouTube
+         new MustacheRenderer());%0A    %7D%0A    public CourseRenderer(Iterable%3CRenderer%3E custom
 Renderer
 (),%0A
@@ -607,34 +607,33 @@
 %3E customRenderer
-()
+s
 ,%0A              
@@ -648,99 +648,241 @@
     
-                                                            new EmbeddedVideoRenderer());%0A%0A
+Renderer defaultRenderer,%0A                          MustacheRenderer stach)%7B%0A        this.renderers = ImmutableSet.copyOf(customRenderers);%0A        this.standardRenderer = defaultRenderer;%0A        this.mustacheRenderer = stach;%0A    %7D
 %0A%0A  
@@ -1175,17 +1175,17 @@
 urn 
-RENDERERS
+renderers
 .str
@@ -1312,25 +1312,24 @@
  -%3E 
-STANDARD_RENDERER
+standardRenderer
 );%0A 

clean up construction of course renderer