{"id":20676562,"url":"https://github.com/calebowens/view_component-juice","last_synced_at":"2026-04-20T17:04:01.898Z","repository":{"id":61868506,"uuid":"555939988","full_name":"calebowens/view_component-juice","owner":"calebowens","description":"Adding an Elm inspired turbo interface into view components","archived":false,"fork":false,"pushed_at":"2022-12-20T18:35:42.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T12:05:13.818Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/calebowens.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-22T17:39:42.000Z","updated_at":"2022-12-20T18:07:25.000Z","dependencies_parsed_at":"2023-01-30T01:31:01.282Z","dependency_job_id":null,"html_url":"https://github.com/calebowens/view_component-juice","commit_stats":null,"previous_names":["calebowens/view_compoent-juice"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebowens%2Fview_component-juice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebowens%2Fview_component-juice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebowens%2Fview_component-juice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebowens%2Fview_component-juice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/calebowens","download_url":"https://codeload.github.com/calebowens/view_component-juice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242906417,"owners_count":20204837,"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-16T21:12:59.805Z","updated_at":"2026-04-20T17:04:01.848Z","avatar_url":"https://github.com/calebowens.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ViewComponent::Juice\n\nThe goal of this gem is to enable writing of interactive view components by levereging the power of turbo, removing the need to write JS.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'view_component-juice'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install view_component-juice\n\n## Usage\n\nCurrently a child messaging a parent and a component messaging itself works as expected, but due to the way context is maintained by passing a query parameter a child couldn't message another child. To resolve this, state needs to be stored in a cookie so its more gobally available.\n\nA demonstration component\n```rb\nclass BoardListComponent \u003c ViewComponent::Base\n  # Its got the juice!\n  include ViewComponent::Juice::Juicy\n\n  # We want to list the user's boards so we need to authenticate them.\n  # Juice will try to call a method `current_\u003cname\u003e` like what devise provides\n  # and will then make that available with the same method name\n  AUTHENTICATE = %i[user]\n\n  # Optional, but when you provide it, it will check that all the messages\n  # being sent are one of these\n  MESSAGES = %i[open close]\n\n  # This is called when first instanciated in a view and sets up the initial \n  # component state\n  def setup(board_ids:)\n    @list_open = true\n\n    # For a production application it would be wise to use a scoped id or friendly\n    # ID as context is currently not encrypted in the client browser.\n    context['board_ids'] = board_ids\n  end\n\n  # This is called when the the component is going to be rendered again\n  def update(message)\n    # As setup is only called when its first rendered in the client,\n    # if we didn't set @list_open here, it would be undefined as juice recreates\n    # the component instance.\n    @list_open = message == :open\n  end\n\n  def boards\n    @boards ||= current_user.boards.where(context['board_ids'])\n  end\nend\n```\n\n```haml\n- # frame is provided by the concern and makes the \u003cturbo-frame\u003e tag with a unique ID\n= frame do\n  - if @list_open\n    .board-list\n      - # send_message generates a link to the juice controller which will do an update\n      - # cycle\n      = link_to 'Close', send_message(:close)\n      %p Boards:\n\n      - boards.each do |board|\n        = link_to board.name, board\n\n      %hr\n      = link_to 'Create new Board', new_board_path\n  - else\n    = link_to 'Open', send_message(:open), class: 'board-list__closed-button'\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/calebowens/view_component-juice.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebowens%2Fview_component-juice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalebowens%2Fview_component-juice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebowens%2Fview_component-juice/lists"}