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

Routing helper #14

Merged
merged 2 commits into from
Feb 13, 2015
Merged

Routing helper #14

merged 2 commits into from
Feb 13, 2015

Conversation

jodosha
Copy link
Member

@jodosha jodosha commented Feb 12, 2015

What

Routing helper for full stack Lotus web applications.

Explanation

For a given application called Web::Application, at the runtime Lotus creates a routes factory called Web::Routes.

By including this module in a view, it makes that factory avaliable as routes.

Basic usage in template

module Web::Views::Home
  class Index
    include Web::View
    include Lotus::Helpers
  end
end

# ERB template
# <%= routes.home_path %>

Basic usage in view

module Web::Views::Home
  class Index
    include Web::View
    include Lotus::Helpers
  end

  def link_to_home
    %(<a href="#{ routes.home_path }">Home</a>)
  end
end

# ERB template
# <%= link_to_home %>

Technical notes

This is different from Rails routing helpers. Over there, they are available directly in templates and helpers. Here, I wanted to avoid to overload views with a lot of method missing hackery.

Right now views respond to:

  • concrete methods defined by developers
  • exposures from actions
  • helpers

Adding all the routes available for an application as direct methods would increase a lot the complexity of the view scope. It's better to have the routes factory even if a little bit unhandy.

Ref hanami/hanami#151

@jodosha jodosha self-assigned this Feb 12, 2015
module Helpers
# Routing helper for full stack Lotus web applications.
#
# For a given application called <tt>Web::Application</tt>, at the runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'at runtime' instead of 'at the runtime'

@runlevel5
Copy link
Member

💯

jodosha added a commit that referenced this pull request Feb 13, 2015
@jodosha jodosha merged commit 0f43c2e into master Feb 13, 2015
@jodosha jodosha deleted the routing-helper branch February 13, 2015 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants