Coder Social home page Coder Social logo

handy_generators's Introduction

HandyGenerators

This gem adds some handy generators to your Rails app.

Installation

Add this line to your application's Gemfile:

gem 'handy_generators'

And then execute:

$ bundle

Usage

After you add the gem to your Gemfile and run bundle, you'll have access to the following generators.

Edit Links Helper

Generators

rails generate handy_generators:edit_links_helper

This generator will add a helper and a partial for displaying edit and delete links for a record. This uses pundit by default to check whether a user should be able to edit and/or delete the record before displaying the link. If you'd like to always display these links when you use the helper in the view or handle the logic yourself, simply add --pundit false to your command.

rails generate handy_generators:edit_links_helper --pundit false

Running this generator will add the following helpers to your Rails app.

Helpers

edit_links(record:, edit_classes: '', delete_classes: '')

The edit_links helper receives three parameters record, edit_classes, and delete_classes. Record is the only required parameter, edit_classes and delete_classes will be empty by default, if you'd like to add classes you can pass them as parameters to the helper. The default helper uses pundit, and it will check if the logged in user has permission to edit or delete the record before displaying the links. If not, it will display the edit or delete links to all users.

edit_record_link(record:, classes: '')

The edit_record_link helper will just display an edit link, it won't check if the user has permission before displaying the link. Classes that you pass in as a parameter will be applied to the link.

delete_record_link(record:, classes: '')

The delete_record_link helper will display just display a delete link, with a confirm. It also doesn't check if the user has permission before displaying the link. Classes that you pass in as a parameter will be applied to the link.

Development

After checking out the repo, run bin/setup to install dependencies. 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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com//handy_generators. 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.

License

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

Code of Conduct

Everyone interacting in the HandyGenerators project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com//handy_generators/blob/master/CODE_OF_CONDUCT.md).

handy_generators's People

Contributors

dakotalmartinez avatar

Stargazers

Yao avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.