rundoc 4.1.4 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -1
- data/.standard.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/README.md +36 -9
- data/lib/rundoc/cli.rb +4 -1
- data/lib/rundoc/code_command/background/log/clear.rb +12 -2
- data/lib/rundoc/code_command/background/log/read.rb +12 -2
- data/lib/rundoc/code_command/background/process_spawn.rb +3 -1
- data/lib/rundoc/code_command/background/start.rb +25 -6
- data/lib/rundoc/code_command/background/stdin_write.rb +21 -8
- data/lib/rundoc/code_command/background/stop.rb +12 -2
- data/lib/rundoc/code_command/background/wait.rb +15 -3
- data/lib/rundoc/code_command/background.rb +2 -0
- data/lib/rundoc/code_command/bash/cd.rb +7 -7
- data/lib/rundoc/code_command/bash.rb +43 -19
- data/lib/rundoc/code_command/comment.rb +33 -0
- data/lib/rundoc/code_command/deferred.rb +66 -0
- data/lib/rundoc/code_command/file_command/append.rb +29 -8
- data/lib/rundoc/code_command/file_command/remove.rb +27 -5
- data/lib/rundoc/code_command/no_such_command.rb +8 -3
- data/lib/rundoc/code_command/pipe.rb +36 -16
- data/lib/rundoc/code_command/pre/erb.rb +28 -18
- data/lib/rundoc/code_command/print/erb.rb +28 -4
- data/lib/rundoc/code_command/print/text.rb +27 -8
- data/lib/rundoc/code_command/raw.rb +17 -5
- data/lib/rundoc/code_command/rundoc/require.rb +25 -17
- data/lib/rundoc/code_command/rundoc_command.rb +21 -8
- data/lib/rundoc/code_command/website/driver.rb +2 -0
- data/lib/rundoc/code_command/website/navigate.rb +18 -12
- data/lib/rundoc/code_command/website/screenshot.rb +17 -11
- data/lib/rundoc/code_command/website/visit.rb +23 -12
- data/lib/rundoc/code_command/website.rb +2 -0
- data/lib/rundoc/code_command/write.rb +37 -9
- data/lib/rundoc/code_command.rb +5 -48
- data/lib/rundoc/context/after_build.rb +2 -0
- data/lib/rundoc/context/execution.rb +2 -0
- data/lib/rundoc/document.rb +6 -2
- data/lib/rundoc/fenced_code_block.rb +10 -7
- data/lib/rundoc/peg_parser.rb +17 -9
- data/lib/rundoc/version.rb +3 -1
- data/lib/rundoc.rb +52 -17
- data/rundoc.gemspec +2 -0
- data/test/rundoc/code_commands/append_file_test.rb +35 -10
- data/test/rundoc/code_commands/background_test.rb +24 -22
- data/test/rundoc/code_commands/bash_test.rb +10 -5
- data/test/rundoc/code_commands/comment_test.rb +116 -0
- data/test/rundoc/code_commands/pipe_test.rb +2 -2
- data/test/rundoc/code_commands/print_test.rb +13 -25
- data/test/rundoc/code_commands/remove_contents_test.rb +8 -3
- data/test/rundoc/code_section_test.rb +28 -21
- data/test/rundoc/peg_parser_test.rb +17 -1
- data/test/test_helper.rb +4 -2
- metadata +6 -6
- data/lib/rundoc/code_command/rundoc/depend_on.rb +0 -13
- data/test/fixtures/depend_on/dependency/rundoc.md +0 -5
- data/test/fixtures/depend_on/main/rundoc.md +0 -10
|
@@ -1,13 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Rundoc::CodeCommand::FileCommand
|
|
2
|
-
class
|
|
3
|
-
|
|
4
|
+
class RemoveArgs
|
|
5
|
+
attr_reader :filename
|
|
4
6
|
|
|
5
7
|
def initialize(filename)
|
|
6
8
|
@filename = filename
|
|
7
9
|
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class RemoveRunner
|
|
13
|
+
NEWLINE = Object.new
|
|
14
|
+
def NEWLINE.to_s
|
|
15
|
+
""
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def NEWLINE.empty?
|
|
19
|
+
false
|
|
20
|
+
end
|
|
21
|
+
include Rundoc::CodeCommand::FileUtil
|
|
22
|
+
|
|
23
|
+
attr_reader :io, :contents
|
|
24
|
+
|
|
25
|
+
def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
|
|
26
|
+
@filename = user_args.filename
|
|
27
|
+
@io = io
|
|
28
|
+
@contents = contents.dup if contents && !contents.empty?
|
|
29
|
+
end
|
|
8
30
|
|
|
9
31
|
def to_md(env)
|
|
10
|
-
if env[:commands].any? { |c| c[:
|
|
32
|
+
if env[:commands].any? { |c| c[:visibility].not_hidden? }
|
|
11
33
|
raise "Must call remove in its own code section"
|
|
12
34
|
end
|
|
13
35
|
|
|
@@ -17,7 +39,7 @@ class Rundoc::CodeCommand::FileCommand
|
|
|
17
39
|
end
|
|
18
40
|
|
|
19
41
|
def call(env = {})
|
|
20
|
-
puts "Deleting '#{contents.strip}' from #{filename}"
|
|
42
|
+
io.puts "Deleting '#{contents.strip}' from #{filename}"
|
|
21
43
|
raise "#{filename} does not exist" unless File.exist?(filename)
|
|
22
44
|
|
|
23
45
|
regex = /^\s*#{Regexp.quote(contents)}/
|
|
@@ -30,4 +52,4 @@ class Rundoc::CodeCommand::FileCommand
|
|
|
30
52
|
end
|
|
31
53
|
end
|
|
32
54
|
|
|
33
|
-
Rundoc.register_code_command(:"file.remove", Rundoc::CodeCommand::FileCommand::
|
|
55
|
+
Rundoc.register_code_command(keyword: :"file.remove", args_klass: Rundoc::CodeCommand::FileCommand::RemoveArgs, runner_klass: Rundoc::CodeCommand::FileCommand::RemoveRunner)
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Rundoc
|
|
2
|
-
|
|
3
|
-
class NoSuchCommand
|
|
4
|
+
module CodeCommand
|
|
5
|
+
class NoSuchCommand
|
|
6
|
+
def initialize(user_args: nil, render_command: false, render_result: false, io: nil, contents: nil)
|
|
7
|
+
end
|
|
8
|
+
|
|
4
9
|
def call(env = {})
|
|
5
|
-
raise
|
|
10
|
+
raise UnknownCommand
|
|
6
11
|
end
|
|
7
12
|
end
|
|
8
13
|
end
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Rundoc
|
|
2
|
-
|
|
3
|
-
class
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
# => "test\ntmp.file\n"
|
|
4
|
+
module CodeCommand
|
|
5
|
+
class PipeArgs
|
|
6
|
+
attr_reader :line
|
|
7
|
+
|
|
7
8
|
def initialize(line)
|
|
8
|
-
@
|
|
9
|
+
@line = line
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class PipeRunner
|
|
14
|
+
attr_reader :io
|
|
15
|
+
|
|
16
|
+
def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
|
|
17
|
+
@io = io
|
|
18
|
+
@delegate = parse(user_args.line)
|
|
9
19
|
end
|
|
10
20
|
|
|
11
21
|
# before: "",
|
|
@@ -14,10 +24,10 @@ module Rundoc
|
|
|
14
24
|
# [[cmd, output], [cmd, output]]
|
|
15
25
|
def call(env = {})
|
|
16
26
|
last_command = env[:commands].last
|
|
17
|
-
puts "Piping: results of '#{last_command[:command]}' to '#{@delegate}'"
|
|
27
|
+
io.puts "Piping: results of '#{last_command[:command]}' to '#{@delegate}'"
|
|
18
28
|
|
|
19
29
|
@delegate.push(last_command[:output])
|
|
20
|
-
@delegate.call(env)
|
|
30
|
+
@delegate.build(io: io).call(env)
|
|
21
31
|
end
|
|
22
32
|
|
|
23
33
|
def to_md(env = {})
|
|
@@ -31,17 +41,27 @@ module Rundoc
|
|
|
31
41
|
|
|
32
42
|
actual = actual.first if actual.is_a?(Array)
|
|
33
43
|
|
|
34
|
-
actual
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
if actual.runner_klass == Rundoc::CodeCommand::NoSuchCommand
|
|
45
|
+
bash_deferred(code)
|
|
46
|
+
else
|
|
47
|
+
actual
|
|
48
|
+
end
|
|
39
49
|
rescue Parslet::ParseFailed
|
|
40
|
-
|
|
50
|
+
bash_deferred(code)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private def bash_deferred(code)
|
|
54
|
+
deferred = Rundoc::CodeCommand::Deferred.new(
|
|
55
|
+
args_instance: Rundoc::CodeCommand::BashArgs.new(code),
|
|
56
|
+
runner_klass: Rundoc::CodeCommand::BashRunner
|
|
57
|
+
)
|
|
58
|
+
deferred.render_command = false
|
|
59
|
+
deferred.render_result = false
|
|
60
|
+
deferred
|
|
41
61
|
end
|
|
42
62
|
end
|
|
43
63
|
end
|
|
44
64
|
end
|
|
45
65
|
|
|
46
|
-
Rundoc.register_code_command(:pipe, Rundoc::CodeCommand::
|
|
47
|
-
Rundoc.register_code_command(:|, Rundoc::CodeCommand::
|
|
66
|
+
Rundoc.register_code_command(keyword: :pipe, args_klass: Rundoc::CodeCommand::PipeArgs, runner_klass: Rundoc::CodeCommand::PipeRunner)
|
|
67
|
+
Rundoc.register_code_command(keyword: :|, args_klass: Rundoc::CodeCommand::PipeArgs, runner_klass: Rundoc::CodeCommand::PipeRunner)
|
|
@@ -1,44 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative "../print/erb"
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
class
|
|
5
|
+
module Rundoc::CodeCommand
|
|
6
|
+
class PreErbArgs
|
|
7
|
+
attr_reader :line
|
|
8
|
+
|
|
5
9
|
def initialize(line)
|
|
6
10
|
@line = line
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class PreErbRunner
|
|
15
|
+
attr_reader :io, :contents
|
|
16
|
+
|
|
17
|
+
def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
|
|
18
|
+
@line = user_args.line
|
|
7
19
|
@binding = RUNDOC_ERB_BINDINGS[RUNDOC_DEFAULT_ERB_BINDING]
|
|
8
20
|
@code = nil
|
|
9
21
|
@command = nil
|
|
10
22
|
@template = nil
|
|
11
|
-
@
|
|
12
|
-
@
|
|
13
|
-
|
|
14
|
-
@
|
|
15
|
-
@render_command = false
|
|
23
|
+
@render_command = render_command
|
|
24
|
+
@render_result = render_result
|
|
25
|
+
@io = io
|
|
26
|
+
@contents = contents.dup if contents && !contents.empty?
|
|
16
27
|
end
|
|
17
28
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@render_delegate_result = value
|
|
29
|
+
def render_command?
|
|
30
|
+
@render_command
|
|
21
31
|
end
|
|
22
32
|
|
|
23
|
-
def
|
|
24
|
-
@
|
|
33
|
+
def render_result?
|
|
34
|
+
@render_result
|
|
25
35
|
end
|
|
26
36
|
|
|
27
37
|
def code
|
|
28
38
|
@code ||= begin
|
|
29
39
|
vis = +""
|
|
30
|
-
vis +=
|
|
31
|
-
vis +=
|
|
40
|
+
vis += render_command? ? ">" : "-"
|
|
41
|
+
vis += render_result? ? ">" : "-"
|
|
32
42
|
code = [@line, @contents]
|
|
33
43
|
.compact
|
|
34
44
|
.reject(&:empty?)
|
|
35
45
|
.join("\n")
|
|
36
46
|
@template = ":::#{vis} #{code}"
|
|
37
47
|
|
|
38
|
-
puts "pre.erb: Applying ERB, template:\n#{@template}"
|
|
48
|
+
io.puts "pre.erb: Applying ERB, template:\n#{@template}"
|
|
39
49
|
result = ERB.new(@template).result(@binding)
|
|
40
|
-
puts "pre.erb: ERB result:\n#{result}"
|
|
41
|
-
puts "pre.erb: done, ready to delegate"
|
|
50
|
+
io.puts "pre.erb: ERB result:\n#{result}"
|
|
51
|
+
io.puts "pre.erb: done, ready to delegate"
|
|
42
52
|
result
|
|
43
53
|
end
|
|
44
54
|
end
|
|
@@ -60,4 +70,4 @@ class Rundoc::CodeCommand
|
|
|
60
70
|
end
|
|
61
71
|
end
|
|
62
72
|
end
|
|
63
|
-
Rundoc.register_code_command(:"pre.erb", Rundoc::CodeCommand::
|
|
73
|
+
Rundoc.register_code_command(keyword: :"pre.erb", args_klass: Rundoc::CodeCommand::PreErbArgs, runner_klass: Rundoc::CodeCommand::PreErbRunner, always_hidden: true)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "erb"
|
|
2
4
|
|
|
3
5
|
class EmptyBinding
|
|
@@ -10,14 +12,36 @@ class EmptyBinding
|
|
|
10
12
|
end
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
module Rundoc::CodeCommand
|
|
14
16
|
RUNDOC_ERB_BINDINGS = Hash.new { |h, k| h[k] = EmptyBinding.create }
|
|
15
17
|
RUNDOC_DEFAULT_ERB_BINDING = "default"
|
|
16
18
|
|
|
17
|
-
class
|
|
19
|
+
class PrintERBArgs
|
|
20
|
+
attr_reader :line, :binding_name
|
|
21
|
+
|
|
18
22
|
def initialize(line = nil, binding: RUNDOC_DEFAULT_ERB_BINDING)
|
|
19
23
|
@line = line
|
|
20
|
-
@
|
|
24
|
+
@binding_name = binding
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class PrintERBRunner
|
|
29
|
+
attr_reader :contents
|
|
30
|
+
|
|
31
|
+
def initialize(user_args:, render_command:, render_result:, io: nil, contents: nil)
|
|
32
|
+
@line = user_args.line
|
|
33
|
+
@binding = RUNDOC_ERB_BINDINGS[user_args.binding_name]
|
|
34
|
+
@render_command = render_command
|
|
35
|
+
@render_result = render_result
|
|
36
|
+
@contents = contents.dup if contents && !contents.empty?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def render_command?
|
|
40
|
+
@render_command
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def render_result?
|
|
44
|
+
@render_result
|
|
21
45
|
end
|
|
22
46
|
|
|
23
47
|
def to_md(env)
|
|
@@ -45,4 +69,4 @@ class Rundoc::CodeCommand
|
|
|
45
69
|
end
|
|
46
70
|
end
|
|
47
71
|
end
|
|
48
|
-
Rundoc.register_code_command(:"print.erb", Rundoc::CodeCommand::
|
|
72
|
+
Rundoc.register_code_command(keyword: :"print.erb", args_klass: Rundoc::CodeCommand::PrintERBArgs, runner_klass: Rundoc::CodeCommand::PrintERBRunner)
|
|
@@ -1,8 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rundoc::CodeCommand
|
|
4
|
+
class PrintTextArgs
|
|
5
|
+
attr_reader :line
|
|
6
|
+
|
|
7
|
+
def initialize(line = nil)
|
|
4
8
|
@line = line
|
|
5
9
|
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class PrintTextRunner
|
|
13
|
+
attr_reader :contents
|
|
14
|
+
|
|
15
|
+
def initialize(user_args:, render_command:, render_result:, io: nil, contents: nil)
|
|
16
|
+
@line = user_args.line
|
|
17
|
+
@render_command = render_command
|
|
18
|
+
@render_result = render_result
|
|
19
|
+
@contents = contents.dup if contents && !contents.empty?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def render_command?
|
|
23
|
+
@render_command
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def render_result?
|
|
27
|
+
@render_result
|
|
28
|
+
end
|
|
6
29
|
|
|
7
30
|
def to_md(env)
|
|
8
31
|
if render_before?
|
|
@@ -12,10 +35,6 @@ class Rundoc::CodeCommand
|
|
|
12
35
|
""
|
|
13
36
|
end
|
|
14
37
|
|
|
15
|
-
def hidden?
|
|
16
|
-
!render_result?
|
|
17
|
-
end
|
|
18
|
-
|
|
19
38
|
def call(env = {})
|
|
20
39
|
if render_before?
|
|
21
40
|
""
|
|
@@ -30,4 +49,4 @@ class Rundoc::CodeCommand
|
|
|
30
49
|
end
|
|
31
50
|
end
|
|
32
51
|
|
|
33
|
-
Rundoc.register_code_command(:"print.text", Rundoc::CodeCommand::
|
|
52
|
+
Rundoc.register_code_command(keyword: :"print.text", args_klass: Rundoc::CodeCommand::PrintTextArgs, runner_klass: Rundoc::CodeCommand::PrintTextRunner)
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Rundoc
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
module CodeCommand
|
|
5
|
+
# Wraps lines inside a fenced code block that are not rundoc commands.
|
|
6
|
+
# These are rendered as-is without executing any code.
|
|
7
|
+
#
|
|
8
|
+
# Example:
|
|
9
|
+
#
|
|
10
|
+
# ```ruby
|
|
11
|
+
# gem 'sqlite3' <- parsed as Raw
|
|
12
|
+
# :::>> $ echo "hi" <- parsed as a code command
|
|
13
|
+
# ```
|
|
14
|
+
class Raw
|
|
15
|
+
attr_reader :contents
|
|
16
|
+
|
|
17
|
+
def initialize(user_args: nil, render_command: true, render_result: true, io: nil, contents: nil)
|
|
18
|
+
@contents = contents.dup if contents && !contents.empty?
|
|
7
19
|
end
|
|
8
20
|
|
|
9
21
|
def call(env = {})
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ::Rundoc::CodeCommand
|
|
2
4
|
class RundocCommand
|
|
3
|
-
class
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
# in current document
|
|
5
|
+
class RequireArgs
|
|
6
|
+
attr_reader :path
|
|
7
|
+
|
|
7
8
|
def initialize(path)
|
|
8
9
|
raise "Path must be relative (i.e. start with `.` or `..`. #{path.inspect} does not" unless path.start_with?(".")
|
|
9
10
|
@path = Pathname.new(path)
|
|
10
11
|
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class RequireRunner
|
|
15
|
+
attr_reader :io
|
|
16
|
+
|
|
17
|
+
def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
|
|
18
|
+
@path = user_args.path
|
|
19
|
+
@io = io
|
|
20
|
+
@render_result = render_result
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def render_result?
|
|
24
|
+
@render_result
|
|
25
|
+
end
|
|
11
26
|
|
|
12
27
|
def to_md(env = {})
|
|
13
28
|
""
|
|
@@ -24,28 +39,21 @@ class ::Rundoc::CodeCommand
|
|
|
24
39
|
output_dir: execution_context.output_dir,
|
|
25
40
|
screenshots_dirname: execution_context.screenshots_dir,
|
|
26
41
|
with_contents_dir: execution_context.with_contents_dir
|
|
27
|
-
)
|
|
42
|
+
),
|
|
43
|
+
io: io
|
|
28
44
|
).to_md
|
|
29
45
|
|
|
30
46
|
if render_result?
|
|
31
|
-
puts "rundoc.require: Done executing #{@path.to_s.inspect}, putting contents into document"
|
|
47
|
+
io.puts "rundoc.require: Done executing #{@path.to_s.inspect}, putting contents into document"
|
|
32
48
|
env[:before] << output
|
|
33
49
|
else
|
|
34
|
-
puts "rundoc.require: Done executing #{@path.to_s.inspect}, quietly"
|
|
50
|
+
io.puts "rundoc.require: Done executing #{@path.to_s.inspect}, quietly"
|
|
35
51
|
end
|
|
36
52
|
|
|
37
53
|
""
|
|
38
54
|
end
|
|
39
|
-
|
|
40
|
-
def hidden?
|
|
41
|
-
!render_result?
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def not_hidden?
|
|
45
|
-
!hidden?
|
|
46
|
-
end
|
|
47
55
|
end
|
|
48
56
|
end
|
|
49
57
|
end
|
|
50
58
|
|
|
51
|
-
Rundoc.register_code_command(:"rundoc.require", ::Rundoc::CodeCommand::RundocCommand::
|
|
59
|
+
Rundoc.register_code_command(keyword: :"rundoc.require", args_klass: ::Rundoc::CodeCommand::RundocCommand::RequireArgs, runner_klass: ::Rundoc::CodeCommand::RundocCommand::RequireRunner)
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ::Rundoc
|
|
2
|
-
|
|
3
|
-
class
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
module CodeCommand
|
|
5
|
+
class RundocCommandArgs
|
|
6
|
+
attr_reader :code
|
|
7
|
+
|
|
8
|
+
def initialize(code = "")
|
|
9
|
+
@code = code
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class RundocCommandRunner
|
|
14
|
+
attr_reader :io, :contents
|
|
15
|
+
|
|
16
|
+
def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
|
|
17
|
+
@io = io
|
|
18
|
+
@contents = contents.dup if contents && !contents.empty?
|
|
19
|
+
@contents = user_args.code + (@contents || +"")
|
|
6
20
|
end
|
|
7
21
|
|
|
8
22
|
def to_md(env = {})
|
|
@@ -10,7 +24,7 @@ module ::Rundoc
|
|
|
10
24
|
end
|
|
11
25
|
|
|
12
26
|
def call(env = {})
|
|
13
|
-
puts "Running: #{contents}"
|
|
27
|
+
io.puts "Running: #{contents}"
|
|
14
28
|
eval(contents) # rubocop:disable Security/Eval
|
|
15
29
|
""
|
|
16
30
|
end
|
|
@@ -18,8 +32,7 @@ module ::Rundoc
|
|
|
18
32
|
end
|
|
19
33
|
end
|
|
20
34
|
|
|
21
|
-
Rundoc.register_code_command(:rundoc,
|
|
22
|
-
Rundoc.register_code_command(:"rundoc.configure",
|
|
35
|
+
Rundoc.register_code_command(keyword: :rundoc, args_klass: Rundoc::CodeCommand::RundocCommandArgs, runner_klass: Rundoc::CodeCommand::RundocCommandRunner)
|
|
36
|
+
Rundoc.register_code_command(keyword: :"rundoc.configure", args_klass: Rundoc::CodeCommand::RundocCommandArgs, runner_klass: Rundoc::CodeCommand::RundocCommandRunner)
|
|
23
37
|
|
|
24
|
-
require "rundoc/code_command/rundoc/depend_on"
|
|
25
38
|
require "rundoc/code_command/rundoc/require"
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Rundoc::CodeCommand::Website
|
|
2
|
-
class
|
|
4
|
+
class NavigateArgs
|
|
5
|
+
attr_reader :name
|
|
6
|
+
|
|
3
7
|
def initialize(name:)
|
|
4
8
|
@name = name
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class NavigateRunner
|
|
13
|
+
attr_reader :io, :contents
|
|
14
|
+
|
|
15
|
+
def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
|
|
16
|
+
@name = user_args.name
|
|
5
17
|
@driver = nil
|
|
18
|
+
@io = io
|
|
19
|
+
@contents = contents.dup if contents && !contents.empty?
|
|
6
20
|
end
|
|
7
21
|
|
|
8
22
|
def driver
|
|
@@ -14,20 +28,12 @@ class Rundoc::CodeCommand::Website
|
|
|
14
28
|
end
|
|
15
29
|
|
|
16
30
|
def call(env = {})
|
|
17
|
-
puts "website.navigate [#{@name}]: #{contents}"
|
|
31
|
+
io.puts "website.navigate [#{@name}]: #{contents}"
|
|
18
32
|
driver.safe_eval(contents, env)
|
|
19
33
|
""
|
|
20
34
|
end
|
|
21
|
-
|
|
22
|
-
def hidden?
|
|
23
|
-
true
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def not_hidden?
|
|
27
|
-
!hidden?
|
|
28
|
-
end
|
|
29
35
|
end
|
|
30
36
|
end
|
|
31
37
|
|
|
32
|
-
Rundoc.register_code_command(:"website.nav", Rundoc::CodeCommand::Website::
|
|
33
|
-
Rundoc.register_code_command(:"website.navigate", Rundoc::CodeCommand::Website::
|
|
38
|
+
Rundoc.register_code_command(keyword: :"website.nav", args_klass: Rundoc::CodeCommand::Website::NavigateArgs, runner_klass: Rundoc::CodeCommand::Website::NavigateRunner)
|
|
39
|
+
Rundoc.register_code_command(keyword: :"website.navigate", args_klass: Rundoc::CodeCommand::Website::NavigateArgs, runner_klass: Rundoc::CodeCommand::Website::NavigateRunner)
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Rundoc::CodeCommand::Website
|
|
2
|
-
class
|
|
4
|
+
class ScreenshotArgs
|
|
5
|
+
attr_reader :name, :upload
|
|
6
|
+
|
|
3
7
|
def initialize(name:, upload: false)
|
|
4
8
|
@name = name
|
|
5
9
|
@upload = upload
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class ScreenshotRunner
|
|
14
|
+
attr_reader :io
|
|
15
|
+
|
|
16
|
+
def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
|
|
17
|
+
@name = user_args.name
|
|
18
|
+
@upload = user_args.upload
|
|
6
19
|
@driver = nil
|
|
20
|
+
@io = io
|
|
7
21
|
end
|
|
8
22
|
|
|
9
23
|
def driver
|
|
@@ -15,7 +29,7 @@ class Rundoc::CodeCommand::Website
|
|
|
15
29
|
end
|
|
16
30
|
|
|
17
31
|
def call(env = {})
|
|
18
|
-
puts "Taking screenshot: #{driver.current_url}"
|
|
32
|
+
io.puts "Taking screenshot: #{driver.current_url}"
|
|
19
33
|
filename = driver.screenshot(
|
|
20
34
|
upload: @upload,
|
|
21
35
|
screenshots_dir: env[:context].screenshots_dir
|
|
@@ -25,14 +39,6 @@ class Rundoc::CodeCommand::Website
|
|
|
25
39
|
env[:before] << ""
|
|
26
40
|
""
|
|
27
41
|
end
|
|
28
|
-
|
|
29
|
-
# def hidden?
|
|
30
|
-
# true
|
|
31
|
-
# end
|
|
32
|
-
|
|
33
|
-
# def not_hidden?
|
|
34
|
-
# !hidden?
|
|
35
|
-
# end
|
|
36
42
|
end
|
|
37
43
|
end
|
|
38
|
-
Rundoc.register_code_command(:"website.screenshot", Rundoc::CodeCommand::Website::
|
|
44
|
+
Rundoc.register_code_command(keyword: :"website.screenshot", args_klass: Rundoc::CodeCommand::Website::ScreenshotArgs, runner_klass: Rundoc::CodeCommand::Website::ScreenshotRunner)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class Rundoc::CodeCommand::Website
|
|
4
|
-
class
|
|
4
|
+
class VisitArgs
|
|
5
|
+
attr_reader :name, :url, :scroll, :height, :width, :visible, :max_attempts
|
|
6
|
+
|
|
5
7
|
def initialize(name:, url: nil, scroll: nil, height: 720, width: 1024, visible: false, max_attempts: 3)
|
|
6
8
|
@name = name
|
|
7
9
|
@url = url
|
|
@@ -11,6 +13,22 @@ class Rundoc::CodeCommand::Website
|
|
|
11
13
|
@visible = visible
|
|
12
14
|
@max_attempts = max_attempts
|
|
13
15
|
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class VisitRunner
|
|
19
|
+
attr_reader :io, :contents
|
|
20
|
+
|
|
21
|
+
def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
|
|
22
|
+
@name = user_args.name
|
|
23
|
+
@url = user_args.url
|
|
24
|
+
@scroll = user_args.scroll
|
|
25
|
+
@height = user_args.height
|
|
26
|
+
@width = user_args.width
|
|
27
|
+
@visible = user_args.visible
|
|
28
|
+
@max_attempts = user_args.max_attempts
|
|
29
|
+
@io = io
|
|
30
|
+
@contents = contents.dup if contents && !contents.empty?
|
|
31
|
+
end
|
|
14
32
|
|
|
15
33
|
def driver
|
|
16
34
|
@driver ||= Driver.new(
|
|
@@ -18,7 +36,8 @@ class Rundoc::CodeCommand::Website
|
|
|
18
36
|
url: @url,
|
|
19
37
|
height: @height,
|
|
20
38
|
width: @width,
|
|
21
|
-
visible: @visible
|
|
39
|
+
visible: @visible,
|
|
40
|
+
io: io
|
|
22
41
|
).tap do |driver|
|
|
23
42
|
Driver.add(@name, driver)
|
|
24
43
|
end
|
|
@@ -32,7 +51,7 @@ class Rundoc::CodeCommand::Website
|
|
|
32
51
|
message = "Visting: #{@url}"
|
|
33
52
|
message << "and executing:\n#{contents}" unless contents.nil? || contents.empty?
|
|
34
53
|
|
|
35
|
-
puts message
|
|
54
|
+
io.puts message
|
|
36
55
|
|
|
37
56
|
driver.visit(@url, max_attempts: @max_attempts) if @url
|
|
38
57
|
driver.scroll(@scroll) if @scroll
|
|
@@ -42,15 +61,7 @@ class Rundoc::CodeCommand::Website
|
|
|
42
61
|
|
|
43
62
|
""
|
|
44
63
|
end
|
|
45
|
-
|
|
46
|
-
def hidden?
|
|
47
|
-
true
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def not_hidden?
|
|
51
|
-
!hidden?
|
|
52
|
-
end
|
|
53
64
|
end
|
|
54
65
|
end
|
|
55
66
|
|
|
56
|
-
Rundoc.register_code_command(:"website.visit", Rundoc::CodeCommand::Website::
|
|
67
|
+
Rundoc.register_code_command(keyword: :"website.visit", args_klass: Rundoc::CodeCommand::Website::VisitArgs, runner_klass: Rundoc::CodeCommand::Website::VisitRunner)
|