@@ -167,24 +167,56 @@ <h2 id="modularity">Modularity and Encapsulation</h2>
167167
168168< p > As the amount of JSON grows, its size makes it harder to manage. Jsonnet has various constructs
169169to help. A file can be broken into parts, as one Jsonnet file can import other Jsonnet files (and
170- therefore other JSON files). Values can be held in local variables and fields, which are only
171- visible within their scopes. Functions can be defined to factor out common descriptions, and error
172- statements can be used to validate inputs. Jsonnet provides a standard library that is implicitly
173- imported and contains useful functions for data manipulation, among other things.</ p >
170+ therefore other JSON files), or a whole text file can be imported as a string value. Values can be
171+ held in local variables and fields, which are only visible within their scopes. Functions can be
172+ defined to factor out common descriptions, and error statements can be used to validate inputs.
173+ Jsonnet provides a standard library that is implicitly imported and contains useful functions for
174+ data manipulation, among other things.</ p >
174175
175176< h3 id ="imports "> Imports</ h3 >
176177
177178< p > The first example below factors out some cocktails into a separate file. This may be useful to
178- allow concurrent modifications by different mixologists. The < code > import</ code > construct yields
179- the content of the < tt > martinis.libsonnet</ tt > file. The < code > +</ code > operator is object
180- concatenation, which combines two objects to form a single object. Note that the Cosmopolitan field
181- is defined in both files, so the one on the right hand side is used. This means that
182- < tt > bar_menu.jsonnet</ tt > has overridden the recipe from < tt > martinis.libsonnet</ tt > with a different
183- recipe (one that uses Cointreau instead of Triple Sec, among other changes).</ p >
179+ allow concurrent modifications by different mixologists.</ p >
184180
181+ < p > The < code > import</ code > construct yields the content of the < tt > martinis.libsonnet</ tt > file
182+ evaluated as a Jsonnet object. The < code > +</ code > operator is object concatenation, which combines
183+ two objects to form a single object. Note that the Cosmopolitan field is defined in both files, so
184+ the one on the right hand side is used. This means that < tt > bar_menu.jsonnet</ tt > has overridden
185+ the recipe from < tt > martinis.libsonnet</ tt > with a different recipe (one that uses Cointreau instead
186+ of Triple Sec, among other changes).</ p >
187+
188+ < p > The < code > importstr</ code > construct yields a string with the content of
189+ the < tt > bar_menu.6.manhattan_garnish.txt</ tt > file without any processing beyond UTF-8 decoding.</ p >
190+
191+ < table >
192+ < tr > < td > < span class ="TableHeader "> Input (Jsonnet)</ span > </ td > </ tr >
193+
194+ < tr >
195+ < td >
185196< pre > < code > {% include examples/martinis.libsonnet %}</ code > </ pre >
197+ </ td >
198+ </ tr >
186199
200+ < tr >
201+ < td >
202+ < pre > < code > // bar_menu.6.manhattan_garnish.txt
203+ {% include examples/bar_menu.6.manhattan_garnish.txt %}</ code > </ pre >
204+ </ td >
205+ </ tr >
206+
207+ < tr >
208+ < td >
187209< pre > < code > {% include examples/bar_menu.6.jsonnet %}</ code > </ pre >
210+ </ td >
211+ </ tr >
212+
213+ < tr > < td > < span class ="TableHeader "> Output (JSON)</ span > </ td > </ tr >
214+ < tr >
215+ < td >
216+ < pre > < code > {% include examples/bar_menu.6.jsonnet.golden %}</ code > </ pre >
217+ </ td >
218+ </ tr >
219+ </ table >
188220
189221< p > By convention, Jsonnet code that is intended only for importing has a < tt > .libsonnet</ tt >
190222extension. This is not enforced, it simply allows you to distinguish between the two kinds of files
0 commit comments