File tree Expand file tree Collapse file tree 4 files changed +23
-19
lines changed
generators/rails_script/install Expand file tree Collapse file tree 4 files changed +23
-19
lines changed Original file line number Diff line number Diff line change @@ -22,26 +22,9 @@ def create_controllers
2222
2323 def insert_layout_javascript
2424 say <<-RUBY
25- In order to complete installation, you must add the following JavaScript snippet before the CLOSING body tag in your application layout.
25+ In order to complete installation, you must include the following helper BEFORE the closing body tag in the application layout:
2626
27- ERB:
28- <script>
29- jQuery(function() {
30- window.$this = new (App.<%= controller_path.split(/\\ /|_/).map(&:capitalize).join('') %> || App.Base)();
31- if (typeof $this.<%= action_name %> === 'function') {
32- return $this.<%= action_name%>.call();
33- }
34- });
35- </script>
36-
37- HAML:
38- :javascript
39- jQuery(function() {
40- window.$this = new (App.\# {controller_path.split(/\\ /|_/).map(&:capitalize).join('')} || App.Base)();
41- if (typeof $this.\# {action_name} === 'function') {
42- return $this.\# {action_name}.call();
43- }
44- });
27+ <%= include_rails_script %>
4528 RUBY
4629 end
4730
Original file line number Diff line number Diff line change 11require 'rails_script/version'
2+ require 'rails_script/loader_helper'
23require 'rails_script/railtie' if defined? ( Rails )
34
45module RailsScript
Original file line number Diff line number Diff line change 1+ module RailsScript
2+ module LoaderHelper
3+
4+ def include_rails_script
5+ javascript_tag <<-RUBY
6+ jQuery(function() {
7+ window.$this = new (App.#{ controller_path . split ( /\/ |_/ ) . map ( &:capitalize ) . join ( '' ) } || App.Base)();
8+ if (typeof $this.#{ action_name } === 'function') {
9+ return $this.#{ action_name } .call();
10+ }
11+ });
12+ RUBY
13+ end
14+
15+ end
16+ end
Original file line number Diff line number Diff line change @@ -3,5 +3,9 @@ class Railtie < Rails::Railtie
33 config . app_generators do |g |
44 g . templates . unshift File ::expand_path ( '../../templates' , __FILE__ )
55 end
6+
7+ initializer 'rails_Script.loader_helper' do
8+ ActionView ::Base . send :include , LoaderHelper
9+ end
610 end
711end
You can’t perform that action at this time.
0 commit comments