Gem example
olimart opened this issue · comments
Do you have a working example of a gem that leverages Komponent ready for a Rails app.?
We do not have an example gem which embed components. If you want to wrap your components in a gem you can refer to the additional paths.
ok mais concrètement où devraient se trouver les composants dans le gem?
/frontend/components
/lib/frontend/components
Pour le moment j'obtiens
my_gem/lib/my_gem.rb:16:in `block in <class:Railtie>': undefined method `root' for #<MyGem::Railtie:0x007f8229fb10c8> (NoMethodError)
avec le code sous additional path dans my_gem.rb
I think the documentation is wrong about the self
, try replacing it with Yastyle.root
when using it in your initializers defined in your gem. I should update the readme if it's working for you too.
Getting undefined method `root' for Komponent:Module (NoMethodError)
with the following
module Yastyle
class Railtie < Rails::Railtie
config.after_initialize do |app|
app.config.komponent.component_paths.append(Komponent.root.join("frontend/components"))
end
initializer "yastyle.action_dispatch" do |app|
ActiveSupport.on_load :action_controller do
ActionController::Base.prepend_view_path Komponent.root.join("frontend")
end
end
initializer 'yastyle.autoload', before: :set_autoload_paths do |app|
app.config.autoload_paths << Komponent.root.join("frontend")
end
private
def self.root
Pathname.new(File.dirname(__dir__))
end
end
end
Put access modifier and root
method inside Yastyle
module but outside Railtie
class.
I'm getting this time
There was an error while trying to load the gem 'yastyle'. (Bundler::GemRequireError)
Gem Load Error is: undefined local variable or method `config' for Yastyle:Module
require "yastyle/version"
module Yastyle
config.after_initialize do |app|
app.config.komponent.component_paths.append(Komponent.root.join("frontend/components"))
end
initializer "yastyle.action_dispatch" do |app|
ActiveSupport.on_load :action_controller do
ActionController::Base.prepend_view_path Komponent.root.join("frontend")
end
end
initializer 'yastyle.autoload', before: :set_autoload_paths do |app|
app.config.autoload_paths << Komponent.root.join("frontend")
end
private
def self.root
Pathname.new(File.dirname(__dir__))
end
class Railtie < Rails::Railtie
end
end
I think what @florentferry meant was:
require "yastyle/version"
module Yastyle
class Railtie < Rails::Railtie
config.after_initialize do |app|
app.config.komponent.component_paths.append(Komponent.root.join("frontend/components"))
end
initializer "yastyle.action_dispatch" do |app|
ActiveSupport.on_load :action_controller do
ActionController::Base.prepend_view_path Komponent.root.join("frontend")
end
end
initializer 'yastyle.autoload', before: :set_autoload_paths do |app|
app.config.autoload_paths << Komponent.root.join("frontend")
end
end
private
def self.root
Pathname.new(File.dirname(__dir__))
end
end
Getting undefined method `root' for Komponent:Module (NoMethodError)
at app.config.autoload_paths << Komponent.root.join("frontend")
Actually, Komponent.root
should be Yastyle.root
in your case (you have to use the name of your Gem module)
Then, put your components in a frontend/components
folder, which should be placed in the path returned by your Yastyle.root
method.
Seems this issue been resolved, I closing it. I shoulda merge a PR with an update to readme on how to wrap components in a gem.