h3rald / glyph

A Ruby-powered Rapid Document Authoring Framework
http://www.h3rald.com/glyph/
Other
76 stars 7 forks source link

Plugin System #149

Open h3rald opened 14 years ago

h3rald commented 14 years ago

Glyph should support a simple plugin architecture.

tammymakesthings commented 13 years ago

As a start to this, what about a way to define "hooks" - chunks of Ruby code which can be run before or after various operations. For example, I'd very much like it if I could create a file - say ~/.glyph_hooks.rb - where I could put something like this:

after :init do |project_dir|
  ['journals', 'research'].each do |extra_dir|
     (dir/extra_dir.strip).mkpath
  end
end

And after I "glyph init" any project, it would run that code. I think the set of available hooks should include at least the following:

before :init do |project_path|
end

after :init do |project_path|
end

before :compile do |project_path, project_config, compile_format|
end

after :compile do |project_path, project_config, compile_format|
end

before :add do |project_path, project_config, file_name|
end

after :add do |project_path, project_config, file_name|
end

I'm not sure if I have the Ruby metaprogramming skills to tackle this idea on my own, but I'd be happy to collaborate on such a feature. Also, it might make sense to create the hooks file as ~/.glyph/hooks.rb, and move the global Glyph config to ~/.glyph/config or something.

h3rald commented 13 years ago

It definitely sounds interesting and very doable! I didn't think of hooks originally, mainly because you can define your own commands and rake tasks, but sometimes you may want to extend the existing commands, that's true, and it would be much easier in this way.

Actually this doesn't seem to relate to what I had in mind for a plugin system, so I created a separate feature for this: see #187.

Regarding the global configuration file, for now it's in ~/.glyphrc -- something I'm not too keen of, so moving it to ~/.glyph/config.yml would definitely be better, especially if you have other "global" files in mind, like hooks.rb.

Questions

tammymakesthings commented 13 years ago

I think your comments about project hooks make sense, and I think Glyph::PROJECT/lib/hooks.rb is probably a very sensible place for them.

As for possible use cases, here are some ideas I could think of:

Those are just a few examples off the top of my head.

h3rald commented 13 years ago

Yes, all the examples definitely makes sense. If you want, you can try implementing this yourself, otherwise I'll definitely add it anyway, just let me know!