Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i create a gem which will generate a css file from a template

I have a set of css files which I use in almost all projects. I would like to create a gem which has a generator inside it. I managed to write some code using the tutorial given here http://guides.rubyonrails.org/generators.html

However i am not sure about how to move this to a gem and use a command like device install ....

like image 408
Krishna Prasad Varma Avatar asked Dec 06 '25 16:12

Krishna Prasad Varma


1 Answers

There are actually two ways of doing this (and both involve a Rails Engine afaik).

  • You create a engine that contains a generator for your file
  • You create a engine that bundles the CSS file so you can require it without having it present in your code repository. (Similar to the jQuery gem).

To create an engine just follow this guide: http://edgeguides.rubyonrails.org/engines.html. Just without the mountable option and anything you put inside your app/assets/stylesheet directory will be available through require inside your CSS manifest. The relevant part in the guide is in 6.4 besides the general boilerplate setup you have to do.

For a generateor the same applies, you just have to put the generator in the generators directory as you would with the app and can then run it from there with the engine prefix.

like image 68
Tigraine Avatar answered Dec 08 '25 06:12

Tigraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!