rundoc 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/CHANGELOG.md +10 -0
  4. data/README.md +219 -96
  5. data/bin/rundoc +4 -68
  6. data/lib/rundoc.rb +1 -0
  7. data/lib/rundoc/cli.rb +84 -0
  8. data/lib/rundoc/code_command.rb +3 -2
  9. data/lib/rundoc/code_command/background/process_spawn.rb +28 -2
  10. data/lib/rundoc/code_command/background/start.rb +1 -0
  11. data/lib/rundoc/code_command/bash/cd.rb +20 -2
  12. data/lib/rundoc/code_command/no_such_command.rb +4 -0
  13. data/lib/rundoc/code_command/rundoc/depend_on.rb +37 -0
  14. data/lib/rundoc/code_command/rundoc/require.rb +41 -0
  15. data/lib/rundoc/code_command/rundoc_command.rb +4 -1
  16. data/lib/rundoc/code_command/website.rb +7 -0
  17. data/lib/rundoc/code_command/website/driver.rb +111 -0
  18. data/lib/rundoc/code_command/website/navigate.rb +29 -0
  19. data/lib/rundoc/code_command/website/screenshot.rb +28 -0
  20. data/lib/rundoc/code_command/website/visit.rb +47 -0
  21. data/lib/rundoc/code_section.rb +13 -4
  22. data/lib/rundoc/parser.rb +4 -3
  23. data/lib/rundoc/peg_parser.rb +1 -1
  24. data/lib/rundoc/version.rb +1 -1
  25. data/rundoc.gemspec +6 -2
  26. data/test/fixtures/build_logs/rundoc.md +56 -0
  27. data/test/fixtures/depend_on/dependency/rundoc.md +5 -0
  28. data/test/fixtures/depend_on/main/rundoc.md +10 -0
  29. data/test/fixtures/java/rundoc.md +9 -0
  30. data/test/fixtures/rails_4/rundoc.md +1 -1
  31. data/test/fixtures/rails_5/rundoc.md +3 -3
  32. data/test/fixtures/{rails_5_beta → rails_6}/rundoc.md +79 -86
  33. data/test/fixtures/require/dependency/rundoc.md +5 -0
  34. data/test/fixtures/require/main/rundoc.md +10 -0
  35. data/test/fixtures/screenshot/rundoc.md +10 -0
  36. data/test/rundoc/peg_parser_test.rb +33 -0
  37. metadata +71 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed87bdf4593dcd65e6823a9ef5231802b0282aed932c119022cfc44d2ec6f9d8
4
- data.tar.gz: 0d7a80aab3b225049978eb30ca301f817203a564aa9787dcd0026a89b61c101d
3
+ metadata.gz: e99ebdb76543d50700d87e4e1d369584785d88500a4ba261b203fc526391234a
4
+ data.tar.gz: 41c77800630c17ca1cb1e123cd9930290bcdd3e6bf87c7db42da3e4d32159070
5
5
  SHA512:
6
- metadata.gz: ff4a68baac0e70330af729e752dc96e01c95e1da4ffe0e4850d8fca619e026adbaea940fed31982d41bcc41308ffdb7c3625145c2209ea0db7ec22b714738377
7
- data.tar.gz: '09e9a757c31ea81c31b1e1d1c70da5241f2b756c39a2f6701e0d4b9f2a108647d21fb6d40edd31417b5136f3eb72f802c03020b7af9d42677d8f6efd96e3bf4d'
6
+ metadata.gz: f7e5ab57b964760255e72017c7caa23b13ed3b4042763858d56518a737cf9ac0274f0c8a9c1189b0af061ff47f250cf9438e38302a5664b469166071ff380bf2
7
+ data.tar.gz: f086f8a367a1770d6dd9bb85832637e94d93b8198e2eaf5e2c38f4b20881a852134d148a9655c517e1eb41c81f1797003e16cd0b1137ddba88ac2c494ca38649
data/.gitignore CHANGED
@@ -1,7 +1,14 @@
1
1
  test/fixtures/*/project/
2
2
  test/fixtures/*/tmp/
3
3
  test/fixtures/*/myapp/
4
+
5
+ test/fixtures/*/*/project/
6
+ test/fixtures/*/*/tmp/
7
+ test/fixtures/*/*/myapp/
8
+
9
+
4
10
  *.gem
5
11
 
6
12
  .DS_Store
7
13
  Gemfile.lock
14
+ .env
@@ -1,3 +1,13 @@
1
+ ## master
2
+
3
+ ## 1.0.1
4
+
5
+ - Allow non-headless browser sessions and navigation [#23](https://github.com/schneems/rundoc/pull/23)
6
+ - Fix issue where a background task's log file was not present before it was attempted to be opened.
7
+ - Allow composability of documents `rundoc.depend_on` and `rundoc.require` [#19](https://github.com/schneems/rundoc/pull/19)
8
+ - The `rundoc` command is now `rundoc.configure`.
9
+ - Ignore chdir warning since that affect is intentional [#20](https://github.com/schneems/rundoc/pull/20)
10
+
1
11
  ## 1.0.0
2
12
 
3
13
  - Now using a propper PEG parser (parslet)
data/README.md CHANGED
@@ -4,34 +4,29 @@
4
4
 
5
5
  ## What
6
6
 
7
- This library allows you to "run" your docs and embed the code as well as results back into the documentation.
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:
8
8
 
9
- 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.
9
+ Write documentation:
10
10
 
11
- Think of runDOC as your ever-vigilant tech editor and writing partner.
11
+ Install by running:
12
12
 
13
- 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.
14
-
15
- Write more technical content, faster and with a better consistency by using runDOC.
16
-
17
- ## Why
18
-
19
- I wrote a [Rails course for the University of Texas](http://schneems.com), that required I build an app and write
20
- 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.
21
-
22
-
23
- While I was writing the course I dreamed of a system where the docs and the
24
- code could automatically stay in sync. One where if I had a typo in my tutorials, an automatic tech-editor would know and tell me. One where I couldn't accidentally skip over critical sections leaving true novices confused.
13
+ ```
14
+ :::>> $ gem install rails --no-document
15
+ ```
25
16
 
26
- Dream no more, because runDOC does just that:
17
+ Now if you "run" this document you'll get this output:
27
18
 
28
- Write docs, build software.
19
+ Install by running:
29
20
 
30
- ## Isn't this Overkill?
21
+ ```
22
+ $ gem install rails --no-document
23
+ Successfully installed rails-5.2.2
24
+ 1 gem installed
25
+ ```
31
26
 
32
- No. Many new doc writers skip steps accidentally, or omit lines of code with `...` and assume their readers can follow along. Even if this is true for 80% of your users, 20% of people will become frustrated and may give up as a result. I found by including [check steps](http://schneems.com/post/60359275700/prepare-do-test-make-your-technical-writing-shine) such as running `ls` to ensure directory contents were the difference between good docs and great ones. The only problem: the output of `ls` on a Rails 4.0.0 and 4.0.1 project may be different. So the only way to ensure output is to actually run the command and copy it into your docs. With runDOC you don't need to do that. Rundoc runs the command then it can insert the output for you.
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.
33
28
 
34
- If you don't intend on updating or revising your content, then this project is overkill. On the other hand if you're writing docs without the intent of revising them, you probably shouldn't be writing technical docs.
29
+ Think of RunDOC as your ever-vigilant tech editor and writing partner.
35
30
 
36
31
  ## Install
37
32
 
@@ -52,32 +47,53 @@ gem 'rundoc`
52
47
  Run the `rundoc build` command on any markdown file
53
48
 
54
49
  ```sh
55
- $ rundoc build --path runDOC.md
50
+ $ rundoc build --path my/path/to/run_doc.md
56
51
  ```
57
52
 
58
- 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
+ > 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.
59
54
 
60
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.
61
56
 
62
57
  ## Quick docs
63
58
 
64
- - [$]()
65
- - [fail.$]()
66
- - [file.write]()
67
- - [file.append]()
68
- - [file.remove]()
69
- - [background.start]()
70
- - [background.stop]()
71
- - [background.log.read]()
72
- - [background.log.clear]()
73
-
74
- ## Write it:
75
-
76
- Rundoc uses github flavored markdown. This means you write like normal but in your code sections
77
- you can add special annotations that when run through runDOC can
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
78
94
  generate a project.
79
95
 
80
- All runDOC commands are prefixed with three colons `:::` and are inclosed in a code block a
96
+ All RunDOC commands are prefixed with three colons `:::` and are inclosed in a code block a
81
97
  command such as `$` which is an alias for `bash` commands like this:
82
98
 
83
99
  ```
@@ -112,26 +128,9 @@ This code block might generate an output something like this to your markdown do
112
128
  Gemfile.lock Rakefile config db lib public test vendor
113
129
  ```
114
130
 
115
- That's the syntax, let's look at different runDOC commands
116
-
117
- ## Rendering Cheat Sheet
118
-
119
- 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. You can skip a trailing `-`.
131
+ ### Stdin
120
132
 
121
-
122
- - `:::>-` (yes command, not result)
123
- - `:::>>` (yes command, yes result)
124
- - `:::--` (not command, not result)
125
- - `:::->` (not command, yes result)
126
-
127
- ## Shell Commands
128
-
129
- Current Commands:
130
-
131
- - `$`
132
- - `fail.$`
133
-
134
- Anything you pass to `$` will be run in a shell. Any items below the command will be passed into the stdin of the bash command so:
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:
135
134
 
136
135
  ```
137
136
  :::>> $ tail -n 2
@@ -151,7 +150,76 @@ Would output:
151
150
 
152
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).
153
152
 
154
- If a shell command returns a non-zero exit status an error will be raised, if you expect a command to fail you can run it with `fail.$` keyword
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
176
+
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:
178
+
179
+ ```
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
+
155
223
 
156
224
  ```
157
225
  :::>> fail.$ cat /dev/null/foo
@@ -176,7 +244,8 @@ Some commands may be custom, for example when running `cd` you likely want to ch
176
244
  However this command would fall on its face:
177
245
 
178
246
  ```
179
- :::>> $ cd myapp/config && cat database.yml
247
+ :::>> $ cd myapp && cat config/database.yml
248
+ :::>> $ rails g scaffold users # <=== This command would be in the wrong directory, not `myapp`
180
249
  ```
181
250
 
182
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.
@@ -191,9 +260,7 @@ Current Commands:
191
260
  - `file.append`
192
261
  - `file.remove`
193
262
 
194
- If the exact filename is not known you can use a [file glob (\*)](https://github.com/schneems/rundoc/pull/6).
195
-
196
- Use the `file.write` keyword followed by a filename, on the next line(s) put the contents of the file
263
+ Use the `file.write` keyword followed by a filename, on the next line(s) put the contents of the file:
197
264
 
198
265
  ```
199
266
  :::>- file.write config/routes.rb
@@ -207,6 +274,8 @@ Use the `file.write` keyword followed by a filename, on the next line(s) put the
207
274
  end
208
275
  ```
209
276
 
277
+ > If the exact filename is not known you can use a [file glob (\*)](https://GitHub.com/schneems/rundoc/pull/6).
278
+
210
279
  If you wanted to change `users` to `products` you could write to the same file again.
211
280
 
212
281
  ```
@@ -294,7 +363,6 @@ You can stop the process by referencing the name:
294
363
 
295
364
  You can also get the log contents:
296
365
 
297
-
298
366
  ```
299
367
  :::>> background.log.read(name: "server")
300
368
  ```
@@ -305,12 +373,92 @@ You can also truncate the logs:
305
373
  :::>> background.log.clear(name: "server")
306
374
  ```
307
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
455
+
308
456
  ## Configure
309
457
 
310
- You can configure your docs in your docs use the `runDOC` command
458
+ You can configure your docs in your docs use the `RunDOC` command
311
459
 
312
460
  ```
313
- :::-- rundoc
461
+ :::-- rundoc.configure
314
462
  ```
315
463
 
316
464
  Note: Make sure you run this as a hidden command (with `-`).
@@ -321,10 +469,10 @@ This will eval any code you put under that line (in Ruby). If you want to run so
321
469
 
322
470
 
323
471
  ```
324
- :::-- rundoc
472
+ :::-- rundoc.configure
325
473
  Rundoc.configure do |config|
326
474
  config.after_build do
327
- puts "you could push to github here"
475
+ puts "you could push to GitHub here"
328
476
  puts "You could do anything here"
329
477
  puts "This code will run after the docs are done building"
330
478
  end
@@ -334,10 +482,10 @@ This will eval any code you put under that line (in Ruby). If you want to run so
334
482
 
335
483
  **Project Root**
336
484
 
337
- 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.
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.
338
486
 
339
487
  ```
340
- :::-- rundoc
488
+ :::-- rundoc.configure
341
489
  Rundoc.configure do |config|
342
490
  config.project_root = "myapp"
343
491
  end
@@ -350,7 +498,7 @@ This will also be the root directory that the `after_build` is executed in.
350
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:
351
499
 
352
500
  ```
353
- :::-- rundoc
501
+ :::-- rundoc.configure
354
502
  Rundoc.configure do |config|
355
503
  config.filter_sensitive("schneems@exmaple.com" => "developer@example.com")
356
504
  end
@@ -358,31 +506,6 @@ Sometimes sensitive info like usernames, email addresses, or passwords may be in
358
506
 
359
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
360
508
 
361
- ## TODO
362
-
363
- This is a section for brainstorming. If it's here it's not guaranteed to get worked on, but it will be considered.
364
-
365
- - Seperate parsing from running. This will help for easier linting of syntax etc.
366
- - Cache SHAs and output of each code block. If one sha changes, re-generate all code blocks, otherwise allow a re-render without code execution. Configure a check sum for busting the cache for instance a new version of Rails is released.
367
-
368
-
369
- - A way to run background processes indefinitely such as `rails server`
370
- - Maybe a way to truncate them after only a period of time such as grab a few lines of `heroku local`.
371
-
372
-
373
- ```
374
- :::>- background.start(command: "rails server")
375
- ```
376
-
377
- ```
378
- :::>> background.read("rails server")
379
- :::>- | $ head -n 23
380
- :::>- background.clear
381
- ```
382
-
509
+ ## Copyright
383
510
 
384
- - Breakpoints?
385
- - Better line matching for backtrace
386
- - `-=` command (runs command, only shows output, does not show command) ?
387
- - An easy test syntax?
388
- - Screenshot tool(s) ?!?!?!?!?!?! :)
511
+ All content Copyright Richard Schneeman © 2019