sam / harbor

Harbor is a Ruby Web Framework.
https://github.com/sam/harbor
MIT License
3 stars 6 forks source link

Site generator should use new application layout #4

Closed sam closed 12 years ago

sam commented 12 years ago

Given harbor setup petshop:

petshop/controllers/home.rb
petshop/env/default.rb
petshop/env/stage.rb
petshop/env/production.rb
petshop/forms/example.rb
petshop/helpers/general.rb
petshop/lib/boot.rb
petshop/lib/petshop.rb
petshop/log
petshop/models
petshop/public/images
petshop/public/javascripts
petshop/public/stylesheets
petshop/views/layouts/application.html.erb
petshop/views/home/index.html.erb
Bauerpauer commented 12 years ago

Bringin' it wayyy back with the petshop ;)

sam commented 12 years ago

Note: Added boot.rb. This is to give Harbor internals (like server or console) a way to load your app (petshop.rb in this case) without forcing you to have a file called application.rb that defines class Petshop < Harbor::Application.

This should be a generated file with a note not to modify.

fgrehm commented 12 years ago

I couldn't spot a place where we can grab the application root path, should the generated boot.rb do that job? Where should this variable be located? I was thinking about something along the lines of Rails.root, with returns a Pathname instance that we could use to set up the default view path for example.

sam commented 12 years ago

We should have a config.root I think. I agree setting it in boot.rb makes sense.

boot.rb could be basically:

require "lib/petshop"

config.root = Petshop.root = File.dirname(__FILE__).parent
config.load!(Petshop.root + "env")

# Configuration#views would return a ViewCollection object that handled mapping all the views paths perhaps?
config.views.add(Petshop.root + "views")

# Configuration#controllers would return the Controller Container/Autoloader.
config.controllers.add(Petshop.root + "controllers")

Just an idea.

It doesn't matter that config.root could be overwritten multiple times with a "last-in-wins" as long as your "root app" is required last. You could bundle, system-gem, git-submodule, or old-school vendor the other apps. Doesn't matter as long as you require them first then. Their generated boot.rb will handle the first-pass setup for us.

By having a Harbor::Application::root method available (and set in boot.rb), we can still easily get at the relative assets for a "mounted" application.

sam commented 12 years ago

Also, I know @Bauerpauer is a fan of nesting everything under /lib, which is mostly how we do it today. In my own projects I tend to maintain a flatter structure with views, controllers and public hanging off the root so that's what I've described above.

sam commented 12 years ago

Updated example to include /forms and /helpers.

Bauerpauer commented 12 years ago

I think this works for me. What about a log directory?

sam commented 12 years ago

Added log, and layouts. The 3rd level of ul doesn't appear to format correctly.

sam commented 12 years ago

Done in d59f245b04d7a64c77440e4bfd9beaf7518109bb.