Rakefile in watir-webdriver-0.0.6 vs Rakefile in watir-webdriver-0.0.7
- old
+ new
@@ -12,14 +12,16 @@
gem.authors = ["Jari Bakken"]
gem.add_dependency "selenium-webdriver", '>= 0.0.26'
gem.add_development_dependency "rspec"
- gem.add_development_dependency "webidl"
+ gem.add_development_dependency "webidl", ">= 0.0.4"
gem.add_development_dependency "sinatra", ">= 1.0"
+ gem.add_development_dependency "nokogiri"
gem.add_development_dependency "activesupport", ">= 2.3.5" # for pluralization during code generation
end
+
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
@@ -36,60 +38,80 @@
spec.rcov_opts = %w[--exclude spec,ruby-debug,/Library/Ruby,.gem --include lib/watir-webdriver]
end
task :spec => :check_dependencies
+task :lib do
+ $LOAD_PATH.unshift(File.expand_path("lib", File.dirname(__FILE__)))
+end
+
namespace :html5 do
- IDL_PATH = "support/html5/html5.idl"
- SPEC_URI = "http://dev.w3.org/html5/spec/Overview.html" # TODO: use http://www.whatwg.org/specs/web-apps/current-work/source
+ SPEC_URI = "http://www.whatwg.org/specs/web-apps/current-work/"
+ SPEC_PATH = "support/html5.html"
- desc "Print IDL parts from #{SPEC_URI}"
- task :extract do
- require "nokogiri"
+ task :html_lib => :lib do
+ require 'watir-webdriver/html'
+ end
+
+ desc "Download the HTML5 spec from #{SPEC_URI}"
+ task :download do
require "open-uri"
- doc = Nokogiri.HTML(open(SPEC_URI))
- puts doc.search("//pre[@class='idl']").map { |e| e.inner_text }.join("\n\n")
+ mv SPEC_PATH, "#{SPEC_PATH}.old" if File.exist?(SPEC_PATH)
+ downloaded_bytes = 0
+
+ File.open(SPEC_PATH, "w") do |io|
+ io << "<!-- downloaded from #{SPEC_URI} on #{Time.now} -->\n"
+ io << data = open(SPEC_URI).read
+ downloaded_bytes = data.bytesize
+ end
+
+ puts "#{SPEC_URI} => #{SPEC_PATH} (#{downloaded_bytes} bytes)"
end
- desc 'Re-enerate the base Watir element classes from the spec '
- task :generate do
- require "support/html5/watir_visitor"
+ desc "Print IDL parts from #{SPEC_URI}"
+ task :print => :html_lib do
+ extractor = Watir::HTML::SpecExtractor.new(SPEC_PATH)
- code = WatirVisitor.generate_from(IDL_PATH)
- old_file = "lib/watir-webdriver/elements/generated.rb"
+ extractor.process.each do |tag_name, interface_definitions|
+ puts "#{tag_name.ljust(10)} => #{interface_definitions.map { |e| e.name }}"
+ end
- File.open("#{old_file}.new", "w") { |file| file << code }
- if File.exist?(old_file)
- system "diff -Naut #{old_file} #{old_file}.new | less"
+ extractor.print_hierarchy
+
+ unless extractor.errors.empty?
+ puts "\n\n<======================= ERRORS =======================>\n\n"
+ puts extractor.errors.join("\n" + "="*80 + "\n")
end
end
- desc 'Check the syntax of support/html5/*.idl'
- task :syntax do
- require 'webidl'
- parser = WebIDL::Parser::IDLParser.new
- failures = []
- Dir['support/html5/*.idl'].each do |path|
- unless parser.parse(File.read(path))
- failures << [path, parser.failure_reason]
- end
+ desc 'Re-enerate the base Watir element classes from the spec '
+ task :generate => :html_lib do
+ old_file = "lib/watir-webdriver/elements/generated.rb"
+ generator = Watir::HTML::Generator.new
+
+ File.open("#{old_file}.new", "w") do |file|
+ generator.generate(SPEC_PATH, file)
end
- if failures.any?
- puts "Parse errors!"
- failures.each { |path, reason| puts "#{path.ljust(40)}: #{reason}" }
- else
- puts "Syntax OK."
+ if File.exist?(old_file)
+ system "diff -Naut #{old_file} #{old_file}.new | less"
end
end
+ desc 'Move generated.rb.new to generated.rb'
+ task :overwrite do
+ file = "lib/watir-webdriver/elements/generated.rb"
+ mv "#{file}.new", file
+ end
+
end # html5
task :default => :spec
begin
require 'yard'
- require 'support/yard_handlers'
+ Rake::Task[:lib].invoke
+ require "yard/handlers/watir"
YARD::Rake::YardocTask.new do |task|
task.options = %w[--debug] # this is pretty slow, so nice with some output
end
rescue LoadError
task :yard do