Code Monkey home page Code Monkey logo

baked_file_system_mounter's Introduction

baked_file_system_mounter

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:

  1. Assemble those assets file into binary when build.

  2. 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>

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      baked_file_system_mounter:
        github: crystal-china/baked_file_system_mounter
  2. Run shards install

Usage

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

Development

TODO: Write development instructions here

Contributing

  1. Fork it (https://github.com/crystal-china/baked_file_system_mounter/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

baked_file_system_mounter's People

Contributors

zw963 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.