browser_gui 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -114,3 +114,24 @@ You can still pass arguments to Sinatra (such as setting the port number), like
114
114
  The double dash `--` stops the option processing in the script and passes the
115
115
  remaining options to Sinatra. The `-t` option is parsed by the script and the
116
116
  `-p` option is parsed by Sinatra.
117
+
118
+ ## Changing the initial URL that the browser opens
119
+
120
+ By default, the browser opens the URL `http://localhost:<port>/` where `<port>`
121
+ is the Sinatra port (4567 by default, but you can change that with the `-p port`
122
+ option). You can add parameters to the URL or change the URL to something else
123
+ by setting the `browser_url` variable, as in the following example.
124
+
125
+ ```
126
+ #!/usr/bin/env ruby
127
+
128
+ require "sinatra"
129
+ require "browser_gui"
130
+
131
+ # Change the URL that the browser opens to /hello and add a parameter.
132
+ set :browser_url, "/hello?world=1"
133
+
134
+ get "/hello" do
135
+ "params: #{params.inspect}"
136
+ end
137
+ ```
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "sinatra"
4
+ require "browser_gui"
5
+
6
+ # Change the URL that the browser opens to /hello and add a parameter.
7
+ set :browser_url, "/hello?world=1"
8
+
9
+ get "/hello" do
10
+ "params: #{params.inspect}"
11
+ end
@@ -1,3 +1,3 @@
1
1
  module BrowserGui
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/browser_gui.rb CHANGED
@@ -19,4 +19,8 @@ end
19
19
 
20
20
  # Sinatra uses an "at_exit" block to start the server, so we have to use
21
21
  # an "at_exit" block to open the browser.
22
- at_exit { BrowserGui.open_browser("http://localhost:#{settings.port}/") }
22
+ at_exit {
23
+ browser_url = settings.respond_to?(:browser_url) ? settings.browser_url : "/"
24
+ browser_host = settings.respond_to?(:browser_host) ? settings.browser_host : "localhost"
25
+ BrowserGui.open_browser("http://#{browser_host}:#{settings.port}#{browser_url}")
26
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser_gui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-22 00:00:00.000000000 Z
12
+ date: 2013-04-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Use with Sinatra to create command-line scripts that open the browser
15
15
  as a GUI.
@@ -25,6 +25,7 @@ files:
25
25
  - README.md
26
26
  - Rakefile
27
27
  - browser_gui.gemspec
28
+ - examples/browser_url.rb
28
29
  - examples/gui_optional.rb
29
30
  - examples/simple_form.rb
30
31
  - examples/simple_markdown.rb