From 417935cc972d1e6b3947441d67845ed980693251 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Thu, 26 Aug 2010 19:22:22 -0300 Subject: [PATCH] Add a Raw HTML block --- app/controllers/admin/environment_design_controller.rb | 2 +- app/models/raw_html_block.rb | 13 +++++++++++++ app/views/box_organizer/_raw_html_block.rhtml | 1 + test/unit/raw_html_block_test.rb | 25 +++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/models/raw_html_block.rb create mode 100644 app/views/box_organizer/_raw_html_block.rhtml create mode 100644 test/unit/raw_html_block_test.rb diff --git a/app/controllers/admin/environment_design_controller.rb b/app/controllers/admin/environment_design_controller.rb index 024fe21..ab139e2 100644 --- a/app/controllers/admin/environment_design_controller.rb +++ b/app/controllers/admin/environment_design_controller.rb @@ -3,7 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController protect 'edit_environment_design', :environment def available_blocks - @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock ] + @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock ] end end diff --git a/app/models/raw_html_block.rb b/app/models/raw_html_block.rb new file mode 100644 index 0000000..366c87a --- /dev/null +++ b/app/models/raw_html_block.rb @@ -0,0 +1,13 @@ +class RawHTMLBlock < Block + + def self.description + _('Raw HTML') + end + + settings_items :html, :type => :text + + def content + (title.blank? ? '' : block_title(title)) + html.to_s + end + +end diff --git a/app/views/box_organizer/_raw_html_block.rhtml b/app/views/box_organizer/_raw_html_block.rhtml new file mode 100644 index 0000000..8c84f98 --- /dev/null +++ b/app/views/box_organizer/_raw_html_block.rhtml @@ -0,0 +1 @@ +<%= labelled_form_field(_('HTML code'), text_area(:block, :html, :style => 'width: 100%', :rows => 15)) %> diff --git a/test/unit/raw_html_block_test.rb b/test/unit/raw_html_block_test.rb new file mode 100644 index 0000000..e2be8d6 --- /dev/null +++ b/test/unit/raw_html_block_test.rb @@ -0,0 +1,25 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class RawHTMLBlockTest < ActiveSupport::TestCase + + should 'describe itself' do + assert_not_equal Block.description, RawHTMLBlock.description + end + + should 'store HTML' do + block = RawHTMLBlock.new(:html => 'HTML!') + assert_equal 'HTML!', block.html + end + + should 'not filter HTML' do + html = '"' + block = RawHTMLBlock.new(:html => html) + assert_equal html, block.html + end + + should 'return html as content' do + block = RawHTMLBlock.new(:html => "HTML") + assert_match(/HTML$/, block.content) + end + +end -- libgit2 0.21.2