sleipnir-api 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/History.txt +32 -0
  2. data/Manifest.txt +20 -3
  3. data/Rakefile +11 -1
  4. data/TODO.txt +4 -10
  5. data/bin/grepnir +1 -1
  6. data/examples/close_dup.rb +1 -1
  7. data/examples/close_err.rb +12 -0
  8. data/examples/command_list.rb +135 -0
  9. data/examples/open_last_url_by_firefox.rb +44 -0
  10. data/examples/open_selected_links.rb +40 -0
  11. data/helper/rake.rb +3 -57
  12. data/helper/rake/rake.rb +58 -0
  13. data/helper/{rake_sh_filter.rb → rake/rake_sh_filter.rb} +0 -0
  14. data/helper/{util.rb → rake/util.rb} +0 -0
  15. data/lib/sleipnir_api/cli/grepnir.rb +2 -3
  16. data/lib/sleipnir_api/command.rb +126 -0
  17. data/lib/sleipnir_api/commands.rb +264 -0
  18. data/lib/sleipnir_api/profile.rb +166 -27
  19. data/lib/sleipnir_api/profile/ini.rb +202 -0
  20. data/lib/sleipnir_api/profile/key.rb +120 -0
  21. data/lib/sleipnir_api/profile/section.rb +147 -0
  22. data/lib/sleipnir_api/profile/util.rb +82 -0
  23. data/lib/sleipnir_api/searcher.rb +133 -0
  24. data/lib/sleipnir_api/security.rb +88 -18
  25. data/lib/sleipnir_api/sleipnir.rb +91 -7
  26. data/lib/sleipnir_api/tab.rb +68 -2
  27. data/lib/sleipnir_api/tabbed_ie.rb +33 -0
  28. data/lib/sleipnir_api/util.rb +25 -0
  29. data/lib/sleipnir_api/version.rb +2 -2
  30. data/scripts/gesture2rb.rb +42 -0
  31. data/scripts/make_gesture.rb +271 -0
  32. data/scripts/subcategory.csv +253 -0
  33. data/spec/sleipnir_api/profile_mock_spec.rb +80 -6
  34. data/spec/sleipnir_api/profile_section_mock_spec.rb +143 -0
  35. data/spec/sleipnir_api/profile_spec.rb +191 -0
  36. data/spec/sleipnir_api/security_spec.rb +58 -0
  37. data/spec/sleipnir_api/tab_mock_spec.rb +0 -5
  38. data/spec/sleipnir_api/tab_spec.rb +27 -0
  39. data/spec/spec_helper.rb +20 -0
  40. metadata +22 -5
  41. data/helper/helper.rb +0 -3
@@ -1,3 +1,35 @@
1
+ == 0.3.0 / 2007-09-23
2
+
3
+ * API changes:
4
+ * SleipnirAPI::Tab
5
+ +search+:: support Sleipnir 2.x.
6
+ * SleipnirAPI::Security
7
+ +enable?+:: support multiple arguments.
8
+ +disable?+:: ditto.
9
+ * SleipnirAPI::Sleipnir
10
+ +profile+:: support default keyword arguments.
11
+ +exec_command+:: support SleipnirAPI::Command object.
12
+ * New API:
13
+ * SleipnirAPI::Command
14
+ * new class to represent Sleipnir menu commands.
15
+ it can specify SleipnirAPI::Sleipnir#exec_command.
16
+ * SleipnirAPI::Profile::Ini
17
+ * new class to represent ini file.
18
+ * SleipnirAPI::Profile::Seciton
19
+ * new class to represent ini section.
20
+ * SleipnirAPI::Profile::Key
21
+ * new class to represent ini section key.
22
+ * SleipnirAPI::Profile
23
+ +ini+:: get SleipnirAPI::Profile::Ini object.
24
+ * SleipnirAPI::Tab
25
+ +watir+:: get Watir object [experimental].
26
+ +elem_by_tag+:: get IHTMLElement. (shortcut of document.getElementsByTagName).
27
+ +base_uri+:: get document base (<base> or location.href).
28
+ +base_uris+:: get base uri in <head>.
29
+ * SleipnirAPI::Security
30
+ +enable!+:: set security config.
31
+ +disable!+:: ditto.
32
+
1
33
  == 0.2.1 / 2007-07-30
2
34
 
3
35
  * grepnir:
@@ -6,27 +6,42 @@ Rakefile
6
6
  TODO.txt
7
7
  bin/grepnir
8
8
  examples/close_dup.rb
9
+ examples/close_err.rb
10
+ examples/command_list.rb
11
+ examples/open_last_url_by_firefox.rb
12
+ examples/open_selected_links.rb
9
13
  examples/reload.rb
10
- helper/helper.rb
11
14
  helper/rake.rb
12
- helper/rake_sh_filter.rb
13
- helper/util.rb
15
+ helper/rake/rake.rb
16
+ helper/rake/rake_sh_filter.rb
17
+ helper/rake/util.rb
14
18
  lib/sleipnir_api.rb
15
19
  lib/sleipnir_api/cli/base.rb
16
20
  lib/sleipnir_api/cli/grepnir.rb
21
+ lib/sleipnir_api/command.rb
22
+ lib/sleipnir_api/commands.rb
17
23
  lib/sleipnir_api/dialog.rb
18
24
  lib/sleipnir_api/key_state.rb
19
25
  lib/sleipnir_api/output.rb
20
26
  lib/sleipnir_api/process.rb
21
27
  lib/sleipnir_api/profile.rb
28
+ lib/sleipnir_api/profile/ini.rb
29
+ lib/sleipnir_api/profile/key.rb
30
+ lib/sleipnir_api/profile/section.rb
31
+ lib/sleipnir_api/profile/util.rb
22
32
  lib/sleipnir_api/registry.rb
33
+ lib/sleipnir_api/searcher.rb
23
34
  lib/sleipnir_api/security.rb
24
35
  lib/sleipnir_api/sleipnir.rb
25
36
  lib/sleipnir_api/tab.rb
37
+ lib/sleipnir_api/tabbed_ie.rb
26
38
  lib/sleipnir_api/util.rb
27
39
  lib/sleipnir_api/version.rb
28
40
  lib/sleipnir_api/win32api.rb
41
+ scripts/gesture2rb.rb
42
+ scripts/make_gesture.rb
29
43
  scripts/rdoc_filter.rb
44
+ scripts/subcategory.csv
30
45
  setup.rb
31
46
  spec/dsl/behaviour_eval.rb
32
47
  spec/matchers/exit_with.rb
@@ -36,6 +51,8 @@ spec/sleipnir_api/dialog_mock_spec.rb
36
51
  spec/sleipnir_api/key_state_mock_spec.rb
37
52
  spec/sleipnir_api/output_spec.rb
38
53
  spec/sleipnir_api/profile_mock_spec.rb
54
+ spec/sleipnir_api/profile_section_mock_spec.rb
55
+ spec/sleipnir_api/profile_spec.rb
39
56
  spec/sleipnir_api/registry_spec.rb
40
57
  spec/sleipnir_api/security_mock_spec.rb
41
58
  spec/sleipnir_api/security_spec.rb
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ rescue LoadError
18
18
  exit
19
19
  end
20
20
 
21
- require 'helper/helper'
21
+ require 'helper/rake'
22
22
 
23
23
  include FileUtils
24
24
  require File.join(File.dirname(__FILE__), 'lib', 'sleipnir_api', 'version')
@@ -28,8 +28,12 @@ EMAIL = "miyamuko@gmail.com"
28
28
  DESCRIPTION = "Ruby interface to the Sleipnir COM API"
29
29
  GEM_NAME = 'sleipnir-api' # what ppl will type to install your gem
30
30
  RDOC_DIR = "./html"
31
+ EXAMPLES_DIR = "#{RDOC_DIR}/examples"
31
32
  NEWS_FILE = "news.txt"
32
33
 
34
+
35
+ directory EXAMPLES_DIR
36
+
33
37
  @config_file = "~/.rubyforge/user-config.yml"
34
38
  @config = nil
35
39
  def rubyforge_username
@@ -148,6 +152,12 @@ Rake::RDocTask.new(:docs) do |rd|
148
152
  rd.options << '--charset=UTF-8'
149
153
  end
150
154
 
155
+ desc "Build the command list HTML Files."
156
+ task :example => [EXAMPLES_DIR] do
157
+ sh "ruby examples/command_list.rb > #{EXAMPLES_DIR}/exec_command.html"
158
+ end
159
+ task :docs => [:example]
160
+
151
161
  # remove HTML comment and so on.
152
162
  task :docs do
153
163
  ruby "scripts/rdoc_filter.rb #{RDOC_DIR}/**/*.html"
data/TODO.txt CHANGED
@@ -1,16 +1,12 @@
1
1
  == TODO
2
2
 
3
- * search, hilight を自前で実装する
3
+ * hilight を自前で実装する
4
4
  * Sleipnir 2.x じゃサポートしていない
5
5
  * 1.66 で hilight を同じページに対して何回も実行するとだんだん重くなる
6
6
  * watir サポート
7
- * InternetExplorer.Application 互換のインターフェイスを提供する
8
- Adapter を作ってタブごとに watir オブジェクトを取得できればよい?
9
- * InternetExplorer.Application == IWebBrowser2 == pnir.browser
10
- * ie.document == DispHTMLDocument == pnir.document
11
- * ie.parentWindow == DispHTMLWindow2 == pnir.window
12
- * ipnir
13
- * intaractive sleipnir shell
7
+ * test
8
+ * pnirsh
9
+ * sleipnir shell
14
10
  * JavaScript の実行
15
11
  * Sleipnir の起動・終了を WMI を使わずに実装。
16
12
  * Sleipnir の終了時に Window Handle をちゃんと見る。
@@ -23,6 +19,4 @@
23
19
  * dRuby
24
20
  * Rinda
25
21
  * Gearman
26
- * ExecCommand
27
- * コマンドの一覧
28
22
  * Sleipnir 2.x のサポート
@@ -53,7 +53,7 @@
53
53
  #
54
54
  # == CAVEATS
55
55
  #
56
- # * Sleipnir 2.x ではハイライト (-H) と選択 (-S) はサポートしていないので、
56
+ # * Sleipnir 2.x ではハイライト (-H) はサポートしていません。
57
57
  # オプションを指定しても単純に無視します。
58
58
  #
59
59
  # * Sleipnir 1.x で同じページに対して何回もハイライト処理をすると
@@ -3,7 +3,7 @@ require "set"
3
3
  $LOAD_PATH << File.join(File.dirname(__FILE__), "../lib")
4
4
  require "sleipnir_api"
5
5
 
6
- SleipnirAPI.new do |pnir|
6
+ SleipnirAPI.connect do |pnir|
7
7
  url2tab = pnir.to_set.classify{|e| e.document.URL }.select{|url,tabs| tabs.size > 1 }
8
8
  url2tab.each do |url,tabs|
