
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Simple library for building view components in Ruby on Rails.
Declare a component by name, and define its sections and attributes:
# app/helpers/components_helper.rb
define_component :card, sections: [:body, :footer], attributes: [:title]
Define its structure using a partial view:
# app/views/components/_card.html.haml
.card
%h1= card[:title]
.content
= card[:body]
.footer
= card[:footer]
Use it in your views:
-# app/views/welcome/index.html.haml
= card title: 'A value' do |c|
- c.body do
A block of HAML
= link_to 'My page', my_page_path
- c.footer do
%span Another block of HAML
Add view_components
to your Gemfile:
source 'https://rubygems.org'
gem 'view_components'
Each component is defined by its structure, sections and attributes. To register a component, first invoke define_component
in a view helper, such as components_helper
:
# app/helpers/components_helper.rb
define_component :card, sections: [:body, :footer], attributes: [:title]
The name of the component must be a valid identifier, as well as the sections and the attributes. This gem will then look for a partial view with defined name in the components
views folder; app/views/components/_card.html.haml
in the example.
The partial view will receive a hash as a local variable with the same name as the view (again, card
), which will contain both the values of the attributes and sections.
define_component
will also define a method for your views with the specified name, that can be used as a builder for the component. The content of each block will be captured and inserted in the specified location in the partial view.
Next in the roadmap is adding support for collections, which should act as sections that are inserted multiple times in the component.
FAQs
Unknown package
We found that view_components demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.