Last active
August 18, 2016 00:41
-
-
Save th3hunt/7d8673a4571aae6da874 to your computer and use it in GitHub Desktop.
A teaspoon boot loader that works with browserify rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/teaspoon.rb | |
module Teaspoon | |
module BootHelper | |
def create_browserify_bundle(suite) | |
bundle = File.join(Rails.root, 'tmp/javascripts', "suites/#{suite.name}.js") | |
bundle_dir = File.dirname(bundle) | |
FileUtils.mkdir_p(bundle_dir) unless File.directory?(bundle_dir) | |
specs = suite.spec_assets(false).map { |asset| "#{asset.gsub(/\.js.*$/, '')}" } | |
File.open(bundle, 'w') do |bundle_file| | |
yield bundle_file if block_given? | |
specs.each { |spec| bundle_file.puts "require('../../../spec/javascripts/#{spec}');" } | |
end | |
end | |
end | |
class Engine < ::Rails::Engine | |
isolate_namespace Teaspoon | |
config.to_prepare do | |
Teaspoon::SuiteController.helper(BootHelper) if Rails.env.development? || Rails.env.test? | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- fixtures/teaspoon/_browserify_boot.html.erb --> | |
<% create_browserify_bundle(@suite) %> | |
<%= javascript_include_tag "suites/#{@suite.name}" %> | |
<%= javascript_include_tag @suite.helper if @suite.helper %> | |
<script> | |
Teaspoon.onWindowLoad(Teaspoon.execute); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment