Skip to content

Commit

Permalink
added ability to link to youtube videos as part of enhancement #9
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1380 committed Aug 7, 2015
1 parent 0283f96 commit b45cd63
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.willshex.blogwt.client.markdown.plugin.CachedIncludePlugin;
import com.willshex.blogwt.client.markdown.plugin.GalleryPlugin;
import com.willshex.blogwt.client.markdown.plugin.MapPlugin;
import com.willshex.blogwt.client.markdown.plugin.YoutubePlugin;
import com.willshex.blogwt.shared.helper.PropertyHelper;

import emoji.gwt.emoji.Emoji;
Expand Down Expand Up @@ -110,7 +111,7 @@ protected void registerPlugins () {

registerPlugins(new WebSequencePlugin(ensureManager()), includePlugin,
new GalleryPlugin(), mapsApiKey == null ? null : new MapPlugin(
mapsApiKey, ensureManager()));
mapsApiKey, ensureManager()), new YoutubePlugin());
}

public Processor () {
Expand All @@ -127,7 +128,8 @@ public Processor () {
@Override
public void openImage (StringBuilder out, String link, String title) {
super.openImage(out, link, title);
out.append(" class=\"img-responsive " + Resources.RES.styles().image() + "\" ");
out.append(" class=\"img-responsive "
+ Resources.RES.styles().image() + "\" ");
}

/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// YoutubePlugin.java
// blogwt
//
// Created by William Shakour (billy1380) on 7 Aug 2015.
// Copyright © 2015 WillShex Limited. All rights reserved.
//
package com.willshex.blogwt.client.markdown.plugin;

import java.util.List;
import java.util.Map;

import org.markdown4j.Plugin;

/**
* @author William Shakour (billy1380)
*
*/
public class YoutubePlugin extends Plugin {

public static final String ASPECT_16_9 = "16by9";
public static final String ASPECT_4_3 = "4by3";

public static final String RESPONSIVE_CLASS = "embed-responsive";
public static final String RESPONSIVE_ITEM_CLASS = "embed-responsive-item";

public YoutubePlugin () {
super("youtube");
}

@Override
public void emit (StringBuilder out, List<String> lines,
Map<String, String> params) {

boolean hasAllowFullscreen = params.containsKey("allowfullscreen"), hasResponsive = params
.containsKey("responsive"), hasWidth = params
.containsKey("width"), hasHeight = params.containsKey("height"), hasSrc = params
.containsKey("src"), hasFrameBorder = params
.containsKey("frameborder");

if (hasResponsive) {
String aspect = ASPECT_16_9;

if (params.containsKey("aspectratio")) {
switch (params.get("aspectratio")) {
case ASPECT_4_3:
aspect = ASPECT_4_3;
break;
}
}

out.append("<div class=\"");
out.append(RESPONSIVE_CLASS);
out.append(" ");
out.append(RESPONSIVE_CLASS);
out.append("-");
out.append(aspect);
out.append("\">");
} else {
out.append("<div class=\"text-center\">");
}

out.append("<iframe");
out.append(" ");

if (hasWidth && !hasResponsive) {
out.append("width=\"");
out.append(params.get("width"));
out.append("\"");
out.append(" ");
}

if (hasHeight && !hasResponsive) {
out.append("height=\"");
out.append(params.get("height"));
out.append("\"");
out.append(" ");
}

if (hasSrc) {
out.append("src=\"");
out.append(params.get("src"));
out.append("\"");
out.append(" ");
}

if (hasFrameBorder) {
out.append("frameborder=\"");
out.append(params.get("frameborder"));
out.append("\"");
out.append(" ");
}

if (hasAllowFullscreen) {
out.append("allowfullscreen");
out.append(" ");
}

out.append("></iframe></div>");

}
}

0 comments on commit b45cd63

Please sign in to comment.