From 95a4ed6e4a3a1bcf505b610f9f8cb12ebf7bc80b Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Mon, 18 Feb 2013 15:01:56 -0700 Subject: [PATCH] Add Tag#label method --- app/helpers/recurring_todos_helper.rb | 2 +- app/helpers/todos_helper.rb | 2 +- app/models/tag.rb | 4 ++++ test/unit/tag_test.rb | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/helpers/recurring_todos_helper.rb b/app/helpers/recurring_todos_helper.rb index ce78a1a8..d3114cad 100644 --- a/app/helpers/recurring_todos_helper.rb +++ b/app/helpers/recurring_todos_helper.rb @@ -3,7 +3,7 @@ module RecurringTodosHelper def recurring_todo_tag_list tags_except_starred = @recurring_todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME} tag_list = tags_except_starred. - collect{|t| content_tag(:span,link_to(t.name, tag_path(t.name)), :class => "tag #{t.name.gsub(' ','-')}")}. + collect{|t| content_tag(:span,link_to(t.name, tag_path(t.name)), :class => "tag #{t.label}")}. join('') return content_tag :span, tag_list.html_safe, :class => "tags" end diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 663979f0..d00f1e34 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -131,7 +131,7 @@ module TodosHelper end def tag_span (tag, mobile=false) - content_tag(:span, :class => "tag #{tag.name.gsub(' ','-')}") { link_to(tag.name, tag_path(tag.name, :format => mobile ? :m : nil)) } + content_tag(:span, :class => "tag #{tag.label}") { link_to(tag.name, tag_path(tag.name, :format => mobile ? :m : nil)) } end def tag_list(todo=@todo, mobile=false) diff --git a/app/models/tag.rb b/app/models/tag.rb index 92bdaa20..f859874c 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -26,4 +26,8 @@ class Tag < ActiveRecord::Base taggings.create :taggable => taggable, :user => user end + def label + @label ||= name.gsub(' ', '-') + end + end diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb index 330d42d7..fee7332c 100644 --- a/test/unit/tag_test.rb +++ b/test/unit/tag_test.rb @@ -41,5 +41,9 @@ class TagTest < ActiveSupport::TestCase assert tag.name == "strip spaces" end + + def test_tag_label + assert_equal 'one-two-three', Tag.new(:name => 'one two three').label + end end