Skip to content

Commit 1f6fce1

Browse files
committed
Improved theming for admin vs site.
- Added $theme_path, $base_path - Added CMS_RESPONSE.module_resource_url (...) instead of using hardcoded "/module/" + name + ... - Use base_path rather than base_url (note ROC CMS is not yet working with EWF standalone "base" url option)
1 parent 3dc478b commit 1f6fce1

File tree

19 files changed

+198
-40
lines changed

19 files changed

+198
-40
lines changed

examples/demo/site/modules/messaging/files/css/messaging.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.messaging-box fieldset {
2-
resize: both;
32
display: flex;
43
flex-wrap: wrap;
54
align-items: flex-start;

examples/demo/site/modules/messaging/files/scss/messaging.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.messaging-box {
22
fieldset {
3-
resize: both;
43
display: flex;
54
flex-wrap: wrap;
65
align-items: flex-start;

examples/demo/site/themes/bootstrap/page.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<!-- EWF CMS -->
7-
<link rel="stylesheet" href="{$site_url/}theme/css/style.css">
7+
<link rel="stylesheet" href="{$theme_path/}css/style.css">
88

99
<!-- jQuery dep -->
10-
<script src="{$site_url/}theme/js/jquery-1.10.2.min.js"></script>
11-
<script src="{$site_url/}theme/js/popup_search.js"></script>
10+
<script src="{$theme_path/}js/jquery-1.10.2.min.js"></script>
11+
<script src="{$theme_path/}js/popup_search.js"></script>
1212

1313
{if isset="$head"}{$head/}{/if}
1414
{if isset="$styles"}{$styles/}{/if}

modules/admin/cms_admin_module_administration.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ feature -- Hooks
133133
response_alter (a_response: CMS_RESPONSE)
134134
-- <Precursor>
135135
do
136-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/admin.css", Void), Void)
136+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/admin.css", Void), Void)
137137
end
138138

139139
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)

modules/auth/cms_authentication_module.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ feature -- Response Alter
11571157
response_alter (a_response: CMS_RESPONSE)
11581158
do
11591159
a_response.add_javascript_url ("https://www.google.com/recaptcha/api.js")
1160-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/auth.css", Void), Void)
1160+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/auth.css", Void), Void)
11611161
end
11621162

11631163
feature {NONE} -- Implementation

modules/blog/cms_blog_module.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ feature -- Hooks
139139

140140
response_alter (a_response: CMS_RESPONSE)
141141
do
142-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/blog.css", Void), Void)
142+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/blog.css", Void), Void)
143143
end
144144

145145
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)

modules/comments/cms_comments_module.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ feature -- Hooks
9090

9191
response_alter (a_response: CMS_RESPONSE)
9292
do
93-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/comments.css", Void), Void)
93+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/comments.css", Void), Void)
9494
end
9595

9696
end

modules/contact/src/cms_contact_module.e

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ feature -- Hooks
186186
l_tpl_block.set_value (l_recaptcha_site_key, "recaptcha_site_key")
187187
end
188188
a_response.add_block (l_tpl_block, "content")
189-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/contact.css", Void), Void)
189+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/contact.css", Void), Void)
190190
else
191191
debug ("cms")
192192
a_response.add_warning_message ("Error with block [" + a_block_id + "]")
@@ -200,7 +200,7 @@ feature -- Hooks
200200
local
201201
f: CMS_FORM
202202
do
203-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/contact.css", Void), Void)
203+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/contact.css", Void), Void)
204204
if attached smarty_template_block (Current, "contact", api) as l_tpl_block then
205205
if attached recaptcha_site_key (api) as l_recaptcha_site_key then
206206
l_tpl_block.set_value (l_recaptcha_site_key, "recaptcha_site_key")
@@ -281,7 +281,7 @@ feature -- Hooks
281281
do
282282
write_information_log (generator + ".handle_post_contact")
283283
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
284-
r.add_style (r.url ("/module/" + name + "/files/css/contact.css", Void), Void)
284+
r.add_style (r.module_resource_url (Current, "/files/css/contact.css", Void), Void)
285285
r.values.force (False, "has_error")
286286

287287
create vars.make_caseless (5)

modules/feed_aggregator/feed_aggregator_module.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ feature -- Hook
326326

327327
response_alter (a_response: CMS_RESPONSE)
328328
do
329-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/feed_aggregator.css", Void), Void)
329+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/feed_aggregator.css", Void), Void)
330330
end
331331

332332
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)

modules/files/cms_files_module.e

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ feature -- Handler
146146
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
147147

148148
-- add style
149-
r.add_style (r.url ("/module/" + name + "/files/css/files.css", Void), Void)
149+
r.add_style (r.module_resource_url (Current, "/files/css/files.css", Void), Void)
150150

151151
create body.make_empty
152152

@@ -245,7 +245,7 @@ feature -- Handler
245245
body.append ("<h1> Upload files </h1>%N")
246246