9
9
  tabs.sort_by{|e|
@@ -0,0 +1,12 @@
1
+ require "set"
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "../lib")
4
+ require "sleipnir_api"
5
+
6
+ SleipnirAPI.connect do |pnir|
7
+ pnir.each_eval do
8
+ if location.href =~ /shdoclc.dll\/navcancl.htm/
9
+ close(true)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,135 @@
1
+ $KCODE = "s"
2
+
3
+ require "erb"
4
+ require "optparse"
5
+
6
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "../lib")
7
+ require "sleipnir_api"
8
+
9
+ puts ERB.new(DATA.read, 0, "%<>").result(binding)
10
+
11
+ __END__
12
+ <html>
13
+ <head>
14
+ <title>Sleipnir.API - ExecCommand �Ɏw��”\�ȃR�}���h�̈ꗗ</title>
15
+ <meta http-equiv="Content-type" content="text/html; charset=Shift_JIS" />
16
+ <style type="text/css">
17
+ <!--
18
+ body {
19
+ color: #16160e;
20
+ background: #fffffc;
21
+ }
22
+ input {
23
+ width: 10em;
24
+ }
25
+ table, th, td {
26
+ border-collapse: collapse;
27
+ border: 1px solid #e9dfe5;
28
+ }
29
+ th {
30
+ background: #fdeff2;
31
+ }
32
+ th, td {
33
+ padding: 4px;
34
+ }
35
+ #search {
36
+ color: #393f4c;
37
+ width: 100%;
38
+ }
39
+ -->
40
+ </style>
41
+
42
+ <script type="text/javascript">
43
+ <!--
44
+ var data = {};
45
+ % SleipnirAPI::Command.each_with_index do |cmd,i|
46
+ data["c<%= i %>"] = ["<%= cmd.command_id %>", <%= cmd.path.map{|e| e.downcase.inspect }.join(", ") %>];
47
+ <% end %>
48
+ var cache = {};
49
+
50
+ function lookup(names, q) {
51
+ var queries = q.toLowerCase().split(/\s+/);
52
+ for (var i = 0; i < queries.length; i++) {
53
+ if (!lookup1(names, queries[i])) {
54
+ return false;
55
+ }
56
+ }
57
+ return true;
58
+ }
59
+
60
+ function lookup1(names, query) {
61
+ for (var i = 0; i < names.length; i++) {
62
+ if (names[i].indexOf(query) > -1) {
63
+ return true;
64
+ }
65
+ }
66
+ return false;
67
+ }
68
+
69
+ function do_search(q) {
70
+ for (var key in data) {
71
+ var names = data[key];
72
+ var e = cache[key] = cache[key] || document.getElementById(key);
73
+ if (e != undefined && lookup(names, q)) {
74
+ e.style.display = "";
75
+ } else {
76
+ e.style.display = "none";
77
+ }
78
+ }
79
+ }
80
+
81
+ function setup_event() {
82
+ var input = document.getElementById("search");
83
+ input.onfocus = function() {
84
+ if (input.value == "Search...") {
85
+ input.value = "";
86
+ input.style.color = "black";
87
+ }
88
+ };
89
+ input.onblur = function() {
90
+ if (input.value == "") {
91
+ input.value = "search";
92
+ input.style.color = "#393f4c";
93
+ }
94
+ };
95
+
96
+ var form = document.getElementById("search_box");
97
+ form.onsubmit = function() {
98
+ var q = input.value;
99
+ input.style.backgroundColor = "#f6bfbc";
100
+ window.setTimeout(function () {
101
+ do_search(q);
102
+ input.style.backgroundColor = "";
103
+ input.focus();
104
+ }, 100);
105
+
106
+ return false;
107
+ };
108
+ }
109
+ -->
110
+ </script>
111
+
112
+ </head>
113
+ <body onload="setup_event();">
114
+ <h1>Sleipnir.API - ExecCommand �Ɏw��”\�ȃR�}���h�̈ꗗ</h1>
115
+
116
+ <p>Sleipnir 1.66 �p�ł��B2.x �� ExecCommand ���T�|�[�g���Ă��܂���B</p>
117
+
118
+ <form id="search_box">
119
+ <input accesskey="a" id="search" value="Search..."/>
120
+ </form>
121
+
122
+ <table style="width: 100%">
123
+ <tr>
124
+ <th style="width: 20%">�R�}���h ID</th>
125
+ <th style="width: 80%">�R�}���h</th>
126
+ </tr>
127
+ % SleipnirAPI::Command.each_with_index do |cmd,i|
128
+ <tr id="c<%= i %>">
129
+ <td><%= cmd.command_id %></td>
130
+ <td><%= cmd.path.join(" �� ") %></td>
131
+ </tr>
132
+ % end
133
+ </table>
134
+ </body>
135
+ </html>
@@ -0,0 +1,44 @@
1
+ require "timeout"
2
+ require "win32ole"
3
+ require "win32/registry"
4
+
5
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "../lib")
6
+ require "sleipnir_api"
7
+
8
+ class Firefox
9
+
10
+ def initialize
11
+ @exe = find_exe
12
+ @wsh = WIN32OLE.new("WScript.Shell")
13
+ end
14
+
15
+ def open(url, wait = true)
16
+ @wsh.Exec("#{@exe} #{url}")
17
+ wait_for_activate if wait
18
+ end
19
+
20
+ def wait_for_activate(timeout = 30)
21
+ timeout(timeout) {
22
+ sleep(0.2) until @wsh.AppActivate(" - Mozilla Firefox")
23
+ }
24
+ end
25
+
26
+ def find_exe
27
+ Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE, "SOFTWARE\\Mozilla\\Mozilla Firefox") do |reg|
28
+ curr = reg.read_s("CurrentVersion")
29
+ reg.open("#{curr}\\Main") do |r|
30
+ return r.read_s("PathToExe")
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ SleipnirAPI.connect do |pnir|
37
+ last_url = pnir.profile.LastWnd.LastWindow2.Item0_URL.list
38
+ break if last_url.empty?
39
+ firefox = Firefox.new
40
+ last_url.each do |url|
41
+ firefox.open(url)
42
+ sleep(0.5)
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ require "uri"
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "../lib")
4
+ require "sleipnir_api"
5
+
6
+ def traverse_elem(elem, &block)
7
+ elem.childNodes.each do |child|
8
+ case child.nodeName
9
+ when "#text"
10
+ # ignore
11
+ else
12
+ block.call(child)
13
+ traverse_elem(child, &block)
14
+ end
15
+ end
16
+ end
17
+
18
+ SleipnirAPI.connect do |pnir|
19
+ links = []
20
+ pnir.active_tab.document {|doc|
21
+ selection = doc.Selection
22
+ break if selection.Type == "None"
23
+ div = doc.createElement("div")
24
+ div.innerHTML = selection.createRange.HtmlText
25
+ base = URI(pnir.active_tab.base_uri)
26
+ traverse_elem(div) do |e|
27
+ case e.nodeName
28
+ when "BASE"
29
+ base = URI(e["href"])
30
+ when "A"
31
+ links << (base + e["href"]).to_s
32
+ end
33
+ end
34
+ }
35
+
36
+ (links - pnir.map{|e| e.location.href }).uniq.each do |link|
37
+ puts "open #{link}"
38
+ pnir.open(link, false)
39
+ end
40
+ end
@@ -1,58 +1,4 @@
1
- require "rubygems"
2
- require "rake"
1
+ require "helper/rake/util"
2
+ require "helper/rake/rake"
3
+ require "helper/rake/rake_sh_filter"
3
4
 
4
- def tasks
5
- Rake.application.instance_eval { @tasks }
6
- end
7
-
8
- def current_scope
9
- Rake.application.instance_eval { @scope.last }
10
- end
11
-
12
- def task_defined?(task_name)
13
- Rake::Task.task_defined?(task_name)
14
- end
15
-
16
- def remove_tasks(*task_names)
17
- task_names.flatten.each do |task_name|
18
- remove_task(task_name)
19
- end
20
- end
21
-
22
- def remove_task(task_name)
23
- tasks.delete(task_name.to_s)
24
- end
25
-
26
- def lookup_task(task_name)
27
- Rake::Task[task_name] rescue nil
28
- end
29
-
30
- def rakecall(task_name)
31
- lookup_task(task_name).invoke
32
- end
33
-
34
- def override_task(task_args, &block)
35
- task_name, deps = Rake.application.resolve_args(task_args)
36
- original = lookup_task(task_name)
37
- orgproc = lambda {} # nop
38
- if original
39
- Rake.application.last_comment = original.comment
40
- deps |= original.prerequisites
41
- orgproc = lambda{ original.execute }
42
- end
43
-
44
- remove_task(task_name)
45
- Rake::Task.define_task(task_name => deps) do |t|
46
- block.call(t, orgproc)
47
- end
48
- end
49
-
50
- def task_for_windows(task_args, &block)
51
- override_task(task_args) do |t, org|
52
- if windows?
53
- block.call(t)
54
- else
55
- org.call
56
- end
57
- end
58
- end