diff --git a/cms-safe.ecf b/cms-safe.ecf index 2562261..0ddd5a4 100644 --- a/cms-safe.ecf +++ b/cms-safe.ecf @@ -1,5 +1,5 @@ - + @@ -14,14 +14,16 @@ - + + + @@ -30,7 +32,6 @@ - diff --git a/cms.ecf b/cms.ecf index 2c92e6d..efd3245 100644 --- a/cms.ecf +++ b/cms.ecf @@ -15,14 +15,16 @@ - + + + @@ -31,7 +33,6 @@ - diff --git a/src/kernel/content/block/condition/cms_block_expression_condition.e b/src/kernel/content/block/condition/cms_block_expression_condition.e index 531fef1..0691f84 100644 --- a/src/kernel/content/block/condition/cms_block_expression_condition.e +++ b/src/kernel/content/block/condition/cms_block_expression_condition.e @@ -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 ("") 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 diff --git a/src/kernel/content/cms_block.e b/src/kernel/content/cms_block.e index e629b93..544da41 100644 --- a/src/kernel/content/cms_block.e +++ b/src/kernel/content/cms_block.e @@ -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 + -- . + 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 diff --git a/src/kernel/content/cms_block_region.e b/src/kernel/content/cms_block_region.e index 750ebd6..b5b7929 100644 --- a/src/kernel/content/cms_block_region.e +++ b/src/kernel/content/cms_block_region.e @@ -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)" diff --git a/src/kernel/content/cms_smarty_template_block.e b/src/kernel/content/cms_smarty_template_block.e index bdb76b3..bfff2ab 100644 --- a/src/kernel/content/cms_smarty_template_block.e +++ b/src/kernel/content/cms_smarty_template_block.e @@ -15,9 +15,12 @@ inherit select out end + SHARED_TEMPLATE_CONTEXT rename out as tpl_out + undefine + is_equal end create diff --git a/src/service/response/cms_response.e b/src/service/response/cms_response.e index 1d22c8f..6adc338 100644 --- a/src/service/response/cms_response.e +++ b/src/service/response/cms_response.e @@ -423,7 +423,18 @@ feature -- Blocks initialization Result := setup.text_item_or_default ("blocks." + a_block_id + ".region", a_default_region) end -feature -- Block management +feature -- Block management + + update_block (a_block: CMS_BLOCK) + -- Update parameters for block `a_block' according to configuration. + do + if + attached setup.text_item ("blocks." + a_block.name + ".weight") as w and then + w.is_integer + then + a_block.set_weight (w.to_integer) + end + end block_conditions (a_block_id: READABLE_STRING_8): detachable ARRAYED_LIST [CMS_BLOCK_EXPRESSION_CONDITION] -- Condition associated with `a_block_id' in configuration, if any. @@ -567,6 +578,9 @@ feature -- Blocks end get_blocks + -- Get block from CMS core, and from modules. + local + l_region: CMS_BLOCK_REGION do debug ("refactor_fixme") fixme ("find a way to have this in configuration or database, and allow different order") @@ -592,6 +606,19 @@ feature -- Blocks end hooks.invoke_block (Current) + + across + regions as reg_ic + loop + l_region := reg_ic.item + across + l_region.blocks as ic + loop + update_block (ic.item) + end + l_region.sort + end + debug ("cms") put_block (create {CMS_CONTENT_BLOCK}.make ("made_with", Void, "Made with EWF", Void), "footer", True) end @@ -641,6 +668,7 @@ feature -- Blocks do create s.make_empty create Result.make ("page_top", Void, s, Void) + Result.set_weight (-5) Result.set_is_raw (True) end @@ -652,6 +680,7 @@ feature -- Blocks create s.make_from_string (theme.menu_html (primary_menu, True, Void)) create l_hb.make_empty create Result.make ("header", Void, l_hb, Void) + Result.set_weight (-4) Result.set_is_raw (True) end @@ -683,6 +712,7 @@ feature -- Blocks if attached message as m and then not m.is_empty then create Result.make ("message", Void, "
" + m + "
", Void) Result.set_is_raw (True) + Result.set_weight (-2) end end @@ -699,6 +729,7 @@ feature -- Blocks end end create Result.make ("content", Void, s, Void) + Result.set_weight (-1) Result.set_is_raw (True) end @@ -922,8 +953,10 @@ feature -- Generation across regions as reg_ic loop + l_region := reg_ic.item + -- region blocks Already sorted. across - reg_ic.item.blocks as ic + l_region.blocks as ic loop if attached {CMS_SMARTY_TEMPLATE_BLOCK} ic.item as l_tpl_block then -- Apply page variables to smarty block.