Include code from this repository in the Google Developer Academy documentation site.
In this exercise you will each pull code from this repository using the includecode template tag to include snippets in our documentation site. This repository has a sample code file android_client.kt
which has an example for Creating a Fitness API client in Kotlin using the Android Fit SDK. You also have an exercise2
folder under your devsite GDA workspace in google3 which has the iX (information eXperience) document for this code sample.
# Path to the exercise2 folder
google3_root> third_party/devsite/internal/en/experimental/gda/<USERNAME>
# Structure
exercise2
|-- adding-snippets.md # file you must work on
|-- adding-snippets-sol.md # solution file to validate your work
- The solution for the iX documentation changes is available in the file
adding-snippets-sol.md
under theexercise2
directory in google3 - The solution for the source code changes is available in this repository under the git branch
answers
Using the includecode template tag in the iX document and region tags in the source code file, embed the code snippets pulled from this repository in the documentation.
Check if this repository has been set up to be mirrored into Gerrit (Git-on-Borg)
.
- Go to: https://github.git.corp.google.com/
- Paste
GoogleDeveloperAcademy
in the repository to find for field - Press
FIND
and check if thecode-snippets
repository has been mirrored
Clone this repository locally and create new branch to work on. After completing this step, you should be able to see a branch after your <USERNAME> in this repository.
git clone https://github.com/GoogleDeveloperAcademy/code-snippets
cd code-snippets
git checkout -b <USERNAME>
git push --set-upstream origin <USERNAME>
Add a region tag covering the entire source code file android_client.kt
.
# add the region as explained in the slides encompassing the whole file
# save the file
git add android_client.kt
git commit -m "chore: add first region tag"
git push
Update the iX document adding-snippets.md
under your google3 GDA workspace to include code from this file using the includecode template tag. For this step include the code in the space where you find the first TODO in the document.
🎯 HINT 1: To point to a region_tag from a specific git branch use the git_revision attribute of the includecode template.
🎯 HINT 2: The expected format for the git_revision attribute isrefs/heads/<BRANCH_NAME>
Stage and view the iX document (adding-snippets.md) through Cider
.
- Cider > Tools > DevSite > Stage current file
- Cider > Tools > DevSite > Open staged file
🚀 ⚡YOU SHOULD SEE THE CODE FROM THE android_client.kt
FILE RENDERED IN THE DOCUMENT ⚡🚀
- Add 5 different region tags to each of the different sections (1, 2, 3, 4, 5) in the
android_client.kt
file and include each of them seperately in place of the 5TODO
s in the iX document adding-snippets.md - Try to highlight specific sections of different sections
- Try if you can create a second language tab for
Groovy
(you can include the same Kotlin code to practice)