{"id":15033149,"url":"https://github.com/mfinelli/bankrupt","last_synced_at":"2026-03-15T08:13:34.265Z","repository":{"id":62553966,"uuid":"142278897","full_name":"mfinelli/bankrupt","owner":"mfinelli","description":"A sinatra helper for assets in development and production","archived":false,"fork":false,"pushed_at":"2021-08-21T16:56:00.000Z","size":129,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-21T13:40:15.755Z","etag":null,"topics":["assets","ruby","rubygem","sinatra"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/bankrupt","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mfinelli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-25T09:34:05.000Z","updated_at":"2021-08-25T19:35:12.000Z","dependencies_parsed_at":"2022-11-03T05:00:20.815Z","dependency_job_id":null,"html_url":"https://github.com/mfinelli/bankrupt","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfinelli%2Fbankrupt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfinelli%2Fbankrupt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfinelli%2Fbankrupt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfinelli%2Fbankrupt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfinelli","download_url":"https://codeload.github.com/mfinelli/bankrupt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243351841,"owners_count":20276908,"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":["assets","ruby","rubygem","sinatra"],"created_at":"2024-09-24T20:20:14.121Z","updated_at":"2025-12-26T08:04:00.803Z","avatar_url":"https://github.com/mfinelli.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bankrupt\n\n[![RubyGems](https://img.shields.io/gem/v/bankrupt.svg)](https://rubygems.org/gems/bankrupt)\n![Build Status](https://github.com/mfinelli/bankrupt/workflows/CI/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/mfinelli/bankrupt/badge.svg?branch=master)](https://coveralls.io/github/mfinelli/bankrupt?branch=master)\n[![Maintainability](https://api.codeclimate.com/v1/badges/f13a4521623d19c8eb4a/maintainability)](https://codeclimate.com/github/mfinelli/bankrupt/maintainability)\n[![Inline docs](http://inch-ci.org/github/mfinelli/bankrupt.svg?branch=master)](http://inch-ci.org/github/mfinelli/bankrupt)\n\nA [sinatra](http://sinatrarb.com) helper to path assets during development and\nproduction.\n\n## Usage\n\n### Sinatra\n\nBefore loading your app set a few constants:\n\n```ruby\nCDN = CONFIG[:cdn_url].to_s.freeze\n\nrequire 'bankrupt/util'\nASSETS = Bankrupt::Util.parse_manifest(\n  File.join(APP_ROOT, 'tmp', 'assets.json')\n).freeze\n```\n\nThen include bankrupt as a helper in your app:\n\n```ruby\nrequire 'bankrupt'\n\nclass App \u003c Sinatra::Base\n  set :public_folder, File.join(APP_ROOT, 'public')\n\n  helpers Bankrupt\n\n  # TODO: there is a better way to do this\n  def initialize\n    @_assets = {}\n    super\n  end\nend\n```\n\nNow, in your views you can use the helper methods:\n\n```slim\n== stylesheet('app.css')\n```\n\nIn development mode it will load app.css from your local public directory but\nin production it will load the CDN URL and include integrity hashes and\nanonymous crossorigin attributes.\n\nThere's also a helper for `script` tags:\n\n```slim\n== javascript('app.js')\n```\n\nFor images you can optionally pass a hash of options to apply additional\nattributes to the image:\n\n```slim\n== image('img.jpg', alt: 'img')\n```\n\nTo get the full path of an asset:\n\n```slim\na href=raw('file.pdf')\n  | Click me!\n```\n\n### Rake\n\nYou can use the bundled rake task to generate the manifest file in the correct\nformat using any assets found in the `public` folder. You can also upload the\nassets to an s3 bucket for use with cloudfront as a CDN.\n\nMake sure to add the extra dependencies to your gemfile:\n\n```ruby\ngem 'aws-sdk-s3'\ngem 'mini_mime'\n```\n\nIn your rakefile you'll need to define several constants and then include\nthe tasks:\n\n```ruby\nrequire 'bankrupt/tasks'\nrequire 'logger'\n\nAPP_ROOT = __dir__.freeze unless defined?(APP_ROOT)\nCDN_BUCKET = 'your-s3-bucket'.freeze unless defined?(CDN_BUCKET)\nCDN_PREFIX = 'project'.freeze unless defined?(CDN_PREFIX)\n\nunless defined?(VERSION)\n  VERSION = JSON.parse(File.read(File.join(APP_ROOT, 'package.json')),\n                       symbolize_names: true).fetch(:version).freeze\nend\n\nLOG = Logger.new(STDOUT) unless defined?(LOG)\n```\n\nFinally set your default task:\n\n```ruby\ntask default: if ENV['CLOUDBUILD'].to_s.casecmp?('true')\n                %i[bankrupt:cdn]\n              else\n                %i[bankrupt:manifest]\n              end\n```\n\nNote that it's possible to upload some files to the CDN _without_ their hash\nappended. Create a `.bankrupt.yml` file in the root of your project and provide\nan array of file globs to store \"hashless\":\n\n```yaml\n---\nhashless:\n  - \"*.pdf\"\n  - \"image.png\"\n```\n\n### Rspec\n\nIf you're testing your app with rspec or similar you need to stub the `CDN` and\n`ASSETS` constants.\n\n```ruby\nrequire 'rack/test'\n\nRSpec.describe App do\n  include Rack::Test::Methods\n\n  before do\n    stub_const('CDN', '')\n    stub_const('ASSETS', {})\n  end\n\n  let(:app) { described_class }\n\n  describe 'GET /' do\n    before { get '/' }\n\n    it 'returns a 200' do\n      expect(last_response).to be_ok\n    end\n  end\nend\n```\n\n## License\n\n```\nCopyright 2018-2021 Mario Finelli\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfinelli%2Fbankrupt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfinelli%2Fbankrupt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfinelli%2Fbankrupt/lists"}