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

Raw block helpers #573

Closed
wants to merge 2 commits into from
Closed

Raw block helpers #573

wants to merge 2 commits into from

Conversation

jezell
Copy link

@jezell jezell commented Jul 11, 2013

Adds support for raw block helpers. Example:

{{{{markdown}}}}
In handlebars.js text like {{name}} will not be substituted with the value of the variable name.
{{{{/markdown}}}}

Fixes #559

@kpdecker
Copy link
Collaborator

Generally I like this but do worry about the performance overhead that this may introduce for something that is not a super common use case. How much size does this add to the generated parser file?

@jezell
Copy link
Author

jezell commented Jul 15, 2013

File sizes for output:

handlebars.js - 75kb
handlebars.min.js - 52kb
handlebars.runtime.js - 11kb
handlebars.runtime.min.js - 8kb

<com>[\s\S]*?"--}}" { yytext = yytext.substr(0, yyleng-4); this.popState(); return 'COMMENT'; }

<mu>"{{{{" { return 'OPEN_RAW_BLOCK'; }
<mu>"}}}}" { this.popState(); this.begin('raw'); return 'CLOSE_RAW_BLOCK'; }
<mu>"{{{{"[^\x00]*"}}}}" { yytext = yytext.substr(4, yyleng-8); this.popState(); return 'RAW_BLOCK'; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this construct? I don't see it used in the productions below.

@kpdecker
Copy link
Collaborator

I'm not sure how common this use case is but it only adds ~1.6kb and I've noted a few places that the jison output can be optimized. We will need to document this but after that happens I'll merge it.

@kpdecker
Copy link
Collaborator

I can try to document but a PR would certainly make that process faster :)

@kpdecker
Copy link
Collaborator

@jezell We just landed some major changes to the code organization. Would you be willing to rebase this onto master?

@shturm
Copy link

shturm commented Jun 14, 2014

I'm still experiencing the issue this merge should resolve. I'm trying to put <pre><code> tag with javascript content into a template and it fires an error. To be precise

{{#markdown}}
 ` ` `
/*global module:false*/


  // Project configuration.
  grunt.initConfig({
    // Metadata.
    pkg: grunt.file.readJSON('package.json'), // provides access to the JSON metadata
    // this demonstrates grunt templates so you can insert a banner in your source files
    // this is a varialble, so you can name it however you like
    banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
      '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
      '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
      '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
      ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',


    // Task configuration. When you have registered grunt plugins
    // they are available for execution by being configured here

    concat: { // `concat` task, cocatenates files together
      options: { // global options for `concat` task
        banner: '<%= banner %>', // this will be included in all output files
        stripBanners: true // remove banners (e.g. license text) of input files
      },
      dist: { // `concat` subtask. Name doesn't matter. Can be invoked with `grunt concat:dist`
        src: ['src/jquery.js','src/business-logic.js','misc.js'], // files to concatenate in the same order
        dest: 'dist/app.js' // output filename of cocatenated files
      }
    },
    uglify: { // uglify task
      options: { // global options for all `uglify` subtasks
        banner: '<%= banner %>' // banner to be included in uglified files
      },
      dist: { // `uglify` subtask
        src: '<%= concat.dist.dest %>', // takes whatever `concat` task has produced
        dest: 'dist/app.min.js' // and minifies it into the file specified
      }
    },
    copy: { // `copy` task
      main: { 
        src: 'index.html', // files/folders to be copied
        dest: 'dist/' // destination for the files
      }
    },
    jshint: { // `jshint` task.
      options: { // `jshint` options. For details see https://github.com/gruntjs/grunt-contrib-jshint#options
        curly: true,
        eqeqeq: true,
        immed: true,
        latedef: true,
        newcap: true,
        noarg: true,
        sub: true,
        undef: true,
        unused: true,
        boss: true,
        eqnull: true,
        browser: true,
        globals: {}
      },
      gruntfile: { // `jshint` subtask
        src: 'Gruntfile.js' // single file to be checked
      },
      source: { // `jshint` subtask
        src: ['src/business-logic.js','misc.js'] // following files are to be checked
      }
    },

    watch: { // `watch` task - executes other tasks when specified files change
      gruntfile: { // `watch` subtask
        files: '<%= jshint.gruntfile.src %>', // if the grunt configuration file changes
        tasks: ['jshint:gruntfile'] // it will execute only the `gruntfile` subtask of the `jshint` task
      },
      source: { // `watch` subtask.
        files: 'src/**/*.(css|js)', // if any CSS or JS files change but only in the src/ folder
        tasks: ['jshint:source','concat','uglify'] // it will execute the specified tasks and/or subtasks
      }
    }
  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-qunit');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-watch');

  // Default task. Defines which tasks to execute if there are no tasks/subtasks specified
  // when grunt is executed.
  grunt.registerTask('default', ['jshint', 'concat', 'uglify','copy']);

  // You can define custom names yourself.
  // grunt.registerTask('mycustomtask', ['concat', 'uglify']);

};
` ` `
{{/markdown}}

Adding changing double braces with 4 doesn't work in this case. E.g.

{{{{#markdown}}}} {{thisShouldNotBeReplaced}} {{{{/markdown}}}}

@kpdecker
Copy link
Collaborator

@shturm please open a new issue. Discussion of issues on a closed issue are very likely to be lost.

We will want to see an example of the code failing, I'm not sure quite sure what exactly is failing from your comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No way to directly process a block's inner text?
3 participants