open 0.1.30 → 0.2.13

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.

Potentially problematic release.


This version of open might be problematic. Click here for more details.

Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +73 -9
  3. data/bin/open +1 -1
  4. data/bin/open_in_browser +1 -1
  5. data/doc/README.gen +72 -8
  6. data/doc/deprecated_code/deprecated_code.md +26 -0
  7. data/img/open_logo.png +0 -0
  8. data/lib/open/base/base.rb +262 -122
  9. data/lib/open/books/README.md +8 -0
  10. data/lib/open/books/books.rb +99 -0
  11. data/lib/open/constants/constants.rb +85 -8
  12. data/lib/open/in_browser/in_browser.rb +476 -304
  13. data/lib/open/in_editor/in_editor.rb +348 -155
  14. data/lib/open/last/last.rb +14 -12
  15. data/lib/open/nano_open/nano_open.rb +4 -3
  16. data/lib/open/{open.rb → open/open.rb} +597 -653
  17. data/lib/open/project/project.rb +3 -2
  18. data/lib/open/requires/failsafe_require_of_beautiful_url.rb +9 -0
  19. data/lib/open/requires/require_the_project.rb +2 -2
  20. data/lib/open/requires/require_yaml.rb +13 -0
  21. data/lib/open/these_files/these_files.rb +1 -1
  22. data/lib/open/toplevel_methods/browser.rb +71 -0
  23. data/lib/open/toplevel_methods/delay.rb +23 -0
  24. data/lib/open/toplevel_methods/e.rb +14 -0
  25. data/lib/open/toplevel_methods/editor.rb +41 -0
  26. data/lib/open/toplevel_methods/host_os.rb +25 -0
  27. data/lib/open/toplevel_methods/is_on_roebe.rb +16 -0
  28. data/lib/open/toplevel_methods/is_on_windows.rb +26 -0
  29. data/lib/open/toplevel_methods/misc.rb +50 -0
  30. data/lib/open/version/version.rb +2 -2
  31. data/lib/open/with_delay/with_delay.rb +9 -11
  32. data/open.gemspec +1 -1
  33. data/test/testing_open.rb +1 -1
  34. data/test/testing_open_in_browser.rb +16 -0
  35. data/test/testing_open_via_launchy.rb +3 -0
  36. data/test/testing_shortcuts.rb +3 -0
  37. metadata +24 -8
  38. data/lib/open/toplevel_code/toplevel_code.rb +0 -189
@@ -2,56 +2,127 @@
2
2
  # Encoding: UTF-8
3
3
  # frozen_string_literal: true
4
4
  # =========================================================================== #
5
+ # === Open::Base
6
+ #
7
+ # Usage example:
8
+ #
9
+ # Open::Base.new(ARGV)
10
+ #
11
+ # =========================================================================== #
5
12
  # require 'open/base/base.rb'
6
- # < Base
13
+ # < ::Open::Base
7
14
  # =========================================================================== #
8
15
  module Open
9
16
 
10
17
  class Base # === Open::Base
11
18
 
12
- require 'yaml'
19
+ alias e puts
13
20
 
14
21
  require 'fileutils'
15
-
16
- begin
17
- require 'colours'
18
- include Colours::E
19
- rescue LoadError; end
20
-
21
- begin
22
- require 'beautiful_url'
23
- rescue LoadError
24
- # puts 'BeautifulUrl is not available.'
25
- end
22
+ require 'open/requires/require_yaml.rb'
23
+ require 'open/constants/constants.rb'
24
+ require 'open/project/project.rb'
25
+ require 'open/toplevel_methods/delay.rb'
26
+ require 'open/toplevel_methods/misc.rb'
27
+ require 'open/toplevel_methods/host_os.rb'
26
28
 
27
29
  begin
28
30
  require 'opn'
29
31
  rescue LoadError; end
30
32
 
31
33
  begin
32
- require 'convert_global_env'
34
+ require 'roebe/classes/find_expanded_alias.rb'
33
35
  rescue LoadError; end
