diff options
author | francis <francis> | 2007-11-01 05:35:40 +0000 |
---|---|---|
committer | francis <francis> | 2007-11-01 05:35:40 +0000 |
commit | 5aeb7d884e40291b00e424b5df43e6abbd931051 (patch) | |
tree | b44f349ac558c33e35806004a6584b1db99c6280 /app/helpers/link_to_helper.rb | |
parent | 28fb182fa965467b73ad0b9bea506de8050305d3 (diff) |
Make "rake spec:check" not check views or helpers, as I don't think
we need specialist test files for them (and even if I did they
are screwed, as they can't call functions in controllers/views/routes
from the test framework).
Move various link to URL helpers into their own file, for ease of
calling from views and controllers.
Document Spec directory in top level README.
Diffstat (limited to 'app/helpers/link_to_helper.rb')
-rw-r--r-- | app/helpers/link_to_helper.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb new file mode 100644 index 000000000..b621916b7 --- /dev/null +++ b/app/helpers/link_to_helper.rb @@ -0,0 +1,46 @@ +# app/helpers/application_helper.rb: +# This module is included into all controllers via controllers/application.rb +# - +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: link_to_helper.rb,v 1.1 2007-11-01 05:35:43 francis Exp $ + +module LinkToHelper + + # Links to various models + # XXX consolidate with simplify_url_part in controllers/application.rb so + # ones with calls to simplify_url_part are only in one place + + def request_link(info_request) + link_to h(info_request.title), show_request_url(:id => info_request) + end + + def public_body_link_short(public_body) + link_to h(public_body.short_name), show_public_body_url(:simple_short_name => simplify_url_part(public_body.short_name)) + end + def public_body_link(public_body) + link_to h(public_body.name), show_public_body_url(:simple_short_name => simplify_url_part(public_body.short_name)) + end + + def user_link(user) + link_to h(user.name), show_user_url(:simple_name => simplify_url_part(user.name)) + end + + def info_request_link(info_request) + link_to h(info_request.title), show_request_url(:id => info_request) + end + + # Simplified links to our objects + # XXX See controllers/user_controller.rb controllers/body_controller.rb for inverse + # XXX consolidate somehow with stuff in helpers/application_helper.rb + def simplify_url_part(text) + text.downcase! + text.gsub!(/ /, "-") + text.gsub!(/[^a-z0-9_-]/, "") + text + end + +end + |