Skip to content

Instantly share code, notes, and snippets.

@th3hunt
Last active August 18, 2016 00:41
Show Gist options
  • Save th3hunt/7d8673a4571aae6da874 to your computer and use it in GitHub Desktop.
Save th3hunt/7d8673a4571aae6da874 to your computer and use it in GitHub Desktop.
A teaspoon boot loader that works with browserify rails
# 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
<!-- 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