Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Play is a Java and Scala web application framework with excellent efficiency that unifies components and APIs for contemporary web application development. Web developers created the play for the creation of web applications.
Framework documentation for developers is crucial. Developers must go through the framework's code to find the information they need without documentation.
In this blog, we will discuss the guidelines for writing play documentation.
Guidelines for Writing Play Documentation
Any communicable material used to describe, clarify, or provide instructions for specific product characteristics, a system, or a procedure, such as its components, assembly, installation, maintenance, and use, is considered documentation.
The guidelines for writing Play documentation are also essential for web developers. The Play documentation is written in Markdown and includes code snippets taken from source files that had been tested, run, and compiled.
When writing Play documentation, a few rules must be followed. Let’s discuss all the guidelines for writing the play documentation.
Gender-Neutral
The Play community respects the diversity of genders. According to the guidelines for writing play documentation, please try to utilise unisex names and gender-neutrallanguage when generating examples in the documentation.
Speaking and writing in a way that "does not discriminate against a single gender, social gender, or gender identity, and does not reinforce gender stereotypes" is what is meant by gender-neutral language, also known as gender-inclusive language.
A given name that is gender-neutral is known as a unisex name. A unisex name is used for both genders, such as Alexis, Clare, Gale, or Kimberly.
Markdown Files
In our guidelines for writing play documentation, we discussed that the play documentation is written in Markdown format. Now, let’s understand what a markdown file is.
Regardless of their folder, all markdown files must have distinct names across the entire documentation. The play utilises wiki-style linking and documentation rendering.
Newline characters in the midst of paragraphs are interpreted as hard wraps and are translated into line breaks, much like GitHub's flavour of markdown. Therefore, a single line should be included in each paragraph.
Linking Documents
One of the most important concepts in the guidelines for writing play documentation is to link different documents. We should use the Wiki markup syntax to make links to other documentation pages, as in:
[Optional [Description|| ScalaRouting]]
Images should follow the above syntax. External links should utilise the regular Markdown link syntax rather than the syntax mentioned above.
Sample Codes
The guidelines for writing play documentation recommend importing all supported code examples from outside compiled files. The syntax is as follows:
@[some-Label](code/Feature.scala)
The lines that need to be extracted should then be delimited in the file using #some-label, as in:
Object FeatureSpec extends Specification {
" feature" should {
"do something" in {
//#some-label
val msg = Seq("Coding", "Ninjas").mkString(" ")
//#some-label
msg must_== "Coding Ninjas"
}
}
}
The val message =... line in the example above will be extracted and presented as code on the page. All code examples should be examined to make sure they compile, run, and, if it makes sense, that they perform the functions described in the documentation. It shouldn't attempt to test the features individually.
The same classloader is used to execute all scala, java, routes, and template code samples. They must all be appropriately namespaced and contained in a package that matches the section of the documentation they are related to.
The code that should be in the documentation might not always be an exact match with the code you can create using the above recommendations. Using package names like controllers is particularly necessary for specific code samples. There are a few directives you can add to the code to tell the code samples extractor to modify the sample as a last resort if there are no other options. Which are:
###replace: fun — Substitute fun for the following line. You can choose to end this command with ###.
###insert: fun — which will insert fun before the following line. You can choose to end this command with ###.
###skip — which means to skip the current line.
###skip: l — Remove the following l lines.
Guidelines for writing play documentation for several categories of code samples are shown below:
Scala
The code sample should, if feasible, be contained within the spec, and all Scala code samples should be tested using the spec. Where appropriate, local class and method definitions are encouraged. Additionally suggested is scoping import statements within blocks.
Java
Every Java code sample should go through JUnit testing. Simple code samples are typically easy to incorporate in the JUnit test, but it becomes more challenging when the code sample is a method or a class.
The use of local and inner classes should be preferred. However, in some cases, this may not be practical. For instance, a static method can only be present on a static inner class, which requires adding the static modifier to the class, which would not be present if the class was an outer class.
As a result, it could occasionally be essential to separate Java code samples into separate files.
Route Files
The best way to test route files is with Specs in Scala or JUnit in Java. To keep them apart from other routes code samples, routes files should be titled with the complete package name, such as scalaguide.http.routing.routes.
The reverse router inside the namespace declared by the file is generated by the routes compiler used by the documentation while it is running in a specific mode. This means that even while a routes code sample might utilise references to classes that appear to be absolute, they are relative to the router's namespace.
As a result, in the routes file mentioned above, a controller with the name scalaguide.http.routing.controllers.Application will be referenced by the route controllers.Application.
Scala Templates
Specs in Scala or JUnit in Java should be used to test samples of the Scala template code. It should be noted that depending on whether templates are found in the Scala documentation or the Java documentation, different default imports are used when compiling them. Therefore, it's crucial to test them in the appropriate environment.
When it's practicable, template code samples should be consolidated into a single file. However, there are times when this may not be possible, like when a parameter declaration is included in the code sample.
Sbt Code
Extract sbt code samples into *.sbt files. The evaluateSbtFiles task compiles and loads these files independently for testing; by loading, it means that it executes the settings definitions (i.e., creates a Seq[Setting[_]]), but not the tasks or settings that have been stated.
Any plugins that the code snippets require must be plugins to the sbt project since the classloader used to run these files is the same as the sbt classloader.
Testing
In the context of the guidelines for writing the play documentation, we will discuss the testing of the documentation.
We can test the documentation using the following methods:
→ You must develop and publish Play locally before producing the documentation. Run sbt publishLocal from the root directory of the playframework repository to accomplish this.
→ Run sbt run from within the documentation directory to make sure the documentation renders appropriately. This will launch a little Play server that only serves documentation.
→ Run the sbt test to verify that the code samples compile, run, and pass the tests.
→ Run sbt validateDocs to ensure that the documentation is structurally sound. This verifies that all documentation markdown filenames are unique, that there are no broken wiki links, code references, or resource linkages, and that there are no orphaned pages.
Frequently Asked Questions
What is the Markdown method in the guidelines for writing play documentation?
An easy-to-use markup language is markdown. It enables you to format a written document in digital form using standard formatting methods, such as headings, emphasis, lists, graphics, and links. The file extensions for markdown files are.md or .markdown.
Which element is responsible for creating the play framework?
Model-view-controller (MVC) architecture is used by the Play Framework, an open-source online application framework. It was created in Scala and is compatible with Java and other programming languages that are compiled to JVM bytecode.
Why do we use a play framework?
Scala & Java developers may create web applications quickly and easily with Play Framework. Play's architecture is lightweight, stateless and suitable for the web. Play, based on Akka, gives highly scalable applications predictable and low resource consumption (CPU, memory, threads).
Conclusion
In this blog, we have discussed guidelines for writing play documentation. We discussed the markdown files, Gender-neutral languages, Sample codes, and testing documentation.
We hope this blog increases your knowledge regarding the Play framework. We recommend you to visit our curated section of web technology and cover some interesting topics such as: