From 13a8c19489e3ee0320f378ee71b9f95f2fed825c Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Mon, 23 Jul 2007 19:35:59 +0000 Subject: [PATCH] ActionItem8: better interface for using help. --- app/helpers/application_helper.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++------------ app/views/features/index.rhtml | 4 ++++ test/functional/application_controller_test.rb | 37 +++++++++++++++++++++++++++++++++---- test/mocks/test/test_controller.rb | 24 ++++++++++++++++++++---- 4 files changed, 101 insertions(+), 20 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 49331b7..0234033 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -76,39 +76,71 @@ module ApplicationHelper end end - # Displays context help. Pass the content of the help message in the block - # passed to this method. Example: + # Displays context help. You can pass the content of the help message as the + # first parameter or using template code inside a block passed to this + # method. *Note*: the block is ignored if content is not + # nil + # + # The method returns the text generated, so you can also use it inside a + # <%= ... %> + # + # Follow some examples ... + # + # Passing the text as argument: + # + # <% help 'This your help message' %> + # + # Using a block: # # <% help do %> # This is the help message to be displayed. It can contain any HTML you - # want: bold, italic, and even - # <%= link_to '', 'links' %> using Rails helpers. + # want: bold, italic. It can also contain calls + # to any Rails helper, like <%= link_to 'home', :controller => 'home' %>. # <% end %> # # You can also pass an optional argument to force the use of textile in your # help message: # - # <% help :textile do %> + # <% help nil, :textile do %> # You can also use *textile*! # <% end %> # + # or, using the return of the method: + # + # <%= help 'this is your help message' %> + # # Formally, the type argument can be :html or # :textile. It defaults to :html. # # TODO: implement correcly the 'Help' button click - def help(type = :html, &block) - content = capture(&block) + def help(content = nil, type = :html, &block) + + if content.nil? + return '' if block.nil? + content = capture(&block) + end + if type == :textile content = RedCloth.new(content).to_html end + + # TODO: implement this button, and add style='display: none' to the help + # message DIV button = link_to_function(_('Help'), "alert('change me, Leandro!')") - concat(content_tag('div', button + content_tag('div', content, :class => 'help_message'), :class => 'help_box'), block.binding) + + text = content_tag('div', button + content_tag('div', content, :class => 'help_message'), :class => 'help_box') + + unless block.nil? + concat(text, block.binding) + end + + text end - # alias for help(:textile). Pass a block in the same way you would - # do if you called help directly. - def help_textile(&block) - help(:textile, &block) + # alias for help(content, :textile). You can pass a block in the + # same way you would do if you called help directly. + def help_textile(content = nil, &block) + help(content, :textile, &block) end end diff --git a/app/views/features/index.rhtml b/app/views/features/index.rhtml index 1dfefb1..aa79e58 100644 --- a/app/views/features/index.rhtml +++ b/app/views/features/index.rhtml @@ -1,3 +1,7 @@

<%= _('Enable/Disable features') %>

<%= render :partial => 'features_table' %> + +<%= help_textile _(' +Here you can enable or disable several features of your virtual community. Each feature represents some funcionality that your virtual community can use you enable it. +') %> diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 5e19e64..3a9cd7e 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -53,8 +53,8 @@ class ApplicationControllerTest < Test::Unit::TestCase assert_not_nil assigns(:chosen_icons_theme) end - def test_should_generate_help_box - get :help + def test_should_generate_help_box_when_passing_string + get :help_with_string assert_tag({ :tag => 'div', :attributes => { :class => 'help_box'}, @@ -66,8 +66,37 @@ class ApplicationControllerTest < Test::Unit::TestCase }) end - def test_should_generate_help_box_expanding_textile_markup - get :help_textile + def test_should_generate_help_box_when_passing_block + get :help_with_block + assert_tag({ + :tag => 'div', + :attributes => { :class => 'help_box'}, + :descendant => { + :tag => 'div', + :content => /my_help_message/, + :attributes => { :class => 'help_message'} + } + }) + end + + def test_should_generate_help_box_expanding_textile_markup_when_passing_string + get :help_textile_with_string + assert_tag({ + :tag => 'div', + :attributes => { :class => 'help_box'}, + :descendant => { + :tag => 'div', + :attributes => { :class => 'help_message'}, + :descendant => { + :tag => 'strong', + :content => /my_bold_help_message/ + } + } + }) + end + + def test_should_generate_help_box_expanding_textile_markup_when_passing_block + get :help_textile_with_block assert_tag({ :tag => 'div', :attributes => { :class => 'help_box'}, diff --git a/test/mocks/test/test_controller.rb b/test/mocks/test/test_controller.rb index f9a41cb..8beb290 100644 --- a/test/mocks/test/test_controller.rb +++ b/test/mocks/test/test_controller.rb @@ -8,12 +8,28 @@ class TestController < ApplicationController render :text => 'post_only' end - def help - render :inline => '<% help { %> my_help_message <% } %>' + def help_with_string + render :inline => '<%= help "my_help_message" %>' end - def help_textile - render :inline => '<% help_textile { %> *my_bold_help_message* <% } %>' + def help_with_block + render :inline => ' + <% help do %> + my_help_message + <% end %> + ' + end + + def help_textile_with_string + render :inline => '<%= help_textile "*my_bold_help_message*" %>' + end + + def help_textile_with_block + render :inline => ' + <% help_textile do %> + *my_bold_help_message* + <% end %> + ' end end -- libgit2 0.21.2