bridgetownrb / bridgetown

A next-generation progressive site generator & fullstack framework, powered by Ruby
https://www.bridgetownrb.com
MIT License
1.13k stars 114 forks source link

Configuration options not set by init in initializers.rb #716

Closed fbuys closed 1 year ago

fbuys commented 1 year ago

Bridgetown Version: bridgetown 1.2.0 "Bonny Slope"

To Reproduce

Current behavior

Inside the plugin initializer I am outputting like this:

  pp config.to_h
  print "sample_plugin config: " 
  pp config.sample_plugin
...[rest of config object],
 "init_params"=>{"sample_plugin"=>{"my_setting"=>"test-config-option"}},
 "sample_plugin"=>{}}
sample_plugin config: {}

Expected behavior

I would like to access the config options set in the app initializer.

  print "sample_plugin config: " 
  pp config.sample_plugin

should output:

sample_plugin config: { my_setting: "test-config-option" }

Computing environment (please complete the following information):

jaredcwhite commented 1 year ago

@fbuys I think you'd need to add my_setting as a keyword argument to your initializer for this to work: https://github.com/fbuys/bridgetown-sample-plugin/blob/47f37124f50c81b964c52ba8a981e0f398cda411/lib/sample_plugin.rb

There's probably somewhere in the documentation we should illustrate this more clearly. Also it's best to keep my_setting as an optional kwarg (aka default to nil or some value) unless you absolutely need it.

fbuys commented 1 year ago

Hey I pushed a PR that might be helpful.