Commit 13a8c19489e3ee0320f378ee71b9f95f2fed825c
1 parent
ae14ca6c
Exists in
master
and in
23 other branches
ActionItem8: better interface for using help.
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@121 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
101 additions
and
20 deletions
Show diff stats
app/helpers/application_helper.rb
| ... | ... | @@ -76,39 +76,71 @@ module ApplicationHelper |
| 76 | 76 | end |
| 77 | 77 | end |
| 78 | 78 | |
| 79 | - # Displays context help. Pass the content of the help message in the block | |
| 80 | - # passed to this method. Example: | |
| 79 | + # Displays context help. You can pass the content of the help message as the | |
| 80 | + # first parameter or using template code inside a block passed to this | |
| 81 | + # method. *Note*: the block is ignored if <tt>content</tt> is not | |
| 82 | + # <tt>nil</tt> | |
| 83 | + # | |
| 84 | + # The method returns the text generated, so you can also use it inside a | |
| 85 | + # <%= ... %> | |
| 86 | + # | |
| 87 | + # Follow some examples ... | |
| 88 | + # | |
| 89 | + # Passing the text as argument: | |
| 90 | + # | |
| 91 | + # <% help 'This your help message' %> | |
| 92 | + # | |
| 93 | + # Using a block: | |
| 81 | 94 | # |
| 82 | 95 | # <% help do %> |
| 83 | 96 | # 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. | |
| 97 | + # want: <strong>bold</strong>, <em>italic</em>. It can also contain calls | |
| 98 | + # to any Rails helper, like <%= link_to 'home', :controller => 'home' %>. | |
| 86 | 99 | # <% end %> |
| 87 | 100 | # |
| 88 | 101 | # You can also pass an optional argument to force the use of textile in your |
| 89 | 102 | # help message: |
| 90 | 103 | # |
| 91 | - # <% help :textile do %> | |
| 104 | + # <% help nil, :textile do %> | |
| 92 | 105 | # You can also use *textile*! |
| 93 | 106 | # <% end %> |
| 94 | 107 | # |
| 108 | + # or, using the return of the method: | |
| 109 | + # | |
| 110 | + # <%= help 'this is your help message' %> | |
| 111 | + # | |
| 95 | 112 | # Formally, the <tt>type</tt> argument can be <tt>:html</tt> or |
| 96 | 113 | # <tt>:textile</tt>. It defaults to <tt>:html</tt>. |
| 97 | 114 | # |
| 98 | 115 | # TODO: implement correcly the 'Help' button click |
| 99 | - def help(type = :html, &block) | |
| 100 | - content = capture(&block) | |
| 116 | + def help(content = nil, type = :html, &block) | |
| 117 | + | |
| 118 | + if content.nil? | |
| 119 | + return '' if block.nil? | |
| 120 | + content = capture(&block) | |
| 121 | + end | |
| 122 | + | |
| 101 | 123 | if type == :textile |
| 102 | 124 | content = RedCloth.new(content).to_html |
| 103 | 125 | end |
| 126 | + | |
| 127 | + # TODO: implement this button, and add style='display: none' to the help | |
| 128 | + # message DIV | |
| 104 | 129 | 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) | |
| 130 | + | |
| 131 | + text = content_tag('div', button + content_tag('div', content, :class => 'help_message'), :class => 'help_box') | |
| 132 | + | |
| 133 | + unless block.nil? | |
| 134 | + concat(text, block.binding) | |
| 135 | + end | |
| 136 | + | |
| 137 | + text | |
| 106 | 138 | end |
| 107 | 139 | |
| 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) | |
| 140 | + # alias for <tt>help(content, :textile)</tt>. You can pass a block in the | |
| 141 | + # same way you would do if you called <tt>help</tt> directly. | |
| 142 | + def help_textile(content = nil, &block) | |
| 143 | + help(content, :textile, &block) | |
| 112 | 144 | end |
| 113 | 145 | |
| 114 | 146 | end | ... | ... |
app/views/features/index.rhtml
| 1 | 1 | <h2><%= _('Enable/Disable features') %></h2> |
| 2 | 2 | |
| 3 | 3 | <%= render :partial => 'features_table' %> |
| 4 | + | |
| 5 | +<%= help_textile _(' | |
| 6 | +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. | |
| 7 | +') %> | ... | ... |
test/functional/application_controller_test.rb
| ... | ... | @@ -53,8 +53,8 @@ class ApplicationControllerTest < Test::Unit::TestCase |
| 53 | 53 | assert_not_nil assigns(:chosen_icons_theme) |
| 54 | 54 | end |
| 55 | 55 | |
| 56 | - def test_should_generate_help_box | |
| 57 | - get :help | |
| 56 | + def test_should_generate_help_box_when_passing_string | |
| 57 | + get :help_with_string | |
| 58 | 58 | assert_tag({ |
| 59 | 59 | :tag => 'div', |
| 60 | 60 | :attributes => { :class => 'help_box'}, |
| ... | ... | @@ -66,8 +66,37 @@ class ApplicationControllerTest < Test::Unit::TestCase |
| 66 | 66 | }) |
| 67 | 67 | end |
| 68 | 68 | |
| 69 | - def test_should_generate_help_box_expanding_textile_markup | |
| 70 | - get :help_textile | |
| 69 | + def test_should_generate_help_box_when_passing_block | |
| 70 | + get :help_with_block | |
| 71 | + assert_tag({ | |
| 72 | + :tag => 'div', | |
| 73 | + :attributes => { :class => 'help_box'}, | |
| 74 | + :descendant => { | |
| 75 | + :tag => 'div', | |
| 76 | + :content => /my_help_message/, | |
| 77 | + :attributes => { :class => 'help_message'} | |
| 78 | + } | |
| 79 | + }) | |
| 80 | + end | |
| 81 | + | |
| 82 | + def test_should_generate_help_box_expanding_textile_markup_when_passing_string | |
| 83 | + get :help_textile_with_string | |
| 84 | + assert_tag({ | |
| 85 | + :tag => 'div', | |
| 86 | + :attributes => { :class => 'help_box'}, | |
| 87 | + :descendant => { | |
| 88 | + :tag => 'div', | |
| 89 | + :attributes => { :class => 'help_message'}, | |
| 90 | + :descendant => { | |
| 91 | + :tag => 'strong', | |
| 92 | + :content => /my_bold_help_message/ | |
| 93 | + } | |
| 94 | + } | |
| 95 | + }) | |
| 96 | + end | |
| 97 | + | |
| 98 | + def test_should_generate_help_box_expanding_textile_markup_when_passing_block | |
| 99 | + get :help_textile_with_block | |
| 71 | 100 | assert_tag({ |
| 72 | 101 | :tag => 'div', |
| 73 | 102 | :attributes => { :class => 'help_box'}, | ... | ... |
test/mocks/test/test_controller.rb
| ... | ... | @@ -8,12 +8,28 @@ class TestController < ApplicationController |
| 8 | 8 | render :text => '<span>post_only</span>' |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | - def help | |
| 12 | - render :inline => '<% help { %> my_help_message <% } %>' | |
| 11 | + def help_with_string | |
| 12 | + render :inline => '<%= help "my_help_message" %>' | |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | - def help_textile | |
| 16 | - render :inline => '<% help_textile { %> *my_bold_help_message* <% } %>' | |
| 15 | + def help_with_block | |
| 16 | + render :inline => ' | |
| 17 | + <% help do %> | |
| 18 | + my_help_message | |
| 19 | + <% end %> | |
| 20 | + ' | |
| 21 | + end | |
| 22 | + | |
| 23 | + def help_textile_with_string | |
| 24 | + render :inline => '<%= help_textile "*my_bold_help_message*" %>' | |
| 25 | + end | |
| 26 | + | |
| 27 | + def help_textile_with_block | |
| 28 | + render :inline => ' | |
| 29 | + <% help_textile do %> | |
| 30 | + *my_bold_help_message* | |
| 31 | + <% end %> | |
| 32 | + ' | |
| 17 | 33 | end |
| 18 | 34 | |
| 19 | 35 | end | ... | ... |