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

Fix: Website commands now use lazy lookup #98

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## HEAD

- Fix: Internal error in `background.wait` introduced in 4.1.2 (https://github.com/zombocom/rundoc/pull/97)
- Fix: Website commands such as `:::>> website.visit(...)` now use lazy lookup (like Background tasks since 4.1.2). This allows `pre.erb` to be used with these commands (https://github.com/zombocom/rundoc/pull/98)

## 4.1.2

Expand Down
8 changes: 6 additions & 2 deletions lib/rundoc/code_command/website/navigate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ class Rundoc::CodeCommand::Website
class Navigate < Rundoc::CodeCommand
def initialize(name:)
@name = name
@driver = Rundoc::CodeCommand::Website::Driver.find(name)
@driver = nil
end

def driver
@driver ||= Rundoc::CodeCommand::Website::Driver.find(@name)
end

def to_md(env = {})
Expand All @@ -11,7 +15,7 @@ def to_md(env = {})

def call(env = {})
puts "website.navigate [#{@name}]: #{contents}"
@driver.safe_eval(contents, env)
driver.safe_eval(contents, env)
""
end

Expand Down
13 changes: 9 additions & 4 deletions lib/rundoc/code_command/website/screenshot.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
class Rundoc::CodeCommand::Website
class Screenshot < Rundoc::CodeCommand
def initialize(name:, upload: false)
@driver = Rundoc::CodeCommand::Website::Driver.find(name)
@name = name
@upload = upload
@driver = nil
end

def driver
@driver ||= Rundoc::CodeCommand::Website::Driver.find(@name)
end

def to_md(env = {})
""
end

def call(env = {})
puts "Taking screenshot: #{@driver.current_url}"
filename = @driver.screenshot(
puts "Taking screenshot: #{driver.current_url}"
filename = driver.screenshot(
upload: @upload,
screenshots_dir: env[:context].screenshots_dir
)

relative_filename = filename.relative_path_from(env[:context].output_dir)
env[:before] << "![Screenshot of #{@driver.current_url}](#{relative_filename})"
env[:before] << "![Screenshot of #{driver.current_url}](#{relative_filename})"
""
end

Expand Down
29 changes: 18 additions & 11 deletions lib/rundoc/code_command/website/visit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ def initialize(name:, url: nil, scroll: nil, height: 720, width: 1024, visible:
@name = name
@url = url
@scroll = scroll
@driver = Driver.new(
name: name,
url: url,
height: height,
width: width,
visible: visible
)
Driver.add(@name, @driver)
@height = height
@width = width
@visible = visible
end

def driver
@driver ||= Driver.new(
name: @name,
url: @url,
height: @height,
width: @width,
visible: @visible
).tap do |driver|
Driver.add(@name, driver)
end
end

def to_md(env = {})
Expand All @@ -26,11 +33,11 @@ def call(env = {})

puts message

@driver.visit(@url) if @url
@driver.scroll(@scroll) if @scroll
driver.visit(@url) if @url
driver.scroll(@scroll) if @scroll

return "" if contents.nil? || contents.empty?
@driver.safe_eval(contents, env)
driver.safe_eval(contents, env)

""
end
Expand Down
2 changes: 2 additions & 0 deletions test/integration/website_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def test_screenshot_command
```
:::>> website.visit(name: "example", url: "http://example.com")
:::>> website.screenshot(name: "example")
:::>> website.navigate(name: "example")
session.execute_script "window.scrollBy(0,10)"
```
RUBY

Expand Down
Loading