{"id":21040139,"url":"https://github.com/robacarp/asset_manager","last_synced_at":"2026-02-22T12:35:21.039Z","repository":{"id":263073071,"uuid":"889262506","full_name":"robacarp/asset_manager","owner":"robacarp","description":"A modular tool for rendering front-end assets in a cache-able way for backend crystal servers. Import Maps and a little more.","archived":false,"fork":false,"pushed_at":"2024-11-16T00:20:52.000Z","size":9,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T20:51:25.798Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robacarp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-15T23:44:09.000Z","updated_at":"2025-01-10T03:52:20.000Z","dependencies_parsed_at":"2024-11-16T04:47:45.638Z","dependency_job_id":null,"html_url":"https://github.com/robacarp/asset_manager","commit_stats":null,"previous_names":["robacarp/asset_manager"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robacarp%2Fasset_manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robacarp%2Fasset_manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robacarp%2Fasset_manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robacarp%2Fasset_manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robacarp","download_url":"https://codeload.github.com/robacarp/asset_manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251354442,"owners_count":21576198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T13:44:56.680Z","updated_at":"2026-02-22T12:35:16.003Z","avatar_url":"https://github.com/robacarp.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# asset_manager\n\nAsset Manager is a Crystal shard that helps you manage and deliver front-end assets in a Crystal web application.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n asset_manager:\n   github: robacarp/asset_manager\n```\n\n2. Run `shards install`\n\n## Getting started\n\nAsset manager needs to be configured before it can be used. Here is an example configuration:\n\n```crystal\nrequire \"asset_manager\"\n\nAssetManager.configure do |c|\n  # The path to the directory containing your source files\n  c.source_path = Path.new(\"src/\")\n\n  # The path to the directory where you want the hashed files to be written\n  c.output_path = Path.new(\"public/assets/\")\n\n  # The path prefix which is rendered by html helpers\n  c.rendered_path = Path.new(\"/assets\")\nend\n```\n\nOnce you have configured asset manager, you can use the `AssetManager::HTMLHelpers` module in your views to render links to assets:\n\n```erb\n\u003c%= stylesheet_tag_for \"stylesheets/app.css\" %\u003e\n\u003c%= script_tag_for \"javascript/analytics.js\", module: true %\u003e\n\u003c%= script_tag_for \"javascript/index.js\", module: true %\u003e\n```\n\nEach of these will render a link to the hashed file, which will be created in the output path, with a name like: `stylesheets/builds/tailwind-averyveryveryveryveryveryVERYlonghashstring.css`.\n\n## Rendering an import map\n\nAn [Import Map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) is a way of tersely specifying the dependencies in a javascript project without using URLs in the JS `import` statement. This technology is [widely available in modern browsers](https://caniuse.com/import-maps) and makes it substantially easier to manage a javascript-heavy web application.\n\nTo build an import map, AssetManager provides an ImportMap class:\n\n```crystal\n# local paths are relative to Config.source_path\nAssetManager::ImportMap.build do\n  # Subfolder of source_path where javascript files are located.\n  javascript_path_prefix \"javascript\"\n\n  # Add remote dependencies to the map. These can be imported into javascript now like this: `import posthog from \"posthog-js\"`\n  remote \"posthog-js\", path: \"https://cdn.jsdelivr.net/npm/posthog-js@1.126.0/+esm\"\n  remote \"stimulus\", path: \"https://cdn.jsdelivr.net/npm/stimulus@3.2.2/+esm\"\n\n  # Add local depencies to the map:\n  # Don't put the javascript path prefix in the path, it's assumed.\n  local \"application\", path: \"application.js\"\n\n  # import checkout from \"checkout.js\"\n  # preload: false means the browser will wait for an `import` statement to load this file.\n  local \"checkout\", path: \"checkout.js\", preload: false\n\n  # Add an entire tree of files to the map.\n  # For a file at:\n  #  - src/javascript/controllers/checkout.js\n  # It will be checksummed and copied to the output path:\n  #  - public/assets/controllers/checkout-11234abcdefghi.js\n  # this will add an entry so that it can be imported like this:\n  #  - import checkout from \"controllers/checkout\"\n  glob \"controllers/**/*.js\"\nend\n```\n\nThen you can render the import map in your layout:\n\n```erb\n\u003c%= render_javascript_import_map %\u003e\n```\n\nThis will render:\n\n- `\u003cscript type=\"importmap\"\u003e` tag with the import map JSON\n- a `\u003clink rel=\"modulepreload\" href=\"...\"\u003e` tag for each mapped file with `preload: true`\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobacarp%2Fasset_manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobacarp%2Fasset_manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobacarp%2Fasset_manager/lists"}