sleipnir-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/History.txt +3 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +41 -0
  4. data/README.txt +56 -0
  5. data/Rakefile +201 -0
  6. data/TODO.txt +11 -0
  7. data/examples/reload.rb +18 -0
  8. data/helper/helper.rb +3 -0
  9. data/helper/rake.rb +58 -0
  10. data/helper/rake_sh_filter.rb +23 -0
  11. data/helper/util.rb +19 -0
  12. data/lib/sleipnir_api.rb +177 -0
  13. data/lib/sleipnir_api/dialog.rb +155 -0
  14. data/lib/sleipnir_api/key_state.rb +49 -0
  15. data/lib/sleipnir_api/output.rb +319 -0
  16. data/lib/sleipnir_api/process.rb +69 -0
  17. data/lib/sleipnir_api/profile.rb +332 -0
  18. data/lib/sleipnir_api/registry.rb +30 -0
  19. data/lib/sleipnir_api/security.rb +263 -0
  20. data/lib/sleipnir_api/sleipnir.rb +489 -0
  21. data/lib/sleipnir_api/tab.rb +359 -0
  22. data/lib/sleipnir_api/util.rb +16 -0
  23. data/lib/sleipnir_api/version.rb +9 -0
  24. data/lib/sleipnir_api/win32api.rb +17 -0
  25. data/scripts/rdoc_filter.rb +74 -0
  26. data/setup.rb +1585 -0
  27. data/spec/matchers/path_eql.rb +41 -0
  28. data/spec/sleipnir_api/dialog_mock_spec.rb +99 -0
  29. data/spec/sleipnir_api/key_state_mock_spec.rb +72 -0
  30. data/spec/sleipnir_api/output_spec.rb +242 -0
  31. data/spec/sleipnir_api/profile_mock_spec.rb +128 -0
  32. data/spec/sleipnir_api/registry_spec.rb +13 -0
  33. data/spec/sleipnir_api/security_mock_spec.rb +82 -0
  34. data/spec/sleipnir_api/security_spec.rb +129 -0
  35. data/spec/sleipnir_api/sleipnir_mock_spec.rb +70 -0
  36. data/spec/sleipnir_api/sleipnir_spec.rb +295 -0
  37. data/spec/sleipnir_api/tab_mock_spec.rb +98 -0
  38. data/spec/sleipnir_api/tab_spec.rb +105 -0
  39. data/spec/sleipnir_api_spec.rb +17 -0
  40. data/spec/spec.opts +0 -0
  41. data/spec/spec_helper.rb +8 -0
  42. metadata +91 -0
