Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and improve how to add behavior to Gobierto with plugins #2394

Open
amiedes opened this issue Jun 27, 2019 · 0 comments
Open

Document and improve how to add behavior to Gobierto with plugins #2394

amiedes opened this issue Jun 27, 2019 · 0 comments

Comments

@amiedes
Copy link
Contributor

amiedes commented Jun 27, 2019

It's not a priority right now, but I think it's nice to keep this in mind.

Description

In the two Railtie plugins we've made so far we're staring to have a pattern:

  1. Webpack needs to be aware of the new js files:
Webpacker::Compiler.watched_paths += [
  "app/javascript/packs/*.js",
  "app/javascript/custom_fields_data_grid_plugin/*.js",
  "app/javascript/custom_fields_data_grid_plugin/**/*.js"
]
  1. We need to load Gobierto models
conf.autoload_paths += Dir[Pathname.new(base_path).join('app', 'models')]
conf.eager_load_paths += Dir[Pathname.new(base_path).join("app", "models")]
  1. We have a generic way of inserting custom modules into Gobierto classes, so each plugin can add new behavior. Right now it's only used for HR/indicators/budgets plugins, but this would have been useful when we had to adapt Gobierto classes for gencat:
def attach_module(config, origin, module_class)
  if config.plugins_attached_modules[origin]
    config.plugins_attached_modules[origin].append(module_class)
  else
    config.plugins_attached_modules[origin] = [module_class]
  end
end

# ... Railtie declaration ...

attach_module(conf, "::GobiertoPlans::CategoryTermDecorator", ::GobiertoPlans::CategoryTermDecoratorBudgetsAttachment)

Proposed solution

Create a generic Gobierto::Plugin < Rails::Railtie that declares the attach_module method, and loads gobierto models and js files. Then a plugin can inherit from this class, and to modify/add new methods to a class only has to call:

attach_module(conf, "<GobiertoClass>", CustomModule)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant