PLEASE ABIDE BY OUR
If you need to report an incident, fill out our anonymous incident report form or email coc@drupalcampcolorado.org. Visit https://2019.drupalcampcolorado.org/code-conduct for the full code of conduct and contact information for the CoC team.
Sunday, August 4, 2019
9:00am - 3:00pm
First-time, Mentored, and General contributions
Why I'm giving this talk
Who should document
What makes up documentation
When to write
Where it should go
Why document
Tools that help build out docs
Examples of Drupal and Symfony open source projects
D7 + Commerce + Custom Code + No Docs =
# Adding Quotes To Checkout Process.
This module was modified for the [issue-link] issue. The business wanted
to add a way for users to save and print out quotes. They decided to work
that into the checkout process alongside the purchase order option.
I'm adding this readme for sanity's sake so the next person has some back
story.
## The Payment Options
This module contains the "purchase order" and "quote" payment options
during the checkout process. The "credit card" option is created by the
commerce_stripe module.
The purchase order option allows a user to enter a special code rather
than a credit card to make a purchase. The quote option allows a user to
save the checkout items in a printable format that they can send to
someone for approval.
...
D7 + Commerce + Custom Code + Some Docs =
"Material that provides official information or evidence or that serves as a record."
The why more than the what...
"Good code is self-documenting."
Comment on why you did something and not what you are doing
Review them before you make a pull request
"A junior dev will tell you what they are doing, a mid-level dev will tell you why they are doing it this way, and a senior dev will tell you why they aren't doing it a different way."
Put them on their own lines
// WHAT:
// Set the default value of age.
$age = 32;
// WHY:
// Discard the first element in the array because...
$age = $data[1]['_foo']['age'];
// Really Obvious Code
// The comments are moved to function declaration.
$age = getAge($data);
// MEAN:
// Richard did it this way cause he smells :P
/**
* Static class providing Drupal specific Gettext functionality.
*
* The operations are related to pumping data from a source to a destination,
* for example:
* - Remote files http://*.po to memory
* - File public://*.po to database
*/
class Gettext {
/**
* Provides the node submission form.
*
* @param \Drupal\node\NodeTypeInterface $node_type
* The node type entity for the node.
*
* @return array
* A node submission form.
*/
public function add(NodeTypeInterface $node_type) {
“Annotations basically let you inject behavior and can promote decoupling.”
The configuration is all in one place
Don’t have to inherit from a class in Doctrine as you do in Propel
Plugins like Entities and Controller Annotations in Drupal
Can be used for properties as well as methods and classes
It can be parsed and added to API docs which is not as easy to do with YAML files
/**
* Executes interface translation queue tasks.
*
* @QueueWorker(
* id = "locale_translation",
* title = @Translation("Update translations"),
* cron = {"time" = 30}
* )
*/
class LocaleTranslation extends QueueWorkerBase {
/**
* Defines the node entity class.
*
* @ContentEntityType(
* id = "node",
* label = @Translation("Content"),
* ...
*/
class Node extends EditorialContentEntityBase implements NodeInterface {
/**
* Provides the node submission form.
*
* @param \Drupal\node\NodeTypeInterface $node_type
* The node type entity for the node.
*
* @return array
* A node submission form.
*/
public function add(NodeTypeInterface $node_type): array {
// @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
// @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
Note the...
# Truth betold there was more to this in the original file...
before_install:
# Check whether anything in the testing folder has changed.
- git checkout ${TRAVIS_PULL_REQUEST_BRANCH}
- git diff dev..${TRAVIS_PULL_REQUEST_BRANCH} tests/behat/features > foo.txt
# Debug statement.
- cat foo.txt
- if [ $(wc -c <foo.txt) -le 2 ]; then echo "No change to beaht/features." && exit 1; fi
# Properly documented, could be improved:
┃ B ↑ Foo#complicated
# Undocumented:
┃ U ↑ Foo
┃ U ↗ Foo#filename
You might want to look at these files:
┃ lib/foo.rb
Grade distribution (undocumented, C, B, A): █ ▁ ▄ ▄
Only considering priority objects: ↑ ↗ → (use '--help' for options).
“They are less willing to read documents that focus on conceptual information, although conceptual information, such as background information on the problem or domain addressed by the API, determines how efficiently API documentation can be used."
(Jeong et al., 2009; Ko & Riche, 2011)
Comments can’t be trusted
Allows for sloppy code over self-documenting code
Place comments in “hidden documentation” a.k.a the git log
“Clutter” or “pollute” the codebase.
“Indeed, the ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code. ...[Therefore,] making it easy to read makes it easier to write.”
- Robert C Martin
**Bolded Text** and Stuff::
// This is kinda like a code block?
array.map(e => e.foo);
.. image:: netlify-dns-dashboard.png
:width: 200px
:align: center
:height: 100px
:alt: alternate text
Welcome to Sphinx Example's documentation!
==========================================
.. toctree::
:maxdepth: 2
:caption: Contents:
import Video from '../components/video'
# My blog post
Here is some code:
```
my code!
```
And here's a video:
<Video width={300} src="video.mp4" />
---
name: Button
---
import { Playground, Props } from 'docz'
import { Button } from './'
# Button
<Props of={Button} />
## Basic usage
<Playground>
<Button>Click me</Button>
<Button kind="secondary">Click me</Button>
</Playground>
A crap ton of menu paths load the individual types of code - files, functions, classes, etc.
Uses hook_load() to take wildcards in paths and load the data for page callbacks. This is interesting because there is already a hook_load for nodes.
# build the image...
$ docker build . -t symfony-docs
# ...and start the local web server
# (if it's already in use, change the '8080' port by any other port)
$ docker run --rm -p 8080:80 symfony-docs
Sunday, August 4, 2019
9:00am - 3:00pm
First-time, Mentored, and General contributions