247247
-- set style
248-
r.add_style (r.url ("/module/" + name + "/files/css/files.css", Void), Void)
248+
r.add_style (r.module_resource_url (Current, "/files/css/files.css", Void), Void)
249249

250250
if api.has_permission (upload_files_permission) then
251251
body.append ("<p>Please choose file(s) to upload.</p>")
@@ -269,8 +269,8 @@ feature -- Handler
269269
body.append ("<a href=%""+ r.url (uploads_location, Void) +"?basic_upload=no%">Use advanced file uploading.</a>%N")
270270
else
271271
-- add JS for dropzone
272-
r.add_javascript_url (r.url ("/module/" + name + "/files/js/dropzone.js", Void))
273-
r.add_style (r.url ("/module/" + name + "/files/js/dropzone.css", Void), Void)
272+
r.add_javascript_url (r.module_resource_url (Current, "/files/js/dropzone.js", Void))
273+
r.add_style (r.module_resource_url (Current, "/files/js/dropzone.css", Void), Void)
274274

275275
-- create form to choose files and upload them
276276
body.append ("<form action=%"" + r.url (uploads_location, Void) + "%" class=%"dropzone%">")

modules/messaging/src/cms_messaging_module.e

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ feature -- Hooks
109109
local
110110
f: CMS_FORM
111111
do
112-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/messaging.css", Void), Void)
112+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/messaging.css", Void), Void)
113113
-- TODO: use template to overwrite/customize
114114
-- if attached smarty_template_block (Current, "messaging", api) as l_tpl_block then
115115
-- across
@@ -215,7 +215,7 @@ $(document).ready(function() {
215215
});
216216
});
217217
</script>
218-
]")
218+
]")
219219
Result := f
220220
end
221221

