Commit 68bc67de9dfeefb076c052152c618a6ef42f3326
Exists in
master
and in
27 other branches
Merge branch 'AI3031-community_track_embed_block' into rails235
Showing
13 changed files
with
146 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class EmbedController < ApplicationController | ||
2 | + layout 'embed' | ||
3 | + | ||
4 | + def block | ||
5 | + @block = Block.find(params[:id]) | ||
6 | + if !@block.embedable? || !@block.visible? | ||
7 | + render 'unavailable.rhtml', :status => 403 | ||
8 | + end | ||
9 | + rescue ActiveRecord::RecordNotFound | ||
10 | + render 'not_found.rhtml', :status => 404 | ||
11 | + end | ||
12 | + | ||
13 | +end |
app/helpers/boxes_helper.rb
@@ -219,6 +219,17 @@ module BoxesHelper | @@ -219,6 +219,17 @@ module BoxesHelper | ||
219 | buttons << thickbox_inline_popup_icon(:help, _('Help on this block'), {}, "help-on-box-#{block.id}") << content_tag('div', content_tag('h2', _('Help')) + content_tag('div', block.help, :style => 'margin-bottom: 1em;') + thickbox_close_button(_('Close')), :style => 'display: none;', :id => "help-on-box-#{block.id}") | 219 | buttons << thickbox_inline_popup_icon(:help, _('Help on this block'), {}, "help-on-box-#{block.id}") << content_tag('div', content_tag('h2', _('Help')) + content_tag('div', block.help, :style => 'margin-bottom: 1em;') + thickbox_close_button(_('Close')), :style => 'display: none;', :id => "help-on-box-#{block.id}") |
220 | end | 220 | end |
221 | 221 | ||
222 | + if block.embedable? | ||
223 | + embed_code = block.embed_code | ||
224 | + embed_code = instance_eval(&embed_code) if embed_code.respond_to?(:call) | ||
225 | + html = content_tag('div', | ||
226 | + content_tag('h2', _('Embed block code')) + | ||
227 | + content_tag('div', _('Below, you''ll see a field containing embed code for the block. Just copy the code and paste it into your website or blogging software.'), :style => 'margin-bottom: 1em;') + | ||
228 | + content_tag('textarea', embed_code, :style => 'margin-bottom: 1em; width:100%; height:40%;', :readonly => 'readonly') + | ||
229 | + thickbox_close_button(_('Close')), :style => 'display: none;', :id => "embed-code-box-#{block.id}") | ||
230 | + buttons << thickbox_inline_popup_icon(:embed, _('Embed code'), {}, "embed-code-box-#{block.id}") << html | ||
231 | + end | ||
232 | + | ||
222 | content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar') | 233 | content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar') |
223 | end | 234 | end |
224 | 235 |
app/models/block.rb
@@ -16,6 +16,23 @@ class Block < ActiveRecord::Base | @@ -16,6 +16,23 @@ class Block < ActiveRecord::Base | ||
16 | 16 | ||
17 | named_scope :enabled, :conditions => { :enabled => true } | 17 | named_scope :enabled, :conditions => { :enabled => true } |
18 | 18 | ||
19 | + def embedable? | ||
20 | + false | ||
21 | + end | ||
22 | + | ||
23 | + def embed_code | ||
24 | + me = self | ||
25 | + lambda do | ||
26 | + content_tag('iframe', '', | ||
27 | + :src => url_for(:controller => 'embed', :action => 'block', :id => me.id, :only_path => false), | ||
28 | + :frameborder => 0, | ||
29 | + :width => 1024, | ||
30 | + :height => 768, | ||
31 | + :class => "embed block #{me.class.name.to_css_class}" | ||
32 | + ) | ||
33 | + end | ||
34 | + end | ||
35 | + | ||
19 | # Determines whether a given block must be visible. Optionally a | 36 | # Determines whether a given block must be visible. Optionally a |
20 | # <tt>context</tt> must be specified. <tt>context</tt> must be a hash, and | 37 | # <tt>context</tt> must be specified. <tt>context</tt> must be a hash, and |
21 | # may contain the following keys: | 38 | # may contain the following keys: |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +<%= display_block(@block) %> |
@@ -0,0 +1,6 @@ | @@ -0,0 +1,6 @@ | ||
1 | +<div id='not-found'> | ||
2 | + <p> | ||
3 | + <%= _('You may have clicked an expired link or mistyped the address.') %> | ||
4 | + <%= _('If you clicked a link that was in another site, or was given to you by someone else, it would be nice if you tell them that their link is not valid anymore.') %> | ||
5 | + </p> | ||
6 | +</div> |
@@ -0,0 +1,35 @@ | @@ -0,0 +1,35 @@ | ||
1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
2 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= html_language %>" lang="<%= html_language %>"> | ||
3 | + <head> | ||
4 | + <title>Noosfero embed block</title> | ||
5 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
6 | + <%= noosfero_stylesheets %> | ||
7 | + <%= noosfero_javascript %> | ||
8 | + </head> | ||
9 | + <body class="<%= h body_classes %>"> | ||
10 | + <div id="embed"> | ||
11 | + <div id="wrap-1"> | ||
12 | + <div id="wrap-2"> | ||
13 | + <div id="content"> | ||
14 | + <div id="content-inner"> | ||
15 | + <div class="boxes" id="boxes"> | ||
16 | + <div class="box box-1" id="box-1"> | ||
17 | + <div class="blocks"> | ||
18 | + <%= yield %> | ||
19 | + </div> | ||
20 | + </div> | ||
21 | + </div> | ||
22 | + </div> | ||
23 | + </div> | ||
24 | + </div> | ||
25 | + </div> | ||
26 | + </div> | ||
27 | + | ||
28 | + <script type="text/javascript"> | ||
29 | + jQuery(document).ready(function(){ | ||
30 | + jQuery('a').attr('target','_blank'); | ||
31 | + }); | ||
32 | + </script> | ||
33 | + | ||
34 | + </body> | ||
35 | +</html> |
config/routes.rb
@@ -31,6 +31,9 @@ ActionController::Routing::Routes.draw do |map| | @@ -31,6 +31,9 @@ ActionController::Routing::Routes.draw do |map| | ||
31 | map.connect 'thumbnails/*stuff', :controller => 'not_found', :action => 'nothing' | 31 | map.connect 'thumbnails/*stuff', :controller => 'not_found', :action => 'nothing' |
32 | map.connect 'user_themes/*stuff', :controller => 'not_found', :action => 'nothing' | 32 | map.connect 'user_themes/*stuff', :controller => 'not_found', :action => 'nothing' |
33 | 33 | ||
34 | + # embed controller | ||
35 | + map.embed 'embed/:action/:id', :controller => 'embed', :id => /\d+/ | ||
36 | + | ||
34 | # online documentation | 37 | # online documentation |
35 | map.doc 'doc', :controller => 'doc', :action => 'index' | 38 | map.doc 'doc', :controller => 'doc', :action => 'index' |
36 | map.doc_section 'doc/:section', :controller => 'doc', :action => 'section' | 39 | map.doc_section 'doc/:section', :controller => 'doc', :action => 'section' |
plugins/community_track/lib/community_track_plugin/track_card_list_block.rb
@@ -12,4 +12,8 @@ class CommunityTrackPlugin::TrackCardListBlock < CommunityTrackPlugin::TrackList | @@ -12,4 +12,8 @@ class CommunityTrackPlugin::TrackCardListBlock < CommunityTrackPlugin::TrackList | ||
12 | 'track_card' | 12 | 'track_card' |
13 | end | 13 | end |
14 | 14 | ||
15 | + def embedable? | ||
16 | + true | ||
17 | + end | ||
18 | + | ||
15 | end | 19 | end |
public/designs/icons/tango/style.css
1 | /******************SMALL ICONS********************/ | 1 | /******************SMALL ICONS********************/ |
2 | +.icon-embed { background-image: url(Tango/16x16/apps/utilities-terminal.png) } | ||
2 | .icon-edit { background-image: url(Tango/16x16/apps/text-editor.png) } | 3 | .icon-edit { background-image: url(Tango/16x16/apps/text-editor.png) } |
3 | .icon-home { background-image: url(Tango/16x16/actions/go-home.png) } | 4 | .icon-home { background-image: url(Tango/16x16/actions/go-home.png) } |
4 | .icon-home-not { background-image: url(mod/16x16/actions/go-home-not.png) } | 5 | .icon-home-not { background-image: url(mod/16x16/actions/go-home-not.png) } |
@@ -0,0 +1,39 @@ | @@ -0,0 +1,39 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class EmbedControllerTest < ActionController::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + login_as(create_admin_user(Environment.default)) | ||
7 | + @block = LoginBlock.create! | ||
8 | + @block.class.any_instance.stubs(:embedable?).returns(true) | ||
9 | + @environment = Environment.default | ||
10 | + @environment.boxes.create! | ||
11 | + @environment.boxes.first.blocks << @block | ||
12 | + end | ||
13 | + | ||
14 | + should 'be able to get embed block' do | ||
15 | + get :block, :id => @block.id | ||
16 | + assert_tag :tag => 'div', :attributes => { :id => "block-#{@block.id}" } | ||
17 | + end | ||
18 | + | ||
19 | + should 'display error message when not found block' do | ||
20 | + Block.delete_all | ||
21 | + get :block, :id => 1 | ||
22 | + assert_tag :tag => 'div', :attributes => { :id => "not-found" } | ||
23 | + end | ||
24 | + | ||
25 | + should 'display error message when block is not visible/public' do | ||
26 | + @block.display = 'never' | ||
27 | + assert @block.save | ||
28 | + get :block, :id => @block.id | ||
29 | + assert_tag :tag => 'div', :attributes => { :id => "unavailable" } | ||
30 | + end | ||
31 | + | ||
32 | + should 'display error message when block is not embedable' do | ||
33 | + @block.class.any_instance.stubs(:embedable?).returns(false) | ||
34 | + get :block, :id => @block.id | ||
35 | + assert_tag :tag => 'div', :attributes => { :id => "unavailable" } | ||
36 | + end | ||
37 | + | ||
38 | + | ||
39 | +end |
test/integration/routing_test.rb
@@ -270,5 +270,8 @@ class RoutingTest < ActionController::IntegrationTest | @@ -270,5 +270,8 @@ class RoutingTest < ActionController::IntegrationTest | ||
270 | assert_routing('/work/free-software/versions', :controller => 'content_viewer', :action => 'article_versions', :page => [ 'work', 'free-software'] ) | 270 | assert_routing('/work/free-software/versions', :controller => 'content_viewer', :action => 'article_versions', :page => [ 'work', 'free-software'] ) |
271 | end | 271 | end |
272 | 272 | ||
273 | + should 'have route to get HTML code of Blocks to embed' do | ||
274 | + assert_routing('/embed/block/12345', :controller => 'embed', :action => 'block', :id => '12345') | ||
275 | + end | ||
273 | 276 | ||
274 | end | 277 | end |
test/unit/block_test.rb
@@ -223,6 +223,16 @@ class BlockTest < ActiveSupport::TestCase | @@ -223,6 +223,16 @@ class BlockTest < ActiveSupport::TestCase | ||
223 | assert !block.visible?(3) | 223 | assert !block.visible?(3) |
224 | end | 224 | end |
225 | 225 | ||
226 | + should 'not be embedable by default' do | ||
227 | + assert !Block.new.embedable? | ||
228 | + end | ||
229 | + | ||
230 | + should 'generate embed code' do | ||
231 | + b = Block.new | ||
232 | + b.stubs(:url_for).returns('http://myblogtest.com/embed/block/1') | ||
233 | + assert_equal "<iframe class=\"embed block block\" frameborder=\"0\" height=\"768\" src=\"http://myblogtest.com/embed/block/1\" width=\"1024\"></iframe>", b.embed_code.call | ||
234 | + end | ||
235 | + | ||
226 | should 'default value for display_user is all' do | 236 | should 'default value for display_user is all' do |
227 | block = Block.new | 237 | block = Block.new |
228 | assert_equal 'all', block.display_user | 238 | assert_equal 'all', block.display_user |