uwa 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/bin/uwa +63 -0
  2. data/lib/uwa.rb +3 -0
  3. data/lib/uwa/config.rb +8 -0
  4. data/lib/uwa/widget.rb +84 -0
  5. metadata +65 -0
data/bin/uwa ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'uwa'
4
+ require 'getoptlong'
5
+
6
+ CONFIG = {
7
+ :host => '0.0.0.0',
8
+ :port => '42080',
9
+ :dynamic => false,
10
+ :debug => false,
11
+ :path => '.'
12
+ }
13
+
14
+ OPTIONS = [
15
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT, 'Display this help' ],
16
+ [ '--host', '-b', GetoptLong::REQUIRED_ARGUMENT, 'Set host/ip' ],
17
+ [ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT, 'Set port' ],
18
+ [ '--path', '-i', GetoptLong::REQUIRED_ARGUMENT, 'Set path to scan for widget' ],
19
+ [ '--dynamic', '-r', GetoptLong::NO_ARGUMENT, 'Enable dynamic mode (auto reload)' ],
20
+ [ '--debug', '-d', GetoptLong::NO_ARGUMENT, 'Enable debug mode' ],
21
+ ]
22
+
23
+ opts = GetoptLong.new(*OPTIONS.collect{|o| o[0..-2]})
24
+ opts.each do |opt, arg|
25
+ case opt
26
+ when '--help'
27
+ puts "Usage #{File.basename(__FILE__)} [OPTION]"
28
+ OPTIONS.each do |opt|
29
+ default = CONFIG[opt.first[2..-1].to_sym]
30
+ default = default.nil? ? '' : "(default = #{default})"
31
+ puts "%2s, %-15s: %s %s" % [opt[1], opt[0], opt[3], default]
32
+ end
33
+ exit
34
+ when '--host'
35
+ CONFIG[:host] = arg
36
+ when '--port'
37
+ CONFIG[:port] = arg
38
+ when '--path'
39
+ CONFIG[:path] = arg
40
+ when '--dynamic'
41
+ CONFIG[:dynamic] = true
42
+ when '--debug'
43
+ CONFIG[:debug] = true
44
+ end
45
+ end
46
+
47
+ begin
48
+ m = Mongrel::HttpServer.new(CONFIG[:host], CONFIG[:port])
49
+ Dir[File.join(CONFIG[:path], '*')].each do |d|
50
+ if File.directory?(d)
51
+ name = File.basename(d)
52
+ require File.join(d, 'widget.rb')
53
+ klass = self.class.const_get(name.capitalize + 'Widget')
54
+ widget = klass.new
55
+ widget.script = File.join(d, 'script.js')
56
+ widget.css = File.join(d, 'style.css')
57
+ m.register('/' + name.downcase, widget)
58
+ end
59
+ end
60
+ m.run.join
61
+ rescue
62
+ puts "Error: #{$!.message}"
63
+ end
data/lib/uwa.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'mongrel'
2
+ require 'builder'
3
+ require 'uwa/widget'
data/lib/uwa/config.rb ADDED
@@ -0,0 +1,8 @@
1
+ module UWA
2
+ NAME = 'UWA'
3
+ VERSION = '0.1'
4
+ DESC = 'Widget server that implements UWA specs (http://dev.netvibes.com/doc/universal_widget_api)'
5
+ AUTHOR = 'Florent Solt'
6
+ EMAIL = 'florent@solt.biz'
7
+ HOMEPAGE = 'http://gnetvibes.rubyforge.org'
8
+ end
data/lib/uwa/widget.rb ADDED
@@ -0,0 +1,84 @@
1
+ require 'rubygems'
2
+
3
+ module UWA
4
+ class Widget < Mongrel::HttpHandler
5
+ attr_accessor :title, :icon, :apiVersion, :inline, :debugMode,
6
+ :preferences, :css, :script
7
+
8
+ def initialize
9
+ super
10
+ @author = 'No author'
11
+ @description = 'No description'
12
+ @title = 'Widget'
13
+ @icon = 'http://www.netvibes.com/favicon.ico'
14
+ @apiVersion = '1.0'
15
+ @inline = 'true'
16
+ @debugMode = 'false'
17
+ @preferences = []
18
+ @css = nil
19
+ @script = nil
20
+ @cache = {:config => nil, :css => nil, :script => nil}
21
+ end
22
+
23
+ def process(req,res)
24
+ res.start(200) do |head, out|
25
+ head["Content-Type"] = "text/html"
26
+ xml = Builder::XmlMarkup.new(:indent => 4, :target => out)
27
+ xml.instruct!
28
+ xml.declare! :DOCTYPE, :html, :PUBLIC, '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
29
+ xml.html(:xmlns => 'http://www.w3.org/1999/xhtml', 'xmlns:widget' => 'http://www.netvibes.com/ns/') do |xml|
30
+ xml.head do |xml|
31
+ xml.meta(:name => 'author', :content => @author)
32
+ xml.meta(:name => 'description', :content => @description)
33
+ xml.meta(:name => 'apiVersion', :content => @apiVersion)
34
+ xml.meta(:name => 'inline', :content => @inline)
35
+ xml.meta(:name => 'debugMode', :content => @debugMode)
36
+ xml.link(:rel => :stylesheet, :type => 'text/css', :href => 'http://www.netvibes.com/themes/uwa/style.css')
37
+ xml.script("", :type => 'text/javascript', :src => 'http://www.netvibes.com/js/UWA/load.js.php?env=Standalone')
38
+ xml.tag!('widget:preferences') do |xml|
39
+ @preferences.each do |pref|
40
+ xml.preference(pref)
41
+ end
42
+ end
43
+ xml.title(@title)
44
+ xml.link(:rel => :icon, :type => 'image/png', :href => @icon)
45
+ xml.style(css, :type => 'text/css')
46
+ xml.script(script, :type => 'text/javascript')
47
+ end
48
+ xml.body do |xml|
49
+ body xml
50
+ end
51
+ end
52
+ xml.target!
53
+ end
54
+ end
55
+
56
+ def script
57
+ begin
58
+ if CONFIG[:dynamic]
59
+ File.read(@script)
60
+ else
61
+ @cache[:script] ||= File.read(@script)
62
+ end
63
+ rescue Errno::ENOENT
64
+ nil
65
+ end
66
+ end
67
+
68
+ def css
69
+ begin
70
+ if CONFIG[:dynamic]
71
+ File.read(@css)
72
+ else
73
+ @cache[:css] ||= File.read(@css)
74
+ end
75
+ rescue Errno::ENOENT
76
+ nil
77
+ end
78
+ end
79
+
80
+ def body(xml)
81
+ xml.em('Loading...')
82
+ end
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: uwa
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.1"
7
+ date: 2007-03-25 00:00:00 +01:00
8
+ summary: Widget server that implements UWA specs (http://dev.netvibes.com/doc/universal_widget_api)
9
+ require_paths:
10
+ - lib
11
+ email: florent@solt.biz
12
+ homepage: http://gnetvibes.rubyforge.org
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Florent Solt
31
+ files:
32
+ - lib/uwa/config.rb
33
+ - lib/uwa/widget.rb
34
+ - lib/uwa.rb
35
+ test_files: []
36
+
37
+ rdoc_options: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ executables:
42
+ - uwa
43
+ extensions: []
44
+
45
+ requirements: []
46
+
47
+ dependencies:
48
+ - !ruby/object:Gem::Dependency
49
+ name: mongrel
50
+ version_requirement:
51
+ version_requirements: !ruby/object:Gem::Version::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "1.0"
56
+ version:
57
+ - !ruby/object:Gem::Dependency
58
+ name: builder
59
+ version_requirement:
60
+ version_requirements: !ruby/object:Gem::Version::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.1.1
65
+ version: