Crafting Gems with App Assets
I followed http://railscasts.com/episodes/245-new-gem-with-bundler to create a gem with a packer and this is great for gems where I only need the lib, is there a standard practice for gem stones where do I need to create widgets with assets / controllers / models / views?
source to share
You would like to create an engine at this point. Reading the engine manual should get you off to a great start.
The bare-bones components you need inside your gem is a file in lib/your_gem.rb
that serves a purpose simply to demand from your gem. If your gem has no other dependencies then it looks like this:
require 'your_gem/engine'
One line, so much power. For the file lib/your_gem/engine.rb
that is required for this, there is this code:
module YourGem
class Engine < Rails::Engine
end
end
By simply inheriting from Rails::Engine
, this calls the inheritance hook on Rails::Engine
, which notifies the framework that there is an engine at the location of your gem.
If you then create the file in app/assets/stylesheets/your_gem/beauty.css
, you can include it in your application (assuming you have a resource pipeline, of course) using this line:
<%= stylesheet_link_tag "your_gem/beauty" %>
Now that I have given you the short version, I really recommend reading the Top-down Engine Manual to better understand it.
source to share