assemble files inside current directories into executable binary use backed_file_system
at compile time, then mount it on new file system at runtime.
Let us assume there are assets folders like this:
PROJECT_ROOT/
src/assets/
└── materialize
├── css
│ └── materialize.min.css
└── js
└── materialize.min.js
What we want is:
-
Assemble those assets file into binary when build.
-
When copying binary into
/public
directory (on target host), running it will extract assets, like this:
my_app*
public/
└── materialize
├── css
│ └── materialize.min.css
└── js
└── materialize.min.js
3 directories, 2 files
With following configuration.
require "baked_file_system_mounter"
BakedFileSystemMounter.assemble(
{
"src/assets" => "public",
}
)
{% if flag?(:release) %}
BakedFileSystemStorage.mount
{% end %}
Then, use can use those assets both in development(src/assets/materialize) and production(public/materialize), like this:
<html>
<head>
<link rel="stylesheet" href="/materialize/css/materialize.min.css" />
</head>
<body>
<%= yield_content "footer" %>
</body>
</html>
-
Add the dependency to your
shard.yml
:dependencies: baked_file_system_mounter: github: crystal-china/baked_file_system_mounter
-
Run
shards install
You can passing a Hash
as argument for mapping.
require "baked_file_system_mounter"
#
# we assemble all files in `src/assets`,`db` into executable binary when we build,
BakedFileSystemMounter.assemble(
{
"src/assets" => "public",
"db" => "db"
}
)
if APP_ENV == "production"
# we assemble the db into db folder too
# Then mount files in `src/assets` into `public` and files in `db` into `db`.
# folder will be created it if not exists.
BakedFileSystemStorage.mount
end
You can pass a Array as argument too.
BakedFileSystemMounter.assemble(["public", "db"])
# It's same as:
# BakedFileSystemMounter.assemble(
# {
# "public" => "public",
# "db" => "db"
# }
# )
if APP_ENV == "production"
BakedFileSystemStorage.mount
end
It can be used to mount assets outside current directory, e.g. /tmp
BakedFileSystemMounter.assemble(
{
"sounds" => "/tmp/sounds",
}
)
if APP_ENV == "production"
BakedFileSystemStorage.mount
end
TODO: Write development instructions here
- Fork it (https://github.com/crystal-china/baked_file_system_mounter/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Billy.Zheng - creator and maintainer