inspectorgadget 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2007-09-09
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 FIXME full name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,38 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/inspectorgadget.rb
9
+ lib/inspectorgadget/version.rb
10
+ lib/inspectorgadget/dsl_attr_accessor.rb
11
+ lib/inspectorgadget/google_gadget_spec.rb
12
+ lib/inspectorgadget/module_preferences.rb
13
+ lib/inspectorgadget/sticky_attributes.rb
14
+ lib/inspectorgadget/user_preference.rb
15
+ log/debug.log
16
+ script/destroy
17
+ script/destroy.cmd
18
+ script/generate
19
+ script/generate.cmd
20
+ script/txt2html
21
+ script/txt2html.cmd
22
+ setup.rb
23
+ tasks/deployment.rake
24
+ tasks/environment.rake
25
+ tasks/website.rake
26
+ test/test_helper.rb
27
+ test/test_inspectorgadget.rb
28
+ test/test_dsl_attribute_accessor.rb
29
+ test/test_google_gadget_spec.rb
30
+ test/test_module_preferences.rb
31
+ test/test_sticky_attributes.rb
32
+ test/test_user_preference.rb
33
+ test/xml_test_helper.rb
34
+ website/index.html
35
+ website/index.txt
36
+ website/javascripts/rounded_corners_lite.inc.js
37
+ website/stylesheets/screen.css
38
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1 @@
1
+ README
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'inspectorgadget/version'
2
+
3
+ AUTHOR = 'Farooq Ali' # can also be an array of Authors
4
+ EMAIL = "farooq@thoughtworks.com"
5
+ DESCRIPTION = "Universal Google Gadget specification DSL"
6
+ GEM_NAME = 'inspectorgadget' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'inspectorgadget' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Inspectorgadget::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'inspectorgadget documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
54
+ p.summary = DESCRIPTION
55
+ p.url = HOMEPATH
56
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
+ p.test_globs = ["test/**/test_*.rb"]
58
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
+
60
+ # == Optional
61
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
62
+ p.extra_deps = ['builder'] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
+
64
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
+
66
+ end
67
+
68
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'inspectorgadget'
@@ -0,0 +1,15 @@
1
+ module InspectorGadget
2
+ module DslAttrAccessor
3
+
4
+ def dsl_attr_accessor(*attrs)
5
+ attrs.each do |attr|
6
+ attr_writer attr
7
+ define_method attr do |*args|
8
+ instance_variable_set("@#{attr}", args.first) unless args.empty?
9
+ instance_variable_get("@#{attr}")
10
+ end
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,66 @@
1
+ require 'rubygems'
2
+ require 'builder'
3
+
4
+ module InspectorGadget
5
+
6
+ class GoogleGadgetSpec
7
+ extend DslAttrAccessor
8
+ attr_accessor :user_prefs
9
+ dsl_attr_accessor :content, :content_type, :content_href
10
+
11
+ def initialize(&block)
12
+ @module_prefs = ModulePreferences.new
13
+ @user_prefs = []
14
+ @content_type = :html
15
+ instance_eval(&block) if block_given?
16
+ self
17
+ end
18
+
19
+ def content(*args)
20
+ return @content if args.empty?
21
+ value = args.pop
22
+ if value.is_a?(Hash) && value.key?(:url)
23
+ @content_type, @content_href = :url, value[:url]
24
+ else
25
+ @content = value
26
+ end
27
+ end
28
+
29
+ def module_prefs(&block)
30
+ yield @module_prefs if block_given?
31
+ @module_prefs
32
+ end
33
+
34
+ def user_pref(*args, &block)
35
+ up = UserPreference.new(*args)
36
+ up.instance_eval(&block) if block_given?
37
+ @user_prefs << up
38
+ end
39
+
40
+ def method_missing(name, *args)
41
+ begin
42
+ @module_prefs.send(name, *args)
43
+ rescue NoMethodError
44
+ super.send(name, *args)
45
+ end
46
+ end
47
+
48
+ def to_xml(target = '')
49
+ xml = Builder::XmlMarkup.new(:target => target, :indent => 2)
50
+ xml.instruct!
51
+ xml.Module do
52
+ @module_prefs.to_xml(xml)
53
+ @user_prefs.each {|user_pref| user_pref.to_xml(xml)}
54
+ puts "Warning: Google will reject your gadget spec's content section because you specified a URL content type" if @content_type == :url && @content
55
+ content_attrs = {}
56
+ content_attrs[:type] = @content_type if @content_type
57
+ content_attrs[:href] = @content_href if @content_href
58
+ xml.Content content_attrs do
59
+ xml.cdata! @content.is_a?(IO) ? @content.readlines.join : @content.to_s
60
+ end
61
+ end
62
+ target
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,36 @@
1
+ module InspectorGadget
2
+
3
+ class ModulePreferences
4
+ include StickyAttributes
5
+ attr_reader :required_features, :may_be_required, :supported_locales
6
+
7
+ def initialize(properties = {})
8
+ properties.each { |name, value| send name, value } if properties.is_a? Hash
9
+ @required_features, @may_be_required, @supported_locales = [], [], []
10
+ end
11
+
12
+ def require_features(*features)
13
+ @required_features.concat features
14
+ end
15
+
16
+ def may_require(type, value, optional_params = {})
17
+ @may_be_required << optional_params.update(:type => type, :value => value)
18
+ end
19
+
20
+ def supports_locale(options = nil)
21
+ if options.is_a? Hash
22
+ raise ArgumentError.new("You must provide the lang and/or country when using supports_locale") unless options.key?(:lang) || options.key?(:country)
23
+ @supported_locales << options
24
+ end
25
+ end
26
+
27
+ def to_xml(xml)
28
+ xml.ModulePrefs(sticky_attributes) do
29
+ @required_features.each { |feature| xml.Require :feature => feature }
30
+ @may_be_required.each { |may_require| xml.MayRequire may_require }
31
+ @supported_locales.each { |locale| xml.Locale locale }
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,26 @@
1
+ module InspectorGadget
2
+ module StickyAttributes
3
+
4
+ def method_missing(method_name, *args)
5
+ attr_name = method_name.to_s.split(/=|\?/).first.to_sym
6
+ unless args.empty?
7
+ attr_value = args.first
8
+ eval %(class << self
9
+ def #{attr_name}(*attr_args)
10
+ @#{attr_name} = attr_args.first unless attr_args.empty?
11
+ @#{attr_name}
12
+ end
13
+ attr_writer :#{attr_name}
14
+ alias_method :#{attr_name}?, :#{attr_name}
15
+ end)
16
+ sticky_attributes[attr_name] = attr_value
17
+ end
18
+
19
+ respond_to?(method_name) ? send(method_name, *args) : super
20
+ end
21
+
22
+ def sticky_attributes
23
+ @sticky_attributes ||= {}
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ module InspectorGadget
2
+
3
+ class UserPreference
4
+ include StickyAttributes
5
+
6
+ def initialize(properties = {})
7
+ properties.each { |name, value| send name, value } if properties.is_a? Hash
8
+ @enum_values = []
9
+ end
10
+
11
+ def enum_values(*values)
12
+ @enum_values = values.flatten unless values.empty?
13
+ @enum_values
14
+ end
15
+
16
+ def is_required
17
+ self.required = true
18
+ end
19
+
20
+ def is_optional
21
+ self.required = false
22
+ end
23
+
24
+ def to_xml(xml)
25
+ default_vals = sticky_attributes[:default_value].to_a.flatten
26
+ if sticky_attributes[:datatype].to_s == 'list' && !default_vals.empty?
27
+ sticky_attributes[:default_value] = default_vals.join('|')
28
+ end
29
+
30
+ write_enum_values = proc do
31
+ enum_values.each do |enum_value|
32
+ xml.EnumValue :value => enum_value
33
+ end
34
+ end
35
+
36
+ enum_values.empty?? xml.UserPref(sticky_attributes) : xml.UserPref(sticky_attributes,&write_enum_values)
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,9 @@
1
+ module Inspectorgadget #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ Dir.chdir(File.dirname(__FILE__)+'/inspectorgadget') do
4
+ require 'version'
5
+ require 'dsl_attr_accessor'
6
+ require 'sticky_attributes'
7
+ require 'user_preference'
8
+ require 'module_preferences'
9
+ require 'google_gadget_spec'
10
+
11
+ # Dir['inspectorgadget/**/*.rb'].each { |f| puts f; require f }
12
+ end
13
+
14
+ module Inspectorgadget
15
+ end
data/log/debug.log ADDED
File without changes
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1 @@
1
+ @ruby script/destroy %*
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1 @@
1
+ @ruby script/generate %*
data/script/txt2html ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'newgem'
6
+ rescue LoadError
7
+ puts "\n\nGenerating the website requires the newgem RubyGem"
8
+ puts "Install: gem install newgem\n\n"
9
+ exit(1)
10
+ end
11
+ require 'redcloth'
12
+ require 'syntax/convertors/html'
13
+ require 'erb'
14
+ require File.dirname(__FILE__) + '/../lib/inspectorgadget/version.rb'
15
+
16
+ version = Inspectorgadget::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/inspectorgadget'
18
+
19
+ class Fixnum
20
+ def ordinal
21
+ # teens
22
+ return 'th' if (10..19).include?(self % 100)
23
+ # others
24
+ case self % 10
25
+ when 1: return 'st'
26
+ when 2: return 'nd'
27
+ when 3: return 'rd'
28
+ else return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
+
47
+ else
48
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
+ exit!
50
+ end
51
+
52
+ template = ERB.new(File.open(template).read)
53
+
54
+ title = nil
55
+ body = nil
56
+ File.open(src) do |fsrc|
57
+ title_text = fsrc.readline
58
+ body_text = fsrc.read
59
+ syntax_items = []
60
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
+ ident = syntax_items.length
62
+ element, syntax, source = $1, $2, $3
63
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
+ "syntax-temp-#{ident}"
65
+ }
66
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
+ body = RedCloth.new(body_text).to_html
68
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
+ end
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)
@@ -0,0 +1 @@
1
+ @ruby script/txt2html %*