From 4648199ea878a0fdb79046a74a770524f7e6b04a Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 3 Feb 2015 15:35:45 -0300 Subject: [PATCH] site_tour: parse profile fields in tooltip description --- plugins/site_tour/lib/site_tour_plugin/site_tour_helper.rb | 14 ++++++++++++++ plugins/site_tour/lib/site_tour_plugin/tour_block.rb | 2 +- plugins/site_tour/public/edit_tour_block.css | 8 ++++++++ plugins/site_tour/test/unit/site_tour_helper_test.rb | 17 +++++++++++++++++ plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block.html.erb | 1 + plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block_group_item.html.erb | 4 +++- plugins/site_tour/views/tour_actions.html.erb | 3 ++- 7 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 plugins/site_tour/lib/site_tour_plugin/site_tour_helper.rb create mode 100644 plugins/site_tour/test/unit/site_tour_helper_test.rb diff --git a/plugins/site_tour/lib/site_tour_plugin/site_tour_helper.rb b/plugins/site_tour/lib/site_tour_plugin/site_tour_helper.rb new file mode 100644 index 0000000..f18e900 --- /dev/null +++ b/plugins/site_tour/lib/site_tour_plugin/site_tour_helper.rb @@ -0,0 +1,14 @@ +module SiteTourPlugin::SiteTourHelper + + def parse_tour_description(description) + p = profile rescue nil + if !p.nil? && description.present? + description.gsub('{profile.identifier}', p.identifier). + gsub('{profile.name}', p.name). + gsub('{profile.url}', url_for(p.url)) + else + description + end + end + +end diff --git a/plugins/site_tour/lib/site_tour_plugin/tour_block.rb b/plugins/site_tour/lib/site_tour_plugin/tour_block.rb index a4a6207..65db701 100644 --- a/plugins/site_tour/lib/site_tour_plugin/tour_block.rb +++ b/plugins/site_tour/lib/site_tour_plugin/tour_block.rb @@ -8,7 +8,7 @@ class SiteTourPlugin::TourBlock < Block before_save do |block| block.actions.reject! {|i| i[:group_name].blank? && i[:selector].blank? && i[:description].blank?} - block.group_triggers.reject! {|i| i[:group_name].blank? && i[:selector].blank? && i[:event].blank?} + block.group_triggers.reject! {|i| i[:group_name].blank? && i[:selector].blank?} end def self.description diff --git a/plugins/site_tour/public/edit_tour_block.css b/plugins/site_tour/public/edit_tour_block.css index 42bd538..1b42fb7 100644 --- a/plugins/site_tour/public/edit_tour_block.css +++ b/plugins/site_tour/public/edit_tour_block.css @@ -1,3 +1,11 @@ +#edit-tour-block #tooltip-actions h3 { + margin-bottom: 5px; +} + +#edit-tour-block .special-attributes { + color: rgb(157, 157, 157); +} + #edit-tour-block .list-items { margin-bottom: 25px; } diff --git a/plugins/site_tour/test/unit/site_tour_helper_test.rb b/plugins/site_tour/test/unit/site_tour_helper_test.rb new file mode 100644 index 0000000..fcca9d7 --- /dev/null +++ b/plugins/site_tour/test/unit/site_tour_helper_test.rb @@ -0,0 +1,17 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class SiteTourHelperTest < ActionView::TestCase + + include SiteTourPlugin::SiteTourHelper + + should 'parse tooltip description' do + assert_equal 'test', parse_tour_description("test") + end + + should 'replace profile attributes in tooltip description' do + profile = fast_create(Profile) + expects(:profile).returns(profile).at_least_once + assert_equal "name #{profile.name}, identifier #{profile.identifier}, url #{url_for profile.url}", parse_tour_description("name {profile.name}, identifier {profile.identifier}, url {profile.url}") + end + +end diff --git a/plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block.html.erb b/plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block.html.erb index 752def8..36b2090 100644 --- a/plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block.html.erb +++ b/plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block.html.erb @@ -6,6 +6,7 @@

<%= _('Tooltip Actions') %>

+
<%= _('Special fields for description: {profile.name}, {profile.identifier}, {profile.url}.') %>
  • <%= _('Group Name') %>
  • <%= _('Selector') %>
  • diff --git a/plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block_group_item.html.erb b/plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block_group_item.html.erb index a8481f5..e1f1dea 100644 --- a/plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block_group_item.html.erb +++ b/plugins/site_tour/views/box_organizer/site_tour_plugin/_tour_block_group_item.html.erb @@ -7,7 +7,9 @@ <%= text_field_tag 'block[group_triggers][][selector]', group[:selector], :class => 'selector' %>
  • - <%= text_field_tag 'block[group_triggers][][event]', group[:event], :class => 'description' %> + <%= select_tag 'block[group_triggers][][event]', + options_for_select(['mouseenter', 'mouseleave', 'mouseover', 'mouseout', 'click', 'change', 'select', 'keydown', 'keyup', 'keypress', 'focus', 'blur', 'submit', 'drag', 'drop'], group[:event]), + :class => 'description' %>
  • <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-tour-block-item") %> diff --git a/plugins/site_tour/views/tour_actions.html.erb b/plugins/site_tour/views/tour_actions.html.erb index c3f55c6..1113de2 100644 --- a/plugins/site_tour/views/tour_actions.html.erb +++ b/plugins/site_tour/views/tour_actions.html.erb @@ -1,3 +1,4 @@ +<% extend SiteTourPlugin::SiteTourHelper %> <% js_file = defined?(:js_file) ? js_file : nil %> <%= javascript_include_tag(js_file) if js_file.present? %> @@ -6,7 +7,7 @@ jQuery( document ).ready(function( $ ) { <% actions.group_by {|h| h[:group_name]}.each do |group, group_actions| %> <% group_actions.each_with_index do |action, index| %> - <%= "siteTourPlugin.add('#{j action[:group_name]}', '#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %> + <%= "siteTourPlugin.add('#{j action[:group_name]}', '#{j action[:selector]}', '#{j parse_tour_description(action[:description])}', #{index + 1});" %> <% end %> <% end %> -- libgit2 0.21.2