Permalink
Browse files

Added folder colorization + no file size for folders.

  • Loading branch information...
1 parent 96040c0 commit 1a7cf9506e4f7e7b1665f4f390276d830d20f9d5 @akoprow akoprow committed Mar 8, 2012
Showing with 59 additions and 45 deletions.
  1. +34 −30 resources/style.css
  2. +25 −15 src/dropbox.opa
View
@@ -1,38 +1,42 @@
- #Body {
- background-color: #444;
- }
- #terminal {
- border: 1px solid gray;
- padding: 4px;
- margin-top: 80px;
- overflow-y: scroll;
- width: 100%;
- height: 500px;
- font-family: courier, monospace;
- color: white;
- font-size: 14px;
- background-color: black;
- }
- .search-index {
- color: yellow;
- }
- .search-title {
- color: red;
- }
- .search-pubDate {
- color: dimgrey;
- }
- .username {
- color: lime;
- }
- .prompt {
- color: #0BC;
- }
+#Body {
+ background-color: #444;
+}
+#terminal {
+ border: 1px solid gray;
+ padding: 4px;
+ margin-top: 80px;
+ overflow-y: scroll;
+ width: 100%;
+ height: 500px;
+ font-family: courier, monospace;
+ color: white;
+ font-size: 14px;
+ background-color: black;
+}
+.search-index {
+ color: yellow;
+}
+.search-title {
+ color: red;
+}
+.search-pubDate {
+ color: dimgrey;
+}
+.username {
+ color: lime;
+}
+.prompt {
+ color: #0BC;
+}
pre {
display: block !important;
white-space: pre !important;
font-family: monospace !important;
background-color: transparent !important;
padding: 0px !important;
margin: 0px !important;
+ line-height: 14px;
+}
+.fn-type-folder {
+ color: #0BC;
}
View
@@ -11,7 +11,7 @@ database Dropbox.conf /dropbox_config
// only providing a single simple function?
type Dropbox.credentials = {no_credentials}
or {string request_secret, string request_token}
- or {Dropbox.creds authenticated}
+ or {Dropbox.creds authenticated, string path}
module DropboxConnect {
@@ -61,7 +61,7 @@ Please re-run your application with: --dropbox-config option")
case {success: s}:
dropbox_creds = {token: s.token, secret: s.secret}
Log.info("Dropbox", "got credentials: {dropbox_creds}")
- {authenticated: dropbox_creds}
+ {authenticated: dropbox_creds, path: "/"}
default:
authentication_failed
}
@@ -98,29 +98,39 @@ Please re-run your application with: --dropbox-config option")
private date_printer = Date.generate_printer("%Y-%m-%d %k:%M")
- private function show_element(Dropbox.element element) {
- info =
+ private function show_element(path, Dropbox.element element) {
+ function get_name(fname) {
+ if (String.has_prefix(path, fname))
+ String.drop_left(String.length(path), fname)
+ else
+ fname
+ }
+ (info, fname, size) =
match (element) {
- case {file, ~metadata, ...}: metadata
- case {folder, ~metadata, ...}: metadata
+ case {file, ~metadata, ...}:
+ name = get_name(metadata.path)
+ (metadata, <>{name}</>, "{metadata.size}")
+ case {folder, ~metadata, ...}:
+ name = <span class="fn-type-folder">{get_name(metadata.path)}</>
+ (metadata, name, "")
}
- size = "{info.size}"
- modification = Option.map(Date.to_formatted_string(date_printer, _), info.modified) ? ""
- name = info.path
- <pre>{size |> pad(10, _)} {modification |> pad(16, _)} {name}</>
+ final_size = size |> pad(10, _)
+ show_date = Date.to_formatted_string(date_printer, _)
+ modification = Option.map(show_date, info.modified) ? ""
+ <pre>{final_size} {modification} {fname}</>
}
- private function files_to_xhtml(files) {
- <>{List.map(show_element, files)}</>
+ private function files_to_xhtml(files, path) {
+ <>{List.map(show_element(path, _), files)}</>
}
function ls(creds) {
match (creds) {
- case {authenticated: creds}:
- db_files = DB.Files("dropbox", "/").metadata(DB.default_metadata_options, creds)
+ case {authenticated: creds, ~path}:
+ db_files = DB.Files("dropbox", path).metadata(DB.default_metadata_options, creds)
response =
match (db_files) {
- case {success: {~contents, ...}}: files_to_xhtml(contents ? [])
+ case {success: {~contents, ...}}: files_to_xhtml(contents ? [], path)
default: <>Dropbox connection failed</>
}
Service.respond_with(response)

0 comments on commit 1a7cf95

Please sign in to comment.