@@ -249,7 +249,7 @@ $(document).ready(function() {
249249
do
250250
if api.has_permission ("message any user") then
251251
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
252-
r.add_style (r.url ("/module/" + name + "/files/css/messaging.css", Void), Void)
252+
r.add_style (r.module_resource_url (Current, "/files/css/messaging.css", Void), Void)
253253

254254
create s.make_empty
255255

modules/node/cms_node_module.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ feature -- Hooks
224224
response_alter (a_response: CMS_RESPONSE)
225225
-- <Precursor>
226226
do
227-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/node.css", Void), Void)
227+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/node.css", Void), Void)
228228
end
229229

230230
block_list: ITERABLE [like {CMS_BLOCK}.name]

modules/taxonomy/cms_taxonomy_module.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ feature -- Hooks
147147

148148
response_alter (a_response: CMS_RESPONSE)
149149
do
150-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/taxonomy.css", Void), Void)
150+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/taxonomy.css", Void), Void)
151151
end
152152

153153
end

modules/wikitext/wikitext_module.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ feature -- Hooks
6464

6565
response_alter (a_response: CMS_RESPONSE)
6666
do
67-
a_response.add_style (a_response.url ("/module/" + name + "/files/css/wikitext.css", Void), Void)
67+
a_response.add_style (a_response.module_resource_url (Current, "/files/css/wikitext.css", Void), Void)
6868
end
6969

7070
end

src/configuration/cms_setup.e

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ feature {NONE} -- Initialization
9999
end
100100

101101
-- Selected theme's name
102-
site_theme_name := text_item_or_default ("theme", "default")
102+
site_theme_name := text_item_or_default ("site.theme", "default")
103103
set_theme (site_theme_name)
104104

105105
-- Administration
@@ -325,6 +325,18 @@ feature -- Settings
325325
is_debug: BOOLEAN
326326
-- Is debug mode enabled?
327327

328+
set_site_mode
329+
-- Switch to site mode.
330+
--| - Change theme
331+
--| - ..
332+
do
333+
if is_theme_valid (site_theme_name) then
334+
set_theme (site_theme_name)
335+
else
336+
-- Keep previous theme!
337+
end
338+
end
339+
328340
set_administration_mode
329341
-- Switch to administration mode.
330342
--| - Change theme
@@ -341,7 +353,7 @@ feature -- Settings
341353
-- Set theme to `a_name`.
342354
do
343355
theme_name := a_name.as_string_32
344-
theme_location := themes_location.extended (theme_name)
356+
theme_location := theme_location_for (theme_name)
345357
end
346358

347359
feature -- Query
@@ -417,7 +429,7 @@ feature -- Access: theme
417429
local
418430
fu: FILE_UTILITIES
419431
do
420-
Result := fu.directory_path_exists (themes_location.extended (a_theme_name))
432+
Result := fu.directory_path_exists (theme_location_for (a_theme_name))
421433
end
422434

423435
theme_information_location: PATH
@@ -437,6 +449,12 @@ feature -- Access: theme
437449
-- Default: same as site theme.
438450
-- TODO: change to builtin "admin" theme?
439451

452+
theme_location_for (a_theme_name: READABLE_STRING_GENERAL): PATH
453+
-- Theme directory location for theme `a_theme_name`.
454+
do
455+
Result := themes_location.extended (a_theme_name)
456+
end
457+
440458
feature -- Access
441459

442460
mailer: NOTIFICATION_MAILER

src/service/cms_api.e

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ feature {NONE} -- Initialize
116116
initialize_site_url
117117
-- Initialize site and base url.
118118
local
119+
l_base_url: detachable READABLE_STRING_8
119120
l_url: detachable STRING_8
120121
i,j: INTEGER
121122
do
@@ -134,12 +135,23 @@ feature {NONE} -- Initialize
134135
if i > 0 then
135136
j := l_url.index_of ('/', i + 3)
136137
if j > 0 then
137-
base_url := l_url.substring (j, l_url.count)
138+
l_base_url := l_url.substring (j, l_url.count)
138139
end
139140
end
141+
if l_base_url /= Void then
142+
base_url := l_base_url
143+
if l_base_url.ends_with_general ("/") then
144+
create base_path.make_from_string (l_base_url)
145+
else
146+
create base_path.make_from_string (l_base_url + "/")
147+
end
148+
else
149+
create base_path.make_from_string ("/")
150+
end
140151
ensure
141152
site_url_set: site_url /= Void
142153
site_url_ends_with_slash: site_url.ends_with_general ("/")
154+
base_path_set: base_path /= Void and then base_path.ends_with_general ("/")
143155
end
144156

145157
initialize_content_types
@@ -380,6 +392,9 @@ feature -- Access: url
380392
--| Usually it is Void, but it could be
381393
--| /project/demo/
382394

395+
base_path: IMMUTABLE_STRING_8
396+
-- Base path, default to "/"
397+
383398
site_url: IMMUTABLE_STRING_8
384399
-- Site url
385400

@@ -493,10 +508,20 @@ feature -- Helpers: html links
493508

494509
feature -- Settings
495510

511+
switch_to_site_mode
512+
do
513+
if is_administration_mode then
514+
setup.set_site_mode
515+
is_administration_mode := False
516+
end
517+
end
518+
496519
switch_to_administration_mode
497520
do
498-
setup.set_administration_mode
499-
is_administration_mode := True
521+
if not is_administration_mode then
522+
setup.set_administration_mode
523+
is_administration_mode := True
524+
end
500525
end
501526

502527
is_administration_mode: BOOLEAN
@@ -1101,6 +1126,14 @@ feature -- Environment/ theme
11011126
Result := setup.files_location
11021127
end
11031128

1129+
files_path: STRING_8
1130+
do
1131+
create Result.make_from_string (base_path)
1132+
Result.append ("files/")
1133+
ensure
1134+
ends_with_slash: Result.ends_with ("/")
1135+
end
1136+
11041137
cache_location: PATH
11051138
-- CMS internal cache location.
11061139
do
@@ -1118,16 +1151,44 @@ feature -- Environment/ theme
11181151
Result := setup.theme_name
11191152
end
11201153

1154+
theme_path: STRING_8
1155+
-- URL path to the theme.
1156+
do
1157+
Result := theme_path_for (theme_name)
1158+
ensure
1159+
ends_with_slash: Result.ends_with ("/")
1160+
end
1161+
11211162
theme_assets_location: PATH
11221163
-- assets (js, css, images, etc).
11231164
do
1124-
debug ("refactor_fixme")
1125-
fixme ("Check if we really need it")
1126-
end
11271165
-- Check how to get this path from the CMS_THEME information.
11281166
Result := theme_location.extended ("assets")
11291167
end
11301168

1169+
feature -- Theming path helpers
1170+
1171+
theme_location_for (a_theme_name: READABLE_STRING_GENERAL): PATH
1172+
do
1173+
Result := setup.theme_location_for (a_theme_name)
1174+
end
1175+
1176+
theme_path_for (a_theme_name: READABLE_STRING_GENERAL): STRING_8
1177+
-- URL path to the theme `a_theme_name`.
1178+
do
1179+
create Result.make_from_string (base_path)
1180+
Result.append ("theme/")
1181+
Result.append (url_encoded (a_theme_name))
1182+
Result.append_character ('/')
1183+
ensure
1184+
ends_with_slash: Result.ends_with ("/")
1185+
end
1186+
1187+
theme_assets_location_for (a_theme_name: READABLE_STRING_GENERAL): PATH
1188+
do
1189+
Result := theme_location_for (a_theme_name).extended ("assets")
1190+
end
1191+
11311192
feature -- Environment/ module
11321193

11331194
module_configuration (a_module: CMS_MODULE; a_name: detachable READABLE_STRING_GENERAL): detachable CONFIG_READER

0 commit comments

Comments
 (0)