Permalink
Browse files

Fix #440: New component Github to display your GitHub repositories on…

… a page.
  • Loading branch information...
1 parent 993fb82 commit 65e1eb3bbd5ad835a1a770c9d48d4404756eb628 @melloware melloware committed Feb 5, 2017
View
@@ -60,6 +60,7 @@
<include>calculator/**</include>
<include>clipboard/**</include>
<include>fluidgrid/**</include>
+ <include>github/**</include>
<include>imageareaselect/**</include>
<include>layout/**</include>
<include>qrcode/**</include>
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2011-2017 PrimeFaces Extensions
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.primefaces.extensions.component.github;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponentBase;
+
+import org.primefaces.component.api.Widget;
+import org.primefaces.util.ComponentUtils;
+
+/**
+ * <code>Github</code> component.
+ *
+ * @author Melloware mellowaredev@gmail.com
+ * @since 6.1
+ */
+@ResourceDependencies({
+ @ResourceDependency(library = "primefaces", name = "jquery/jquery.js"),
+ @ResourceDependency(library = "primefaces-extensions", name = "github/github.css"),
+ @ResourceDependency(library = "primefaces-extensions", name = "github/github.js")
+})
+public class Github extends UIComponentBase implements Widget {
+
+ public static final String COMPONENT_TYPE = "org.primefaces.extensions.component.Github";
+ public static final String COMPONENT_FAMILY = "org.primefaces.extensions.component";
+ private static final String DEFAULT_RENDERER = "org.primefaces.extensions.component.GithubRenderer";
+
+ protected enum PropertyKeys {
+
+ // @formatter:off
+ widgetVar,
+ repository,
+ iconStars,
+ iconForks,
+ iconIssues,
+ style,
+ styleClass,;
+ // @formatter:on
+
+ String toString;
+
+ PropertyKeys(final String toString) {
+ this.toString = toString;
+ }
+
+ PropertyKeys() {
+ }
+
+ @Override
+ public String toString() {
+ return toString != null ? toString : super.toString();
+ }
+ }
+
+ /**
+ * Default constructor
+ */
+ public Github() {
+ setRendererType(DEFAULT_RENDERER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String resolveWidgetVar() {
+ return ComponentUtils.resolveWidgetVar(getFacesContext(), this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public String getWidgetVar() {
+ return (String) getStateHelper().eval(PropertyKeys.widgetVar, null);
+ }
+
+ public void setWidgetVar(final String _widgetVar) {
+ getStateHelper().put(PropertyKeys.widgetVar, _widgetVar);
+ }
+
+ public String getRepository() {
+ return (String) getStateHelper().eval(PropertyKeys.repository, null);
+ }
+
+ public void setRepository(final String _repository) {
+ getStateHelper().put(PropertyKeys.repository, _repository);
+ }
+
+ public void setIconStars(final boolean _iconStars) {
+ getStateHelper().put(PropertyKeys.iconStars, _iconStars);
+ }
+
+ public boolean isIconStars() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.iconStars, true);
+ }
+
+ public void setIconForks(final boolean _iconForks) {
+ getStateHelper().put(PropertyKeys.iconForks, _iconForks);
+ }
+
+ public boolean isIconForks() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.iconForks, true);
+ }
+
+ public void setIconIssues(final boolean _iconIssues) {
+ getStateHelper().put(PropertyKeys.iconIssues, _iconIssues);
+ }
+
+ public boolean isIconIssues() {
+ return (Boolean) getStateHelper().eval(PropertyKeys.iconIssues, true);
+ }
+
+ public String getStyle() {
+ return (String) getStateHelper().eval(PropertyKeys.style, null);
+ }
+
+ public void setStyle(final String _style) {
+ getStateHelper().put(PropertyKeys.style, _style);
+ }
+
+ public String getStyleClass() {
+ return (String) getStateHelper().eval(PropertyKeys.styleClass, null);
+ }
+
+ public void setStyleClass(final String _styleClass) {
+ getStateHelper().put(PropertyKeys.styleClass, _styleClass);
+ }
+
+}
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2011-2017 PrimeFaces Extensions
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.primefaces.extensions.component.github;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.primefaces.renderkit.CoreRenderer;
+import org.primefaces.util.HTML;
+import org.primefaces.util.WidgetBuilder;
+
+/**
+ * Renderer for the {@link Github} component.
+ *
+ * @author Melloware mellowaredev@gmail.com
+ * @since 6.1
+ */
+public class GithubRenderer extends CoreRenderer {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void encodeEnd(final FacesContext context, final UIComponent component) throws IOException {
+ final Github github = (Github) component;
+ encodeMarkup(context, github);
+ encodeScript(context, github);
+ }
+
+ /**
+ * Create the HTML markup for the DOM.
+ */
+ private void encodeMarkup(final FacesContext context, final Github github) throws IOException {
+ final ResponseWriter writer = context.getResponseWriter();
+ final String clientId = github.getClientId(context);
+ final String widgetVar = github.resolveWidgetVar();
+
+ writer.startElement("div", github);
+ writer.writeAttribute("id", clientId, "id");
+ writer.writeAttribute(HTML.WIDGET_VAR, widgetVar, null);
+ writer.writeAttribute("data-repo", github.getRepository(), "data-repo");
+ writer.endElement("div");
+ }
+
+ /**
+ * Create the Javascript.
+ */
+ private void encodeScript(final FacesContext context, final Github github) throws IOException {
+ final WidgetBuilder wb = getWidgetBuilder(context);
+ final String clientId = github.getClientId(context);
+ wb.initWithDomReady("ExtGitHub", github.resolveWidgetVar(), clientId);
+ wb.attr("iconForks", github.isIconForks());
+ wb.attr("iconIssues", github.isIconIssues());
+ wb.attr("iconStars", github.isIconStars());
+ wb.finish();
+ }
+
+}
@@ -63,6 +63,10 @@
<component-class>org.primefaces.extensions.component.exporter.DataExporter</component-class>
</component>
<component>
+ <component-type>org.primefaces.extensions.component.Github</component-type>
+ <component-class>org.primefaces.extensions.component.github.Github</component-class>
+ </component>
+ <component>
<component-type>org.primefaces.extensions.component.Head</component-type>
<component-class>org.primefaces.extensions.component.head.ExtHead</component-class>
</component>
@@ -205,6 +209,11 @@
</renderer>
<renderer>
<component-family>org.primefaces.extensions.component</component-family>
+ <renderer-type>org.primefaces.extensions.component.GithubRenderer</renderer-type>
+ <renderer-class>org.primefaces.extensions.component.github.GithubRenderer</renderer-class>
+ </renderer>
+ <renderer>
+ <component-family>org.primefaces.extensions.component</component-family>
<renderer-type>org.primefaces.extensions.component.HeadRenderer</renderer-type>
<renderer-class>org.primefaces.extensions.component.head.ExtHeadRenderer</renderer-class>
</renderer>
@@ -1296,6 +1296,78 @@
</attribute>
</tag>
<tag>
+ <description><![CDATA[Github is a component to display your Github Repositories.]]></description>
+ <tag-name>github</tag-name>
+ <component>
+ <component-type>org.primefaces.extensions.component.Github</component-type>
+ <renderer-type>org.primefaces.extensions.component.GithubRenderer</renderer-type>
+ </component>
+ <attribute>
+ <description><![CDATA[Unique identifier of the component in a namingContainer.]]></description>
+ <name>id</name>
+ <required>false</required>
+ <type>java.lang.String</type>
+ </attribute>
+ <attribute>
+ <description><![CDATA[Boolean value to specify the rendering of the component, when set to false component will not be rendered.]]></description>
+ <name>rendered</name>
+ <required>false</required>
+ <type>java.lang.Boolean</type>
+ </attribute>
+ <attribute>
+ <description><![CDATA[An el expression referring to a server side UIComponent instance in a backing bean.]]></description>
+ <name>binding</name>
+ <required>false</required>
+ <type>javax.faces.component.UIComponent</type>
+ </attribute>
+ <attribute>
+ <description><![CDATA[Name of the client side widget.]]></description>
+ <name>widgetVar</name>
+ <required>false</required>
+ <type>java.lang.String</type>
+ </attribute>
+ <attribute>
+ <description><![CDATA[Github repository like 'jquery-boilerplate/jquery-boilerplate'.]]></description>
+ <name>repository</name>
+ <required>true</required>
+ <type>java.lang.String</type>
+ </attribute>
+ <attribute>
+ <description><![CDATA[Display the number of stars of the repo. Default is true.]]></description>
+ <name>iconStars</name>
+ <required>false</required>
+ <type>java.lang.Boolean</type>
+ </attribute>
+ <attribute>
+ <description><![CDATA[Display the number of forks of the repo. Default is true.]]></description>
+ <name>iconForks</name>
+ <required>false</required>
+ <type>java.lang.Boolean</type>
+ </attribute>
+ <attribute>
+ <description><![CDATA[Display the number of issues of the repo. Default is true.]]></description>
+ <name>iconIssues</name>
+ <required>false</required>
+ <type>java.lang.Boolean</type>
+ </attribute>
+ <attribute>
+ <description>
+ <![CDATA[Style of the main container element. Default value is null.]]>
+ </description>
+ <name>style</name>
+ <required>false</required>
+ <type>java.lang.String</type>
+ </attribute>
+ <attribute>
+ <description>
+ <![CDATA[Style class of the main container element. Default value is null.]]>
+ </description>
+ <name>styleClass</name>
+ <required>false</required>
+ <type>java.lang.String</type>
+ </attribute>
+ </tag>
+ <tag>
<tag-name>head</tag-name>
<component>
<component-type>org.primefaces.extensions.component.Head</component-type>
Oops, something went wrong.

0 comments on commit 65e1eb3

Please sign in to comment.