Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kombu

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kombu

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Kombu

Kombu provides the ability to render the specified component directly from the controller.

This gem may replace any javascript component except layouts in the views directory.

This gem was inspired by the following projects.

  • React-Rails
  • Inertia.js Rails Adapter

Usage

Setup

Please configure the following settings according to your application.

Rails.application.configure do
  # NOTE: (OPTIONAL) id of the element (div) to mount (default: `vue-root`)
  # config.kombu.default_mount_element_id = 'vue-root'

  # NOTE: (REQUIIRED) Specify a proc that generates a tag that reads a javascript entry.
  # See `lib/kombu/renderable.rb` for instance variables provided by kombu that can be used within proc.
  config.kombu.javascript_entry_tag_proc = -> { helpers.javascript_pack_tag(@entry, defer: true) }

  # NOTE: (REQUIIRED) Specify a proc that generates a tag that reads a css entry.
  # See `lib/kombu/renderable.rb` for instance variables provided by kombu that can be used within proc.
  config.kombu.stylesheet_entry_tag_proc = -> { helpers.stylesheet_pack_tag(@entry) }

  # NOTE: (OPTIONAL) template of the view to render that contains the component. (default: See below)
  # config.kombu.default_entry_view_template = <<~ERB
  #   <div id="<%= @kombu_mount_element_id %>">
  #     <%= kombu_component_tag %>
  #   </div>
  #   <% content_for :stylesheet do %>
  #     <%= kombu_stylesheet_entry_tag %>
  #   <% end %>
  #   <% content_for :javascript do %>
  #     <%= kombu_javascript_entry_tag %>
  #   <% end %>
  # ERB
end

Use Kombu::Renderable

If you include Kombu::Renderable in any controller, you can use kombu_render_component which can render component directly.

class ArticlesController < ApplicationController
  include Kombu::Renderable

  def index
    @title = 'Articles'
    @articles = [{ id: 1, title: 'artile1', body: 'body1' }, { id: 2, title: 'artile2', body: 'body2' }]
    kombu_render_component('article-index-page', attributes: { 'title': @title, ':articles': @articles.to_json })
    # NOTE: The following html is rendered.
    # <div id="vue-root"><artile-index-page title="Articles" :articles="[{"id":1,"title":"artile1","body":"body1"},{"id":2,"title":"artile2","body":"body2"}]"></div>
</artile-index-page>
  end
end

(Optional) Rename method name.

If you do not like the method name, you can change it to any name you like.

module ComponentRenderable
  extend ActiveSupport::Concern
  include Kombu::Renderable

  included do
    alias render_component kombu_render_component
  end
end
class ArticlesController < ApplicationController
  include ComponentRenderable

  def index
    @title = 'Articles'
    @articles = [{ id: 1, title: 'artile1', body: 'body1' }, { id: 2, title: 'artile2', body: 'body2' }]
    render_component('article-index-page', attributes: { 'title': @title, ':articles': @articles.to_json })
  end
end

Testing (RSpec only)

Kombu provides a matcher to validate values passed to kombu_render_component. You can use kombu_component_rendered by enabling it in RSpec.configure.

require 'kombu/test/rspec/matchers/component_renderd_matcher'

RSpec.configure do |config|
  config.include Kombu::RSpec::Matchers::ComponentRenderedMatcher, type: :request
end
describe 'GET /articles', type: :request do
  before { get articles_path }

  it 'Specific arguments must be passed to render_component.' do
    title = 'Articles'
    articles = [{ id: 1, title: 'artile1', body: 'body1' }, { id: 2, title: 'artile2', body: 'body2' }]
    expect(controller).to kombu_component_rendered('article-index-page', attributes: { 'title': title, ':articles': articles.to_json })
  end
end

How do it work

See lib/kombu/renderable.rb.

Installation

Add this line to your application's Gemfile:

gem "kombu"

And then execute:

$ bundle install

Or install it yourself as:

$ gem install kombu

Contributing

Contribution directions go here.

License

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

FAQs

Package last updated on 25 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc