Skip to content

Instantly share code, notes, and snippets.

@Defite
Forked from Lerg/index-content.js
Last active March 20, 2016 20:14
Show Gist options
  • Select an option

  • Save Defite/4b7b8b8eff175e8c9106 to your computer and use it in GitHub Desktop.

Select an option

Save Defite/4b7b8b8eff175e8c9106 to your computer and use it in GitHub Desktop.

Revisions

  1. Defite renamed this gist Mar 20, 2016. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions index-content.js → content.js
    Original file line number Diff line number Diff line change
    @@ -33,11 +33,8 @@ coreHelpers.content = function (options) {
    downsize(this.html, truncateOptions)
    );
    } else if (truncateOptions.hasOwnProperty('preview')) {
    var split = this.html.split('<!--preview-->', 2)
    var split = this.html.split('<!--more-->', 2)
    var output = split[0]
    if (split[1]) {
    output += '<div class="continue">● ● ●</div>'
    }
    return new hbs.handlebars.SafeString(output)
    }

  2. @Lerg Lerg revised this gist Jun 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index-content.js
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    //
    // Enables tag-safe truncation of content by characters or words.
    //
    // If cut option is used, then only the content before cut is returned.
    // If preview option is used then only the content before <!--preview--> is returned.
    //
    // **returns** SafeString content html, complete or truncated.
    //
  3. @Lerg Lerg revised this gist Jun 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index-content.js
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ coreHelpers.content = function (options) {
    var split = this.html.split('<!--preview-->', 2)
    var output = split[0]
    if (split[1]) {
    output += '<div class="continue">● ● ●/div>'
    output += '<div class="continue">● ● ●</div>'
    }
    return new hbs.handlebars.SafeString(output)
    }
  4. @Lerg Lerg revised this gist Jun 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index-content.js
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ coreHelpers.content = function (options) {
    var split = this.html.split('<!--preview-->', 2)
    var output = split[0]
    if (split[1]) {
    output += '<div class="continue">&hellip;</div>'
    output += '<div class="continue">● ● ●/div>'
    }
    return new hbs.handlebars.SafeString(output)
    }
  5. @Lerg Lerg created this gist Jun 20, 2014.
    45 changes: 45 additions & 0 deletions index-content.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    // ### Content Helper
    //
    // *Usage example:*
    // `{{content}}`
    // `{{content words="20"}}`
    // `{{content characters="256"}}`
    // `{{content preview="true"}}`
    //
    // Turns content html into a safestring so that the user doesn't have to
    // escape it or tell handlebars to leave it alone with a triple-brace.
    //
    // Enables tag-safe truncation of content by characters or words.
    //
    // If cut option is used, then only the content before cut is returned.
    //
    // **returns** SafeString content html, complete or truncated.
    //
    coreHelpers.content = function (options) {
    var truncateOptions = (options || {}).hash || {};
    truncateOptions = _.pick(truncateOptions, ['words', 'characters', 'preview']);
    _.keys(truncateOptions).map(function (key) {
    truncateOptions[key] = parseInt(truncateOptions[key], 10);
    });

    if (truncateOptions.hasOwnProperty('words') || truncateOptions.hasOwnProperty('characters')) {
    // Due to weirdness in downsize the 'words' option
    // must be passed as a string. refer to #1796
    // TODO: when downsize fixes this quirk remove this hack.
    if (truncateOptions.hasOwnProperty('words')) {
    truncateOptions.words = truncateOptions.words.toString();
    }
    return new hbs.handlebars.SafeString(
    downsize(this.html, truncateOptions)
    );
    } else if (truncateOptions.hasOwnProperty('preview')) {
    var split = this.html.split('<!--preview-->', 2)
    var output = split[0]
    if (split[1]) {
    output += '<div class="continue">&hellip;</div>'
    }
    return new hbs.handlebars.SafeString(output)
    }

    return new hbs.handlebars.SafeString(this.html);
    };