Improved video content filter to be more flexible, and allow custom template.
This commit is contained in:
@@ -24,8 +24,8 @@ feature {NONE} -- Initialization
|
||||
default_create
|
||||
do
|
||||
Precursor
|
||||
width := 420
|
||||
height := 315
|
||||
default_width := 420
|
||||
default_height := 315
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -38,6 +38,36 @@ feature -- Access
|
||||
|
||||
help: STRING = "Embed video using the following pattern: [video:url width:X height:Y], width and height are optionals."
|
||||
|
||||
feature -- Settings
|
||||
|
||||
default_width: INTEGER;
|
||||
-- Specifies the width of an <iframe> in pixels.
|
||||
|
||||
default_height: INTEGER
|
||||
-- Specifies the height of an <iframe> in pixels.
|
||||
|
||||
template: detachable READABLE_STRING_8
|
||||
-- Optional template using $url, $att .
|
||||
-- For instance:
|
||||
-- <iframe src="$url" $att></iframe>"
|
||||
|
||||
feature -- Settings change
|
||||
|
||||
set_default_width (w: like default_width)
|
||||
do
|
||||
default_width := w
|
||||
end
|
||||
|
||||
set_default_height (h: like default_height)
|
||||
do
|
||||
default_height := h
|
||||
end
|
||||
|
||||
set_template (tpl: like template)
|
||||
do
|
||||
template := tpl
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
filter (a_text: STRING_8)
|
||||
@@ -77,10 +107,10 @@ feature -- Conversion
|
||||
local
|
||||
i,j,n: INTEGER
|
||||
s,k,v: STRING_8
|
||||
l_url: STRING_8
|
||||
l_width, l_height: detachable STRING
|
||||
l_url, l_att: STRING_8
|
||||
l_width, l_height, l_extra: detachable STRING
|
||||
do
|
||||
s := a_text.substring (a_lower + 1, a_upper - 1)
|
||||
s := a_text.substring (a_lower + 7, a_upper - 1)
|
||||
s.left_adjust
|
||||
i := next_space_position (s, 1)
|
||||
if i > 0 then
|
||||
@@ -96,6 +126,8 @@ feature -- Conversion
|
||||
j := s.index_of (':', i)
|
||||
if j > 0 then
|
||||
k := s.head (j - 1)
|
||||
k.left_adjust
|
||||
k.right_adjust
|
||||
s.remove_head (j)
|
||||
s.left_adjust
|
||||
i := 1
|
||||
@@ -103,10 +135,14 @@ feature -- Conversion
|
||||
j := next_space_position (s, 1)
|
||||
if j > 0 then
|
||||
v := s.head (j - 1)
|
||||
v.left_adjust
|
||||
v.right_adjust
|
||||
s.remove_head (j)
|
||||
s.left_adjust
|
||||
else
|
||||
v := s.substring (i, n)
|
||||
v.left_adjust
|
||||
v.right_adjust
|
||||
s.wipe_out
|
||||
end
|
||||
n := s.count
|
||||
@@ -116,41 +152,69 @@ feature -- Conversion
|
||||
elseif k.is_case_insensitive_equal ("height") then
|
||||
l_height := v
|
||||
else
|
||||
check supported: False end
|
||||
-- Ignore
|
||||
end
|
||||
else
|
||||
s.left_adjust
|
||||
s.right_adjust
|
||||
if not s.is_whitespace then
|
||||
l_extra := s
|
||||
end
|
||||
i := n + 1
|
||||
end
|
||||
end
|
||||
else
|
||||
s.remove_head (6)
|
||||
l_url := s
|
||||
end
|
||||
if not l_url.is_whitespace then
|
||||
create Result.make_from_string ("<iframe src=%"")
|
||||
Result.append (l_url)
|
||||
Result.append_character ('%"')
|
||||
if l_width = Void then
|
||||
if width > 0 then
|
||||
l_width := width.out
|
||||
if default_width > 0 then
|
||||
l_width := default_width.out
|
||||
end
|
||||
end
|
||||
if l_height = Void then
|
||||
if height > 0 then
|
||||
l_height := height.out
|
||||
if default_height > 0 then
|
||||
l_height := default_height.out
|
||||
end
|
||||
end
|
||||
create l_att.make_empty
|
||||
if l_width /= Void then
|
||||
Result.append (" width=%"")
|
||||
Result.append (l_width)
|
||||
Result.append_character ('%"')
|
||||
if not l_att.is_empty then
|
||||
l_att.append_character (' ')
|
||||
end
|
||||
l_att.append ("width=%"")
|
||||
l_att.append (l_width)
|
||||
l_att.append_character ('%"')
|
||||
end
|
||||
if l_height /= Void then
|
||||
Result.append (" height=%"")
|
||||
Result.append (l_height)
|
||||
Result.append_character ('%"')
|
||||
if not l_att.is_empty then
|
||||
l_att.append_character (' ')
|
||||
end
|
||||
l_att.append ("height=%"")
|
||||
l_att.append (l_height)
|
||||
l_att.append_character ('%"')
|
||||
end
|
||||
if l_extra /= Void and then not l_extra.is_empty then
|
||||
if not l_att.is_empty and not l_extra[1].is_space then
|
||||
l_att.append_character (' ')
|
||||
end
|
||||
l_att.append (l_extra)
|
||||
end
|
||||
|
||||
if attached template as tpl then
|
||||
create Result.make_from_string (tpl)
|
||||
Result.replace_substring_all ("$url", l_url)
|
||||
Result.replace_substring_all ("$att", l_att)
|
||||
else
|
||||
create Result.make_from_string ("<iframe src=%"")
|
||||
Result.append (l_url)
|
||||
Result.append_character ('%"')
|
||||
if not l_att.is_empty then
|
||||
Result.append_character (' ')
|
||||
end
|
||||
Result.append (l_att)
|
||||
Result.append ("></iframe>")
|
||||
end
|
||||
Result.append ("frameborder=%"0%" allowfullscreen></iframe>")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -171,12 +235,23 @@ feature -- Conversion
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
next_non_space_position (a_text: STRING; a_start_index: INTEGER): INTEGER
|
||||
local
|
||||
n: INTEGER
|
||||
do
|
||||
from
|
||||
Result := a_start_index
|
||||
n := a_text.count
|
||||
until
|
||||
not a_text[Result].is_space or Result > n
|
||||
loop
|
||||
Result := Result + 1
|
||||
end
|
||||
if Result > n then
|
||||
Result := 0
|
||||
end
|
||||
end
|
||||
|
||||
width: INTEGER;
|
||||
-- Specifies the width of an <iframe> in pixels.
|
||||
|
||||
height: INTEGER
|
||||
-- Specifies the height of an <iframe> in pixels.
|
||||
invariant
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user