inspectorgadget 0.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.
@@ -0,0 +1,27 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class DslAttributeAccessorTest < Test::Unit::TestCase
4
+ include InspectorGadget
5
+
6
+ def test_dsl_attr_accessor_creates_methods
7
+ object = create_class_with_dsl_accessor
8
+ assert_respond_to(object, :foo)
9
+ assert_respond_to(object, :foo=)
10
+ end
11
+
12
+ def test_creates_traditional_and_dsl_writers
13
+ object = create_class_with_dsl_accessor
14
+ object.foo 'baz'
15
+ assert object.instance_variables.include?("@foo")
16
+
17
+ object = create_class_with_dsl_accessor
18
+ object.foo = 'bar'
19
+ assert object.instance_variables.include?("@foo")
20
+ end
21
+
22
+ def test_creates_traditional_reader
23
+ object = create_class_with_dsl_accessor
24
+ object.instance_variable_set "@foo", 'baz'
25
+ assert_equal 'baz', object.foo
26
+ end
27
+
28
+ def create_class_with_dsl_accessor
29
+ klass = Class.new
30
+ klass.extend DslAttrAccessor
31
+ klass.send(:dsl_attr_accessor, :foo)
32
+ klass.new
33
+ end
34
+ private :create_class_with_dsl_accessor
35
+
36
+ end
@@ -0,0 +1,86 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'rexml/document'
3
+
4
+ class GoogleGadgetSpecTest < Test::Unit::TestCase
5
+ include InspectorGadget
6
+ include REXML
7
+
8
+ def test_create_google_gadget_spec
9
+ gadget = GoogleGadgetSpec.new
10
+
11
+ mp = gadget.module_prefs
12
+ assert_instance_of ModulePreferences, gadget.module_prefs
13
+ assert_equal [], gadget.user_prefs
14
+ assert_equal :html, gadget.content_type
15
+ assert_nil gadget.content_href
16
+ assert_nil gadget.content
17
+ end
18
+
19
+ def test_setting_module_preferences
20
+ gadget = GoogleGadgetSpec.new
21
+
22
+ module_prefs = gadget.module_prefs do |mp|
23
+ assert_same gadget.module_prefs, mp
24
+ end
25
+
26
+ assert_same gadget.module_prefs, module_prefs
27
+ end
28
+
29
+ def test_add_user_preferences
30
+ gadget = GoogleGadgetSpec.new
31
+ new_user_pref = nil
32
+ gadget.user_pref do |up|
33
+ new_user_pref = up
34
+ end
35
+ assert_equal [new_user_pref], gadget.user_prefs
36
+ end
37
+
38
+ def test_forwards_NoMethodMethodError_to_super_after_method_missing_chain
39
+ assert_raise NoMethodError do
40
+ GoogleGadgetSpec.new do
41
+ hello
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_to_xml_file_using_string_content
47
+ gadget = GoogleGadgetSpec.new
48
+ gadget.user_pref :name => 'mycolor'
49
+ gadget.content = "hello world"
50
+
51
+ gadget.module_prefs.expects(:to_xml)
52
+ gadget.user_prefs.each{|up| up.expects(:to_xml)}
53
+ xml = gadget.to_xml
54
+
55
+ doc = Document.new(xml)
56
+ assert_xpath doc, "/Module"
57
+ assert_xpath doc, "/Module/Content"
58
+ assert_equal "hello world", cdata_value(doc, "/Module/Content")
59
+ end
60
+
61
+ def test_to_xml_file_using_IO_content
62
+ gadget = GoogleGadgetSpec.new
63
+ gadget.user_pref :name => 'mycolor'
64
+ gadget.content = IO.new(0)
65
+ gadget.module_prefs.expects(:to_xml)
66
+ gadget.user_prefs.each{|up| up.expects(:to_xml)}
67
+ gadget.content.expects(:readlines).returns(['mocked','content'])
68
+
69
+ xml = gadget.to_xml
70
+
71
+ doc = Document.new(xml)
72
+ assert_xpath doc, "/Module"
73
+ assert_xpath doc, "/Module/Content"
74
+ assert_equal "mockedcontent", cdata_value(doc, "/Module/Content")
75
+ end
76
+
77
+ def test_to_xml_writes_url_content_type_attributes
78
+ gadget = GoogleGadgetSpec.new do
79
+ content_type :url
80
+ content_href 'www.google.com'
81
+ end
82
+ doc = Document.new gadget.to_xml
83
+ assert_xpath(doc, "/Module/Content", :type => :url, :href => 'www.google.com')
84
+ end
85
+
86
+ end
@@ -0,0 +1,13 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/inspectorgadget'
3
+
4
+ #asserts number of elements returned by an xpath (executed on a ReXML doc)
5
+ def assert_xpath(doc, path, attributes = {}, expected_matches = 1)
6
+ xpath = path + "[" + attributes.collect{|k,v| "@#{k}='#{v}'"}.join(' and ') + "]"
7
+ assert_equal expected_matches, doc.get_elements(xpath).length
8
+ end
9
+
10
+ #first matching element's first cdata
11
+ def cdata_value(doc, xpath)
12
+ doc.root.get_elements(xpath)[0].cdatas[0].value
13
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestInspectorgadget < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,87 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'mocha'
3
+ require 'rexml/document'
4
+ require 'rexml/text'
5
+
6
+ class ModulePreferenceTest < Test::Unit::TestCase
7
+ include InspectorGadget
8
+ include REXML
9
+
10
+ def test_instantiating_with_hash_attributes
11
+ mp = ModulePreferences.new :title => 'hello world example'
12
+ assert_equal 'hello world example', mp.title
13
+ end
14
+
15
+ def test_require_feature
16
+ mp = ModulePreferences.new
17
+ mp.require_features "setprefs", "another1"
18
+ assert_equal ["setprefs", "another1"], mp.required_features
19
+ end
20
+
21
+ def test_may_require
22
+ mp = ModulePreferences.new
23
+ mp.may_require :browser, 'firefox'
24
+ mp.may_require :plugin, 'flash', :min_version => '8', :cdata => 'abcd'
25
+
26
+ assert_equal({:type => :browser, :value => 'firefox'}, mp.may_be_required.first)
27
+ assert_equal({:type => :plugin, :value => 'flash', :min_version => '8', :cdata => 'abcd'}, mp.may_be_required.last)
28
+ end
29
+
30
+ def test_locale_without_required_params
31
+ mp = ModulePreferences.new
32
+ assert_raise(ArgumentError) do
33
+ mp.supports_locale :messages => 'bundle.xml'
34
+ mp.supports_locale {}
35
+ end
36
+ assert_equal [], mp.supported_locales
37
+ end
38
+
39
+ def test_locale_with_required_params
40
+ mp = ModulePreferences.new
41
+ en_locale = {:lang => :en, :country => :us, :messages => 'bundle.xml'}
42
+ ar_locale = {:lang => :ar}
43
+ mp.supports_locale en_locale
44
+ mp.supports_locale ar_locale
45
+
46
+ assert_equal [en_locale, ar_locale], mp.supported_locales
47
+ end
48
+
49
+ def test_forwards_to_super_after_method_missing_chain
50
+ assert_raise(NoMethodError) do
51
+ mp = ModulePreferences.new
52
+ mp.hello
53
+ end
54
+ end
55
+
56
+ def test_to_xml_writes_attributes_hash_as_xml_element_attributes
57
+ mp = ModulePreferences.new :title => 'farooq'
58
+ xml = ''
59
+ builder = Builder::XmlMarkup.new(:target => xml)
60
+ mp.to_xml(builder)
61
+
62
+ #verify generated xml:
63
+ doc = Document.new xml
64
+ assert_xpath doc, "/ModulePrefs", :title => 'farooq'
65
+ end
66
+
67
+ def test_to_xml_writes_Require_and_MayRequire_and_Locale
68
+ mp = ModulePreferences.new
69
+ mp.require_features :setprefs, :hello
70
+ mp.may_require :plugin, 'flash'
71
+ mp.may_require :browser, 'firefox'
72
+ mp.supports_locale :country => :us, :lang => :en
73
+
74
+ xml = ''
75
+ builder = Builder::XmlMarkup.new(:target => xml)
76
+ mp.to_xml(builder)
77
+
78
+ #verify generated xml:
79
+ doc = Document.new xml
80
+ assert_xpath doc, "/ModulePrefs"
81
+ assert_xpath doc, "/ModulePrefs/Require", :feature => :setprefs
82
+ assert_xpath doc, "/ModulePrefs/Require", :feature => :hello
83
+ assert_xpath doc, "/ModulePrefs/MayRequire", :type => :plugin, :value => 'flash'
84
+ assert_xpath doc, "/ModulePrefs/MayRequire", :type => :browser, :value => 'firefox'
85
+ assert_xpath doc, "/ModulePrefs/Locale", :country => :us, :lang => :en
86
+ end
87
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'date'
3
+
4
+ class StickyAttributesTest < Test::Unit::TestCase
5
+ include InspectorGadget
6
+
7
+ def test_calling_setters_and_then_getters
8
+ super_glue = Object.new.extend StickyAttributes
9
+
10
+ {:brand => "UHU",
11
+ :strength => 100,
12
+ :sticks_to => :everything}.each do |attr_name,attr_value|
13
+
14
+ #test w/ and w/o equals operator (e.g. super_glue.brand= and super_glue.brand)
15
+ ["#{attr_name}=", attr_name].each do |method_name|
16
+ super_glue.send method_name, attr_value
17
+ assert_equal attr_value, super_glue.instance_variable_get("@#{attr_name}")
18
+ assert_equal attr_value, super_glue.send(attr_name)
19
+
20
+ #only needed for explicit sticky attributes:
21
+ assert_respond_to super_glue, method_name
22
+ end
23
+ end
24
+ end
25
+
26
+ def test_forwards_method_missing_to_super_if_the_attribute_is_not_defined
27
+ assert_raise(NoMethodError) { Object.new.extend(StickyAttributes).title }
28
+ end
29
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'rexml/document'
3
+
4
+ class UserPreferenceTest < Test::Unit::TestCase
5
+ include InspectorGadget
6
+ include REXML
7
+
8
+ def test_instantiating_with_hash_sets_attributes
9
+ mp = UserPreference.new :name => 'helloworldexample'
10
+ assert_equal 'helloworldexample', mp.name
11
+ end
12
+
13
+ def test_create_user_preference_with_enum
14
+ up = UserPreference.new
15
+ up.name = "mycolor"
16
+ up.display_name "Color"
17
+ up.default_value "Yellow"
18
+ up.datatype "enum"
19
+ up.enum_values "Red", "Green", "Yellow", "Blue", "Pink", "Orange"
20
+
21
+ assert_equal "mycolor", up.name
22
+ assert_equal "Color", up.display_name
23
+ assert_equal "Yellow", up.default_value
24
+ assert_equal "enum", up.datatype
25
+ assert_equal ["Red", "Green", "Yellow", "Blue", "Pink", "Orange"], up.enum_values
26
+ end
27
+
28
+ def test_to_xml
29
+ attributes = { :name => "mycolor", :display_name => "Color" }
30
+ up = UserPreference.new attributes
31
+ xml = ""
32
+ up.to_xml(Builder::XmlMarkup.new(:target => xml))
33
+
34
+ doc = Document.new(xml)
35
+ assert_xpath(doc, "/UserPref", attributes)
36
+ end
37
+
38
+ def test_serializes_default_value_for_list_datatypes
39
+ up = UserPreference.new
40
+ up.datatype = "list"
41
+ up.default_value ["zdnet", "pc", "Apple Insider"]
42
+ xml = ""
43
+ up.to_xml(Builder::XmlMarkup.new(:target => xml))
44
+ doc = Document.new(xml)
45
+ assert_xpath(doc, "/UserPref", :datatype => "list", :default_value => "zdnet|pc|Apple Insider")
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ module XmlTestHelper
2
+ #asserts number of elements returned by an xpath (executed on a ReXML doc)
3
+ def assert_xpath(doc, path, attributes = {}, expected_matches = 1)
4
+ xpath = path + "[" + attributes.collect{|k,v| "@#{k}='#{v}'"}.join(' and ') + "]"
5
+ assert_equal expected_matches, doc.get_elements(xpath).length
6
+ end
7
+
8
+ #first matching element's first cdata
9
+ def cdata_value(doc, xpath)
10
+ doc.root.get_elements(xpath)[0].cdatas[0].value
11
+ end
12
+ end
@@ -0,0 +1,91 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ Inspector Gadget
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>Inspector Gadget</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/inspectorgadget"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/inspectorgadget" class="numbers">0.0.1</a>
37
+ </div>
38
+ <h1>&#x2192; &#8216;inspectorgadget&#8217;</h1>
39
+
40
+
41
+ <h2>What
42
+ InspectorGadget is a ruby <span class="caps">API</span> to create universal google gadget specifications</h2>
43
+
44
+
45
+ <h2>Installing</h2>
46
+
47
+
48
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">inspectorgadget</span></pre></p>
49
+
50
+
51
+ <h2>Usage and examples at <a href="http://jroller.com/page/abstractScope/entry/inspector_gadget" title=":ruby">InspectorGadget by got?</a></h2>
52
+
53
+
54
+ <h2>Forum</h2>
55
+
56
+
57
+ <p><a href="http://groups.google.com/group/inspectorgadget">http://groups.google.com/group/inspectorgadget</a></p>
58
+
59
+
60
+ <p><span class="caps">TODO</span> &#8211; create Google Group &#8211; inspectorgadget</p>
61
+
62
+
63
+ <h2>How to submit patches</h2>
64
+
65
+
66
+ <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
67
+
68
+
69
+ <p>The trunk repository is <code>svn://rubyforge.org/var/svn/inspectorgadget/trunk</code> for anonymous access.</p>
70
+
71
+
72
+ <h2>License</h2>
73
+
74
+
75
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
76
+
77
+
78
+ <h2>Contact</h2>
79
+
80
+
81
+ <p>Comments are welcome. Shoot me an email anytime (<a href="mailto:farooq@thoughtworks.com">farooq@thoughtworks.com</a>) or visit my blog at <a href="http://jroller.com/page/abstractScope">got? :ruby</a></p>
82
+ <p class="coda">
83
+ <a href="FIXME email">FIXME full name</a>, 9th September 2007<br>
84
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
85
+ </p>
86
+ </div>
87
+
88
+ <!-- insert site tracking codes here, like Google Urchin -->
89
+
90
+ </body>
91
+ </html>
data/website/index.txt ADDED
@@ -0,0 +1,35 @@
1
+ h1. Inspector Gadget
2
+
3
+ h1. &#x2192; 'inspectorgadget'
4
+
5
+
6
+ h2. What
7
+ InspectorGadget is a ruby API to create universal google gadget specifications
8
+
9
+ h2. Installing
10
+
11
+ <pre syntax="ruby">sudo gem install inspectorgadget</pre>
12
+
13
+
14
+ h2. Usage and examples at "InspectorGadget by got?(:ruby)":http://jroller.com/page/abstractScope/entry/inspector_gadget
15
+
16
+ h2. Forum
17
+
18
+ "http://groups.google.com/group/inspectorgadget":http://groups.google.com/group/inspectorgadget
19
+
20
+ TODO - create Google Group - inspectorgadget
21
+
22
+ h2. How to submit patches
23
+
24
+ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
25
+
26
+ The trunk repository is <code>svn://rubyforge.org/var/svn/inspectorgadget/trunk</code> for anonymous access.
27
+
28
+ h2. License
29
+
30
+ This code is free to use under the terms of the MIT license.
31
+
32
+ h2. Contact
33
+
34
+ Comments are welcome. Shoot me an email anytime ("farooq@thoughtworks.com":mailto:farooq@thoughtworks.com) or visit my blog at "got? :ruby":http://jroller.com/page/abstractScope
35
+