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

Commit de30389

Browse files
committed
Merge pull request #47 from jwhitley/optional_javascript_path
Introduce fallback for missing #javascript_path
2 parents 937682e + 64f631b commit de30389

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

app/helpers/requirejs_helper.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def _requirejs_data(name, &block)
55
{}.tap do |data|
66
if name
77
name += ".js" unless name =~ /\.js$/
8-
data['main'] = javascript_path(name)
8+
data['main'] = _javascript_path(name)
99
end
1010

1111
data.merge!(yield controller) if block_given?
@@ -17,7 +17,7 @@ def _requirejs_data(name, &block)
1717
def _data_main(name)
1818
if name
1919
name += ".js" unless name =~ /\.js$/
20-
%Q{data-main="#{javascript_path(name)}"}
20+
%Q{data-main="#{_javascript_path(name)}"}
2121
else
2222
""
2323
end
@@ -41,7 +41,7 @@ def requirejs_include_tag(name=nil, &block)
4141

4242
# Generate digestified paths from the modules spec
4343
paths = {}
44-
modules.each { |m| paths[m] = javascript_path(m).sub /\.js$/,'' }
44+
modules.each { |m| paths[m] = _javascript_path(m).sub /\.js$/,'' }
4545

4646
# Override uesr paths, whose mappings are only relevant in dev mode
4747
# and in the build_config.
@@ -53,7 +53,7 @@ def requirejs_include_tag(name=nil, &block)
5353
end
5454

5555
html.concat <<-HTML
56-
<script #{_requirejs_data(name, &block)} src="#{javascript_path 'require.js'}"></script>
56+
<script #{_requirejs_data(name, &block)} src="#{_javascript_path 'require.js'}"></script>
5757
HTML
5858

5959
html.html_safe
@@ -72,6 +72,14 @@ def _once_guard
7272
end
7373

7474
def _almond_include_tag(name, &block)
75-
"<script src='#{javascript_path name}'></script>\n".html_safe
75+
"<script src='#{_javascript_path name}'></script>\n".html_safe
76+
end
77+
78+
def _javascript_path(name)
79+
if defined?(javascript_path)
80+
javascript_path(name)
81+
else
82+
"/assets/#{name}"
83+
end
7684
end
7785
end

0 commit comments

Comments
 (0)