34
36
 
35
37
  begin
36
- require 'roebe/classes/find_expanded_alias.rb'
38
+ require 'colours'
39
+ include Colours::E
37
40
  rescue LoadError; end
38
41
 
39
- require 'open/constants/constants.rb'
40
- require 'open/toplevel_code/toplevel_code.rb'
41
-
42
42
  # ========================================================================= #
43
43
  # === NAMESPACE
44
44
  # ========================================================================= #
45
45
  NAMESPACE = inspect
46
46
 
47
+ # ========================================================================= #
48
+ # === initialize
49
+ # ========================================================================= #
50
+ def initialize(i = ARGV)
51
+ set_commandline_arguments(i)
52
+ end
53
+
54
+ # ========================================================================= #
55
+ # === reset (reset tag)
56
+ # ========================================================================= #
57
+ def reset
58
+ # ======================================================================= #
59
+ # === @namespace
60
+ # ======================================================================= #
61
+ @namespace = NAMESPACE
62
+ # ======================================================================= #
63
+ # === @be_verbose
64
+ # ======================================================================= #
65
+ @be_verbose = true
66
+ end
67
+
68
+ require 'open/toplevel_methods/is_on_windows.rb'
69
+ # ========================================================================= #
70
+ # === is_on_windows?
71
+ # ========================================================================= #
72
+ def is_on_windows?(
73
+ i = ::Open.host_os?
74
+ )
75
+ ::Open.is_on_windows?(i)
76
+ end; alias on_windows? is_on_windows? # === on_windows?
77
+
78
+ # ========================================================================= #
79
+ # === esystem (esystem tag)
80
+ #
81
+ # This method contains a bit of an ad-hoc fix to make this work on
82
+ # windows as well.
83
+ #
84
+ # Eventually may have to rewrite the method a little bit, but for now
85
+ # (September 2021) this has to suffice.
86
+ # ========================================================================= #
87
+ def esystem(
88
+ i,
89
+ do_show_the_command_that_will_be_used = true # This is the default.
90
+ )
91
+ if is_on_windows?
92
+ # i = i.to_s.sub(/\\/,'\\') if i.include?("\\")
93
+ i = '"'+i.to_s+'"' if i.include?(' ')
94
+ end
95
+ e i if do_show_the_command_that_will_be_used
96
+ system(i)
97
+ end
98
+
99
+ # ========================================================================= #
100
+ # === return_pwd
101
+ # ========================================================================= #
102
+ def return_pwd
103
+ "#{Dir.pwd}/".squeeze('/')
104
+ end
105
+
106
+ # ========================================================================= #
107
+ # == snakecase
108
+ # ========================================================================= #
109
+ def snakecase(i)
110
+ i.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
111
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
112
+ tr('-', '_').
113
+ gsub(/\s/, '_').
114
+ gsub(/__+/, '_').
115
+ downcase
116
+ end
117
+
47
118
  # ========================================================================= #
48
119
  # === rev
49
120
  # ========================================================================= #
50
121
  def rev
51
122
  if Object.const_defined? :Colours
52
- ::Colours.rev
123
+ return ::Colours.rev
53
124
  else
54
- ''
125
+ return ''
55
126
  end
56
127
  end
57
128
 
@@ -125,78 +196,68 @@ class Base # === Open::Base
125
196
  end
126
197
 
127
198
  # ========================================================================= #
128
- # === esystem
129
- #
130
- # This is a bit of an ad-hoc fix to make this work on windows as well.
199
+ # === host_os?
131
200
  #
132
- # Eventually may have to rewrite the method a little bit, but for now
133
- # (September 2021) this has to suffice.
201
+ # Return the host-operating system via this method.
134
202
  # ========================================================================= #
135
- def esystem(
136
- i, do_show_the_command_that_will_be_used = true
137
- )
138
- if is_on_windows?
139
- # i = i.to_s.sub(/\\/,'\\') if i.include?("\\")
140
- i = '"'+i.to_s+'"' if i.include?(' ')
141
- end
142
- e i if do_show_the_command_that_will_be_used
143
- system(i)
203
+ def host_os?
204
+ ::Open.host_os?
144
205
  end
145
206
 
207
+ require 'open/toplevel_methods/is_on_roebe.rb'
146
208
  # ========================================================================= #
147
- # === sanitize
209
+ # === is_on_roebe?
148
210
  # ========================================================================= #
149
- def sanitize(i)
150
- return i unless Object.const_defined? :ConvertGlobalEnv
151
- begin
152
- return ConvertGlobalEnv.convert(i)
153
- rescue NoMethodError
154
- i
155
- end
211
+ def is_on_roebe?
212
+ ::Open.is_on_roebe?
156
213
  end
157
214
 
158
215
  # ========================================================================= #
159
- # === return_pwd
216
+ # === namespace?
160
217
  # ========================================================================= #
161
- def return_pwd
162
- "#{Dir.pwd}/".squeeze('/')
218
+ def namespace?
219
+ @namespace
163
220
  end
164
221
 
165
222
  # ========================================================================= #
166
- # == snakecase
223
+ # === ecomment
167
224
  # ========================================================================= #
168
- def snakecase(i)
169
- i.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
170
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
171
- tr('-', '_').
172
- gsub(/\s/, '_').
173
- gsub(/__+/, '_').
174
- downcase
225
+ def ecomment(i = '')
226
+ ::Colours.ecomment(i)
175
227
  end
176
228
 
229
+ require 'open/toplevel_methods/browser.rb'
177
230
  # ========================================================================= #
178
- # === reset (reset tag)
231
+ # === use_which_browser?
179
232
  # ========================================================================= #
180
- def reset
181
- # ======================================================================= #
182
- # === @namespace
183
- # ======================================================================= #
184
- @namespace = NAMESPACE
185
- # ======================================================================= #
186
- # === @be_verbose
187
- # ======================================================================= #
188
- @be_verbose = true
233
+ def use_which_browser?
234
+ ::Open.use_which_browser?
189
235
  end
190
236
 
191
237
  # ========================================================================= #
192
- # === opnn
238
+ # === this_file_was_not_found
239
+ #
240
+ # Use this to notify the user, whenever the open-gem was unable to
241
+ # find a file that was assumed to exist locally.
193
242
  # ========================================================================= #
194
- def opnn(
195
- i = { namespace: @namespace }
196
- )
197
- if Object.const_defined? :Opn
198
- Opn.opn(i)
199
- end
243
+ def this_file_was_not_found(i)
244
+ e "#{rev}No file called `#{sfile(i)}` was found. It "\
245
+ "is assumed to not exist."
246
+ end; alias no_file_exists_at this_file_was_not_found # === no_file_exists_at
247
+ alias no_file_was_found_at this_file_was_not_found # === no_file_was_found_at
248
+
249
+ # ========================================================================= #
250
+ # === mkdir (mkdir tag)
251
+ # ========================================================================= #
252
+ def mkdir(i)
253
+ FileUtils.mkdir_p(i)
254
+ end
255
+
256
+ # ========================================================================= #
257
+ # === touch (touch tag)
258
+ # ========================================================================= #
259
+ def touch(i)
260
+ FileUtils.touch(i)
200
261
  end
201
262
 
202
263
  # ========================================================================= #
@@ -208,6 +269,22 @@ class Base # === Open::Base
208
269
  @commandline_arguments = [i].flatten.compact
209
270
  end
210
271
 
272
+ # ========================================================================= #
273
+ # === commandline_arguments?
274
+ # ========================================================================= #
275
+ def commandline_arguments?
276
+ @commandline_arguments
277
+ end
278
+
279
+ # ========================================================================= #
280
+ # === commandline_arguments_without_hyphens
281
+ # ========================================================================= #
282
+ def commandline_arguments_without_hyphens
283
+ @commandline_arguments.reject {|entry|
284
+ entry.start_with?('--')
285
+ }
286
+ end
287
+
211
288
  # ========================================================================= #
212
289
  # === first_argument?
213
290
  # ========================================================================= #
@@ -215,94 +292,158 @@ class Base # === Open::Base
215
292
  @commandline_arguments.first
216
293
  end
217
294
 
295
+ require 'open/toplevel_methods/editor.rb'
218
296
  # ========================================================================= #
219
- # === rds
297
+ # === use_which_editor?
220
298
  # ========================================================================= #
221
- def rds(i)
222
- i.squeeze('/')
299
+ def use_which_editor?
300
+ ::Open.use_which_editor?
223
301
  end
224
302
 
225
303
  # ========================================================================= #
226
- # === mkdir
304
+ # === opnn
227
305
  # ========================================================================= #
228
- def mkdir(i)
229
- FileUtils.mkdir_p(i)
306
+ def opnn(
307
+ i = {
308
+ namespace: @namespace
309
+ }
310
+ )
311
+ if Object.const_defined? :Opn
312
+ Opn.opn(i)
313
+ end
230
314
  end
231
315
 
232
316
  # ========================================================================= #
233
- # === touch
317
+ # === use_which_delay?
234
318
  # ========================================================================= #
235
- def touch(i)
236
- FileUtils.touch(i)
319
+ def use_which_delay?
320
+ Open.use_which_delay?.to_f
237
321
  end
238
322
 
239
323
  # ========================================================================= #
240
- # === use_which_editor?
324
+ # === opne
241
325
  # ========================================================================= #
242
- def use_which_editor?
243
- ::Open.use_which_editor?
326
+ def opne(i = '')
327
+ opn(namespace: @namespace); e i
244
328
  end
245
329
 
330
+ begin
331
+ require 'beautiful_url'
332
+ rescue LoadError; end
246
333
  # ========================================================================= #
247
- # === use_which_browser?
334
+ # === beautiful_url
335
+ #
336
+ # Wrapper-method towards BeautifulUrl.
248
337
  # ========================================================================= #
249
- def use_which_browser?
250
- ::Open.use_which_browser?
338
+ def beautiful_url(i)
339
+ if beautiful_url_is_available?
340
+ i = BeautifulUrl::BeautifulUrl.new(i).results?
341
+ end
342
+ return i
251
343
  end
252
344
 
253
345
  # ========================================================================= #
254
- # === this_file_was_not_found
255
- #
256
- # Use this whenever we did not find any file.
346
+ # === beautiful_url_is_available?
257
347
  # ========================================================================= #
258
- def this_file_was_not_found(i)
259
- e "No file called `#{sfile(i)}` was found. It "\
260
- "is assumed that it does not exist."
261
- end; alias no_file_exists_at this_file_was_not_found # === no_file_exists_at
262
- alias no_file_was_found_at this_file_was_not_found # === no_file_was_found_at
348
+ def beautiful_url_is_available?
349
+ Object.const_defined? :BeautifulUrl
350
+ end; alias is_beautiful_url_available? beautiful_url_is_available? # === is_beautiful_url_available?
263
351
 
264
352
  # ========================================================================= #
265
- # === host_os?
266
- #
267
- # Return the host-operating system via this method.
353
+ # === try_to_require_the_beautiful_url_project
268
354
  # ========================================================================= #
269
- def host_os?
270
- ::Open.host_os?
355
+ def try_to_require_the_beautiful_url_project
356
+ unless Object.const_defined? :BeautifulUrl
357
+ begin
358
+ require 'open/requires/failsafe_require_of_beautiful_url.rb'
359
+ rescue LoadError; end
360
+ end
271
361
  end
272
362
 
273
363
  # ========================================================================= #
274
- # === is_on_windows?
364
+ # === file_load_default_browser?
275
365
  # ========================================================================= #
276
- def is_on_windows?(i = host_os?)
277
- ::Open.is_on_windows?(i)
278
- end; alias on_windows? is_on_windows? # === on_windows?
366
+ def file_load_default_browser?
367
+ # ======================================================================= #
368
+ # The .yml file will hold which browser is to be used by default.
369
+ # ======================================================================= #
370
+ _ = "#{::Open.project_base_directory?}yaml/use_this_browser.yml"
371
+ if File.exist? _
372
+ return YAML.load_file(_)
373
+ else
374
+ return 'chrome'
375
+ end
376
+ end
279
377
 
280
378
  # ========================================================================= #
281
- # === is_on_roebe?
379
+ # === file_load_default_editor?
282
380
  # ========================================================================= #
283
- def is_on_roebe?
284
- ENV['IS_ROEBE'].to_s == '1'
381
+ def file_load_default_editor?
382
+ # ======================================================================= #
383
+ # The .yml file will hold which editor is to be used by default.
384
+ # ======================================================================= #
385
+ _ = "#{::Open.project_base_directory?}yaml/use_this_editor.yml"
386
+ if File.exist? _
387
+ return YAML.load_file(_)
388
+ else
389
+ return 'bluefish'
390
+ end
285
391
  end
286
392
 
393
+ begin
394
+ require 'convert_global_env'
395
+ rescue LoadError; end
287
396
  # ========================================================================= #
288
- # === ecomment
397
+ # === sanitize_global_environment
398
+ #
399
+ # This method bundles together functionality that ConvertGlobalEnv
400
+ # can handle.
289
401
  # ========================================================================= #
290
- def ecomment(i = '')
291
- ::Colours.ecomment(i)
292
- end
402
+ def sanitize_global_environment(i)
403
+ return i unless Object.const_defined? :ConvertGlobalEnv
404
+ begin
405
+ return ConvertGlobalEnv.convert(i)
406
+ rescue NoMethodError
407
+ return i
408
+ end
409
+ end; alias sanitize sanitize_global_environment # === sanitize
293
410
 
294
411
  # ========================================================================= #
295
- # === beautiful_url
412
+ # === consider_padding
296
413
  #
297
- # Wrapper-method towards BeautifulUrl.
414
+ # Simply add a surrounding '"' to the given input, so that any resulting
415
+ # system() call will still work if we have awkward filenames.
298
416
  # ========================================================================= #
299
- def beautiful_url(i)
300
- if Object.const_defined? :BeautifulUrl
301
- i = BeautifulUrl::BeautifulUrl.new(i).results?
417
+ def consider_padding(i)
418
+ if i.include?(' ') or i.include?('(')
419
+ i = '"'+i+'"'
302
420
  end
303
- return i
421
+ return i # Always return the input, no matter if modified or not.
422
+ end
423
+
424
+ # ========================================================================= #
425
+ # === rds
426
+ # ========================================================================= #
427
+ def rds(i)
428
+ i.squeeze('/')
429
+ end
430
+
431
+ # ========================================================================= #
432
+ # === append_array_to_commandline_arguments
433
+ # ========================================================================= #
434
+ def append_array_to_commandline_arguments(i)
435
+ i = [i].flatten.compact
436
+ @commandline_arguments << i
437
+ @commandline_arguments.flatten!
304
438
  end
305
439
 
440
+ # ========================================================================= #
441
+ # === create_the_internal_hash
442
+ # ========================================================================= #
443
+ def create_the_internal_hash
444
+ @internal_hash = {}
445
+ end; alias reset_the_internal_hash create_the_internal_hash # === reset_the_internal_hash
446
+
306
447
  # ========================================================================= #
307
448
  # === infer_the_namespace
308
449
  #
@@ -319,11 +460,10 @@ class Base # === Open::Base
319
460
  @namespace = _ # And assign it here.
320
461
  end
321
462
 
