From 0b2d24fcf800d48813413fd82bb0716c8d65e889 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Mon, 23 Jul 2007 18:38:35 +0000 Subject: [PATCH] ActionItem8: adding code for generating help boxes --- app/helpers/application_helper.rb | 34 ++++++++++++++++++++++++++++++++++ test/functional/application_controller_test.rb | 29 +++++++++++++++++++++++++++++ test/mocks/test/test_controller.rb | 9 +++++++++ 3 files changed, 72 insertions(+), 0 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1814e81..49331b7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -76,5 +76,39 @@ module ApplicationHelper end end + # Displays context help. Pass the content of the help message in the block + # passed to this method. Example: + # + # <% 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. + # <% end %> + # + # You can also pass an optional argument to force the use of textile in your + # help message: + # + # <% help :textile do %> + # You can also use *textile*! + # <% end %> + # + # 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) + if type == :textile + content = RedCloth.new(content).to_html + end + 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) + 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) + end end diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 0bfc34f..5e19e64 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -53,4 +53,33 @@ class ApplicationControllerTest < Test::Unit::TestCase assert_not_nil assigns(:chosen_icons_theme) end + def test_should_generate_help_box + get :help + 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 + get :help_textile + assert_tag({ + :tag => 'div', + :attributes => { :class => 'help_box'}, + :descendant => { + :tag => 'div', + :attributes => { :class => 'help_message'}, + :descendant => { + :tag => 'strong', + :content => /my_bold_help_message/ + } + } + }) + end + end diff --git a/test/mocks/test/test_controller.rb b/test/mocks/test/test_controller.rb index 4f5fd57..f9a41cb 100644 --- a/test/mocks/test/test_controller.rb +++ b/test/mocks/test/test_controller.rb @@ -7,4 +7,13 @@ class TestController < ApplicationController def post_only render :text => 'post_only' end + + def help + render :inline => '<% help { %> my_help_message <% } %>' + end + + def help_textile + render :inline => '<% help_textile { %> *my_bold_help_message* <% } %>' + end + end -- libgit2 0.21.2