Skip to content
Browse files

Support for per-user backgrounds.

  • Loading branch information...
1 parent 5242054 commit 7f2dbe0a4fc54882d94090240c5f649da3727a66 @akoprow akoprow committed May 4, 2011
Showing with 77 additions and 23 deletions.
  1. +1 −1 Makefile
  2. BIN img/default_bg.png
  3. BIN img/mlstate.png
  4. +9 −5 src/data.opa
  5. +9 −2 src/main.opa
  6. +14 −5 src/pages.opa
  7. +44 −10 src/user.opa
View
2 Makefile
@@ -26,4 +26,4 @@ doc: $(SRC) clean
@firefox doc/index.html &
clean:
- rm -rf *.opx *.opx.broken *.exe _tracks _build opa-debug *.log src/*.api*
+ rm -rf *.opx *.opx.broken *.exe _tracks _build opa-debug *.log src/*.api* opadoc.apix
View
BIN img/default_bg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN img/mlstate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
14 src/data.opa
@@ -5,20 +5,20 @@
package mlstate.twopenny
-/** Users in the system **/
+/** Users in the system */
db /users : stringmap(User.t)
db /users[_]/photo full
db /users[_]/wallpaper full
-/** Messages posted by users **/
+/** Messages posted by the users */
// msg_ref -> msg
db /msgs : Msg.map(Msg.t)
-/** Messages posted by users **/
+/** Messages posted by users */
// user -> date -> msg_ref
db /user_msg : User.map(Date.map(Msg.ref))
-/** References to messages mentioning given users **/
+/** References to messages mentioning given users */
// user -> date -> msg_ref
db /user_mentions : User.map(Date.map(Msg.ref))
@@ -47,7 +47,11 @@ init_data_store() =
; url = "http://mlstate.com"
; photo = some({png = @static_binary_content("img/mlstate.png")})
; passwd = ""
- ; wallpaper = some({png = @static_binary_content("img/mlstate-bg.png")})
+ ; wallpaper =
+ { img = some({png = @static_binary_content("img/mlstate-bg.png")})
+ ; tile = false
+ ; color = Color.of_string("#155B9C")
+ }
}
/users["mlstate"] <- mlstate
| _ ->
View
11 src/main.opa
@@ -9,11 +9,14 @@ package mlstate.twopenny
* {1 Server definition, URL dispatching}
**/
-twopenny_page((title, content))(_req) =
+twopenny_page((title, content, style))(_req) =
body =
<div id=#page>
- {content}
+ <div id=#main>
+ {content}
+ </>
</>
+ |> apply_css(style, _)
Resource.html(title, body)
resources = @static_include_directory("img")
@@ -29,6 +32,10 @@ urls : Parser.general_parser(http_request -> resource) =
Text.to_string(user)
|> User.mk_ref(_)
|> User.get_user_photo_resource(_)
+ | "/img/user-bg/" user=(.*) -> _req ->
+ Text.to_string(user)
+ |> User.mk_ref(_)
+ |> User.get_user_wallpaper_resource(_)
| "/user/" user=(.*) ->
Text.to_string(user)
|> User.mk_ref(_)
View
19 src/pages.opa
@@ -16,8 +16,10 @@ Pages = {{
Coming soon... stay tuned
</>
+ empty_style = []
+
main_page() =
- ("Twopenny", unimplemented)
+ ("Twopenny", unimplemented, empty_style)
@client show_new_message(~{newmsg}) =
exec([#msgs -<- Msg.render(newmsg, {new})])
@@ -47,30 +49,37 @@ Pages = {{
<div class="separator" />
<div id=#msgs onready={setup_msg_updates} />
</>
- ("Twopenny :: {user_string}", content)
+ style = User.get_wallpaper_css(user_ref)
+ ("Twopenny :: {user_string}", content, style)
label_page(label) =
- ("Twopenny :: {Label.to_string(label)}", unimplemented)
+ ("Twopenny :: {Label.to_string(label)}", unimplemented, empty_style)
}}
css = [ page_css, msg_css, msg_box_css, user_css ]
page_css = css
+ body, html, #page {
+ width: 100%;
+ height: 100%;
+ }
body {
margin: 0px;
}
- html {
+ #main {
width: 800px;
margin: auto;
height: 100%;
padding: 15px;
border-left: 1px dotted black;
border-right: 1px dotted black;
+ background: #EEE;
+ opacity: .7;
}
h2 {
color: #777;
- /* FIXME writing helvetica passes syntax checking and is interpreted
+ /* FIXME writing helvetica (small 'h') passes syntax checking and is interpreted
as un-typed CSS, so goes verbose to the page as font:helvetica;
Not cool! */
font-family: Helvetica;
View
54 src/user.opa
@@ -5,6 +5,12 @@
package mlstate.twopenny
+type User.wallpaper =
+ { img : option(image)
+ ; tile : bool
+ ; color : option(color)
+ }
+
type User.t =
/** Name of the user (this is not the login) **/
{ name : string
@@ -26,7 +32,7 @@ type User.t =
/** User's profile photo **/
; photo : option(image)
/** User's wallpaper **/
- ; wallpaper : option(image)
+ ; wallpaper : User.wallpaper
}
type User.ref = private(string)
@@ -35,9 +41,17 @@ type User.map('a) = ordered_map(User.ref, 'a, String.order)
User =
- default_user_photo : resource =
- img = {png = @static_binary_content("img/user.png")}
- Resource.image(img)
+ default_user_photo : image =
+ {png = @static_binary_content("img/user.png")}
+
+ default_user_wallpaper_img : image =
+ {png = @static_binary_content("img/default_bg.png")}
+
+ default_user_wallpaper : User.wallpaper =
+ { img = some(default_user_wallpaper_img)
+ ; tile = false
+ ; color = some(Color.white)
+ }
max_profile_photo_size =
{ max_height_px = 80 max_width_px = 80 }
@@ -56,13 +70,21 @@ User =
get(user_ref : User.ref) : option(User.t) =
?/users[@unwrap(user_ref)]
+ @private get_user_optional_image(user_ref, get_photo, default_photo) =
+ img =
+ match get(user_ref) with
+ | {none} -> default_photo
+ | ~{some=user} ->
+ match get_photo(user) with
+ | {some=photo} -> photo
+ | {none} -> default_photo
+ Resource.image(img)
+
get_user_photo_resource(user_ref : User.ref) : resource =
- match get(user_ref) with
- | {none} -> default_user_photo
- | ~{some=user} ->
- match user.photo with
- | {some=photo} -> Resource.image(photo)
- | {none} -> default_user_photo
+ get_user_optional_image(user_ref, (user -> user.photo), default_user_photo)
+
+ get_user_wallpaper_resource(user_ref : User.ref) : resource =
+ get_user_optional_image(user_ref, (user -> user.wallpaper.img), default_user_wallpaper_img)
ref_to_anchor(user_ref : User.ref) : xhtml =
user = @unwrap(user_ref)
@@ -81,6 +103,18 @@ User =
{User.ref_to_string(user_ref)}
</>
+ get_wallpaper_css(user_ref : User.ref) : css_properties =
+ wallpaper = Option.map((user -> user.wallpaper), get(user_ref)) ? default_user_wallpaper
+ user_bg =
+ { Css_build.no_background with
+ url = some(Url.make("/img/user-bg/{user_ref}"))
+ repeat = if wallpaper.tile then none else some({css_none})
+ color = wallpaper.color
+ }
+ css {
+ background: {user_bg}
+ }
+
}}
user_css = css

0 comments on commit 7f2dbe0

Please sign in to comment.
Something went wrong with that request. Please try again.