8c2dc5c7cb161383e280817fa7fe52f02afb493b
[nit.git] / lib / app / assets.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Portable services to load resources from the assets folder
16 module assets
17
18 # Resource from the assets folder
19 #
20 # At compilation, the asset folder should be at the root of the package.
21 # In practice, this is usually next to the folders `src` and `bin`.
22 #
23 # These assets are packaged with the application.
24 abstract class Asset
25
26 # Path to this asset within the assets folder
27 var path: String
28 end
29
30 # Text file from the assets folder
31 #
32 # Use `to_s` to get the content of this asset.
33 class TextAsset
34 super Asset
35
36 # Text content of this asset
37 redef var to_s = load is lazy
38
39 # Load this asset
40 fun load: String is abstract
41
42 # Error on the last call to `load`, if any
43 var error: nullable Error = null
44 end