Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Vident is a collection of gems that help you create flexible & maintainable component libraries for your Rails application.
Vident also provides a neat Ruby DSL to make wiring up Stimulus easier & less error prone in your view components.
ViewComponent
and Phlex
supported.
I love working with Stimulus, but I find manually crafting the data attributes for targets and actions error-prone and tedious. Vident aims to make this process easier and keep me thinking in Ruby.
Vident has been used with ViewComponent
and Phlex
in production apps for a while now
but is still evolving.
I would love to get your feedback and contributions!
The Greeter ViewComponent (that uses Vident):
Consider a component, the GreeterComponent
:
# app/components/greeter_component.rb
class GreeterComponent < ::Vident::ViewComponent::Base
renders_one :trigger, ButtonComponent
end
with ERB as follows:
<%# app/components/greeter_component.html.erb %>
<%# Rendering the `root` element creates a tag which has stimulus `data-*`s, a unique id & other attributes set. %>
<%# The stimulus controller name (identifier) is derived from the component name, and then used to generate the relavent data attribute names. %>
<%= render root named_classes: {
pre_click: "text-md text-gray-500", # named classes are exposed to Stimulus as `data-<controller>-<name>-class` attributes
post_click: "text-xl text-blue-700",
html_options: {class: "py-2"}
} do |greeter| %>
<%# `greeter` is the root element and exposes methods to generate stimulus targets and actions %>
<input type="text"
<%= greeter.as_target(:name) %>
class="shadow appearance-none border rounded py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<%# Render the slot %>
<%= trigger %>
<%# you can also use the `target_tag` helper to render targets %>
<%= greeter.target_tag(
:span,
:output,
# Stimulus named classes can be referenced to set class attributes at render time
class: "ml-4 #{greeter.named_classes(:pre_click)}"
) do %>
...
<% end %>
<% end %>
Now, imagine we render it in a view, and render a ButtonComponent
in the trigger
slot:
<%= render ::GreeterComponent.new(cta: "Hey!", html_options: {class: "my-4"}) do |greeter| %>
<%# this component has a slot called `trigger` that renders a `ButtonComponent` (which also uses Vident) %>
<% greeter.with_trigger(
# The button component has attributes that are typed
before_clicked: "Greet",
after_clicked: "Greeted! Reset?",
# A stimulus action is added to the button that triggers the `greet` action on the greeter stimulus controller.
# This action will be added to any defined on the button component itself
actions: [
greeter.action(:click, :greet),
],
# We can also override the default button classes of our component, or set other HTML attributes
html_options: {
class: "bg-red-500 hover:bg-red-700"
}
) %>
<% end %>
The output HTML of the above, using Vident, is:
<div class="greeter-component py-2 my-4"
data-controller="greeter-component"
data-greeter-component-pre-click-class="text-md text-gray-500"
data-greeter-component-post-click-class="text-xl text-blue-700"
id="greeter-component-1599855-6">
<input type="text"
data-greeter-component-target="name"
class="shadow appearance-none border rounded py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
<button class="button-component ml-4 whitespace-no-wrap bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded bg-red-500 hover:bg-red-700"
data-controller="button-component"
data-action="click->greeter-component#greet button-component#changeMessage"
data-button-component-after-clicked-message="Greeted! Reset?"
data-button-component-before-clicked-message="Greet"
id="button-component-7799479-7">Hey!</button>
<!-- you can also use the `target_tag` helper to render targets -->
<span class="ml-4 text-md text-gray-500"
data-greeter-component-target="output">
...
</span>
</div>
To see this example in more detail, see the vident-typed-view_component test dummy app.
The core gems are:
vident
to get the base functionalityvident-typed
to optionally define typed attributes for your view componentsGems that provide support for ViewComponent
and Phlex
:
vident-view_component
for using with ViewComponent
and untyped attributesvident-typed-view_component
for using with ViewComponent
and typed attributesvident-phlex
for using with Phlex
and untyped attributesvident-typed-phlex
for using with Phlex
and typed attributesThere is also:
vident-typed-minitest
to get some test helpers for typed attributes (auto generates inputs to test attributes)vident-better_html
to support better_html
if you use it in your Rails appvident-tailwind
to get all the benefits of the amazing tailwind_merge
.This is a work in progress. Here's what's left to do for first release:
lookbook
and those componentsBase classes for your ViewComponent
components or Phlex
components that provides a helper to create the
all important 'root' element component (can be used with templated or template-less components).
implementations of these root components for creating the 'root' element in your view components. Similar to Primer::BaseComponent
but
exposes a simple API for configuring and adding Stimulus controllers, targets and actions. The root component also handles deduplication
of classes, creating a unique ID, setting the element tag type, handling possible overrides set at the render site, and determining stimulus controller identifiers etc
a way to define attributes for your components, either typed or untyped, with default values and optional validation.
Such as...
#cache_key
method that can be used to generate a cache key for
fragment caching or etag generation.ViewComponent
or Phlex
or your own view component systemattribute
method which allows you to define default values, (optionally) types and
if blank or nil values should be allowed.Vident::Caching
and Vident::<ViewComponent | Phlex>::Caching
... implementation has caveats)better_html
This gem (vident
) provides only base functionality but there are a number of gems that provide additional functionality
or an "out of the box" experience.
It's a "pick your own adventure" approach. You decide what frameworks and features you want to use and add the gems as needed.
First, add this line to your application's Gemfile:
gem 'vident'
Then go on to choose the gems you want to use:
ViewComponent
or Phlex
for your view components?For ViewComponent use:
For Phlex use:
Note: you can also use both in the same app.
For example, if you want to use ViewComponent and Phlex in the same app, you might end up with:
gem 'vident'
gem 'vident-view_component'
gem 'vident-phlex'
dry-types
)?If yes, then add vident-typed
to your Gemfile:
gem 'vident-typed'
and then use the relavent *-typed-*
gems for your chosen view component system:
Note you must also include the gem for the view component system you are using.
For example, for ViewComponent, you might end up with:
gem 'vident'
gem 'vident-view_component'
gem 'vident-typed'
gem 'vident-typed-view_component'
If yes, then include vident-better_html
in your Gemfile alongside better_html
and your vident gems of choice.
...
gem 'better_html'
gem 'vident-better_html'
Note that vident-better_html
automatically enables better_html
support in Vident root components.
If yes, then consider adding vident-tailwind
to your Gemfile alongside your vident gems of choice.
...
gem 'vident-tailwind'
When creating your components you can then include Vident::Tailwind
to get all the benefits of the amazing tailwind_merge
.
You can always just use base vident
gems and then roll your own solutions:
vident
to get the base functionality to mix with your own view component systemvident-typed
to define typed attributes for your own view component systemSee the docs directory and visit the individual gem pages for more information.
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/stevegeek/vident. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Vident project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that vident demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.