Created
April 27, 2020 20:20
-
-
Save Yardboy/ca4c21d99dc589d2553bb1aabb94fe17 to your computer and use it in GitHub Desktop.
js.erb template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ from 'jquery' | |
import _ from 'lodash' | |
<% klasses = [] %> | |
<% Dir[Rails.root.join('app', 'javascript', 'pages', '*_page.js*')].each do |file| %> | |
<% | |
page = file.match(%r{.*/pages/(.*).js?}).captures.first | |
next if page == 'base_page' | |
klasses << page.classify | |
%> | |
<%= "import #{klasses.last} from './#{page}.js'" %> | |
<% end %> | |
const Pages = {} | |
<% klasses.each do |klass| %> | |
<%= "Pages.#{klass} = #{klass}" %> | |
<% end %> | |
const runner = () => { | |
const $body = $('body') | |
const controller = _.startCase($body.data('controller')).replace(' ', '') | |
const action = _.startCase($body.data('action')).replace(' ', '') | |
const module = loadPageComponent(controller, action) | |
if (module) { | |
onload(module) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment