Added EncodeHTMl, EncodeJson, EncodeUrl and EncodeXml
This commit is contained in:
parent
a32fde02d0
commit
a224733077
7 changed files with 222 additions and 10 deletions
4
.idea/misc.xml
generated
4
.idea/misc.xml
generated
|
@ -7,6 +7,10 @@
|
|||
<pattern value="rife2.render.Trim" />
|
||||
<pattern value="rife2.render.Uncapitalize" />
|
||||
<pattern value="rife2.render.Uppercase" />
|
||||
<pattern value="rife2.render.EncodeHtml" />
|
||||
<pattern value="rife2.render.EncodeJson" />
|
||||
<pattern value="rife2.render.EncodeUrl" />
|
||||
<pattern value="rife2.render.EncodeXml" />
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="PDMPlugin">
|
||||
|
|
16
README.md
16
README.md
|
@ -7,6 +7,14 @@ This project provides a set of template renderers.
|
|||
|
||||
- **rife.render.Capitalize**
|
||||
- Capitalizes a template value.
|
||||
- **rife.render.EncodeHtml**
|
||||
- Encodes a template value to HTML.
|
||||
- **rife.render.EncodeJson**
|
||||
- Encodes a template value to JSON.
|
||||
- **rife.render.EncodeUrl**
|
||||
- URL-encodes a template value.
|
||||
- **rife.render.EncodeXml**
|
||||
- Encodes a template value to XML.
|
||||
- **rife.render.Lowercase**
|
||||
- Converts a template value to lowercase.
|
||||
- **rife.render.SwapCase**
|
||||
|
@ -22,24 +30,24 @@ This project provides a set of template renderers.
|
|||
|
||||
All rendered can be used at follows:
|
||||
|
||||
```html
|
||||
```
|
||||
<!--v render:rife.render.RendererName:valueId/-->
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```json
|
||||
```
|
||||
{{v render:rife.render.RendererName:valueId}}
|
||||
```
|
||||
|
||||
For example, to capitalize a template `foo` value:
|
||||
|
||||
```html
|
||||
```
|
||||
<!--v render:rife.render.Capitalize:foo/-->
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```json
|
||||
```
|
||||
{{v render:rife.render.Capitalize:foo}}
|
||||
```
|
||||
|
|
|
@ -29,7 +29,7 @@ dependencies {
|
|||
|
||||
configurations {
|
||||
all {
|
||||
resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS);
|
||||
resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
50
lib/src/main/java/rife2/render/EncodeHtml.java
Normal file
50
lib/src/main/java/rife2/render/EncodeHtml.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 rife2.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>Encodes a template value to HTML.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeHtml:valueId/-->
|
||||
* {{v render:rife.render.EncodeHtml:valueId}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeHtml(String)
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeHtml implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeHtml(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife2/render/EncodeJson.java
Normal file
50
lib/src/main/java/rife2/render/EncodeJson.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 rife2.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>Encodes a template value to JSON.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeJson:valueId/-->
|
||||
* {{v render:rife.render.EncodeJson:valueId}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeJson(String)
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeJson implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeJson(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife2/render/EncodeUrl.java
Normal file
50
lib/src/main/java/rife2/render/EncodeUrl.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 rife2.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>URL-encodes a template value.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeUrl:valueId/-->
|
||||
* {{v render:rife.render.EncodeUrl:valueId}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeUrl(String)
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeUrl implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeUrl(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife2/render/EncodeXml.java
Normal file
50
lib/src/main/java/rife2/render/EncodeXml.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 rife2.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>Encodes a template value to XML.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeXml:valueId/-->
|
||||
* {{v render:rife.render.EncodeXml:valueId}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeXml(String)
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeXml implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeXml(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue