Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled RuboCop MethodLength in encapsulate_js_iruby method #73

Merged
merged 2 commits into from
Feb 17, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 35 additions & 23 deletions lib/daru/view/adapters/highcharts/layout_helper_iruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,53 @@ def build_html_output_iruby(type, placeholder, object, &block)
encapsulate_js_iruby core_js
end

# rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength
# rubocop:disable Metrics/PerceivedComplexity
def encapsulate_js_iruby(core_js)
js_output =
if request_is_xhr?
"#{js_start_iruby} #{core_js} #{js_end_iruby}"
# Turbolinks.version < 5
elsif defined?(Turbolinks) && request_is_referrer?
<<-EOJS
#{js_start_iruby}
var f = function(){
document.removeEventListener('page:load', f, true);
#{core_js}
};
document.addEventListener('page:load', f, true);
#{js_end_iruby}
EOJS
to_s(page_load)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't eventListener_pageLoad is better method name?

elsif defined?(Turbolinks) && request_turbolinks_5_tureferrer?
<<-EOJS
#{js_start_iruby}
document.addEventListener("turbolinks:load", function() {
#{core_js}
});
#{js_end_iruby}
EOJS
to_s(turbolinks_load)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't eventListener_turbolinksLoad is better method name?

else
<<-EOJS
#{js_start_iruby}
#{core_js}
#{js_end_iruby}
EOJS
to_s(call_core_js)
end

defined?(raw) ? raw(js_output) : js_output
end
# rubocop:enable Metrics/PerceivedComplexity, Metrics/MethodLength
# rubocop:enable Metrics/PerceivedComplexity

def page_load
<<-EOJS
#{js_start_iruby}
var f = function(){
document.removeEventListener('page:load', f, true);
#{core_js}
};
document.addEventListener('page:load', f, true);
#{js_end_iruby}
EOJS
end

def turbolinks_load
<<-EOJS
#{js_start_iruby}
document.addEventListener("turbolinks:load", function() {
#{core_js}
});
#{js_end_iruby}
EOJS
end

def call_core_js
<<-EOJS
#{js_start_iruby}
#{core_js}
#{js_end_iruby}
EOJS
end

def js_start_iruby
<<-EOJS
Expand Down