Commit 0b2d24fcf800d48813413fd82bb0716c8d65e889

Authored by AntonioTerceiro
1 parent ab04315e

ActionItem8: adding code for generating help boxes

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@119 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/application_helper.rb
@@ -76,5 +76,39 @@ module ApplicationHelper @@ -76,5 +76,39 @@ module ApplicationHelper
76 end 76 end
77 end 77 end
78 78
  79 + # Displays context help. Pass the content of the help message in the block
  80 + # passed to this method. Example:
  81 + #
  82 + # <% help do %>
  83 + # This is the help message to be displayed. It can contain any HTML you
  84 + # want: <strong>bold</strong>, <em>italic</em>, and even
  85 + # <%= link_to '', 'links' %> using Rails helpers.
  86 + # <% end %>
  87 + #
  88 + # You can also pass an optional argument to force the use of textile in your
  89 + # help message:
  90 + #
  91 + # <% help :textile do %>
  92 + # You can also use *textile*!
  93 + # <% end %>
  94 + #
  95 + # Formally, the <tt>type</tt> argument can be <tt>:html</tt> or
  96 + # <tt>:textile</tt>. It defaults to <tt>:html</tt>.
  97 + #
  98 + # TODO: implement correcly the 'Help' button click
  99 + def help(type = :html, &block)
  100 + content = capture(&block)
  101 + if type == :textile
  102 + content = RedCloth.new(content).to_html
  103 + end
  104 + button = link_to_function(_('Help'), "alert('change me, Leandro!')")
  105 + concat(content_tag('div', button + content_tag('div', content, :class => 'help_message'), :class => 'help_box'), block.binding)
  106 + end
  107 +
  108 + # alias for <tt>help(:textile)</tt>. Pass a block in the same way you would
  109 + # do if you called <tt>help</tt> directly.
  110 + def help_textile(&block)
  111 + help(:textile, &block)
  112 + end
79 113
80 end 114 end
test/functional/application_controller_test.rb
@@ -53,4 +53,33 @@ class ApplicationControllerTest &lt; Test::Unit::TestCase @@ -53,4 +53,33 @@ class ApplicationControllerTest &lt; Test::Unit::TestCase
53 assert_not_nil assigns(:chosen_icons_theme) 53 assert_not_nil assigns(:chosen_icons_theme)
54 end 54 end
55 55
  56 + def test_should_generate_help_box
  57 + get :help
  58 + assert_tag({
  59 + :tag => 'div',
  60 + :attributes => { :class => 'help_box'},
  61 + :descendant => {
  62 + :tag => 'div',
  63 + :content => /my_help_message/,
  64 + :attributes => { :class => 'help_message'}
  65 + }
  66 + })
  67 + end
  68 +
  69 + def test_should_generate_help_box_expanding_textile_markup
  70 + get :help_textile
  71 + assert_tag({
  72 + :tag => 'div',
  73 + :attributes => { :class => 'help_box'},
  74 + :descendant => {
  75 + :tag => 'div',
  76 + :attributes => { :class => 'help_message'},
  77 + :descendant => {
  78 + :tag => 'strong',
  79 + :content => /my_bold_help_message/
  80 + }
  81 + }
  82 + })
  83 + end
  84 +
56 end 85 end
test/mocks/test/test_controller.rb
@@ -7,4 +7,13 @@ class TestController &lt; ApplicationController @@ -7,4 +7,13 @@ class TestController &lt; ApplicationController
7 def post_only 7 def post_only
8 render :text => '<span>post_only</span>' 8 render :text => '<span>post_only</span>'
9 end 9 end
  10 +
  11 + def help
  12 + render :inline => '<% help { %> my_help_message <% } %>'
  13 + end
  14 +
  15 + def help_textile
  16 + render :inline => '<% help_textile { %> *my_bold_help_message* <% } %>'
  17 + end
  18 +
10 end 19 end