Ability to register custom template engines... #111

Merged
rossta merged 1 commits from register_custom_template_hook into master 2012-03-22 11:17:13 +00:00
rossta commented 2012-01-22 23:47:43 +00:00 (Migrated from github.com)

...via Jasmine::Headless.register_engine hook

In response to issue #102, I added the ability to register custom template engines not currently supported by default in JHW. The hook may be registered by placing ruby code in #{spec_dir}/helpers/spec_helper.rb. (Perhaps the location of this file can be configurable.)

For example, I am using the following to compile Handlebars templates via the handlebars_assets gem for JHW in my current project:

# spec/javascripts/helpers/spec_helper.rb

require 'sprockets'
require 'handlebars_assets'

module Jasmine::Headless
  class HandlebarsTemplate < HandlebarsAssets::TiltHandlebars
    include Jasmine::Headless::FileChecker
    def evaluate(*args)
      if bad_format?(file)
        alert_bad_format(file)
        return ''
      end
      %{<script type="text/javascript">#{super}</script>}
    end
  end
end

Jasmine::Headless.register_engine '.hbs', Jasmine::Headless::HandlebarsTemplate
...via Jasmine::Headless.register_engine hook In response to [issue #102](https://github.com/johnbintz/jasmine-headless-webkit/issues/102), I added the ability to register custom template engines not currently supported by default in JHW. The hook may be registered by placing ruby code in #{spec_dir}/helpers/spec_helper.rb. (Perhaps the location of this file can be configurable.) For example, I am using the following to compile Handlebars templates via the `handlebars_assets` gem for JHW in my current project: ``` ruby # spec/javascripts/helpers/spec_helper.rb require 'sprockets' require 'handlebars_assets' module Jasmine::Headless class HandlebarsTemplate < HandlebarsAssets::TiltHandlebars include Jasmine::Headless::FileChecker def evaluate(*args) if bad_format?(file) alert_bad_format(file) return '' end %{<script type="text/javascript">#{super}</script>} end end end Jasmine::Headless.register_engine '.hbs', Jasmine::Headless::HandlebarsTemplate ```
johnbintz commented 2012-01-25 14:23:23 +00:00 (Migrated from github.com)

Nice! Thanks for tackling this, I appreciate it. :) I'm going to mull over the implementation and give it a spin in a few days, then figure out if I want to take it in as-is or suggest changes. Other projects are taking my time right now.

Nice! Thanks for tackling this, I appreciate it. :) I'm going to mull over the implementation and give it a spin in a few days, then figure out if I want to take it in as-is or suggest changes. Other projects are taking my time right now.
rossta commented 2012-01-26 05:24:27 +00:00 (Migrated from github.com)

Cool. Perhaps I can help if you're interested in trying another approach.

Cool. Perhaps I can help if you're interested in trying another approach.
aaronjensen commented 2012-03-22 05:41:24 +00:00 (Migrated from github.com)

any updates on this?

any updates on this?
johnbintz commented 2012-03-22 11:17:08 +00:00 (Migrated from github.com)

I've mulled it over and I'm fine with this. Can you also add some info to the docs on the gh-pages branch on how this works?

I've mulled it over and I'm fine with this. Can you also add some info to the docs on the `gh-pages` branch on how this works?
Sign in to join this conversation.
No reviewers
No Label
bug
doc
feature
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: github-migration/jasmine-headless-webkit#111
No description provided.