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

Plugin System #149

Open
h3rald opened this issue Aug 7, 2010 · 4 comments
Open

Plugin System #149

h3rald opened this issue Aug 7, 2010 · 4 comments
Milestone

Comments

@h3rald
Copy link
Owner

h3rald commented Aug 7, 2010

Glyph should support a simple plugin architecture.

@tammymakesthings
Copy link
Contributor

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
Copy link
Owner Author

h3rald commented Nov 28, 2010

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

  • You are basically proposing global hooks, that's fine. What about project hooks? They wouldn't make much sense for the init command, but for other commands they may be useful, and they could definitely live in the Glyph::PROJECT/lib/hooks.rb.
  • Could you provide some examples on possible use cases for these hooks? What would you use them for, exactly?

@tammymakesthings
Copy link
Contributor

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:

  • After a project is init'ed, I'd like to be able to add some additional subdirectories (I write a lot of fiction, and so nearly all my Glyph projects will have directories like journal, research, characters, and so forth. I'd also trigger a shell script I have for creating a remote git repository and checking in the project.
  • Before compiling, I could see a hook that would check the to-be-compiled files into git, for example.
  • If I was publishing documents online, the after :compile hook could copy the files over to my Web site or similar.
  • On a team-based project, the before :add hook could be used to check that files being added followed the appropriate naming conventions etc.

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

@h3rald
Copy link
Owner Author

h3rald commented Nov 30, 2010

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants