ActiveView helper to generate Bootstrap buttons and dropdown-buttons.
Add this line to your application's Gemfile:
gem 'buttons_for'
And then execute:
$ bundle
Or install it yourself as:
$ gem install buttons_for
Run generator to add I18n locales:
$ rails generate buttons_for:install
The gem depends on Bootstrap 3 to create buttons and dropdown-buttons. Bring bootstrap into your project by using Bootstrap for Sass or you preferred method.
buttons_for
depends on Font Awesome icon and CSS
framework, bring Font Awesome into your project using
font-awesome-rails or your preferred method.
buttons_for
has multiple helper methods. The API is intentionally made
quite simple and does not support url generation or any advanced
functionallity. It's just ment as a thin wrapper around link_to
and
should pass the options transparently.
The helpers you'll use the most provide buttons with a color and a
leading icon. The following standard buttons can be used: new
, edit
,
delete
and export
. These buttons are just wrappers around the button
helper
giving it options containing icon and button class.
buttons_for
also provides a helper for creating dropdown buttons. Use
dropdown
with a block containing link
elements to achive this.
Example show button menu:
<%= buttons_for do |b| %>
<%= b.dropdown :actions do %>
<%= b.link "Projects", company_projects_path(@company), icon: "list" %>
<% end %>
<%= b.button t(".lock"), lock_company_path(@company), icon: "lock", class: "btn-default" %>
<%= b.edit edit_company_path(@company) %>
<%= b.delete company_path(@company) %>
<% end %>
</div>
Example index button menu:
<%= buttons_for do |b| %>
<%= b.new url_for(action: :new) %>
<%= b.export url_for(format: :csv) %>
<% end %>
Available options:
- :label - Override standard label.
- :class - Appendse given string to existing CSS classes.
- :icon - Prefix or replace exsiting icon.
The installer copies the file buttons_for.en.yml
into your
config/locales/
directory. Add a corresponding file with your own
locale to translate the buttons.
Sample applicaiton using buttons_for
can be found here.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake rspec
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 tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/blacktangent/buttons_for. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
To test against all supported Rails versions, run:
appraisal rake test
To update all supported Rails to latest patch version:
appraisal update
The gem is available as open source under the terms of the MIT License.