
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.
@hammerstone/refine-stimulus
Advanced tools
Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.
source "https://yourKey@gem.fury.io/hammerstonedev" do
gem "refine-rails"
end
$ yarn add @hammerstone/refine-stimulus
bundle
yarn
In the controller you'd like to filter on, add the apply_filter
method. For this example we'll use Contacts.
@refine_filter = apply_filter(ContactsFilter)
Create a app/filters/contacts_filter.rb
with the following:
class ContactsFilter < Hammerstone::Refine::Filter
@@default_stabilizer = Hammerstone::Refine::Stabilizers::UrlEncodedStabilizer
def initial_query
Contact.all
end
def automatically_stabilize?
true
end
def table
Contact.arel_table
end
def conditions
[
Hammerstone::Refine::Conditions::TextCondition.new("first_name"),
Hammerstone::Refine::Conditions::DateCondition.new("created_at"),
Hammerstone::Refine::Conditions::DateCondition.new("updated_at"),
]
end
end
In your application controller, include Hammerstone::FilterApplicationController
Render the filter partial wherever you want!
<div class="flex flex-col">
<%# Include the this line if you'd like to dump the sql for testing %>
<%#= @refine_filter&.get_query&.to_sql %>
<%= render partial: 'hammerstone/filter_builder_dropdown' %>
</div>
Set the filter stabilized ENV var or credential. If using rails credentials:
EDITOR="subl --wait" bin/rails credentials:edit --environment development
and set NAMESPACE_REFINE_STABILIZERS: 1
If using .env, application.yml or another gem set NAMESPACE_REFINE_STABILIZERS=1
Import the Stimulus Controllers.
Add jquery
yarn add jquery
import jquery from 'jquery'
window.jQuery = jquery
window.$ = jquery
Short description and motivation.
Add this line to your application's Gemfile:
gem "refine-rails"
And then execute:
$ bundle
Or install it yourself as:
$ gem install refine-rails
Installing the JavaScript package:
$ yarn add @hammerstone/refine-stimulus
Also, make sure that your project uses jquery
and binds it as window.$
. Required for catching events dispatched by select2
dropdowns.
Also note that there's currently a bug with esbuild and stimulus 3.0 compatibility.
Where you normally import your Stimulus controllers, add the following lines:
// import { Application } from "stimulus"
import { controllerDefinitions as refineControllers } from "@hammerstone/refine-stimulus"
// window.Stimulus = Application.start()
Stimulus.load(refineControllers)
If loading in Bullet Train,the load command is
application.load(refineControllers)
To manually register (or extend or provide your own replacement for) each Stimulus controller:
// import { Application } from "stimulus"
import {
AddController,
DefaultsController,
DeleteController,
FormController,
StateController,
StoredFilterController,
UpdateController
} from "@hammerstone/refine-stimulus"
// window.Stimulus = Application.start()
Stimulus.register('refine--add', AddController)
Stimulus.register('refine--defaults', DefaultsController)
Stimulus.register('refine--delete', DeleteController)
Stimulus.register('refine--form', FormController)
Stimulus.register('refine--state', StateController)
Stimulus.register('refine--stored-filter', StoredFilterController)
Stimulus.register('refine--update', UpdateController)
From this repo's directory:
We are using yalc
for local package development.
# Add yalc if you don't have it
# From this repo (refine-rails)
yarn global add yalc
# install dependencies
$ yarn
$ yalc publish
From the directory of the project including this package:
yalc add @hammerstone/refine-stimulus
When you make local updates to the package:
# From this repo (refine-rails)
yarn
yalc push
Running yarn
again from your project's directory will revert back to the published version of the package on npm.
yarn build
. This will prepare the different javascript outputsyarn pack
. This will create a new .tgz
file for the new versionyarn publish <tgz filename> --new-version <version number in package.json>
*.tgz
fileAdd ruby gem
source "https://yourAPIKey@gem.fury.io/hammerstonedev" do
gem "refine-rails"
end
Installing the JavaScript package:
$ yarn add @hammerstone/refine-stimulus
In app/javascript/controllers/index.js
add
import { controllerDefinitions as refineControllers } from "@hammerstone/refine-stimulus"
application.load(refineControllers)
ApplicationFilter
class and if we want to ship with an option of sending in initial querystored_filter.rb
(only if using stored filters - best way for users?)2.1.0 2022-08-02
FAQs
Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.
The npm package @hammerstone/refine-stimulus receives a total of 8 weekly downloads. As such, @hammerstone/refine-stimulus popularity was classified as not popular.
We found that @hammerstone/refine-stimulus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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.