Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
yxmatic committed Apr 19, 2013
2 parents 96207e2 + d7dbd14 commit 31452ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
56 changes: 30 additions & 26 deletions app/helpers/requirejs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,51 @@ def _requirejs_data(name, &block)
end.join(" ")
end

def requirejs_include_tag(name=nil, &block)
def requirejs_include_tag(name = nil, options = {}, &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)
end

html = ActiveSupport::SafeBuffer.new

_once_guard do
unless requirejs.run_config.empty?
run_config = requirejs.run_config.dup
unless _priority.empty?
run_config = run_config.dup
run_config[:priority] ||= []
run_config[:priority].concat _priority
end
if Rails.application.config.assets.digest
modules = requirejs.build_config['modules'].map { |m| requirejs.module_name_for m }
html = ActiveSupport::SafeBuffer.new
html.safe_concat "<script>#{requirejs_config_js(name)}</script>\n" unless options[:skip_config]
html.safe_concat %Q|<script #{_requirejs_data(name, &block)} src="#{_javascript_path requirejs.bootstrap_file}" data-turbolinks-track></script>|
html
end
end

# Generate digestified paths from the modules spec
paths = {}
modules.each { |m| paths[m] = _javascript_path(m).sub /\.js$/,'' }
def requirejs_config_js(name = nil)
requirejs = Rails.application.config.requirejs

unless requirejs.run_config.empty?
run_config = requirejs.run_config.dup
unless _priority.empty?
run_config = run_config.dup
run_config[:priority] ||= []
run_config[:priority].concat _priority
end
if Rails.application.config.assets.digest
modules = requirejs.build_config['modules'].map { |m| requirejs.module_name_for m }

if run_config.has_key? 'paths'
# Add paths for assets specified by full URL (on a CDN)
run_config['paths'].each { |k,v| paths[k] = v if v =~ /^https?:/ }
end
# Generate digestified paths from the modules spec
paths = {}
modules.each { |m| paths[m] = _javascript_path(m).sub /\.js$/,'' }

# Override user paths, whose mappings are only relevant in dev mode
# and in the build_config.
run_config['paths'] = paths
if run_config.has_key? 'paths'
# Add paths for assets specified by full URL (on a CDN)
run_config['paths'].each { |k,v| paths[k] = v if v =~ /^https?:/ }
end

run_config['baseUrl'] = baseUrl(name)
html.safe_concat %Q|<script>var require = #{run_config.to_json};#{requirejs.bootstrap_config}</script>\n|
# Override user paths, whose mappings are only relevant in dev mode
# and in the build_config.
run_config['paths'] = paths
end

html.safe_concat %Q|<script #{_requirejs_data(name, &block)} src="#{_javascript_path requirejs.bootstrap_file}" data-turbolinks-track></script>|
html
run_config['baseUrl'] = baseUrl(name)
"var require = #{run_config.to_json};".html_safe
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/requirejs/rails/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def initialize

self.loader = :requirejs
self.bootstrap_file = 'require.js'
self.bootstrap_config = ''

self.driver_template_path = Pathname.new(__FILE__+'/../rjs_driver.js.erb').cleanpath
self.driver_path = self.tmp_dir + 'rjs_driver.js'
Expand Down

0 comments on commit 31452ea

Please sign in to comment.