sleipnir-api 0.1.0

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.
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,359 @@
1
+ require "sleipnir_api/util"
2
+ require "sleipnir_api/key_state"
3
+ require "sleipnir_api/dialog"
4
+ require "sleipnir_api/security"
5
+
6
+ module SleipnirAPI
7
+
8
+ #
9
+ # このクラスは Sleipnir の COM オブジェクト (Sleipnir.API) の wrapper クラスです。
10
+ # Sleipnir のタブを操作する API を定義しています。
11
+ #
12
+ # このオブジェクトは Sleipnir.API の ドキュメント ID を抽象化したものです。
13
+ # 実際のドキュメントオブジェクト (DispHTMLDocument) の抽象化は行いません。
14
+ #
15
+ # * このオブジェクトは SleipnirAPI::Sleipnir#tab または SleipnirAPI::Sleipnir#active_tab で取得します。
16
+ # * SleipnirAPI::KeyState と SleipnirAPI::Dialog で定義されているメソッドが利用できます。
17
+ #
18
+ # 例:
19
+ #
20
+ # pnir = SleipnirAPI.new
21
+ # tab = pnir.open("http://www.ruby-lang.org/", true)
22
+ #
23
+ # tab.location.href #=> http://www.ruby-lang.org/
24
+ # tab.document.getElementsByTagName("h2")
25
+ # tab.navigate("http://rubyforge.org")
26
+ #
27
+ class Tab
28
+ include SleipnirAPI::Util
29
+ include SleipnirAPI::KeyState
30
+ include SleipnirAPI::Dialog
31
+
32
+ # SleipnirAPI::Sleipnir object
33
+ attr_reader :sleipnir
34
+
35
+ # Sleipnir の ドキュメント ID (ドキュメント固有の ID)
36
+ attr_reader :id
37
+
38
+ def initialize(sleipnir, id)
39
+ @sleipnir = sleipnir
40
+ @id = id
41
+ end
42
+
43
+ # このタブの Window Object (DispHTMLWindow2 (WIN32OLE オブジェクト)) を取得します。
44
+ def window
45
+ self.api.GetWindowObject(self.id)
46
+ end
47
+
48
+ # このタブの HTML Document Object (DispHTMLDocument (WIN32OLE オブジェクト)) を取得します。
49
+ def document
50
+ self.api.GetDocumentObject(self.id)
51
+ end
52
+
53
+ # このタブの WebBrowser Object (IWebBrowser2 (WIN32OLE オブジェクト)) を取得します。
54
+ def browser
55
+ self.api.GetWebBrowserObject(self.id)
56
+ end
57
+ alias web_browser browser
58
+
59
+ # このタブの location Object (IHTMLLocation (WIN32OLE オブジェクト)) を取得します。
60
+ def location
61
+ document.location
62
+ end
63
+
64
+ # このタブのセキュリティ設定を操作する SleipnirAPI::Security オブジェクトを取得します。
65
+ def security
66
+ SleipnirAPI::Security.new(self)
67
+ end
68
+
69
+ # このタブのタブ位置を取得します。
70
+ def index
71
+ self.api.GetIndex(self.id)
72
+ end
73
+
74
+ # このタブを閉じます。
75
+ def close
76
+ self.api.Close(self.id)
77
+ end
78
+
79
+ # <tt>url</tt> で指定されたドキュメントをこのタブで開きます。
80
+ def navigate(url)
81
+ self.api.Navigate(self.id, url)
82
+ end
83
+
84
+ # ページ内を指定されたキーワードで検索します。
85
+ #
86
+ # このメソッドを呼ぶたびにキーワードにマッチした次の位置に移動します。
87
+ # キーワードが発見できない、または先頭のキーワードに戻ってきた場合 false を返します。
88
+ def search(keyword)
89
+ self.api.Search(self.id, keyword)
90
+ end
91
+
92
+ # 指定されたキーワードにマッチする部分をハイライトします。
93
+ def hilight(keyword)
94
+ self.api.Hilight(self.id, keyword)
95
+ end
96
+
97
+ # ドキュメントが読み込み中の場合 true を返します。
98
+ def busy?
99
+ self.api.IsBusy(self.id)
100
+ end
101
+
102
+ # ドキュメントが既読の場合 true を返します。
103
+ def read?
104
+ self.api.IsRead(self.id)
105
+ end
106
+
107
+
108
+ # このタブがアクティブなら true を返します。
109
+ def active?
110
+ self.sleipnir.active_index == index
111
+ end
112
+
113
+ # このタブをアクティブにします。
114
+ def activate
115
+ self.sleipnir.active_index = index
116
+ end
117
+
118
+
119
+ # このタブがナビゲートロックされているなら true を返します。
120
+ def navigate_lock?
121
+ self.api.IsNavigateLock(self.id)
122
+ end
123
+
124
+ # このタブのナビゲートロックを状態を変更します。
125
+ #
126
+ # * <tt>enable</tt> に true を指定するとナビゲートロックします。
127
+ # * <tt>enable</tt> に false を指定するとナビゲートロックを解除します。
128
+ def navigate_lock=(enable)
129
+ self.api.SetNavigateLock(self.id, enable)
130
+ end
131
+
132
+
133
+ # 自動更新の時間を取得する。
134
+ def auto_refresh
135
+ self.api.GetAutoRefresh(self.id)
136
+ end
137
+
138
+ # 自動更新の時間を設定する。
139
+ def auto_refresh=(sec)
140
+ self.api.SetAutoRefresh(self.id, sec)
141
+ end
142
+
143
+ # 指定された引き数が同じドキュメントの場合 true を返します。
144
+ #
145
+ # 同値性の判定には Sleipnir のドキュメント ID を利用します。
146
+ def ==(other)
147
+ return true if self.equal?(other)
148
+ return false unless SleipnirAPI::Tab === other
149
+ return self.id == other.id
150
+ end
151
+
152
+ def inspect
153
+ "#<%s:%d>" % [self.class, self.id]
154
+ end
155
+
156
+ end
157
+ end
158
+
159
+
160
+ __END__
161
+ ──────────────────
162
+ [IDispatch] GetWindowObject(long id)
163
+ ──────────────────
164
+
165
+ [説明]
166
+  Window Object を取得する。
167
+
168
+ [引数]
169
+  id: ドキュメント固有の ID
170
+
171
+ [戻り値]
172
+  Windows Object の IDispatch
173
+
174
+
175
+ ───────────────────
176
+ [IDispatch] GetDocumentObject(long id)
177
+ ───────────────────
178
+
179
+ [説明]
180
+  HTML Document Object を取得する。
181
+
182
+ [引数]
183
+  id: ドキュメント固有の ID
184
+
185
+ [戻り値]
186
+  Document Object の IDispatch
187
+
188
+
189
+ ────────────────────
190
+ [IDispatch] GetWebBrowserObject(long id)
191
+ ────────────────────
192
+
193
+ [説明]
194
+  WebBrowser Object を取得する。
195
+
196
+ [引数]
197
+  id: ドキュメント固有の ID
198
+
199
+ [戻り値]
200
+  WebBrowser Object の IDispatch
201
+
202
+
203
+ ───────────
204
+ [void] Close(long id)
205
+ ───────────
206
+
207
+ [説明]
208
+  指定のドキュメントを閉じる。
209
+
210
+ [引数]
211
+  id: ドキュメント固有の ID
212
+
213
+ [戻り値]
214
+  なし
215
+
216
+
217
+ ────────────────────
218
+ [void] Navigate(long id, string strUrl)
219
+ ────────────────────
220
+
221
+ [説明]
222
+  現在のドキュメントで任意の URL にアクセスする。
223
+
224
+ [引数]
225
+  id: ドキュメント固有の ID
226
+  strUrl: ナビゲートする Url
227
+
228
+ [戻り値]
229
+  なし
230
+
231
+
232
+ ────────────
233
+ [long] GetIndex(long id)
234
+ ────────────
235
+
236
+ [説明]
237
+  ドキュメント固有の ID からタブ位置を取得する。
238
+
239
+ [引数]
240
+  id: ドキュメント固有の ID
241
+
242
+ [戻り値]
243
+  タブ位置
244
+
245
+
246
+ ───────────
247
+ [BOOL] IsBusy(long id)
248
+ ───────────
249
+
250
+ [説明]
251
+  ドキュメントが読み込み中か判断する。
252
+
253
+ [引数]
254
+  id: ドキュメント固有の ID
255
+
256
+ [戻り値]
257
+  読み込み中の場合は true
258
+
259
+
260
+ ───────────────
261
+ [BOOL] IsNavigateLock(long id)
262
+ ───────────────
263
+
264
+ [説明]
265
+  ナビゲートロックが有効か取得する。
266
+
267
+ [引数]
268
+  id: ドキュメント固有の ID
269
+
270
+ [戻り値]
271
+  有効ならば true
272
+
273
+
274
+ ───────────────────────
275
+ [void] SetNavigateLock(long id, BOOL bEnable)
276
+ ───────────────────────
277
+
278
+ [説明]
279
+  ナビゲートロックを有効・無効にする。
280
+
281
+ [引数]
282
+  id: ドキュメント固有の ID
283
+  bEnable: 有効にするなら true
284
+
285
+ [戻り値]
286
+  なし
287
+
288
+
289
+ ─────────────────────
290
+ [BOOL] Search(long id, string strKeyword)
291
+ ─────────────────────
292
+
293
+ [説明]
294
+  ページ内検索を実行する。
295
+
296
+ [引数]
297
+  strKeyword: キーワード
298
+
299
+ [戻り値]
300
+  キーワードが発見できない、または先頭のキーワードに戻ってきたら false
301
+
302
+
303
+ ─────────────────────
304
+ [void] Hilight(long id, string strKeyword)
305
+ ─────────────────────
306
+
307
+ [説明]
308
+  ハイライトを実行する。
309
+
310
+ [引数]
311
+  strKeyword: キーワード
312
+
313
+ [戻り値]
314
+  なし
315
+
316
+
317
+ ───────────
318
+ [BOOL] IsRead(long id)
319
+ ───────────
320
+
321
+ [説明]
322
+  ドキュメントが既読か判断する。
323
+
324
+ [引数]
325
+  id: ドキュメント固有の ID
326
+
327
+ [戻り値]
328
+  既読の場合は true
329
+
330
+
331
+ ─────────────────────
332
+ [void] SetAutoRefresh(long id, long nTime)
333
+ ─────────────────────
334
+
335
+ [説明]
336
+  自動更新の時間を設定する。
337
+
338
+ [引数]
339
+  id: ドキュメント固有の ID
340
+  nTime: 更新時間(0 ~ 1000 秒)
341
+
342
+ [戻り値]
343
+  なし
344
+
345
+
346
+ ───────────────
347
+ [long] GetAutoRefresh(long id)
348
+ ───────────────
349
+
350
+ [説明]
351
+  自動更新の時間を取得する。
352
+
353
+ [引数]
354
+  id: ドキュメント固有の ID
355
+
356
+ [戻り値]
357
+  自動更新の時間(単位 = 秒)
358
+
359
+
@@ -0,0 +1,16 @@
1
+ module SleipnirAPI
2
+ module Util #:nodoc:
3
+
4
+ def ensure_version(required_version)
5
+ if self.sleipnir.version < required_version
6
+ raise SleipnirAPI::NotImplementedError,
7
+ "require Sleipnir v#{required_version}, but v#{self.sleipnir.version}"
8
+ end
9
+ end
10
+
11
+ def api
12
+ self.sleipnir.api
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module SleipnirAPI
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require "Win32API"
2
+
3
+ module SleipnirAPI
4
+ module Win32API #:nodoc:
5
+
6
+ GetLongPathName = ::Win32API.new("kernel32", "GetLongPathNameA", "PPL", "L")
7
+
8
+ module_function
9
+
10
+ def get_long_path_name(short_path)
11
+ buf = '\0' * 1024
12
+ len = GetLongPathName.call(short_path, buf, buf.length)
13
+ buf[0...len]
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,74 @@
1
+ class Filter
2
+
3
+ def initialize
4
+ @filter = []
5
+ end
6
+
7
+ def define_replace(regexp, replace, key)
8
+ @filter << [regexp, lambda { replace }, key]
9
+ end
10
+
11
+ def define_insert_before(tag, snippet, key)
12
+ @filter << [tag, lambda { snippet + tag }, key]
13
+ end
14
+
15
+ def define_insert_after(tag, snippet, key)
16
+ @filter << [tag, lambda { tag + snippet }, key]
17
+ end
18
+
19
+ def update!(file)
20
+ b = File.read(file)
21
+ a = @filter.inject(b) {|bb,subs|
22
+ re, sub, key = *subs
23
+ if key and bb =~ /#{Regexp.quote(key)}/
24
+ bb
25
+ else
26
+ bb.gsub(re, &sub)
27
+ end
28
+ }
29
+ if b != a
30
+ puts file
31
+ File.open(file, "w") {|w| w.puts a }
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+
38
+ GOOGLE_ANALYTICS_ACCOUNT = "UA-1161245-7"
39
+ GOOGLE_ANALYTICS = <<GOOGLE
40
+
41
+ <!-- Google Analytics -->
42
+ <div id="google-analytics">
43
+ <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
44
+ </script>
45
+ <script type="text/javascript">
46
+ _uacct = "#{GOOGLE_ANALYTICS_ACCOUNT}";
47
+ urchinTracker();
48
+ </script>
49
+ </div>
50
+
51
+ GOOGLE
52
+
53
+ f = Filter.new
54
+ f.define_replace(/\A\s+/m, "", nil)
55
+ f.define_replace(/\s*<!--.*?-->\s*<html/m, "<html", nil)
56
+ f.define_insert_before("</body>", GOOGLE_ANALYTICS, '<div id="google-analytics">')
57
+ f.define_replace("</frameset>\n</html>", <<NOFRAME, '<div id="google-analytics">')
58
+ </frameset>
59
+
60
+ <noframe>
61
+ <body>
62
+ #{GOOGLE_ANALYTICS}
63
+ </body>
64
+ </noframe>
65
+
66
+ </html>
67
+ NOFRAME
68
+
69
+ tag = %Q{\n<meta name="verify-v1" content="4xi61YK06FtgbbYoHU2oPltUGvJZLrQogTtv+vaPYTI=" />\n}
70
+ f.define_insert_after("<head>", tag, '<meta name="verify-v1"')
71
+
72
+ ARGV.each do |html|
73
+ f.update!(html)
74
+ end