rundoc 0.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/check_changelog.yml +13 -0
- data/.gitignore +9 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +22 -0
- data/Dockerfile +24 -0
- data/Gemfile +1 -0
- data/README.md +276 -74
- data/bin/rundoc +4 -52
- data/lib/rundoc.rb +15 -1
- data/lib/rundoc/cli.rb +84 -0
- data/lib/rundoc/code_command.rb +25 -6
- data/lib/rundoc/code_command/background.rb +9 -0
- data/lib/rundoc/code_command/background/log/clear.rb +17 -0
- data/lib/rundoc/code_command/background/log/read.rb +16 -0
- data/lib/rundoc/code_command/background/process_spawn.rb +96 -0
- data/lib/rundoc/code_command/background/start.rb +38 -0
- data/lib/rundoc/code_command/background/stop.rb +17 -0
- data/lib/rundoc/code_command/background/wait.rb +19 -0
- data/lib/rundoc/code_command/bash.rb +1 -1
- data/lib/rundoc/code_command/bash/cd.rb +21 -3
- data/lib/rundoc/code_command/file_command/append.rb +16 -11
- data/lib/rundoc/code_command/file_command/remove.rb +6 -5
- data/lib/rundoc/code_command/no_such_command.rb +4 -0
- data/lib/rundoc/code_command/pipe.rb +18 -5
- data/lib/rundoc/code_command/raw.rb +18 -0
- data/lib/rundoc/code_command/rundoc/depend_on.rb +37 -0
- data/lib/rundoc/code_command/rundoc/require.rb +41 -0
- data/lib/rundoc/code_command/rundoc_command.rb +6 -2
- data/lib/rundoc/code_command/website.rb +7 -0
- data/lib/rundoc/code_command/website/driver.rb +111 -0
- data/lib/rundoc/code_command/website/navigate.rb +29 -0
- data/lib/rundoc/code_command/website/screenshot.rb +28 -0
- data/lib/rundoc/code_command/website/visit.rb +47 -0
- data/lib/rundoc/code_command/write.rb +22 -7
- data/lib/rundoc/code_section.rb +41 -66
- data/lib/rundoc/parser.rb +5 -4
- data/lib/rundoc/peg_parser.rb +282 -0
- data/lib/rundoc/version.rb +2 -2
- data/rundoc.gemspec +9 -3
- data/test/fixtures/build_logs/rundoc.md +56 -0
- data/test/fixtures/depend_on/dependency/rundoc.md +5 -0
- data/test/fixtures/depend_on/main/rundoc.md +10 -0
- data/test/fixtures/java/rundoc.md +9 -0
- data/test/fixtures/rails_4/rundoc.md +151 -188
- data/test/fixtures/rails_5/rundoc.md +445 -0
- data/test/fixtures/rails_6/rundoc.md +451 -0
- data/test/fixtures/require/dependency/rundoc.md +5 -0
- data/test/fixtures/require/main/rundoc.md +10 -0
- data/test/fixtures/screenshot/rundoc.md +10 -0
- data/test/rundoc/code_commands/append_file_test.rb +33 -6
- data/test/rundoc/code_commands/background_test.rb +69 -0
- data/test/rundoc/code_commands/bash_test.rb +1 -1
- data/test/rundoc/code_commands/pipe_test.rb +1 -1
- data/test/rundoc/code_commands/remove_contents_test.rb +3 -4
- data/test/rundoc/code_section_test.rb +95 -2
- data/test/rundoc/parser_test.rb +7 -13
- data/test/rundoc/peg_parser_test.rb +381 -0
- data/test/rundoc/regex_test.rb +6 -6
- data/test/rundoc/test_parse_java.rb +1 -1
- data/test/test_helper.rb +1 -3
- metadata +143 -18
- data/Gemfile.lock +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0e767697a50da725490c5a2af1dd2a8ef894c9fa79e8260230ec2a41000ffefa
|
4
|
+
data.tar.gz: b682ac2f59204b1a62edd00f46817c27a63c58a95c87fd312803d42a6dd7b668
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cee0548716aa1cd4bb14f1eb21541dc010f5d8c706de49240b9e3245d847fbdfc08c34858a5ba7755d45d091671f3c712bd02a4d91e561927cae3b114780fd7f
|
7
|
+
data.tar.gz: aa340da522f964e0daeb3e7fd3b03bb340ecbe062a18c456474f00392ce660d0f28afdf427c99812013d4765b362e1bc11d1585330c8653118d1b8d0edd97d76
|
@@ -0,0 +1,13 @@
|
|
1
|
+
name: Check Changelog
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
types: [opened, reopened, edited, synchronize]
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v1
|
11
|
+
- name: Check that CHANGELOG is touched
|
12
|
+
run: |
|
13
|
+
cat $GITHUB_EVENT_PATH | jq .pull_request.title | grep -i '\[\(\(changelog skip\)\|\(ci skip\)\)\]' || git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
## master
|
2
|
+
|
3
|
+
## 1.1.1
|
4
|
+
|
5
|
+
- Fix log read race condition (https://github.com/schneems/rundoc/pull/25)
|
6
|
+
|
7
|
+
## 1.1.0
|
8
|
+
|
9
|
+
- Pipe logic is now implemented through a parser (https://github.com/schneems/rundoc/pull/22)
|
10
|
+
- Bugfix, background processes error when the log file is not touched before read, not sure why this is possible but here's a fix for it anyway (https://github.com/schneems/rundoc/commit/620ae55d8a5d3d443cf5e8cb77950a841f92900c)
|
11
|
+
|
12
|
+
## 1.0.1
|
13
|
+
|
14
|
+
- Allow non-headless browser sessions and navigation [#23](https://github.com/schneems/rundoc/pull/23)
|
15
|
+
- Fix issue where a background task's log file was not present before it was attempted to be opened.
|
16
|
+
- Allow composability of documents `rundoc.depend_on` and `rundoc.require` [#19](https://github.com/schneems/rundoc/pull/19)
|
17
|
+
- The `rundoc` command is now `rundoc.configure`.
|
18
|
+
- Ignore chdir warning since that affect is intentional [#20](https://github.com/schneems/rundoc/pull/20)
|
19
|
+
|
20
|
+
## 1.0.0
|
21
|
+
|
22
|
+
- Now using a propper PEG parser (parslet)
|
data/Dockerfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
FROM ruby:2.6.3-stretch
|
2
|
+
|
3
|
+
RUN useradd rundoc
|
4
|
+
RUN curl https://cli-assets.heroku.com/install-ubuntu.sh | sh
|
5
|
+
|
6
|
+
RUN apt-get clean && apt-get update && apt-get install -y locales nodejs
|
7
|
+
|
8
|
+
RUN locale-gen en_US.UTF-8
|
9
|
+
ENV LC_ALL=C.UTF-8
|
10
|
+
ENV LANG=en_US.UTF-8
|
11
|
+
ENV LANGUAGE=en_US.UTF-8
|
12
|
+
ENV DISABLE_SPRING=1
|
13
|
+
|
14
|
+
WORKDIR /home/rundoc
|
15
|
+
RUN mkdir -p /home/rundoc/ && chown -R rundoc:rundoc /home/rundoc
|
16
|
+
USER rundoc
|
17
|
+
RUN mkdir -p /home/rundoc/workdir
|
18
|
+
|
19
|
+
RUN git config --global user.email "developer@example.com"
|
20
|
+
RUN git config --global user.name "Dev Eloper"
|
21
|
+
|
22
|
+
ADD Gemfile Gemfile.lock
|
23
|
+
|
24
|
+
RUN bundle install
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,31 +1,32 @@
|
|
1
|
-
|
1
|
+
# RunDOC
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Write more technical content, faster and with a better consistency by using rundoc. Write in a rundoc compatible markdown format, then run your docs to generate matching projects. Instead of writing a tutorial and then building an example separately, your documentation can build the example app for you. Not only does this keep your doc writing DRY, it also enforces consistency and accuracy. If you make a typo in your docs your project won't build...you'll get early warning and be able to fix it before it has the opportunity to confuse your reader.
|
3
|
+
![](https://www.dropbox.com/s/u354td51brynr4h/Screenshot%202017-05-09%2009.36.33.png?raw=1)
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
Once docs are run, they output a project and fully valid markdown doc (without any of the special rundoc tags). You could configure your project to be automatically pushed to github or anything else you want afterwards, check out the config section.
|
5
|
+
## What
|
10
6
|
|
11
|
-
|
7
|
+
This library allows you to "run" your docs and embed the code as well as results back into the documentation. Here's a quick example:
|
12
8
|
|
13
|
-
|
14
|
-
documentation at the same time. I enjoyed the experience but having to do both essentially doubled my work load, worse than the time wasted copying snippets between the two was my docs were prone to paste errors, keyboard slips, or me just forgetting to add sections that I had implemented in the app. The only way for me to find these errors was to give the docs to someone to actually follow them and build the project. This method of manually checking is extremely time consuming, prone to errors (the developer may work around problems instead of reporting them to you), and makes making minor edits a major pain. Instead of writing your docs once and iterating, I found adding sections required me to start from scratch.
|
9
|
+
Write documentation:
|
15
10
|
|
11
|
+
Install by running:
|
16
12
|
|
17
|
-
|
18
|
-
|
13
|
+
```
|
14
|
+
:::>> $ gem install rails --no-document
|
15
|
+
```
|
19
16
|
|
20
|
-
|
17
|
+
Now if you "run" this document you'll get this output:
|
21
18
|
|
22
|
-
|
19
|
+
Install by running:
|
23
20
|
|
24
|
-
|
21
|
+
```
|
22
|
+
$ gem install rails --no-document
|
23
|
+
Successfully installed rails-5.2.2
|
24
|
+
1 gem installed
|
25
|
+
```
|
25
26
|
|
26
|
-
|
27
|
+
The idea is that as your documentation "runs" it builds a working tutorial. It also acts as tests since if your docs become incorrect due to a typo or bit-rot then when you try to generate them, the process will fail.
|
27
28
|
|
28
|
-
|
29
|
+
Think of RunDOC as your ever-vigilant tech editor and writing partner.
|
29
30
|
|
30
31
|
## Install
|
31
32
|
|
@@ -46,45 +47,77 @@ gem 'rundoc`
|
|
46
47
|
Run the `rundoc build` command on any markdown file
|
47
48
|
|
48
49
|
```sh
|
49
|
-
$ rundoc build --path
|
50
|
+
$ rundoc build --path my/path/to/run_doc.md
|
50
51
|
```
|
51
52
|
|
52
|
-
Note: This command will create and manipulate directories in the working directory of your source markdown file. Best practice is to have your source markdown file in
|
53
|
+
> Note: This command will create and manipulate directories in the working directory of your source markdown file. Best practice is to have your source markdown file in its own empty directory.
|
53
54
|
|
54
55
|
This will generate a project folder with your project in it, and a markdown README.md with the parsed output of the markdown docs, and a copy of the source.
|
55
56
|
|
56
|
-
##
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
## Quick docs
|
58
|
+
|
59
|
+
- [Understanding the Syntax](#rundoc-syntax)
|
60
|
+
- [Dotenv support](#dotenv-support)
|
61
|
+
- [Rendering cheat sheet](#rendering-cheat-sheet)
|
62
|
+
|
63
|
+
### Commands
|
64
|
+
|
65
|
+
- Execute Bash Commands
|
66
|
+
- [$](#shell-commands)
|
67
|
+
- [fail.$](#shell-commands)
|
68
|
+
- Chain commands
|
69
|
+
- [pipe](#pipe)
|
70
|
+
- [|](#pipe)
|
71
|
+
- Manipulate Files
|
72
|
+
- [file.write](#file-commands)
|
73
|
+
- [file.append](#file-commands)
|
74
|
+
- [file.remove](#file-commands)
|
75
|
+
- Boot background processes such as a local server
|
76
|
+
- [background.start](#background)
|
77
|
+
- [background.stop](#background)
|
78
|
+
- [background.log.read](#background)
|
79
|
+
- [background.log.clear](#background)
|
80
|
+
- Take screenshots
|
81
|
+
- [website.visit](#screenshots)
|
82
|
+
- [website.nav](#screenshots)
|
83
|
+
- [website.screenshot](#screenshots)
|
84
|
+
- Configure RunDOC
|
85
|
+
- [rundoc.configure](#configure)
|
86
|
+
- Import and compose documents
|
87
|
+
- [rundoc.depend_on](#compose-multiple-rundoc-documents)
|
88
|
+
- [rundoc.require](#compose-multiple-rundoc-documents)
|
89
|
+
|
90
|
+
## RunDOC Syntax
|
91
|
+
|
92
|
+
RunDOC uses GitHub flavored markdown. This means you write like normal but in your code sections
|
93
|
+
you can add special annotations that when run through RunDOC can
|
60
94
|
generate a project.
|
61
95
|
|
62
|
-
All
|
96
|
+
All RunDOC commands are prefixed with three colons `:::` and are inclosed in a code block a
|
63
97
|
command such as `$` which is an alias for `bash` commands like this:
|
64
98
|
|
65
99
|
```
|
66
|
-
|
100
|
+
:::>- $ git init .
|
67
101
|
```
|
68
102
|
|
69
103
|
Nothing before the three colons matters. The space between the colons
|
70
104
|
and the command is optional.
|
71
105
|
|
72
|
-
|
73
106
|
If you don't want the command to output to your markdown document you
|
74
107
|
can add a minus symbol `-` to the end to prevent it from being
|
75
108
|
rendered.
|
76
109
|
|
77
110
|
```
|
78
|
-
|
111
|
+
:::-- $ git init .
|
79
112
|
```
|
80
113
|
|
81
|
-
Note: If all commands inside of a code block are hidden, the entire codeblock will not be rendered.
|
114
|
+
> Note: If all commands inside of a code block are hidden, the entire codeblock will not be rendered.
|
82
115
|
|
83
116
|
If you want the output of the actual command to be rendered to
|
84
|
-
the screen you can use
|
117
|
+
the screen you can use two arrows so that:
|
85
118
|
|
86
119
|
```
|
87
|
-
|
120
|
+
:::>> $ ls
|
88
121
|
```
|
89
122
|
|
90
123
|
This code block might generate an output something like this to your markdown doc:
|
@@ -95,19 +128,12 @@ This code block might generate an output something like this to your markdown do
|
|
95
128
|
Gemfile.lock Rakefile config db lib public test vendor
|
96
129
|
```
|
97
130
|
|
98
|
-
|
99
|
-
|
100
|
-
## Shell Commands
|
101
|
-
|
102
|
-
Current Commands:
|
103
|
-
|
104
|
-
- `$`
|
105
|
-
- `fail.$
|
131
|
+
### Stdin
|
106
132
|
|
107
|
-
|
133
|
+
Any items below the command will be passed into the stdin of the command. For example using a `$` command you can effectively pipe contents to stdin:
|
108
134
|
|
109
135
|
```
|
110
|
-
|
136
|
+
:::>> $ tail -n 2
|
111
137
|
foo
|
112
138
|
bar
|
113
139
|
baz
|
@@ -122,12 +148,81 @@ Would output:
|
|
122
148
|
bahz
|
123
149
|
```
|
124
150
|
|
125
|
-
This could be useful if you are running an interactive command such as `play new` which requires user input. For more fine grained input you'll need to use a custom repl object (will be covered later).
|
151
|
+
This STDIN feature could be useful if you are running an interactive command such as `play new` which requires user input. For more fine grained input you'll need to use a custom repl object (will be covered later).
|
152
|
+
|
153
|
+
Different commands will do different things with this input. For example the `rundoc` command executes Ruby configuration code:
|
154
|
+
|
155
|
+
```
|
156
|
+
:::-- rundoc
|
157
|
+
Rundoc.configure do |config|
|
158
|
+
config.after_build do
|
159
|
+
puts "you could push to GitHub here"
|
160
|
+
puts "You could do anything here"
|
161
|
+
puts "This code will run after the docs are done building"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
```
|
165
|
+
|
166
|
+
|
167
|
+
And the `website.visit` command allows you to navigate and manipulate a webpage via a Capybara API:
|
168
|
+
|
169
|
+
```
|
170
|
+
:::>> website.visit(name: "localhost", url: "http://localhost:3000", scroll: 100)
|
171
|
+
session.execute_script "window.scrollBy(0,100)"
|
172
|
+
session.click("sign up")
|
173
|
+
```
|
174
|
+
|
175
|
+
### Exact output
|
126
176
|
|
127
|
-
|
177
|
+
RunDOC only cares about things that come after a `:::` section. If you have a "regular" code section, it will be rendered as as normal:
|
128
178
|
|
129
179
|
```
|
130
|
-
|
180
|
+
$ echo "I won't run since i'm missing the :::>> at the front"
|
181
|
+
```
|
182
|
+
|
183
|
+
You can mix non-command code and commands, as long as the things that aren't rendering come first. This can be used to "fake" a command, for example:
|
184
|
+
|
185
|
+
```
|
186
|
+
$ rails new myapp # Not a command since it's missing the ":::>>""
|
187
|
+
:::-> $ rails new myapp --skip-test --skip-yarn --skip-sprockets
|
188
|
+
:::>> | $ head -n 5
|
189
|
+
```
|
190
|
+
|
191
|
+
This will render as:
|
192
|
+
|
193
|
+
```
|
194
|
+
$ rails new myapp # Not a command since it's missing the ":::>>""
|
195
|
+
create
|
196
|
+
create README.md
|
197
|
+
create Rakefile
|
198
|
+
create .ruby-version
|
199
|
+
create config.ru
|
200
|
+
```
|
201
|
+
|
202
|
+
It looks like the command was run without any flags, but in reality `rails new myapp --skip-test --skip-yarn --skip-sprockets | head -n 5` was executed.
|
203
|
+
|
204
|
+
## Rendering Cheat Sheet
|
205
|
+
|
206
|
+
An arrow `>` is shorthand for "render this" and a dash `-` is shorthand for skip this section. The posions two positions are **command** first and **result** second.
|
207
|
+
|
208
|
+
|
209
|
+
- `:::>-` (yes command, not result)
|
210
|
+
- `:::>>` (yes command, yes result)
|
211
|
+
- `:::--` (not command, not result)
|
212
|
+
- `:::->` (not command, yes result)
|
213
|
+
|
214
|
+
## Shell Commands
|
215
|
+
|
216
|
+
Current Commands:
|
217
|
+
|
218
|
+
- `$`
|
219
|
+
- `fail.$`
|
220
|
+
|
221
|
+
Anything you pass to `$` will be run in a shell. If a shell command returns a non-zero exit status an error will be raised. If you expect a non-zero exit status use `fail.$` instead:
|
222
|
+
|
223
|
+
|
224
|
+
```
|
225
|
+
:::>> fail.$ cat /dev/null/foo
|
131
226
|
```
|
132
227
|
|
133
228
|
Even though this command returns a non zero exit status, the contents of the command will be written since we're stating that we don't care if the command fails. This would be the output:
|
@@ -142,14 +237,15 @@ Some commands may be custom, for example when running `cd` you likely want to ch
|
|
142
237
|
|
143
238
|
|
144
239
|
```
|
145
|
-
|
146
|
-
|
240
|
+
:::>> $ cd myapp/config
|
241
|
+
:::>> $ cat database.yml
|
147
242
|
```
|
148
243
|
|
149
|
-
However this command would fall on
|
244
|
+
However this command would fall on its face:
|
150
245
|
|
151
246
|
```
|
152
|
-
|
247
|
+
:::>> $ cd myapp && cat config/database.yml
|
248
|
+
:::>> $ rails g scaffold users # <=== This command would be in the wrong directory, not `myapp`
|
153
249
|
```
|
154
250
|
|
155
251
|
These custom commands are kept to a minimum, and for the most part behave as you would expect them to. Write your docs as you normally would and check the output frequently.
|
@@ -164,10 +260,10 @@ Current Commands:
|
|
164
260
|
- `file.append`
|
165
261
|
- `file.remove`
|
166
262
|
|
167
|
-
Use the `
|
263
|
+
Use the `file.write` keyword followed by a filename, on the next line(s) put the contents of the file:
|
168
264
|
|
169
265
|
```
|
170
|
-
|
266
|
+
:::>- file.write config/routes.rb
|
171
267
|
|
172
268
|
Example::Application.routes.draw do
|
173
269
|
root :to => "pages#index"
|
@@ -178,10 +274,12 @@ Use the `filewrite` keyword followed by a filename, on the next line(s) put the
|
|
178
274
|
end
|
179
275
|
```
|
180
276
|
|
277
|
+
> If the exact filename is not known you can use a [file glob (\*)](https://GitHub.com/schneems/rundoc/pull/6).
|
278
|
+
|
181
279
|
If you wanted to change `users` to `products` you could write to the same file again.
|
182
280
|
|
183
281
|
```
|
184
|
-
|
282
|
+
:::>- file.write config/routes.rb
|
185
283
|
Example::Application.routes.draw do
|
186
284
|
root :to => "pages#index"
|
187
285
|
|
@@ -196,7 +294,7 @@ To fully delete files use bash `$` command such as `::: $ rm foo.rb`.
|
|
196
294
|
To add contents to a file you can use `file.append`
|
197
295
|
|
198
296
|
```
|
199
|
-
|
297
|
+
:::>> file.append myapp/Gemfile
|
200
298
|
gem 'pg'
|
201
299
|
gem 'sextant', group: :development
|
202
300
|
gem 'wicked'
|
@@ -206,7 +304,7 @@ To add contents to a file you can use `file.append`
|
|
206
304
|
The contents of the file (in this example a file named `Gemfile`) will remain unchanged, but the contents of the `file.append` block will now appear in the bottom of the file. If you want to append the contents to a specific part of the file instead of the end of the file you can specify line number by putting a hash (`#`) then a number following it.
|
207
305
|
|
208
306
|
```
|
209
|
-
|
307
|
+
:::>> file.append myapp/Gemfile#22
|
210
308
|
gem 'rails_12factor'
|
211
309
|
```
|
212
310
|
This will add the `gem 'rails_12factor'` on line 22 of the file `myapp/Gemfile`. If line 22 has existing contents, they will be bumped down to line 23.
|
@@ -214,7 +312,7 @@ This will add the `gem 'rails_12factor'` on line 22 of the file `myapp/Gemfile`.
|
|
214
312
|
Some times you may want to remove a small amount of text from an existing file. You can do this using `file.remove`, you pass in the contents you want removed:
|
215
313
|
|
216
314
|
```
|
217
|
-
|
315
|
+
:::>> file.remove myapp/Gemfile
|
218
316
|
gem 'sqlite3'
|
219
317
|
```
|
220
318
|
|
@@ -222,33 +320,145 @@ When this is run, the file `Gemfile` will be modified to not include `gem 'sqlit
|
|
222
320
|
|
223
321
|
Note: `file.remove` currently requires a very explicit match so things like double versus single quotes, whitespace, and letter case all matter. Current best practice is to only use it for single line removals.
|
224
322
|
|
225
|
-
|
226
323
|
## Pipe
|
227
324
|
|
228
325
|
Commands:
|
229
326
|
- `|`
|
230
327
|
- `pipe` (aliased `|`)
|
231
328
|
|
232
|
-
Sometimes you need to need to pass data from one command to another. To do this there is a provided pipe command
|
329
|
+
Sometimes you need to need to pass data from one command to another. To do this there is a provided pipe command `|`.
|
233
330
|
|
234
331
|
Let's say you want to output the first 23 lines of a file but you don't want to confuse your users with an additional pipe command in your shell line you could write something like this:
|
235
332
|
|
236
333
|
```sh
|
237
|
-
|
238
|
-
|
334
|
+
:::> $ cat config/database.yml
|
335
|
+
:::>> | $ head -n 23
|
239
336
|
```
|
240
337
|
|
241
338
|
Anything after the pipe `|` will generate a new command with the output of the previous command passed to it. The pipe command will only ouput its result, so the user will not know it was even executed.
|
242
339
|
|
243
340
|
This command is currently hacked together, and needs a refactor. Use it, but if something does not behave as you would expected open an issue and explain it.
|
244
341
|
|
342
|
+
## Background
|
343
|
+
|
344
|
+
Sometimes you want to start a long lived process like a server in the background. In that case, the `background` namespace has your, well, back.
|
345
|
+
|
346
|
+
To start a process, pass in the command as the first arg, and give it a name (so it can be referenced later):
|
347
|
+
|
348
|
+
```
|
349
|
+
:::>> background.start("rails server", name: "server")
|
350
|
+
```
|
351
|
+
|
352
|
+
You can make the background process wait until it receives a certain string in the logs. For instance to make sure that the server is fully booted:
|
353
|
+
|
354
|
+
```
|
355
|
+
:::>> background.start("rails server", name: "server", wait: "Listening on")
|
356
|
+
```
|
357
|
+
|
358
|
+
You can stop the process by referencing the name:
|
359
|
+
|
360
|
+
```
|
361
|
+
:::-- background.stop(name: "server")
|
362
|
+
```
|
363
|
+
|
364
|
+
You can also get the log contents:
|
365
|
+
|
366
|
+
```
|
367
|
+
:::>> background.log.read(name: "server")
|
368
|
+
```
|
369
|
+
|
370
|
+
You can also truncate the logs:
|
371
|
+
|
372
|
+
```
|
373
|
+
:::>> background.log.clear(name: "server")
|
374
|
+
```
|
375
|
+
|
376
|
+
## Screenshots
|
377
|
+
|
378
|
+
You'll need selenium and `chromedriver` installed on your system to make screenshots work. On a mac you can run:
|
379
|
+
|
380
|
+
```
|
381
|
+
$ brew cask install chromedriver
|
382
|
+
```
|
383
|
+
|
384
|
+
To take a screenshot first "visit" a website. The values you pass in to stdin can be used to further navigate. For more information see the [Capybara DSL](https://www.rubydoc.info/GitHub/teamcapybara/capybara/master#the-dsl). Use the keyword `session`
|
385
|
+
|
386
|
+
Once you're on the page you want to capture you can execute `website.screenshot`:
|
387
|
+
|
388
|
+
```
|
389
|
+
:::>> website.visit(name: "localhost", url: "http://localhost:3000", scroll: 100)
|
390
|
+
session.execute_script "window.scrollBy(0,100)"
|
391
|
+
session.first(:link, "sign up").click
|
392
|
+
|
393
|
+
:::>> website.screenshot(name: "localhost")
|
394
|
+
```
|
395
|
+
|
396
|
+
The result of the screenshot command will be to replace the code section with a markdown link to a relative path of the screenshot.
|
397
|
+
|
398
|
+
Once you've visited a website you can further navigate using `website.nav` or `website.navigate`:
|
399
|
+
|
400
|
+
|
401
|
+
```
|
402
|
+
:::>> website.visit(name: "localhost", url: "http://localhost:3000")
|
403
|
+
:::>> website.navigate(name: "localhost")
|
404
|
+
session.execute_script "window.scrollBy(0,100)"
|
405
|
+
session.first(:link, "sign up").click
|
406
|
+
|
407
|
+
:::>> website.screenshot(name: "localhost")
|
408
|
+
```
|
409
|
+
|
410
|
+
## Upload Screenshots
|
411
|
+
|
412
|
+
You can specify that you want to upload files to S3 instead of hosting them locally by passing in `upload: "s3"` to the screenshot command:
|
413
|
+
|
414
|
+
```
|
415
|
+
:::>> website.visit(name: "localhost", url: "http://localhost:3000", scroll: 100)
|
416
|
+
:::>> website.screenshot(name: "localhost", upload: "s3")
|
417
|
+
```
|
418
|
+
|
419
|
+
To authorize, you'll need to set these environment variables:
|
420
|
+
|
421
|
+
```
|
422
|
+
AWS_ACCESS_KEY_ID
|
423
|
+
AWS_REGION
|
424
|
+
AWS_SECRET_ACCESS_KEY
|
425
|
+
AWS_BUCKET_NAME
|
426
|
+
```
|
427
|
+
|
428
|
+
The bucketeer addon on Heroku is supported out of the box. To specify project specific environment variables see the "dotenv" section below.
|
429
|
+
|
430
|
+
## Compose multiple RunDOC documents
|
431
|
+
|
432
|
+
If you're writing multiple tutorials that all are used together to build one larger project then you can declare dependencies inside of your RunDOC document.
|
433
|
+
|
434
|
+
For example on day two (`day_two/rundoc.md`) of the tutorials you could:
|
435
|
+
|
436
|
+
```
|
437
|
+
:::-- rundoc.depend_on "../day_one/rundoc.md"
|
438
|
+
```
|
439
|
+
|
440
|
+
Now when you build `day_two/rundoc.md` it will also run the steps in `day_one/rundoc.md` first. This way you don't have to copy and paste previous commands.
|
441
|
+
|
442
|
+
You can also break up your document into smaller components:
|
443
|
+
|
444
|
+
|
445
|
+
```
|
446
|
+
:::>> rundoc.require "../shared/rails_new.md"
|
447
|
+
```
|
448
|
+
|
449
|
+
This will replace the code section with the generated contents of `rundoc.require`.
|
450
|
+
|
451
|
+
|
452
|
+
## Dotenv support
|
453
|
+
|
454
|
+
If you need to specify project specific environment variables create a file called `.env` at the same directory as your `rundoc.md` and it will be imported. Add this file to your `.gitignore` so you don't accidentally share with the world
|
245
455
|
|
246
456
|
## Configure
|
247
457
|
|
248
|
-
You can configure your docs in your docs use the `
|
458
|
+
You can configure your docs in your docs use the `RunDOC` command
|
249
459
|
|
250
460
|
```
|
251
|
-
|
461
|
+
:::-- rundoc.configure
|
252
462
|
```
|
253
463
|
|
254
464
|
Note: Make sure you run this as a hidden command (with `-`).
|
@@ -259,10 +469,10 @@ This will eval any code you put under that line (in Ruby). If you want to run so
|
|
259
469
|
|
260
470
|
|
261
471
|
```
|
262
|
-
|
472
|
+
:::-- rundoc.configure
|
263
473
|
Rundoc.configure do |config|
|
264
474
|
config.after_build do
|
265
|
-
puts "you could push to
|
475
|
+
puts "you could push to GitHub here"
|
266
476
|
puts "You could do anything here"
|
267
477
|
puts "This code will run after the docs are done building"
|
268
478
|
end
|
@@ -272,10 +482,10 @@ This will eval any code you put under that line (in Ruby). If you want to run so
|
|
272
482
|
|
273
483
|
**Project Root**
|
274
484
|
|
275
|
-
By default your app builds in a `tmp` directory. If any failures occur the results will remain in `tmp`. On a successful build the contents are copied over to `project`. If you are generating a new rails project in your code `$ rails new myapp`. Then the finished directory would be in `project/myapp`. If you don't like the `./project` prefix you could tell
|
485
|
+
By default your app builds in a `tmp` directory. If any failures occur the results will remain in `tmp`. On a successful build the contents are copied over to `project`. If you are generating a new rails project in your code `$ rails new myapp`. Then the finished directory would be in `project/myapp`. If you don't like the `./project` prefix you could tell RunDOC to output contents in `./myapp` instead.
|
276
486
|
|
277
487
|
```
|
278
|
-
|
488
|
+
:::-- rundoc.configure
|
279
489
|
Rundoc.configure do |config|
|
280
490
|
config.project_root = "myapp"
|
281
491
|
end
|
@@ -288,7 +498,7 @@ This will also be the root directory that the `after_build` is executed in.
|
|
288
498
|
Sometimes sensitive info like usernames, email addresses, or passwords may be introduced to the output readme. Let's say that your email address was `schneems@example.com` you could filter this out of your final document and replace it with `developer@example.com` instead like this:
|
289
499
|
|
290
500
|
```
|
291
|
-
|
501
|
+
:::-- rundoc.configure
|
292
502
|
Rundoc.configure do |config|
|
293
503
|
config.filter_sensitive("schneems@exmaple.com" => "developer@example.com")
|
294
504
|
end
|
@@ -296,14 +506,6 @@ Sometimes sensitive info like usernames, email addresses, or passwords may be in
|
|
296
506
|
|
297
507
|
This command `filter_sensitive` can be called multiple times with different values. Since the config is in Ruby you could iterate over an array of sensitive data
|
298
508
|
|
299
|
-
##
|
300
|
-
|
301
|
-
This is a section for brainstorming. If it's here it's not guaranteed to get worked on, but it will be considered.
|
302
|
-
|
303
|
-
- Breakpoints?
|
304
|
-
- Better line matching for backtrace
|
305
|
-
- `-=` command (runs command, only shows output, does not show command)
|
306
|
-
- A way to run background processes indefinitely such as `rails server`
|
307
|
-
- An easy test syntax?
|
308
|
-
- Screenshot tool(s) ?!?!?!?!?!?! :)
|
509
|
+
## Copyright
|
309
510
|
|
511
|
+
All content Copyright Richard Schneeman © 2019
|