001// Copyright 2020 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry5.corelib.components; 016 017 018import org.apache.tapestry5.BindingConstants; 019import org.apache.tapestry5.ComponentResources; 020import org.apache.tapestry5.MarkupWriter; 021import org.apache.tapestry5.annotations.Parameter; 022import org.apache.tapestry5.annotations.SupportsInformalParameters; 023import org.apache.tapestry5.ioc.annotations.Inject; 024 025/** 026 * Renders an {@code <i>} tag with the CSS class to select a <a href="https://fontawesome.com/v4.7.0/">FontAwesome 4.7.0</a> icon. 027 * If Twitter Bootstrap 3 isn't enabled (i.e @{link Trait#BOOTSTRAP_3 is set to false), 028 * this component automatically and transparently replaces {@link Glyphicon} usages. 029 * 030 * @see org.apache.tapestry5.services.compatibility.Trait#BOOTSTRAP_3 031 * @tapestrydoc 032 * @since 5.5 033 */ 034@SupportsInformalParameters 035public class FontAwesomeIcon 036{ 037 /** 038 * The name of the icon, e.g., "arrow-up", "flag", "fire" etc. 039 */ 040 @Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL) 041 private String name; 042 043 @Inject 044 ComponentResources resources; 045 046 boolean beginRender(MarkupWriter writer) 047 { 048 writer.element("i", 049 "class", "fa fa-" + name); 050 resources.renderInformalParameters(writer); 051 writer.end(); 052 053 return false; 054 } 055}