diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bffd995..d8cc7d6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -48,6 +48,8 @@ module ApplicationHelper include PluginsHelper + include ButtonsHelper + def locale (@page && !@page.language.blank?) ? @page.language : FastGettext.locale end @@ -209,52 +211,6 @@ module ApplicationHelper result end - def button(type, label, url, html_options = {}) - html_options ||= {} - the_class = 'with-text' - if html_options.has_key?(:class) - the_class << ' ' << html_options[:class] - end - button_without_text type, label, url, html_options.merge(:class => the_class) - end - - def button_without_text(type, label, url, html_options = {}) - the_class = "button icon-#{type}" - if html_options.has_key?(:class) - the_class << ' ' << html_options[:class] - end - the_title = html_options[:title] || label - if html_options[:disabled] - content_tag('a', ' '+content_tag('span', label), html_options.merge(:class => the_class, :title => the_title)) - else - link_to(' '+content_tag('span', label), url, html_options.merge(:class => the_class, :title => the_title)) - end - end - - def button_to_function(type, label, js_code, html_options = {}, &block) - html_options[:class] = "button with-text" unless html_options[:class] - html_options[:class] << " icon-#{type}" - link_to_function(label, js_code, html_options, &block) - end - - def button_to_function_without_text(type, label, js_code, html_options = {}, &block) - html_options[:class] = "" unless html_options[:class] - html_options[:class] << " button icon-#{type}" - link_to_function(content_tag('span', label), js_code, html_options, &block) - end - - def button_to_remote(type, label, options, html_options = {}) - html_options[:class] = "button with-text" unless html_options[:class] - html_options[:class] << " icon-#{type}" - link_to_remote(label, options, html_options) - end - - def button_to_remote_without_text(type, label, options, html_options = {}) - html_options[:class] = "" unless html_options[:class] - html_options[:class] << " button icon-#{type}" - link_to_remote(content_tag('span', label), options, html_options.merge(:title => label)) - end - def icon(icon_name, html_options = {}) the_class = "button #{icon_name}" if html_options.has_key?(:class) @@ -934,13 +890,6 @@ module ApplicationHelper content_for(:head) { stylesheet_link_tag(*args) } end - def article_to_html(article, options = {}) - options.merge!(:page => params[:npage]) - content = article.to_html(options) - content = content.kind_of?(Proc) ? self.instance_exec(&content).html_safe : content.html_safe - filter_html(content, article) - end - # Please, use link_to by default! # This method was created to work around to inexplicable # chain of problems when display_short_format was called @@ -1365,16 +1314,6 @@ module ApplicationHelper @no_design_blocks = true end - def filter_html(html, source) - if @plugins && source && source.has_macro? - html = convert_macro(html, source) unless @plugins.enabled_macros.blank? - #TODO This parse should be done through the macro infra, but since there - # are old things that do not support it we are keeping this hot spot. - html = @plugins.pipeline(:parse_content, html, source).first - end - html && html.html_safe - end - def convert_macro(html, source) doc = Nokogiri::HTML.fragment html #TODO This way is more efficient but do not support macro inside of diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index a55c553..44842ea 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -181,4 +181,21 @@ module ArticleHelper end end + def filter_html(html, source) + if @plugins && source && source.has_macro? + html = convert_macro(html, source) unless @plugins.enabled_macros.blank? + #TODO This parse should be done through the macro infra, but since there + # are old things that do not support it we are keeping this hot spot. + html = @plugins.pipeline(:parse_content, html, source).first + end + html && html.html_safe + end + + def article_to_html(article, options = {}) + options.merge!(:page => params[:npage]) + content = article.to_html(options) + content = content.kind_of?(Proc) ? self.instance_exec(&content).html_safe : content.html_safe + filter_html(content, article) + end + end diff --git a/app/helpers/buttons_helper.rb b/app/helpers/buttons_helper.rb new file mode 100644 index 0000000..60872a4 --- /dev/null +++ b/app/helpers/buttons_helper.rb @@ -0,0 +1,47 @@ +module ButtonsHelper + def button(type, label, url, html_options = {}) + html_options ||= {} + the_class = 'with-text' + if html_options.has_key?(:class) + the_class << ' ' << html_options[:class] + end + button_without_text type, label, url, html_options.merge(:class => the_class) + end + + def button_without_text(type, label, url, html_options = {}) + the_class = "button icon-#{type}" + if html_options.has_key?(:class) + the_class << ' ' << html_options[:class] + end + the_title = html_options[:title] || label + if html_options[:disabled] + content_tag('a', ' '+content_tag('span', label), html_options.merge(:class => the_class, :title => the_title)) + else + link_to(' '+content_tag('span', label), url, html_options.merge(:class => the_class, :title => the_title)) + end + end + + def button_to_function(type, label, js_code, html_options = {}, &block) + html_options[:class] = "button with-text" unless html_options[:class] + html_options[:class] << " icon-#{type}" + link_to_function(label, js_code, html_options, &block) + end + + def button_to_function_without_text(type, label, js_code, html_options = {}, &block) + html_options[:class] = "" unless html_options[:class] + html_options[:class] << " button icon-#{type}" + link_to_function(content_tag('span', label), js_code, html_options, &block) + end + + def button_to_remote(type, label, options, html_options = {}) + html_options[:class] = "button with-text" unless html_options[:class] + html_options[:class] << " icon-#{type}" + link_to_remote(label, options, html_options) + end + + def button_to_remote_without_text(type, label, options, html_options = {}) + html_options[:class] = "" unless html_options[:class] + html_options[:class] << " button icon-#{type}" + link_to_remote(content_tag('span', label), options, html_options.merge(:title => label)) + end +end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index efea953..30f0b3b 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -80,12 +80,6 @@ class ApplicationHelperTest < ActionView::TestCase assert_equal '', show_date(nil) end - - should 'append with-text class and keep existing classes' do - expects(:button_without_text).with('type', 'label', 'url', { :class => 'with-text class1'}) - button('type', 'label', 'url', { :class => 'class1' }) - end - should 'generate correct link to category' do cat = mock cat.expects(:path).returns('my-category/my-subcatagory') diff --git a/test/unit/article_block_test.rb b/test/unit/article_block_test.rb index aaa9072..6c00054 100644 --- a/test/unit/article_block_test.rb +++ b/test/unit/article_block_test.rb @@ -87,7 +87,8 @@ require 'block_helper' class ArticleBlockViewTest < ActionView::TestCase include BoxesHelper - ActionView::Base.send :include, ApplicationHelper + ActionView::Base.send :include, ArticleHelper + ActionView::Base.send :include, ButtonsHelper ActionView::Base.send :include, BlockHelper should "take article's content" do @@ -157,6 +158,5 @@ class ArticleBlockViewTest < ActionView::TestCase UploadedFile.any_instance.stubs(:url).returns('myhost.mydomain/path/to/file') assert_tag_in_string render_block_content(block), :tag => 'a', :content => _('Download') - end end diff --git a/test/unit/buttons_helper_test.rb b/test/unit/buttons_helper_test.rb new file mode 100644 index 0000000..0a40939 --- /dev/null +++ b/test/unit/buttons_helper_test.rb @@ -0,0 +1,11 @@ +# encoding: UTF-8 +require_relative "../test_helper" + +class ButtonsHelperTest < ActionView::TestCase + include ButtonsHelper + + should 'append with-text class and keep existing classes' do + expects(:button_without_text).with('type', 'label', 'url', { :class => 'with-text class1'}) + button('type', 'label', 'url', { :class => 'class1' }) + end +end \ No newline at end of file diff --git a/test/unit/manage_products_helper_test.rb b/test/unit/manage_products_helper_test.rb index 4bc2973..4e75443 100644 --- a/test/unit/manage_products_helper_test.rb +++ b/test/unit/manage_products_helper_test.rb @@ -5,6 +5,7 @@ class ManageProductsHelperTest < ActionView::TestCase include ManageProductsHelper include ContentViewerHelper + include ArticleHelper include ActionView::Helpers::AssetTagHelper include ApplicationHelper -- libgit2 0.21.2