Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document all options for theme helpers #69

Closed
loganvolkers opened this issue Jul 24, 2015 · 0 comments
Closed

Document all options for theme helpers #69

loganvolkers opened this issue Jul 24, 2015 · 0 comments

Comments

@loganvolkers
Copy link
Member

Helpers to document:

  • MathHelper
  • Gravatar
  • URLEncode
  • Math

Gravatar:

 "gravatar"

    @Override
    public CharSequence apply(String emailAddress, Options options) throws IOException {
        Boolean secure = options.hash("secure", false);
        if(emailAddress == null){
            return secure ? SECURE_DEFAULT_GRAVATAR_URL : DEFAULT_GRAVATAR_URL;
        }
        Integer s = options.hash("size");
        String d = options.hash("default");
        String f = options.hash("forcedefault");
        String r = options.hash("rating");

Math

 "math"

saasquatch.utils.thirdparty.Expression

UrlEncode

    private static final String DEFAULT_CHARSET = "UTF-8";
    private static final String DEFAULT_SPACING = "+";
    public static final String NAME = "urlencode";

    @Override
    public CharSequence apply(String content, Options options) throws IOException {
        String charset = options.hash("charset", DEFAULT_CHARSET);
        String space = options.hash("space", DEFAULT_SPACING);
        String ret = URLEncoder.encode(content, charset);
        if(!space.equals(DEFAULT_SPACING)) {
            ret = ret.replace(DEFAULT_SPACING, space); 
        }
        return new Handlebars.SafeString(ret);
    }

Asset Helper

    private final String cdnDomain;
    private final String themeId;

    public AssetHelper(String themeId, String cdnDomain) {
        this.themeId = themeId;
        this.cdnDomain = cdnDomain;
    }

    @Override
    public CharSequence apply(String fileUrl, Options options) {
        Context rootContext = HandlebarsFactoryImpl.getRootContext(options);

        String assetVersion = String.valueOf(rootContext.get("assetVersion"));
        Boolean isSecureUrl = Boolean.parseBoolean(String.valueOf(rootContext.get("isSecureUrl")));

        String ret = Cdn.getResourceAt("/theme/" + themeId + "/assets/" + assetVersion + "/" + fileUrl, cdnDomain, isSecureUrl);
        return new Handlebars.SafeString(ret);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant