Skip to content

Commit

Permalink
Bug fixed: An empty block is not rendered with latest Liquid (incl. u…
Browse files Browse the repository at this point in the history
…pdated tests) (#2)
  • Loading branch information
sectore committed Oct 1, 2013
1 parent 24786cf commit f2ba700
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 106 deletions.
35 changes: 16 additions & 19 deletions lib/jekyll-swfobject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ class SWFObjectTag < Liquid::Block
)

@@DEFAULTS = {
:content_id => 'flashcontent',
:width => '100%',
:height => '100%',
:version => '10.0',
:flashvars => '',
:alternative_content => "<p>Please install latest <a href='http://www.adobe.com/go/getflashplayer'>Flash Player Plugin</a>.</p>"
:content_id => 'flashcontent',
:width => '100%',
:height => '100%',
:version => '10.0',
:flashvars => ''
}

def self.DEFAULTS
return @@DEFAULTS
end

def initialize(tag_name, text, tokens)
def initialize(tag_name, markup, tokens)
super

@config = {}
Expand All @@ -60,7 +59,7 @@ def initialize(tag_name, text, tokens)
override_config(config)
end

params = text.split
params = markup.split

# first argument (required) is url of swf
@swf_url = params.shift.strip
Expand All @@ -83,17 +82,22 @@ def override_config(config)
end

def render(context)
output = super
content = super

# raise an error if the swfobject block has no content
if content.strip.size <= 0
raise ScriptError.new("swfobject tag can not be empty")
end

<<-HTML.gsub /^\s+/, '' # remove whitespaces from heredocs
<div id="#{@config[:content_id]}-wrapper" style="width: #{@config[:width]}; height: #{@config[:height]}">
<div id="#{@config[:content_id]}" style="width: 100%; height:100%">#{render_alternative_content(output)}</div>
<div id="#{@config[:content_id]}" style="width: 100%; height:100%">#{content}</div>
</div>
<script type="text/javascript">
// <![CDATA[
#{render_flashvars()}
#{render_params()}
#{render_attributes()}
#{render_params()}
#{render_attributes()}
swfobject.embedSWF(
'#{@swf_url}',
'#{@config[:content_id]}',
Expand All @@ -111,13 +115,6 @@ def render(context)
HTML
end

def render_alternative_content(output)
unless output.strip.size > 0
output = @config[:alternative_content]
end
output
end

def render_params
result = 'var params = {'
@config.each do |key, value|
Expand Down
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'test/unit'
require 'test/unit/assertions'
require 'jekyll'
require 'liquid.rb'
require_relative '../lib/jekyll-swfobject'

# Test assertion helper to check template result
Expand All @@ -26,7 +27,7 @@ def getDefaultData
:content_id => Jekyll::SWFObject::SWFObjectTag.DEFAULTS[:content_id],
:width => Jekyll::SWFObject::SWFObjectTag.DEFAULTS[:width],
:height => Jekyll::SWFObject::SWFObjectTag.DEFAULTS[:height],
:alternative_content => Jekyll::SWFObject::SWFObjectTag.DEFAULTS[:alternative_content],
:alternative_content => "Flash Player required.",
:flashvars => 'var flashvars = {};',
:params => 'var params = {};',
:attributes => 'var attributes = {};',
Expand Down
Loading

0 comments on commit f2ba700

Please sign in to comment.