Improved block condition "path:..." by allowing wildchar.

Added weight data to CMS_BLOCK to be able to sort the block lists,
  and thus order the display of blocks.
Set negative weight for various core block, so that they appear first as expected.
The weight can be set and overwritten in cms.ini , by pref  blocks.{block_id}.weight=integer_weight.
This commit is contained in:
2015-10-16 17:22:22 +02:00
parent 788cf3738d
commit 05472abdd7
7 changed files with 91 additions and 8 deletions

View File

@@ -41,6 +41,8 @@ feature -- Evaluation
satisfied_for_response (res: CMS_RESPONSE): BOOLEAN
local
exp: like expression
l_path: READABLE_STRING_8
kmp: KMP_WILD
do
exp := expression
if exp.same_string ("is_front") then
@@ -50,7 +52,17 @@ feature -- Evaluation
elseif exp.same_string ("<none>") then
Result := False
elseif exp.starts_with ("path:") then
Result := res.location.same_string (exp.substring (6, exp.count))
l_path := exp.substring (6, exp.count)
if l_path.has ('*') then
if l_path.index_of ('*', 1) = l_path.count then
Result := res.location.starts_with_general (l_path.substring (1, l_path.count - 1))
else
create kmp.make (l_path, res.location)
Result := kmp.pattern_matches
end
else
Result := res.location.same_string (l_path)
end
end
end

View File

@@ -6,7 +6,12 @@ deferred class
CMS_BLOCK
inherit
COMPARABLE
DEBUG_OUTPUT
undefine
is_equal
end
feature -- Access
@@ -23,6 +28,10 @@ feature -- Access
html_options: detachable CMS_HTML_OPTIONS
-- Optional addition html options.
weight: INTEGER
-- Weight used to order blocks.
-- Default: 0;
feature -- Status report
is_empty: BOOLEAN
@@ -42,6 +51,14 @@ feature -- Status report
conditions: detachable LIST [CMS_BLOCK_CONDITION]
-- Optional block condition to be enabled.
feature -- Comparison
is_less alias "<" (other: like Current): BOOLEAN
-- <Precursor>.
do
Result := weight < other.weight
end
feature -- Element change
add_css_class (a_class: READABLE_STRING_8)
@@ -83,6 +100,12 @@ feature -- Element change
l_conditions.force (a_condition)
end
set_weight (w: like weight)
-- Set `weight' to `w'.
do
weight := w
end
feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8

View File

@@ -41,6 +41,16 @@ feature -- Element change
blocks.prune_all (b)
end
feature -- Sort
sort
local
cmp: QUICK_SORTER [CMS_BLOCK]
do
create cmp.make (create {COMPARABLE_COMPARATOR [CMS_BLOCK]})
cmp.sort (blocks)
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -15,9 +15,12 @@ inherit
select
out
end
SHARED_TEMPLATE_CONTEXT
rename
out as tpl_out
undefine
is_equal
end
create