]> gitweb.factorcode.org Git - factor.git/commitdiff
webbrowser: open url's in your webbrowser.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 13 Nov 2011 00:18:52 +0000 (16:18 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 13 Nov 2011 00:18:52 +0000 (16:18 -0800)
extra/webbrowser/authors.txt [new file with mode: 0644]
extra/webbrowser/linux/linux.factor [new file with mode: 0644]
extra/webbrowser/linux/platforms.txt [new file with mode: 0644]
extra/webbrowser/macosx/macosx.factor [new file with mode: 0644]
extra/webbrowser/macosx/platforms.txt [new file with mode: 0644]
extra/webbrowser/summary.txt [new file with mode: 0644]
extra/webbrowser/webbrowser-docs.factor [new file with mode: 0644]
extra/webbrowser/webbrowser.factor [new file with mode: 0644]
extra/webbrowser/windows/platforms.txt [new file with mode: 0644]
extra/webbrowser/windows/windows.factor [new file with mode: 0644]

diff --git a/extra/webbrowser/authors.txt b/extra/webbrowser/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/webbrowser/linux/linux.factor b/extra/webbrowser/linux/linux.factor
new file mode 100644 (file)
index 0000000..5a9a8ae
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2011 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: formatting io.launcher present system urls webbrowser ;
+
+IN: webbrowser.unix
+
+M: unix open-file ( path -- )
+    "gnome-open \"%s\"" sprintf try-process ;
+
+M: unix open-url ( url -- )
+    >url present open-file ;
+
diff --git a/extra/webbrowser/linux/platforms.txt b/extra/webbrowser/linux/platforms.txt
new file mode 100644 (file)
index 0000000..a08e1f3
--- /dev/null
@@ -0,0 +1 @@
+linux
diff --git a/extra/webbrowser/macosx/macosx.factor b/extra/webbrowser/macosx/macosx.factor
new file mode 100644 (file)
index 0000000..a510c7c
--- /dev/null
@@ -0,0 +1,15 @@
+! Copyright (C) 2011 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: formatting io.encodings.ascii io.launcher present system
+urls webbrowser ;
+
+IN: webbrowser.macosx
+
+M: macosx open-file ( path -- )
+    "open \"%s\"" sprintf try-process ;
+
+M: macosx open-url ( url -- )
+    >url present "osascript" ascii [
+        "open location \"%s\"" printf
+    ] with-process-writer ;
diff --git a/extra/webbrowser/macosx/platforms.txt b/extra/webbrowser/macosx/platforms.txt
new file mode 100644 (file)
index 0000000..6e806f4
--- /dev/null
@@ -0,0 +1 @@
+macosx
diff --git a/extra/webbrowser/summary.txt b/extra/webbrowser/summary.txt
new file mode 100644 (file)
index 0000000..65e60ae
--- /dev/null
@@ -0,0 +1 @@
+Open URLs in your web browser
diff --git a/extra/webbrowser/webbrowser-docs.factor b/extra/webbrowser/webbrowser-docs.factor
new file mode 100644 (file)
index 0000000..264de1d
--- /dev/null
@@ -0,0 +1,19 @@
+! Copyright (C) 2011 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: help.markup help.syntax strings webbrowser ;
+
+IN: webbrowser
+
+HELP: open-file
+{ $values { "path" string } }
+{ $description
+    "Open a specified file or directory using the default "
+    "application, similar to double-clicking the file's icon."
+} ;
+
+HELP: open-url
+{ $values { "url" string } }
+{ $description
+    "Open a specified url in the default web browser."
+} ;
diff --git a/extra/webbrowser/webbrowser.factor b/extra/webbrowser/webbrowser.factor
new file mode 100644 (file)
index 0000000..33160ca
--- /dev/null
@@ -0,0 +1,18 @@
+! Copyright (C) 2011 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: combinators system ui.operations urls vocabs ;
+
+IN: webbrowser
+
+HOOK: open-file os ( path -- )
+
+HOOK: open-url os ( url -- )
+
+{
+    { [ os macosx?  ] [ "webbrowser.macosx"  ] }
+    { [ os linux?   ] [ "webbrowser.linux"   ] }
+    { [ os windows? ] [ "webbrowser.windows" ] }
+} cond require
+
+[ url? ] \ open-url H{ } define-operation
diff --git a/extra/webbrowser/windows/platforms.txt b/extra/webbrowser/windows/platforms.txt
new file mode 100644 (file)
index 0000000..8e1a559
--- /dev/null
@@ -0,0 +1 @@
+windows
diff --git a/extra/webbrowser/windows/windows.factor b/extra/webbrowser/windows/windows.factor
new file mode 100644 (file)
index 0000000..f7cdd48
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2011 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: present urls webbrowser windows.shell32 windows.user32 ;
+
+IN: webbrowser.windows
+
+M: windows open-file ( path -- )
+    [ f "open" ] dip f f SW_SHOWNORMAL ShellExecute drop ;
+
+M: windows open-url ( url -- )
+    >url present open-file ;
+