{"id":31667865,"url":"https://github.com/andrew/hanami-sprockets","last_synced_at":"2025-10-08T00:48:45.903Z","repository":{"id":317197465,"uuid":"1066368617","full_name":"andrew/hanami-sprockets","owner":"andrew","description":"An alternative to hanami-assets that doesn't rely on npm","archived":false,"fork":false,"pushed_at":"2025-10-01T08:19:13.000Z","size":44,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-07T01:26:35.237Z","etag":null,"topics":["assets","hanami","ruby","sprockets"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/hanami-sprockets","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrew.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"andrew","ko_fi":"andrewnez","buy_me_a_coffee":"andrewnez"}},"created_at":"2025-09-29T11:45:57.000Z","updated_at":"2025-10-01T08:19:12.000Z","dependencies_parsed_at":"2025-10-07T01:23:53.591Z","dependency_job_id":null,"html_url":"https://github.com/andrew/hanami-sprockets","commit_stats":null,"previous_names":["andrew/hanami-sprockets"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/andrew/hanami-sprockets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrew%2Fhanami-sprockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrew%2Fhanami-sprockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrew%2Fhanami-sprockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrew%2Fhanami-sprockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrew","download_url":"https://codeload.github.com/andrew/hanami-sprockets/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrew%2Fhanami-sprockets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278717008,"owners_count":26033535,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["assets","hanami","ruby","sprockets"],"created_at":"2025-10-08T00:48:44.850Z","updated_at":"2025-10-08T00:48:45.898Z","avatar_url":"https://github.com/andrew.png","language":"Ruby","funding_links":["https://github.com/sponsors/andrew","https://ko-fi.com/andrewnez","https://buymeacoffee.com/andrewnez"],"categories":[],"sub_categories":[],"readme":"# Hanami::Sprockets\n\n[![Gem Version](https://badge.fury.io/rb/hanami-sprockets.svg)](https://badge.fury.io/rb/hanami-sprockets)\n\nDrop-in replacement for hanami-assets that uses Sprockets (like Rails) instead of npm/Node.js.\n\nIf you want the Rails asset pipeline in your Hanami app without dealing with npm, this is for you.\n\n## What you get\n\n- Rails-style Sprockets asset pipeline\n- No npm/package.json required\n- Works with existing Sprockets gems (sassc-rails, coffee-rails, etc.)\n- Same API as hanami-assets\n- Asset fingerprinting and precompilation\n- Development middleware for serving assets\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'hanami-sprockets'\n```\n\nAnd then execute:\n\n```bash\nbundle install\n```\n\n## Basic Usage\n\n### Configuration\n\n```ruby\nrequire 'hanami-sprockets'\n\n# Basic configuration\nconfig = Hanami::Assets::Config.new(\n  path_prefix: \"/assets\",\n  digest: true,  # Enable fingerprinting for production\n  subresource_integrity: [:sha256]  # Enable SRI\n)\n\n# Create assets instance\nassets = Hanami::Assets.new(\n  config: config,\n  root: \"/path/to/your/app\"\n)\n```\n\n### Asset Structure\n\nFollow Rails conventions:\n\n```text\napp/\n├── assets/\n│   ├── stylesheets/\n│   │   └── app.css\n│   ├── javascripts/\n│   │   └── app.js\n│   └── images/\n│       └── logo.png\n├── lib/\n│   └── assets/\n└── vendor/\n    └── assets/\n```\n\n### CSS Image References\n\nReference images in CSS using ERB and the `asset_path` helper:\n\n```css\n/* app.css.erb */\n.header {\n  background-image: url('\u003c%= asset_path(\"logo.png\") %\u003e');\n}\n```\n\nThis generates fingerprinted URLs automatically in production. Plain CSS with relative paths also works:\n\n```css\n/* Plain CSS */\n.simple {\n  background-image: url('../images/logo.png');\n}\n```\n\n### Development Server\n\nAdd the middleware to your Rack stack:\n\n```ruby\nuse Hanami::Assets::Middleware, assets\n```\n\n### Using Assets\n\n```ruby\n# Get an asset\nasset = assets[\"app.css\"]\nputs asset.url  # =\u003e \"/assets/app-abc123def.css\"\nputs asset.path # =\u003e \"/assets/app-abc123def.css\"\nputs asset.sri  # =\u003e \"sha256-...\"\n\n# Check if asset exists\nbegin\n  asset = assets[\"missing.css\"]\nrescue Hanami::Assets::AssetMissingError\n  puts \"Asset not found\"\nend\n```\n\n### Template Helpers\n\nInclude the helpers in your templates:\n\n```ruby\nclass MyView\n  include Hanami::Assets::Helpers\n\n  private\n\n  def hanami_assets\n    @hanami_assets # Inject your assets instance\n  end\nend\n```\n\nThen use them in templates:\n\n```erb\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003c%= stylesheet_tag \"reset\", \"app\" %\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003c%= image_tag \"logo\", alt: \"Logo\" %\u003e\n  \u003c%= javascript_tag \"app\", async: true %\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Precompilation\n\nFor production:\n\n```ruby\n# Precompile assets\nmanifest = assets.precompile(\"/path/to/public/assets\")\nputs \"Compiled assets:\", manifest.assets.keys\n```\n\n### Command Line Interface\n\nThe gem includes CLI commands similar to Hanami's asset commands:\n\n#### Compile Assets\n\nCompile assets for production deployment:\n\n```bash\nbundle exec hanami-sprockets compile\n```\n\nWith custom output directory:\n\n```bash\nbundle exec hanami-sprockets compile -o public/dist\n```\n\n#### Watch Assets\n\nWatch assets for changes during development:\n\n```bash\nbundle exec hanami-sprockets watch\n```\n\nThe watch command monitors your asset directories for changes and automatically recompiles when files are modified. Requires the `listen` gem to be available.\n\n#### CLI Options\n\n```bash\nUsage: hanami-sprockets [COMMAND] [OPTIONS]\n\nCommands:\n  compile    Compile assets for production\n  watch      Watch assets for changes and recompile\n\nOptions:\n  -r, --root ROOT      Application root directory\n  -o, --output OUTPUT  Output directory for compiled assets\n  -h, --help           Show help message\n```\n\n### Integration with Hanami CLI\n\nWhen used within a Hanami application, hanami-sprockets provides command classes that can be automatically discovered by Hanami's CLI system. This allows you to use:\n\n```bash\n# Instead of hanami-sprockets compile\nhanami assets compile\n\n# Instead of hanami-sprockets watch\nhanami assets watch\n```\n\nThese commands integrate seamlessly with Hanami's application structure and automatically discover your app's configuration. The gem provides compatible command classes in the `Hanami::CLI::Commands::App::Assets` namespace that follow Hanami's CLI conventions.\n\n## Advanced Configuration\n\n```ruby\nconfig = Hanami::Assets::Config.new do |config|\n  config.path_prefix = \"/assets\"\n  config.digest = Rails.env.production?\n  config.compress = Rails.env.production?\n  config.subresource_integrity = [:sha256, :sha512]\n  config.base_url = ENV['CDN_URL'] # For CDN support\n  config.asset_paths = [\n    \"vendor/assets/custom\",\n    \"lib/special_assets\"\n  ]\n  config.precompile = %w[\n    app.js\n    app.css\n    *.png\n    *.jpg\n    *.svg\n  ]\nend\n```\n\n## Adding processors\n\nJust add the gems you want:\n\n```ruby\ngem 'sassc-rails'      # SCSS/Sass\ngem 'coffee-rails'     # CoffeeScript\ngem 'uglifier'         # JS compression\n```\n\n## Development vs Production\n\n- **Development**: Assets served on-demand via middleware\n- **Production**: Precompile assets with `assets.precompile(\"/path/to/public/assets\")`\n\n## API Reference\n\n### Hanami::Assets\n\nMain class for asset management.\n\n#### Methods\n\n- `#[](path)` - Find and return an asset\n- `#precompile(target_dir)` - Precompile assets for production\n- `#logical_paths` - Get all available asset paths\n- `#subresource_integrity?` - Check if SRI is enabled\n- `#crossorigin?(url)` - Check if URL is cross-origin\n\n### Hanami::Assets::Asset\n\nRepresents a single asset.\n\n#### Asset Methods\n\n- `#url` - Full URL to asset\n- `#path` - Path to asset (without base URL)\n- `#sri` - Subresource integrity hash\n- `#logical_path` - Original path without fingerprint\n- `#digest_path` - Fingerprinted path\n\n### Hanami::Assets::Helpers\n\nTemplate helpers for generating asset HTML tags.\n\n#### Helper Methods\n\n- `stylesheet_tag(*sources, **options)` - Generate `\u003clink\u003e` tags\n- `javascript_tag(*sources, **options)` - Generate `\u003cscript\u003e` tags\n- `image_tag(source, **options)` - Generate `\u003cimg\u003e` tags\n- `asset_url(source)` - Get URL for asset\n- `asset_path(source)` - Get path for asset\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrew%2Fhanami-sprockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrew%2Fhanami-sprockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrew%2Fhanami-sprockets/lists"}