@@ -0,0 +1,489 @@
1
+ require "sleipnir_api/util"
2
+ require "sleipnir_api/tab"
3
+ require "sleipnir_api/output"
4
+ require "sleipnir_api/profile"
5
+ require "sleipnir_api/key_state"
6
+ require "sleipnir_api/dialog"
7
+
8
+ module SleipnirAPI
9
+
10
+ #
11
+ # このクラスは Sleipnir の COM オブジェクト (Sleipnir.API) の wrapper クラスです。
12
+ # Sleipnir 全体を操作する API を定義しています。
13
+ #
14
+ # * このオブジェクトは SleipnirAPI.new または SleipnirAPI.connect で取得します。
15
+ # * SleipnirAPI::KeyState と SleipnirAPI::Dialog で定義されているメソッドが利用できます。
16
+ # * このクラスは Enumerable を include しています。
17
+ #
18
+ # 例:
19
+ #
20
+ # pnir = SleipnirAPI.new
21
+ # pnir.user_agent = "Ruby/SleipnirAPI"
22
+ # pnir.new_tab
23
+ # pnir.open("http://www.ruby-lang.org/", true)
24
+ #
25
+ # pnir.count #=> 2
26
+ # pnir.active_tab.index #=> 1
27
+ # pnir.switch_to_tab("about:blank") #=> #<SleipnirAPI::Tab:24642128>
28
+ # pnir.active_tab.index #=> 0
29
+ # pnir.tabs #=> [#<SleipnirAPI::Tab:24642128>, #<SleipnirAPI::Tab:6685682>]
30
+ # pnir.active_tab.close #=> nil
31
+ # pnir.count #=> 1
32
+ #
33
+ # # Enumerable method
34
+ # read, unread = pnir.partition{|tab| tab.read? }
35
+ # p read
36
+ # p unread
37
+ #
38
+ # alllinks = pnir.inject([]) do |acc,tab|
39
+ # links = []
40
+ # tab.document.getElementsByTagName("a").each do |a|
41
+ # links << a.href if a.href and a.href != ""
42
+ # end
43
+ # acc + links
44
+ # end
45
+ # p alllinks
46
+ #
47
+ class Sleipnir
48
+ include Enumerable
49
+ include SleipnirAPI::Util
50
+ include SleipnirAPI::KeyState
51
+ include SleipnirAPI::Dialog
52
+
53
+ # Sleipnir.API WIN32OLE Object
54
+ attr_reader :api
55
+
56
+ # Sleipnir のウィンドウハンドル
57
+ attr_reader :handle
58
+
59
+ # Sleipnir のバージョン
60
+ attr_reader :version
61
+
62
+
63
+ def initialize(api)
64
+ @api = api
65
+ @version = api.Version
66
+ @handle = api.Handle
67
+ end
68
+
69
+ # self を返します。
70
+ def sleipnir
71
+ self
72
+ end
73
+
74
+ # Sleipnir 2.xx なら true
75
+ def v2?
76
+ self.version >= 200
77
+ end
78
+
79
+ # Sleipnir を終了します。
80
+ def quit
81
+ SleipnirAPI::Process.terminate!(self.handle)
82
+ end
83
+
84
+ # アドレスバーの文字列を取得します。
85
+ def address_bar_string
86
+ api.AddressBarString
87
+ end
88
+
89
+ # アドレスバーの文字列を設定します。
90
+ def address_bar_string=(str)
91
+ api.AddressBarString=(str) #:nodoc:
92
+ end
93
+
94
+ # 検索バーの文字列を取得します。
95
+ def search_bar_string
96
+ api.SearchBarString
97
+ end
98
+
99
+ # 検索バーの文字列を設定します。
100
+ def search_bar_string=(str)
101
+ api.SearchBarString=(str) #:nodoc:
102
+ end
103
+
104
+ # アクティブなドキュメントの URL を取得します。
105
+ def url
106
+ api.URL
107
+ end
108
+
109
+ # アクティブなドキュメントの URL を設定します。
110
+ def url=(url)
111
+ api.URL=(url) #:nodoc:
112
+ end
113
+
114
+ # お気に入りファイルを取得します。
115
+ def favorite_file
116
+ api.FavoriteFile
117
+ end
118
+
119
+ # お気に入りファイルを設定します。
120
+ def favorite_file=(filename)
121
+ api.FavoriteFile=(filename) #:nodoc:
122
+ end
123
+
124
+ # UserAgent を取得します。
125
+ def user_agent
126
+ api.UserAgent
127
+ end
128
+
129
+ # UserAgent を設定します。
130
+ def user_agent=(ua)
131
+ api.UserAgent=(ua) #:nodoc:
132
+ end
133
+
134
+ # Sleipni API の結果を取得します。
135
+ def result
136
+ api.Result
137
+ end
138
+
139
+ # Sleipnir.exe の存在するディレクトリを取得します。
140
+ def app_path
141
+ api.AppPath
142
+ end
143
+
144
+ # スクリプトの読み込まれるディレクトリを取得します。
145
+ def script_path
146
+ api.ScriptPath
147
+ end
148
+
149
+ # リソースの読み込まれるディレクトリを取得します。
150
+ def resource_path
151
+ api.ResourcePath
152
+ end
153
+
154
+ # 各種設定の保存するディレクトリを取得します。
155
+ def user_path
156
+ api.UserPath
157
+ end
158
+
159
+
160
+ # 開かれているドキュメントの数を取得します。
161
+ def count
162
+ api.GetCount
163
+ end
164
+
165
+ # call-seq:
166
+ # tab(index) -> SleipnirAPI::Tab or nil
167
+ #
168
+ # 指定されたタブ位置のドキュメントを返します。
169
+ # 存在しないタブ位置を指定した場合は nil を返します。
170
+ #
171
+ # See Also: SleipnirAPI::Tab
172
+ #
173
+ def tab(index)
174
+ if (0...count).include?(index)
175
+ SleipnirAPI::Tab.new(self, api.GetDocumentId(index))
176
+ end
177
+ end
178
+
179
+ # call-seq:
180
+ # tabs() -> array of SleipnirAPI::Tab
181
+ #
182
+ # すべてのタブに対応する SleipnirAPI::Tab オブジェクトを返します。
183
+ def tabs
184
+ (0...count).map{|i| tab(i) }
185
+ end
186
+
187
+ # call-seq:
188
+ # each {|tab| ... }
189
+ #
190
+ # すべてのタブを走査します。
191
+ #
192
+ # block の引数には SleipnirAPI::Tab オブジェクトが渡されます。
193
+ def each(&block)
194
+ tabs.each(&block)
195
+ end
196
+
197
+
198
+ # アクティブなドキュメントのタブ位置を取得します。
199
+ def active_index
200
+ api.ActiveIndex
201
+ end
202
+
203
+ # 指定されたタブ位置のドキュメントをアクティブにします。
204
+ def active_index=(index)
205
+ api.ActiveIndex=(index) #:nodoc:
206
+ end
207
+
208
+ # call-seq:
209
+ # active_tab -> SleipnirAPI::Tab or nil
210
+ #
211
+ # アクティブなドキュメントの SleipnirAPI::Tab を取得します。
212
+ # アクティブなドキュメントが存在しない場合は nil を返します。
213
+ def active_tab
214
+ tab(active_index)
215
+ end
216
+
217
+ # call-seq:
218
+ # active_document -> DispHTMLDocument or nil
219
+ #
220
+ # アクティブなドキュメントの DispHTMLDocument (WIN32OLE オブジェクト) を取得します。
221
+ # アクティブなドキュメントが存在しない場合は nil を返します。
222
+ def active_document
223
+ if t = active_tab
224
+ t.document
225
+ end
226
+ end
227
+
228
+
229
+ # call-seq:
230
+ # document(index) -> DispHTMLDocument or nil
231
+ #
232
+ # 指定されたタブ位置の DispHTMLDocument (WIN32OLE オブジェクト) を取得します。
233
+ # 存在しないタブ位置を指定した場合は nil を返します。
234
+ def document(index)
235
+ if t = tab(index)
236
+ t.document
237
+ end
238
+ end
239
+
240
+ # call-seq:
241
+ # documents() -> array of DispHTMLDocument
242
+ #
243
+ # すべてのタブに対応する DispHTMLDocument (WIN32OLE オブジェクト) オブジェクトを返します。
244
+ def documents
245
+ tabs.map{|e| e.document }
246
+ end
247
+
248
+ # call-seq:
249
+ # each_document {|doc| ... }
250
+ #
251
+ # すべてのタブのドキュメントオブジェクトを走査します。
252
+ #
253
+ # block の引数には DispHTMLDocument (WIN32OLE) オブジェクトが渡されます。
254
+ def each_document(&block)
255
+ documents.each(&block)
256
+ end
257
+
258
+
259
+ # call-seq:
260
+ # new_tab(url = "about:blank", active = true) -> SleipnirAPI::Tab
261
+ #
262
+ # 新しいタブを作成し SleipnirAPI::Tab を返します。
263
+ #
264
+ # * <tt>url</tt> に nil を指定した場合は about:blank を開きます。
265
+ # * <tt>active</tt> に true を指定した場合、作成したタブがアクティブになります。
266
+ #
267
+ def new_tab(url = "about:blank", active = true)
268
+ docid = api.NewWindow(url || "about:blank", active)
269
+ SleipnirAPI::Tab.new(self, docid)
270
+ end
271
+
272
+ # call-seq:
273
+ # open(url, active = true) -> SleipnirAPI::Tab
274
+ #
275
+ # 新しいタブで指定された url を開き SleipnirAPI::Tab を返します。
276
+ #
277
+ # <tt>url</tt> を省略できない new_tab です。
278
+ #
279
+ def open(url, active = true)
280
+ new_tab(url, active)
281
+ end
282
+
283
+ # call-seq:
284
+ # get_url_tab(url) -> SleipnirAPI::Tab
285
+ #
286
+ # 指定された url を表示している最初の SleipnirAPI::Tab を返します。
287
+ #
288
+ def get_url_tab(url)
289
+ tabs.find {|tab| tab.document.location.href == url }
290
+ end
291
+
292
+ # call-seq:
293
+ # switch_to_tab(tab_or_url) -> SleipnirAPI::Tab
294
+ #
295
+ # 指定された url を表示している最初の SleipnirAPI::Tab をアクティブにして返します。
296
+ #
297
+ def switch_to_tab(tab_or_url)
298
+ case tab_or_url
299
+ when SleipnirAPI::Tab
300
+ t = tab_or_url
301
+ else
302
+ t = get_url_tab(tab_or_url.to_s)
303
+ end
304
+ if t
305
+ t.activate
306
+ t
307
+ end
308
+ end
309
+
310
+
311
+ # 指定されたファイルにお気に入りを保存します。
312
+ #
313
+ # 保存できた場合 true を返します。
314
+ def save_favorite(filename)
315
+ api.SaveFavorite(filename)
316
+ end
317
+
318
+ # 最近閉じたページをファイルに上書き保存します。
319
+ def save_closed_url
320
+ api.SaveClosedURL
321
+ end
322
+
323
+ # ClosedURL.ini を再度読み込みます。
324
+ def reload_closed_url
325
+ api.ReloadClosedURL
326
+ end
327
+
328
+ # 検索バーの履歴に項目を追加します。
329
+ # 文字列がすでに存在する場合は先頭に移動されます。
330
+ def add_search_bar_history
331
+ api.AddSearchBarHistory
332
+ end
333
+
334
+ # Sleipnir の任意のメニューを <tt>cmdid</tt> で指定して実行します。
335
+ # <tt>cmdid</tt> はマウスジェスチャー (Gesture.ini) 等から参照してください。
336
+ def exec_command(cmdid)
337
+ api.ExecCommand(cmdid)
338
+ end
339
+
340
+
341
+ # アウトプットバーを操作するオブジェクトを取得します。
342
+ #
343
+ # See Also: SleipnirAPI::Output
344
+ def output
345
+ SleipnirAPI::Output.new(self)
346
+ end
347
+
348
+ # ini ファイルを操作するオブジェクトを取得します。
349
+ #
350
+ # See Also: SleipnirAPI::Profile
351
+ def profile
352
+ SleipnirAPI::Profile.new(self)
353
+ end
354
+
355
+ end
356
+ end
357
+
358
+
359
+ __END__
360
+ [string] AddressBarString アドレスバーの文字列を取得/設定する。
361
+ [string] SearchBarString 検索バーの文字列を取得/設定する。
362
+ [string] URL アクティブなドキュメントの URL を取得/設定する。
363
+ [long] ActiveIndex アクティブなドキュメントのタブ位置を取得/設定する。
364
+ [string] FavoriteFile お気に入りファイルを取得/設定する。
365
+ [string] AppPath(R) Sleipnir.exe の存在するディレクトリを返す。
366
+ [string] ScriptPath(R) スクリプトの読み込まれるディレクトリを返す。
367
+ [string] ResourcePath(R) リソースの読み込まれるディレクトリ返す。
368
+ [string] UserPath(R) 各種設定の保存するディレクトリを返す。
369
+ [string] UserAgent UserAgent を取得/設定する。
370
+ [long] Handle(R) Sleipnir のウィンドウハンドルを返す。
371
+ [long] Result Sleipni API の結果を返す。
372
+ [long] Version(R) Sleipnir のバージョンを返す。
373
+
374
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
375
+ ■ メソッド
376
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
377
+
378
+ ────────
379
+ [long] GetCount
380
+ ────────
381
+
382
+ [説明]
383
+  開かれているドキュメントの数を返す。
384
+
385
+ [引数]
386
+  なし
387
+
388
+ [戻り値]
389
+  開かれているドキュメントの数
390
+
391
+
392
+ ────────────────
393
+ [long] GetDocumentID(long index)
394
+ ────────────────
395
+
396
+ [説明]
397
+  ドキュメント固有の ID を取得する。
398
+
399
+ [引数]
400
+  index: タブ位置( 0 ~ GetCount-1 )
401
+
402
+ [戻り値]
403
+  ドキュメント固有の ID
404
+
405
+
406
+ ───────────────────────
407
+ [long] NewWindow(string strUrl, bool bActive)
408
+ ───────────────────────
409
+
410
+ [説明]
411
+  新しくドキュメントを開く。
412
+
413
+ [引数]
414
+  strUrl: 新しく開くドキュメントの Url
415
+  bActive: 新しく開くウィンドウをアクティブにするか
416
+
417
+ [戻り値]
418
+  開かれたドキュメント固有の ID
419
+
420
+
421
+ ────────────────────
422
+ [BOOL] SaveFavorite(string strFileName)
423
+ ────────────────────
424
+
425
+ [説明]
426
+  お気に入りを保存する。
427
+
428
+ [引数]
429
+  strFileName: 保存するファイル名(フルパスで指定)
430
+
431
+ [戻り値]
432
+  成功なら true
433
+
434
+
435
+ ───────────
436
+ [void] SaveClosedURL()
437
+ ───────────
438
+
439
+ [説明]
440
+  最近閉じたページをファイルに上書き保存する。
441
+
442
+ [引数]
443
+  なし
444
+
445
+ [戻り値]
446
+  なし
447
+
448
+
449
+ ────────────
450
+ [void] ReloadClosedURL()
451
+ ────────────
452
+
453
+ [説明]
454
+  ClosedURL.ini を再度読み込む。
455
+
456
+ [引数]
457
+  なし
458
+
459
+ [戻り値]
460
+  なし
461
+
462
+
463
+ ───────────────────
464
+ [void] AddSearchBarHistory(string ss)
465
+ ───────────────────
466
+
467
+ [説明]
468
+  検索バーの履歴に項目を追加する。文字列がすでに存在する場合は先頭に移動されます。
469
+
470
+ [引数]
471
+  ss: 追加する文字列
472
+
473
+ [戻り値]
474
+  なし
475
+
476
+
477
+ ───────────────
478
+ [void] ExecCommand(long cmdID)
479
+ ───────────────
480
+
481
+ [説明]
482
+  Sleipnir の任意のメニューを cmdID で指定して実行します。cmdID はマウスジェス
483
+  チャー(Gesture.ini)等から参照してください。
484
+
485
+ [引数]
486
+  cmdID: コマンドID
487
+
488
+ [戻り値]
489
+  なし