app/helpers/requirejs_helper.rb in requirejs-rails-0.9.5 vs app/helpers/requirejs_helper.rb in requirejs-rails-0.9.6

- old
+ new

@@ -1,15 +1,16 @@ -require 'requirejs/error' +require "requirejs/error" +require "requirejs/rails/view_proxy" module RequirejsHelper # EXPERIMENTAL: Additional priority settings appended to # any user-specified priority setting by requirejs_include_tag. # Used for JS test suite integration. mattr_accessor :_priority @@_priority = [] - def requirejs_include_tag(name=nil, &block) + def requirejs_include_tag(name = nil, &block) requirejs = Rails.application.config.requirejs if requirejs.loader == :almond name = requirejs.module_name_for(requirejs.build_config['modules'][0]) return almond_include_tag(name, &block) @@ -73,18 +74,26 @@ html.html_safe end end - def javascript_path(name) + def javascript_path(source, options = {}) if defined?(super) super else - "/assets/#{name}" + view_proxy.javascript_path(source, options) end end + def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block) + if defined?(super) && respond_to?(:output_buffer) && respond_to?(:output_buffer=) + super + else + view_proxy.content_tag(name, content_or_options_with_block, options, escape, &block) + end + end + private def once_guard if defined?(controller) && controller.requirejs_included raise Requirejs::MultipleIncludeError, "Only one requirejs_include_tag allowed per page." @@ -103,7 +112,11 @@ def base_url(js_asset) js_asset_path = javascript_path(js_asset) uri = URI.parse(js_asset_path) asset_host = uri.host && js_asset_path.sub(uri.request_uri, '') [asset_host, Rails.application.config.relative_url_root, Rails.application.config.assets.prefix].join + end + + def view_proxy + @view_proxy ||= Requirejs::Rails::ViewProxy.new end end