Code Monkey home page Code Monkey logo

turbo-ruby's Introduction

Turbo::Ruby

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add turbo-ruby

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install turbo-ruby

Note: Usage in Rails

In order to use turbo-ruby in Rails with the Rails render method you have to install the phlex-rails gem in your app.

Regular Element

# Ruby
Turbo::Elements::TurboStream.new(action: "console_log", message: "Hello World").to_html
<!-- Rails -->
<%= render Turbo::Elements::TurboStream.new(action: "console_log", message: "Hello World") %>

Blocks

# Ruby
Turbo::Elements::TurboStream.new(action: "morph", target: "post_1") do
  %(<div id="post_id">
      <h1>Post 1</h1>
    </div>)
end.to_html
<!-- Rails -->
<%= render Turbo::Elements::TurboStream.new(action: "morph", target: "post_1") do %>
  <div id="post_id">
    <h1>Post 1</h1>
  </div>
<% end %>

Partials (Rails only)

<!-- Rails -->
<%= render Turbo::Elements::TurboStream.new(action: "morph", target: "post_1", view_context: self, partial: "posts/post", locals: { post: @post } %>

Development

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

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

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/turbo-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Turbo::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

turbo-ruby's People

Contributors

marcoroth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

turbo-ruby's Issues

Introduce a `StreamsBuilder` class

Something like:

Turbo::StreamsBuilder.render do |turbo_stream|
  turbo_stream.append(...)
  turbo_stream.console_log(...)
  turbo_stream.morph(...)
end

Which would return one string like:

<turbo-stream action="append" ...>...</turbo-stream>
<turbo-stream action="console_log" ...>...</turbo-stream>
<turbo-stream action="morph" ...>...</turbo-stream>

or inside a model:

class Post < ApplicationRecord
  broadcast_turbo_stream_actions do |turbo_stream|
    turbo_stream.append(...)
    turbo_stream.console_log(...)
    turbo_stream.morph(...)
  end
end

Extract `**rendering` attributes in `Turbo::Elements::TurboStream`

Currently a Turbo::Elements::TurboStream element takes arbitrary attributes which get rendered on the element via the attributes keyword. The **rendering splat is used for taking in arguments for rendering partials.

Ideally the splat can be used for arbitrary attributes which get rendered on the element. We could extract the attributes needed for rendering out of the splat or we explicitly define the required attributes for rendering as keyword arguments.

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.