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

Automatically load (and reload) helper modules from the "helpers" directory #238

Closed
bhollis opened this issue Jan 15, 2012 · 5 comments
Closed

Comments

@bhollis
Copy link
Contributor

bhollis commented Jan 15, 2012

To provide an experience more consistent with Rails, and allow for easier configuration of helpers and iteration on helpers while running preview server, helper modules should be automatically loaded from a "helpers" directory, and should be reloaded when they are changed while running the preview server. This should work similarly to how Rails handles helpers.

@tdreyno
Copy link
Member

tdreyno commented Jan 15, 2012

Would these helper files be Ruby modules or just raw methods in a file?

We already watch and refresh the lib directory, but I guess we don't autoload the files.

@tdreyno
Copy link
Member

tdreyno commented Jan 15, 2012

Should the generated template include helpers, thus creating a more complicated empty project? Or not and simply document this magical directory?

@bhollis
Copy link
Contributor Author

bhollis commented Jan 15, 2012

Ruby modules matching the name of their file (CamelCase to under_score) so that they can be unloaded before being reloaded, like Rails does.

I'd leave it out of the default project, though. Documentation should be fine :-)

@tdreyno
Copy link
Member

tdreyno commented Jan 15, 2012

Done and done.

Created 3 new config variables:

  app.set :helpers_dir, "helpers"
  app.set :helpers_filename_glob, "**/*_helper.rb"
  app.set :helpers_filename_to_module_name_proc, Proc.new { |filename|
    basename = File.basename(filename, File.extname(filename))
    basename.camelcase
  }

These defaults mean files must be in the helpers/ directory and named something_helper.rb and we will get the module name by camelcasing the file name.

@tdreyno tdreyno closed this as completed Jan 15, 2012
@bhollis
Copy link
Contributor Author

bhollis commented Jan 15, 2012

Awesome!

audionerd pushed a commit to audionerd/middleman that referenced this issue Jan 16, 2012
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

2 participants