322
- # ========================================================================= #
323
- # === namespace?
324
- # ========================================================================= #
325
- def namespace?
326
- @namespace
327
- end
463
+ end; end
328
464
 
329
- end; end
465
+ if __FILE__ == $PROGRAM_NAME
466
+ alias e puts
467
+ base = Open::Base.new(ARGV)
468
+ e base.host_os?
469
+ end # base.rb
@@ -0,0 +1,8 @@
1
+ This directory is specifically to enable the functionality of
2
+ "opening books". Books in this context refers to PDF files,
3
+ that is, .pdf files. In order for this functionality to work,
4
+ you need to have .pdf files available locally, and you also
5
+ need to supply a custom file that keeps track of the themes
6
+ of the books, such as "all books that handle the theme
7
+ genetics". Then, once such a file has been made available,
8
+ class Open::Books will simply open all these books.
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Open::Book
6
+ #
7
+ # This class will specifically open "books", that is, .pdf files.
8
+ #
9
+ # Usage example:
10
+ #
11
+ # Open::Book.new(ARGV)
12
+ #
13
+ # =========================================================================== #
14
+ require 'open/base/base.rb'
15
+
16
+ module Open
17
+
18
+ class Book < ::Open::Base # === Open::Book
19
+
20
+ # ========================================================================= #
21
+ # === FILE_TOPICS_PER_BOOK
22
+ # ========================================================================= #
23
+ FILE_TOPICS_PER_BOOK = '/home/x/books/topics_per_book.yml'
24
+
25
+ # ========================================================================= #
26
+ # === initialize
27
+ # ========================================================================= #
28
+ def initialize(
29
+ i = ARGV,
30
+ run_already = true
31
+ )
32
+ reset
33
+ set_commandline_arguments(i)
34
+ run if run_already
35
+ end
36
+
37
+ # ========================================================================= #
38
+ # === reset (reset tag)
39
+ # ========================================================================= #
40
+ def reset
41
+ super()
42
+ infer_the_namespace
43
+ # ======================================================================= #
44
+ # === @dataset
45
+ # ======================================================================= #
46
+ @dataset = nil
47
+ if File.exist?(FILE_TOPICS_PER_BOOK)
48
+ @dataset = YAML.load_file(FILE_TOPICS_PER_BOOK)
49
+ end
50
+ end
51
+
52
+ # ========================================================================= #
53
+ # === main_file?
54
+ # ========================================================================= #
55
+ def main_file?
56
+ FILE_TOPICS_PER_BOOK
57
+ end
58
+
59
+ # ========================================================================= #
60
+ # === open_these_files
61
+ # ========================================================================= #
62
+ def open_these_files(array)
63
+ require 'open/open/open.rb'
64
+ array.map! {|entry|
65
+ entry = entry.dup
66
+ unless entry.include?('/home/x/books/')
67
+ entry.prepend(
68
+ entry.delete_suffix('.pdf')+'/'
69
+ )
70
+ entry.prepend('/home/x/books/')
71
+ end
72
+ entry
73
+ }
74
+ ::Open::Open.new(array)
75
+ end
76
+
77
+ # ========================================================================= #
78
+ # === run (run tag)
79
+ # ========================================================================= #
80
+ def run
81
+ _ = @dataset
82
+ commandline_arguments?.each {|this_topic|
83
+ this_topic = this_topic.dup if this_topic.frozen?
84
+ this_topic.delete!(':') if this_topic.include? ':'
85
+ if _.has_key?(this_topic)
86
+ opne 'Processing the topic '+steelblue(this_topic)+' next.'
87
+ open_these_files(_[this_topic])
88
+ else
89
+ opne 'The topic '+steelblue(this_topic)+' was not '\
90
+ 'found in the file '+main_file?+'.'
91
+ end
92
+ }
93
+ end
94
+
95
+ end; end
96
+
97
+ if __FILE__ == $PROGRAM_NAME
98
+ Open::Book.new(ARGV)
99
+ end # openbooks :java