-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework JS static site code structure
This splits up the generator class as was a problem suspected in this PR review: #15640 (review) It creates a single class for a Browser which extends the capybara-webkit browser to include a way to get a page's contents after jQuery's AJAX calls are done. This is in a StaticSite module just to namespace it and indicate where it's used in the application, rather than it's nature. In other words it's not a _static site browser_ but you could read it that way so maybe this needs changing? All the remaining procedural logic is pushed into the Rake task. From here we could then extract that if we see fit.
- Loading branch information
Showing
3 changed files
with
43 additions
and
63 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'capybara-webkit' | ||
|
||
module StaticSite | ||
class Browser < Capybara::Webkit::Browser | ||
JQUERY_WAIT_TIME = 2 | ||
|
||
def initialize | ||
super(Capybara::Webkit::Connection.new(server: Capybara::Webkit::Server.new)) | ||
allow_unknown_urls | ||
end | ||
|
||
def body_after_jquery_ajax | ||
wait_for_jquery_ajax | ||
restore_pre_js_page_classes | ||
body | ||
end | ||
|
||
def wait_for_jquery_ajax | ||
Timeout.timeout(JQUERY_WAIT_TIME) do | ||
# Errors if jQuery isn't on the page - should we check for that? | ||
loop until evaluate_script('jQuery.active').zero? | ||
end | ||
end | ||
|
||
# Restores page classes modified by running JS on the page | ||
def restore_pre_js_page_classes | ||
execute_script("$('html').addClass('no-js')") | ||
execute_script("$('html').removeClass('flexwrap')") | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.