beautiful_url 1.4.105
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of beautiful_url might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +47 -0
- data/beautiful_url.gemspec +59 -0
- data/bin/beautiful_url +9 -0
- data/doc/README.gen +45 -0
- data/lib/beautiful_url.rb +1 -0
- data/lib/beautiful_url/class/constants.rb +23 -0
- data/lib/beautiful_url/class/generate_tab_completion_for_bash_shell.rb +67 -0
- data/lib/beautiful_url/class/initialize.rb +149 -0
- data/lib/beautiful_url/class/misc.rb +473 -0
- data/lib/beautiful_url/class/reset.rb +50 -0
- data/lib/beautiful_url/class/run.rb +20 -0
- data/lib/beautiful_url/constants/base_constants.rb +221 -0
- data/lib/beautiful_url/constants/constants.rb +9 -0
- data/lib/beautiful_url/constants/encoding.rb +47 -0
- data/lib/beautiful_url/constants/misc.rb +14 -0
- data/lib/beautiful_url/constants/newline.rb +14 -0
- data/lib/beautiful_url/constants/tasks.rb +30 -0
- data/lib/beautiful_url/constants/time.rb +21 -0
- data/lib/beautiful_url/json_generator/json_generator.rb +85 -0
- data/lib/beautiful_url/requires/failsafe_require_of_beautiful_url.rb +9 -0
- data/lib/beautiful_url/requires/require_the_beautiful_url_project.rb +14 -0
- data/lib/beautiful_url/toplevel_methods/current_month.rb +32 -0
- data/lib/beautiful_url/toplevel_methods/local_menu.rb +1675 -0
- data/lib/beautiful_url/toplevel_methods/menu.rb +4778 -0
- data/lib/beautiful_url/toplevel_methods/misc.rb +18 -0
- data/lib/beautiful_url/toplevel_methods/moodle_menu.rb +135 -0
- data/lib/beautiful_url/toplevel_methods/return_location_of_the_menu_file.rb +27 -0
- data/lib/beautiful_url/toplevel_methods/roebe.rb +17 -0
- data/lib/beautiful_url/toplevel_methods/university_menu.rb +13956 -0
- data/lib/beautiful_url/version/version.rb +26 -0
- data/lib/beautiful_url/www/app.rb +168 -0
- data/test/testing_beautiful_url.rb +46 -0
- data/test/testing_the_base_constants.rb +26 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de3f672722341a72f5d4e52cd79c3679e1b4da97a46101127d4b75cf4ec7a1ac
|
4
|
+
data.tar.gz: 39ccecb8f95ad5fc8c14e7f823a8f56255980533f76c6aaa4233732e923f8193
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec535fa493683c10bc35834d9a956a116f0869db257d1afd22eae7b486d6137466d70d8b621f9e13cb3059414840307d3609fd7bc1836fb1202784dd9d310b96
|
7
|
+
data.tar.gz: aebf74a3604182bf44fd4f4d336180d171074e77bc5cbb3cd20ec0c4d43f3efbabde2c86f9d33a42b1cb44e1f68087e69189c1ccd5a3670f77ffa0622f3c97ad
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
|
2
|
+
[![forthebadge](http://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/beautiful_url.svg)](https://badge.fury.io/rb/beautiful_url)
|
4
|
+
|
5
|
+
## Introducing the BeautifulUrl project
|
6
|
+
|
7
|
+
This project has been created to primarily cover my needs to map a
|
8
|
+
given input (typically a symbol, such as :ruby_homepage), to
|
9
|
+
a specific String - a remote URL, in this case
|
10
|
+
**https://www.ruby-lang.org/en/**.
|
11
|
+
|
12
|
+
In fact this is the primary scenario for this project: it provides
|
13
|
+
a simple mapper between symbols, and remote URLs.
|
14
|
+
|
15
|
+
At a later time I also added symbols as shortcuts to local files,
|
16
|
+
so the whole project is a quick way for me to navigate different
|
17
|
+
resources (including **RESTful APIs**).
|
18
|
+
|
19
|
+
I may at a later point add the ability to arbitrarily add new
|
20
|
+
entries via a yaml file, so that other people can extend this
|
21
|
+
project at their own leisure - but for now, the original use
|
22
|
+
case will be kept as-is. Extending the project may happen at
|
23
|
+
a later time.
|
24
|
+
|
25
|
+
## General usage examples:
|
26
|
+
|
27
|
+
BeautifulUrl::BeautifulUrl.new('palemoon', :replace_localhost)
|
28
|
+
BeautifulUrl::BeautifulUrl.new('palemoon' {{ replace_localhost: true }}
|
29
|
+
BeautifulUrl['palemoon'] # ← This is recommended, as it is simpler.
|
30
|
+
|
31
|
+
## Sinatra-Interface
|
32
|
+
|
33
|
+
The BeautifulUrl project has a minimalistic **sinatra interface**.
|
34
|
+
|
35
|
+
You can start it in this way:
|
36
|
+
|
37
|
+
require 'beautiful_url/www/app.rb'
|
38
|
+
|
39
|
+
BeautifulUrl::App.start_sinatra_interface
|
40
|
+
|
41
|
+
Note that this depends on the **cyberweb** project; at the least a
|
42
|
+
subclass defined in the cyberweb project, mostly as that makes
|
43
|
+
it easier for me to handle the same or similar code across
|
44
|
+
many different projects.
|
45
|
+
|
46
|
+
The main purpose of this App is to map given string input into
|
47
|
+
the corresponding URL.
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# =========================================================================== #
|
2
|
+
# Gemspec for Beautiful URL.
|
3
|
+
# =========================================================================== #
|
4
|
+
require 'beautiful_url'
|
5
|
+
|
6
|
+
Gem::Specification.new { |s|
|
7
|
+
|
8
|
+
s.name = 'beautiful_url'
|
9
|
+
s.version = BeautifulUrl.version?
|
10
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
11
|
+
|
12
|
+
DESCRIPTION = <<-EOF
|
13
|
+
|
14
|
+
This is a medium-sized gem which attempts to handle "matching" a String
|
15
|
+
or a Symbol against (remote) URLs. The project was created in order to
|
16
|
+
use short identifiers that can pinpoint to remote URLs, a bit similar
|
17
|
+
to how shorturl is working.
|
18
|
+
|
19
|
+
The gem is, however had, tailored to my use cases, so it will most
|
20
|
+
likely be utterly useless to other people by default. Most downloads
|
21
|
+
of this gem happen by scripts and bots, so do not think that the
|
22
|
+
download numbers imply anything about "real" usage - the gem is
|
23
|
+
way too much tailored to my own use case.
|
24
|
+
|
25
|
+
In the long run, though, the project may be extended to allow the
|
26
|
+
custom loading of yaml files, for a later release - but for now,
|
27
|
+
I do not think that this project will be useful to anyone else.
|
28
|
+
|
29
|
+
More documentation can be found at:
|
30
|
+
|
31
|
+
https://www.rubydoc.info/gems/beautiful_url/
|
32
|
+
|
33
|
+
EOF
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# Show this when a user installs this gem.
|
37
|
+
# ========================================================================= #
|
38
|
+
s.post_install_message = <<-EOF
|
39
|
+
|
40
|
+
You should be able to invoke bin/beautiful_url via:
|
41
|
+
|
42
|
+
beautiful_url
|
43
|
+
|
44
|
+
EOF
|
45
|
+
|
46
|
+
s.summary = DESCRIPTION
|
47
|
+
s.description = DESCRIPTION
|
48
|
+
|
49
|
+
s.authors = ["Robert A. Heiler"]
|
50
|
+
s.email = 'shevegen@gmail.com'
|
51
|
+
s.files = Dir["**/*"]
|
52
|
+
s.licenses = 'GPL-2.0'
|
53
|
+
s.homepage = 'http://rubygems.org/gems/beautiful_url'
|
54
|
+
|
55
|
+
s.required_ruby_version = '>= '+RUBY_VERSION
|
56
|
+
s.required_rubygems_version = '>= '+Gem::VERSION
|
57
|
+
s.rubygems_version = '>= '+Gem::VERSION
|
58
|
+
|
59
|
+
}
|
data/bin/beautiful_url
ADDED
data/doc/README.gen
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
ADD_RUBY_BADGE
|
2
|
+
|
3
|
+
## Introducing the BeautifulUrl project
|
4
|
+
|
5
|
+
This project has been created to primarily cover my needs to map a
|
6
|
+
given input (typically a symbol, such as :ruby_homepage), to
|
7
|
+
a specific String - a remote URL, in this case
|
8
|
+
**https://www.ruby-lang.org/en/**.
|
9
|
+
|
10
|
+
In fact this is the primary scenario for this project: it provides
|
11
|
+
a simple mapper between symbols, and remote URLs.
|
12
|
+
|
13
|
+
At a later time I also added symbols as shortcuts to local files,
|
14
|
+
so the whole project is a quick way for me to navigate different
|
15
|
+
resources (including **RESTful APIs**).
|
16
|
+
|
17
|
+
I may at a later point add the ability to arbitrarily add new
|
18
|
+
entries via a yaml file, so that other people can extend this
|
19
|
+
project at their own leisure - but for now, the original use
|
20
|
+
case will be kept as-is. Extending the project may happen at
|
21
|
+
a later time.
|
22
|
+
|
23
|
+
## General usage examples:
|
24
|
+
|
25
|
+
BeautifulUrl::BeautifulUrl.new('palemoon', :replace_localhost)
|
26
|
+
BeautifulUrl::BeautifulUrl.new('palemoon' {{ replace_localhost: true }}
|
27
|
+
BeautifulUrl['palemoon'] # ← This is recommended, as it is simpler.
|
28
|
+
|
29
|
+
## Sinatra-Interface
|
30
|
+
|
31
|
+
The BeautifulUrl project has a minimalistic **sinatra interface**.
|
32
|
+
|
33
|
+
You can start it in this way:
|
34
|
+
|
35
|
+
require 'beautiful_url/www/app.rb'
|
36
|
+
|
37
|
+
BeautifulUrl::App.start_sinatra_interface
|
38
|
+
|
39
|
+
Note that this depends on the **cyberweb** project; at the least a
|
40
|
+
subclass defined in the cyberweb project, mostly as that makes
|
41
|
+
it easier for me to handle the same or similar code across
|
42
|
+
many different projects.
|
43
|
+
|
44
|
+
The main purpose of this App is to map given string input into
|
45
|
+
the corresponding URL.
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'beautiful_url/requires/require_the_beautiful_url_project.rb'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'beautiful_url/class/constants.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'beautiful_url/constants/constants.rb'
|
8
|
+
|
9
|
+
module BeautifulUrl
|
10
|
+
|
11
|
+
class BeautifulUrl # === BeautifulUrl::BeautifulUrl
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === RUN_ALREADY
|
15
|
+
# ========================================================================= #
|
16
|
+
RUN_ALREADY = true
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === DEFAULT_URL
|
20
|
+
# ========================================================================= #
|
21
|
+
DEFAULT_URL = 'http://localhost/DATA/PROGRAMMING_LANGUAGES/R/R.cgi'
|
22
|
+
|
23
|
+
end; end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'beautiful_url/class/generate_tab_completion_for_bash_shell.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module BeautifulUrl
|
8
|
+
|
9
|
+
class BeautifulUrl # It is part of the class.
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'save_file'
|
13
|
+
rescue LoadError; end
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === generate_tab_completion_for_bash_shell
|
17
|
+
#
|
18
|
+
# This entry point will generate the tab-completion for the BASH shell.
|
19
|
+
#
|
20
|
+
# Invocation examples:
|
21
|
+
#
|
22
|
+
# purl GENERATE
|
23
|
+
# purl --generate
|
24
|
+
#
|
25
|
+
# ========================================================================= #
|
26
|
+
def generate_tab_completion_for_bash_shell
|
27
|
+
begin
|
28
|
+
require 'collect_first_word_of_case_menu'
|
29
|
+
rescue LoadError; end
|
30
|
+
begin
|
31
|
+
require 'opn'
|
32
|
+
rescue LoadError; end
|
33
|
+
opn; e 'Now generating tab completion for the bash shell.'
|
34
|
+
_ = ''.dup # This is the string to store.
|
35
|
+
_ << 'completion_for_purl()
|
36
|
+
{
|
37
|
+
local cur complete_these_words
|
38
|
+
|
39
|
+
COMPREPLY=() # Array variable storing the possible completions.
|
40
|
+
cur="${COMP_WORDS[COMP_CWORD]}"
|
41
|
+
complete_these_words="'
|
42
|
+
beautiful_menu = ::BeautifulUrl[:beautiful_menu]
|
43
|
+
if beautiful_menu.is_a? Array
|
44
|
+
beautiful_menu = beautiful_menu.first
|
45
|
+
end
|
46
|
+
results = CollectFirstWordOfCaseMenu.new(beautiful_menu).result
|
47
|
+
results.sort.each {|entry|
|
48
|
+
_ << entry+"\n"
|
49
|
+
}
|
50
|
+
_ << ' "
|
51
|
+
|
52
|
+
if [[ ${cur} == * ]] ; then
|
53
|
+
COMPREPLY=( $(compgen -W "${complete_these_words}" -- ${cur}) )
|
54
|
+
return 0
|
55
|
+
fi
|
56
|
+
}
|
57
|
+
# Next, available auto-completion for the commands "purl" and "url".
|
58
|
+
complete -F completion_for_purl url
|
59
|
+
complete -F completion_for_purl purl
|
60
|
+
'
|
61
|
+
store_where =
|
62
|
+
"#{BASE_DIR}DATA/PC/OS/LINUX/SHELL/SCRIPTS/completion_for_purl.sh"
|
63
|
+
opn; e 'We will store at `'+store_where+'`.'
|
64
|
+
SaveFile.write_what_into(_, store_where)
|
65
|
+
end; alias generate_tab_completion generate_tab_completion_for_bash_shell # === generate_tab_completion
|
66
|
+
|
67
|
+
end; end # bmenu
|
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === BeautifulUrl::BeautifulUrl
|
6
|
+
#
|
7
|
+
# The class BeautifulUrl wants to make it easier to open local pages -
|
8
|
+
# but it can also make use of shortcuts for remote files.
|
9
|
+
#
|
10
|
+
# It additionally supports the usage of intralinks, e.g. if you wish
|
11
|
+
# to append something like '#foo' to a html page, it is possible
|
12
|
+
# through this project.
|
13
|
+
#
|
14
|
+
# See below for some specific usage examples.
|
15
|
+
#
|
16
|
+
# In the event that a substitute for the given input can not be found,
|
17
|
+
# we will return the original input unmodified.
|
18
|
+
#
|
19
|
+
# Specific usage examples for class BeautifulUrl in ruby code:
|
20
|
+
#
|
21
|
+
# require 'beautiful_url'
|
22
|
+
# url = BeautifulUrl.new('science_news')
|
23
|
+
# url.input?; url.url?; url.remote?
|
24
|
+
# url.do_replace_localhost
|
25
|
+
# url.replace_data
|
26
|
+
# x = BeautifulUrl.new 'geastask'
|
27
|
+
# BeautifulUrl.new('slogans').url?
|
28
|
+
# BeautifulUrl.new('geastask').url_was_found
|
29
|
+
# BeautifulUrl.new('cmd#chroot') # => "http://localhost/DATA/PC/OS/LINUX/LINUX_COMMANDS.cgi#chroot"
|
30
|
+
#
|
31
|
+
# =========================================================================== #
|
32
|
+
# require 'beautiful_url/class/initialize.rb'
|
33
|
+
# =========================================================================== #
|
34
|
+
require 'beautiful_url/class/constants.rb'
|
35
|
+
require 'beautiful_url/class/misc.rb'
|
36
|
+
require 'beautiful_url/class/reset.rb'
|
37
|
+
require 'beautiful_url/class/run.rb'
|
38
|
+
|
39
|
+
module BeautifulUrl
|
40
|
+
|
41
|
+
class BeautifulUrl # === BeautifulUrl::BeautifulUrl
|
42
|
+
|
43
|
+
alias e puts
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === initialize
|
47
|
+
#
|
48
|
+
# Usage examples:
|
49
|
+
#
|
50
|
+
# x = BeautifulUrl::BeautifulUrl.new('palemoon', :replace_localhost)
|
51
|
+
# x = BeautifulUrl::BeautifulUrl.new('palemoon' {{ replace_localhost: true }}
|
52
|
+
#
|
53
|
+
# ========================================================================= #
|
54
|
+
def initialize(
|
55
|
+
commandline_arguments = ARGV,
|
56
|
+
run_already = RUN_ALREADY,
|
57
|
+
&block
|
58
|
+
)
|
59
|
+
reset # Must come first.
|
60
|
+
case commandline_arguments # case tag
|
61
|
+
# ======================================================================= #
|
62
|
+
# === :dont_run_yet
|
63
|
+
# ======================================================================= #
|
64
|
+
when :dont_run_yet,
|
65
|
+
:do_not_run_yet
|
66
|
+
commandline_arguments = DEFAULT_URL
|
67
|
+
run_already = false
|
68
|
+
end
|
69
|
+
set_commandline_arguments(
|
70
|
+
commandline_arguments
|
71
|
+
)
|
72
|
+
case run_already
|
73
|
+
# ======================================================================= #
|
74
|
+
# === :replace_localhost
|
75
|
+
# ======================================================================= #
|
76
|
+
when :replace_localhost,
|
77
|
+
:replace,
|
78
|
+
:replace_localhost_with_data,
|
79
|
+
:do_replace_localhost
|
80
|
+
@replace_localhost_with_data = true # Default, as this is more important.
|
81
|
+
run_already = RUN_ALREADY
|
82
|
+
else
|
83
|
+
if run_already.is_a? Hash # Must come after reset().
|
84
|
+
# =================================================================== #
|
85
|
+
# === :replace_localhost
|
86
|
+
# =================================================================== #
|
87
|
+
if run_already.has_key? :replace_localhost
|
88
|
+
@replace_localhost_with_data = run_already[:replace_localhost]
|
89
|
+
run_already = RUN_ALREADY # Restore the default again.
|
90
|
+
# =================================================================== #
|
91
|
+
# === :replace
|
92
|
+
# =================================================================== #
|
93
|
+
elsif run_already.has_key? :replace
|
94
|
+
@replace_localhost_with_data = run_already[:replace]
|
95
|
+
run_already = RUN_ALREADY # Restore the default again.
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
# ======================================================================= #
|
100
|
+
# === Handle blocks given to us
|
101
|
+
#
|
102
|
+
# This has to occur before run() is called.
|
103
|
+
# ======================================================================= #
|
104
|
+
if block_given?
|
105
|
+
yielded = yield
|
106
|
+
case yielded
|
107
|
+
# ===================================================================== #
|
108
|
+
# === :do_not_replace_the_localhost
|
109
|
+
# ===================================================================== #
|
110
|
+
when :do_not_replace_the_localhost
|
111
|
+
# In this case do nothing.
|
112
|
+
# ===================================================================== #
|
113
|
+
# ===:replace_localhost
|
114
|
+
# ===================================================================== #
|
115
|
+
when :replace_localhost
|
116
|
+
@replace_localhost_with_data = true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
run if run_already
|
120
|
+
end
|
121
|
+
|
122
|
+
end; end
|
123
|
+
|
124
|
+
if __FILE__ == $PROGRAM_NAME
|
125
|
+
_ = BeautifulUrl::BeautifulUrl.new(ARGV)
|
126
|
+
pp _
|
127
|
+
puts _.return_corresponding_entry
|
128
|
+
_.get_rid_of_localhost
|
129
|
+
puts _.return_corresponding_entry
|
130
|
+
end # rb initialize.rb rubyreddit
|
131
|
+
# rb initialize.rb palemoon
|
132
|
+
# Testing this class next:
|
133
|
+
# purl diepasst
|
134
|
+
# purl pc
|
135
|
+
# purl anmeldung
|
136
|
+
# purl pc replace
|
137
|
+
# purl GENERATE
|
138
|
+
# purl science_news
|
139
|
+
# burl ruby#windows
|
140
|
+
# burl std#amino_acids
|
141
|
+
# burl cmd cat
|
142
|
+
# burl scinews
|
143
|
+
# burl gobodist_homepage
|
144
|
+
# sani geastask
|
145
|
+
# purl GENERATE
|
146
|
+
# burl gobodist
|
147
|
+
# burl gobodist#Compile
|
148
|
+
# burl local_php#test
|
149
|
+
# burl stdk#Periodensystem
|
@@ -0,0 +1,473 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'beautiful_url/class/misc.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'beautiful_url/constants/misc.rb'
|
8
|
+
require 'beautiful_url/toplevel_methods/current_month.rb'
|
9
|
+
require 'beautiful_url/toplevel_methods/menu.rb'
|
10
|
+
require 'beautiful_url/toplevel_methods/moodle_menu.rb'
|
11
|
+
require 'beautiful_url/toplevel_methods/roebe.rb'
|
12
|
+
require 'beautiful_url/class/generate_tab_completion_for_bash_shell.rb'
|
13
|
+
|
14
|
+
module BeautifulUrl
|
15
|
+
|
16
|
+
class BeautifulUrl # === BeautifulUrl::BeautifulUrl
|
17
|
+
|
18
|
+
begin
|
19
|
+
require 'opn'
|
20
|
+
rescue LoadError; end
|
21
|
+
|
22
|
+
# ========================================================================= #
|
23
|
+
# === map_the_input_arguments_to_their_corresponding_values
|
24
|
+
#
|
25
|
+
# This method will map the given input to its corresponding value,
|
26
|
+
# if possible.
|
27
|
+
#
|
28
|
+
# Take note that this method will also change @is_registered if the
|
29
|
+
# entry was found.
|
30
|
+
# ========================================================================= #
|
31
|
+
def map_the_input_arguments_to_their_corresponding_values(
|
32
|
+
i = @commandline_arguments
|
33
|
+
)
|
34
|
+
i.map! {|entry|
|
35
|
+
if entry.is_a? Symbol
|
36
|
+
entry = entry.to_s.dup
|
37
|
+
end
|
38
|
+
entry = entry.dup if entry.frozen?
|
39
|
+
# ===================================================================== #
|
40
|
+
# Neither ':' or ',' seem to be useful at the end, so we will chop
|
41
|
+
# them away next (since as of October 2011). Trailing whitespace
|
42
|
+
# will also be removed in the line afterwards.
|
43
|
+
# ===================================================================== #
|
44
|
+
if entry and (entry.end_with?(':') or entry.end_with?(','))
|
45
|
+
entry.chop!
|
46
|
+
end
|
47
|
+
if entry
|
48
|
+
entry.rstrip!
|
49
|
+
# =================================================================== #
|
50
|
+
# Nor is a leading ':' useful here either.
|
51
|
+
# =================================================================== #
|
52
|
+
entry[0,1] = '' if entry.start_with? ':'
|
53
|
+
end
|
54
|
+
# ===================================================================== #
|
55
|
+
# Handle intralink entries when they contain a '#' character.
|
56
|
+
# ===================================================================== #
|
57
|
+
if entry and entry.include?('#')
|
58
|
+
splitted = entry.split('#')
|
59
|
+
set_intralink(splitted.last)
|
60
|
+
entry = splitted.first
|
61
|
+
end
|
62
|
+
old_value = entry.to_s.dup # Use a reference copy here.
|
63
|
+
new_value = ::BeautifulUrl.menu(entry)
|
64
|
+
new_value.flatten! if new_value.is_a? Array
|
65
|
+
if new_value == old_value
|
66
|
+
# =================================================================== #
|
67
|
+
# In this case we did not find anything, so we don't do anything.
|
68
|
+
# =================================================================== #
|
69
|
+
else
|
70
|
+
@is_registered = true
|
71
|
+
entry = new_value
|
72
|
+
end
|
73
|
+
if @intralink and !@intralink.empty?
|
74
|
+
entry = entry.dup if entry.frozen?
|
75
|
+
entry << @intralink # Append in this case.
|
76
|
+
end
|
77
|
+
entry
|
78
|
+
}
|
79
|
+
i.flatten!
|
80
|
+
end; alias check_input_against_menu map_the_input_arguments_to_their_corresponding_values # === check_input_against_menu
|
81
|
+
alias sanitize_input map_the_input_arguments_to_their_corresponding_values # === sanitize_input
|
82
|
+
|
83
|
+
# ========================================================================= #
|
84
|
+
# === is_a_remote_url?
|
85
|
+
#
|
86
|
+
# This method will return true if the URL is remote, false if it is
|
87
|
+
# local, and nil if it was not found at all.
|
88
|
+
#
|
89
|
+
# The variable @url_was_found will tell us whether the url was
|
90
|
+
# found or whether it was not.
|
91
|
+
# ========================================================================= #
|
92
|
+
def is_a_remote_url?
|
93
|
+
if @is_registered
|
94
|
+
_ = @commandline_arguments.all? {|entry|
|
95
|
+
entry.include? 'http'
|
96
|
+
}
|
97
|
+
else
|
98
|
+
_ = nil
|
99
|
+
end
|
100
|
+
_ # Our return value.
|
101
|
+
end; alias remote? is_a_remote_url? # === remote?
|
102
|
+
alias is_a_remote_file? is_a_remote_url? # === is_a_remote_file?
|
103
|
+
|
104
|
+
# ========================================================================= #
|
105
|
+
# === set_shall_we_replace_localhost
|
106
|
+
#
|
107
|
+
# This method simply sets @replace_localhost_with_data to the
|
108
|
+
# passed value, which is true by default.
|
109
|
+
#
|
110
|
+
# If true, we will replace the "localhost" string with the
|
111
|
+
# DATA constant.
|
112
|
+
#
|
113
|
+
# Parameters can be like this:
|
114
|
+
#
|
115
|
+
# :replace => true # Yes, replace localhost with data.
|
116
|
+
# :replace => false # No, do not replace localhost with data.
|
117
|
+
# :replace => :reverse # Replace data with localhost, which is the reverse.
|
118
|
+
#
|
119
|
+
# ========================================================================= #
|
120
|
+
def set_shall_we_replace_localhost(
|
121
|
+
i = true
|
122
|
+
)
|
123
|
+
@replace_localhost_with_data = i
|
124
|
+
end; alias set_replace_localhost set_shall_we_replace_localhost # === set_replace_localhost
|
125
|
+
alias shall_we_replace_localhost= set_shall_we_replace_localhost # === shall_we_replace_localhost=
|
126
|
+
|
127
|
+
# ========================================================================= #
|
128
|
+
# === search_for_this_url
|
129
|
+
#
|
130
|
+
# This will return a string.
|
131
|
+
# ========================================================================= #
|
132
|
+
def search_for_this_url(i)
|
133
|
+
set_commandline_arguments(i)
|
134
|
+
map_the_input_arguments_to_their_corresponding_values
|
135
|
+
handle_additional_actions_after_the_input_arguments_were_already_mapped
|
136
|
+
return string?
|
137
|
+
end
|
138
|
+
|
139
|
+
# ========================================================================= #
|
140
|
+
# === consider_replacing_data_with_localhost
|
141
|
+
# ========================================================================= #
|
142
|
+
def consider_replacing_data_with_localhost
|
143
|
+
if @replace_data_with_localhost
|
144
|
+
do_replace_data_with_localhost
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# ========================================================================= #
|
149
|
+
# === consider_replacing_localhost_with_data
|
150
|
+
# ========================================================================= #
|
151
|
+
def consider_replacing_localhost_with_data
|
152
|
+
if @replace_localhost_with_data
|
153
|
+
do_replace_localhost_with_data_entry
|
154
|
+
end
|
155
|
+
end; alias replace_localhost consider_replacing_localhost_with_data # ===replace_localhost
|
156
|
+
|
157
|
+
# ========================================================================= #
|
158
|
+
# === handle_additional_actions_after_the_input_arguments_were_already_mapped
|
159
|
+
# ========================================================================= #
|
160
|
+
def handle_additional_actions_after_the_input_arguments_were_already_mapped
|
161
|
+
consider_replacing_localhost_with_data
|
162
|
+
consider_replacing_data_with_localhost
|
163
|
+
end; alias consider_replacing_everything handle_additional_actions_after_the_input_arguments_were_already_mapped # === consider_replacing_everything
|
164
|
+
alias consider_replacing_anything handle_additional_actions_after_the_input_arguments_were_already_mapped # === consider_replacing_anything
|
165
|
+
|
166
|
+
# ========================================================================= #
|
167
|
+
# === do_replace_data_entry_with_localhost
|
168
|
+
# ========================================================================= #
|
169
|
+
def do_replace_data_entry_with_localhost
|
170
|
+
@commandline_arguments.map! {|entry|
|
171
|
+
entry = entry.dup if entry.frozen?
|
172
|
+
if entry.include? @data_dir
|
173
|
+
regexp_quoted = Regexp.quote(@data_dir)
|
174
|
+
entry.sub!(regexp_quoted, HTTP_LOCALHOST_STRING)
|
175
|
+
end
|
176
|
+
entry
|
177
|
+
}
|
178
|
+
end; alias do_replace_data_with_localhost do_replace_data_entry_with_localhost # === do_replace_data_with_localhost
|
179
|
+
|
180
|
+
# ========================================================================= #
|
181
|
+
# === menu (menu tag)
|
182
|
+
# ========================================================================= #
|
183
|
+
def menu(
|
184
|
+
i = @commandline_arguments
|
185
|
+
)
|
186
|
+
if i.is_a? Array
|
187
|
+
i.each {|entry| menu(entry) }
|
188
|
+
else
|
189
|
+
case i
|
190
|
+
# ===================================================================== #
|
191
|
+
# === rf --show_help
|
192
|
+
# ===================================================================== #
|
193
|
+
when /^-?-?show(_|-)?help$/i,
|
194
|
+
/^-?-?help$/i
|
195
|
+
show_help
|
196
|
+
# ===================================================================== #
|
197
|
+
# === rf --generate-tab
|
198
|
+
# or
|
199
|
+
# === purl GENERATE
|
200
|
+
# ===================================================================== #
|
201
|
+
when 'AUTOGENERATED','GENERATE',
|
202
|
+
'--generate',
|
203
|
+
'--autogenerate',
|
204
|
+
/^-?-?generate?(-|_)?completion$/,
|
205
|
+
'generate_shell',
|
206
|
+
/^GENE/,
|
207
|
+
'--tab',
|
208
|
+
'--generate-tab' # Could also be 'GENERATE','GENE'
|
209
|
+
generate_tab_completion_for_bash_shell # This here is in another file.
|
210
|
+
exit
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# ========================================================================= #
|
216
|
+
# === is_registered?
|
217
|
+
# ========================================================================= #
|
218
|
+
def is_registered?
|
219
|
+
@is_registered
|
220
|
+
end; alias url_was_found? is_registered? # === url_was_found?
|
221
|
+
alias url_was_found is_registered? # === url_was_found
|
222
|
+
alias is_included? is_registered? # === is_included?
|
223
|
+
|
224
|
+
# ========================================================================= #
|
225
|
+
# === do_replace_localhost_with_data_entry
|
226
|
+
#
|
227
|
+
# This method will replace the leading localhost-string with
|
228
|
+
# the corresponding data-dir value.
|
229
|
+
#
|
230
|
+
# For example, the :
|
231
|
+
#
|
232
|
+
# http://localhost/DATA/PC/palemoon/palemoon.cgi
|
233
|
+
#
|
234
|
+
# Would become:
|
235
|
+
#
|
236
|
+
# /home/x/DATA/PC/palemoon/palemoon.cgi
|
237
|
+
#
|
238
|
+
# ========================================================================= #
|
239
|
+
def do_replace_localhost_with_data_entry
|
240
|
+
@commandline_arguments.map! {|entry|
|
241
|
+
entry = entry.dup if entry.frozen?
|
242
|
+
if entry.include? HTTP_LOCALHOST_STRING
|
243
|
+
regexp_quoted = Regexp.quote(HTTP_LOCALHOST_STRING)
|
244
|
+
entry.sub!(regexp_quoted, home_dir_of_user_x?)
|
245
|
+
end
|
246
|
+
entry
|
247
|
+
}
|
248
|
+
end; alias get_rid_of_localhost do_replace_localhost_with_data_entry # === get_rid_of_localhost
|
249
|
+
alias do_replace_localhost_with_data do_replace_localhost_with_data_entry # === do_replace_localhost_with_data
|
250
|
+
alias do_replace_localhost do_replace_localhost_with_data_entry # === do_replace_localhost
|
251
|
+
|
252
|
+
# ========================================================================= #
|
253
|
+
# === set_commandline_arguments
|
254
|
+
# ========================================================================= #
|
255
|
+
def set_commandline_arguments(i = :default)
|
256
|
+
case i
|
257
|
+
when nil
|
258
|
+
i = DEFAULT_URL
|
259
|
+
end
|
260
|
+
i = [i].flatten.compact
|
261
|
+
@commandline_arguments = i
|
262
|
+
end
|
263
|
+
|
264
|
+
# ========================================================================= #
|
265
|
+
# === replace_localhost_with_data?
|
266
|
+
# ========================================================================= #
|
267
|
+
def replace_localhost_with_data?
|
268
|
+
@replace_localhost_with_data
|
269
|
+
end; alias replace_localhost_with_data replace_localhost_with_data? # === replace_localhost_with_data
|
270
|
+
|
271
|
+
# ========================================================================= #
|
272
|
+
# === set_intralink
|
273
|
+
#
|
274
|
+
# This method sets the @intralink variable. It is the only allowed
|
275
|
+
# way to modify this variable. The @intralink variable can be a
|
276
|
+
# pointer to a local or to a remote page.
|
277
|
+
#
|
278
|
+
# As of August 2014, we will only set @intralink if we provide input.
|
279
|
+
# ========================================================================= #
|
280
|
+
def set_intralink(
|
281
|
+
i = nil, use_this_token = '#'
|
282
|
+
)
|
283
|
+
case i
|
284
|
+
when :default
|
285
|
+
i = nil
|
286
|
+
end
|
287
|
+
if i
|
288
|
+
i[0,0] = use_this_token unless i.empty?
|
289
|
+
end
|
290
|
+
@intralink = i # Must always be set, even to nil.
|
291
|
+
end
|
292
|
+
|
293
|
+
# ========================================================================= #
|
294
|
+
# === set_data_dir
|
295
|
+
#
|
296
|
+
# We need this method so that the user can define another data-dir
|
297
|
+
# that is to be used.
|
298
|
+
# ========================================================================= #
|
299
|
+
def set_data_dir(
|
300
|
+
i = :default
|
301
|
+
)
|
302
|
+
case i
|
303
|
+
# ======================================================================= #
|
304
|
+
# === :default
|
305
|
+
# ======================================================================= #
|
306
|
+
when :default,
|
307
|
+
nil
|
308
|
+
i = DATA_DIR
|
309
|
+
end
|
310
|
+
@data_dir = i
|
311
|
+
end
|
312
|
+
|
313
|
+
# ========================================================================= #
|
314
|
+
# === return_corresponding_entries
|
315
|
+
# ========================================================================= #
|
316
|
+
def return_corresponding_entries
|
317
|
+
@commandline_arguments
|
318
|
+
end; alias input? return_corresponding_entries # === input?
|
319
|
+
alias data return_corresponding_entries # === data
|
320
|
+
alias array return_corresponding_entries # === array
|
321
|
+
alias array? return_corresponding_entries # === array?
|
322
|
+
|
323
|
+
# ========================================================================= #
|
324
|
+
# === return_corresponding_entry
|
325
|
+
# ========================================================================= #
|
326
|
+
def return_corresponding_entry
|
327
|
+
@commandline_arguments.first
|
328
|
+
end; alias url? return_corresponding_entry # === url?
|
329
|
+
|
330
|
+
# ========================================================================= #
|
331
|
+
# === show_result
|
332
|
+
# ========================================================================= #
|
333
|
+
def show_result
|
334
|
+
e return_corresponding_entry
|
335
|
+
end
|
336
|
+
|
337
|
+
# ========================================================================= #
|
338
|
+
# === home_dir_of_user_x?
|
339
|
+
# ========================================================================= #
|
340
|
+
def home_dir_of_user_x?
|
341
|
+
BASE_DIR
|
342
|
+
end
|
343
|
+
|
344
|
+
# ========================================================================= #
|
345
|
+
# === do_ignore_help
|
346
|
+
# ========================================================================= #
|
347
|
+
def do_ignore_help
|
348
|
+
@ignore_help = true
|
349
|
+
end
|
350
|
+
|
351
|
+
# ========================================================================= #
|
352
|
+
# === show_help
|
353
|
+
# ========================================================================= #
|
354
|
+
def show_help(
|
355
|
+
shall_we_exit = :then_exit
|
356
|
+
)
|
357
|
+
unless @ignore_help
|
358
|
+
opn
|
359
|
+
e 'To issue the various instructions, use AUTOGENERATED or GENERATED.'
|
360
|
+
e
|
361
|
+
e 'Alternative, it works as a downcased variant as well, with -- as in:'
|
362
|
+
e
|
363
|
+
e ' --autogenerate'
|
364
|
+
e ' --generate'
|
365
|
+
e
|
366
|
+
exit if shall_we_exit == :then_exit
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
# ========================================================================= #
|
371
|
+
# === url_as_string
|
372
|
+
#
|
373
|
+
# Return the @input in string variant, always. This can be used as
|
374
|
+
# content that can be displayed in other programs.
|
375
|
+
#
|
376
|
+
# Take note that in the past result? returned an Array, from 02.08.2015
|
377
|
+
# up until 04.01.2020. Past that point it will return a String instead.
|
378
|
+
# ========================================================================= #
|
379
|
+
def url_as_string
|
380
|
+
return_corresponding_entry.to_s
|
381
|
+
end; alias url? url_as_string # === url?
|
382
|
+
alias location? url_as_string # === location?
|
383
|
+
alias string url_as_string # === string
|
384
|
+
alias string? url_as_string # === string?
|
385
|
+
alias result? url_as_string # === result?
|
386
|
+
alias result url_as_string # === result
|
387
|
+
alias return_as_string url_as_string # === return_as_string
|
388
|
+
alias [] url_as_string # === []
|
389
|
+
|
390
|
+
# ========================================================================= #
|
391
|
+
# === BeautifulUrl::BeautifulUrl['palemoon']
|
392
|
+
# ========================================================================= #
|
393
|
+
def self.[](
|
394
|
+
i = 'palemoon', &block
|
395
|
+
)
|
396
|
+
new(i, &block).return_as_string
|
397
|
+
end
|
398
|
+
|
399
|
+
end
|
400
|
+
|
401
|
+
# =========================================================================== #
|
402
|
+
# === BeautifulUrl.map
|
403
|
+
#
|
404
|
+
# Usage example:
|
405
|
+
#
|
406
|
+
# BeautifulUrl.map('palemoon') # => "http://localhost/DATA/PC/palemoon/palemoon.cgi"
|
407
|
+
# BeautifulUrl.parse('palemoon') # => "http://localhost/DATA/PC/palemoon/palemoon.cgi"
|
408
|
+
#
|
409
|
+
# =========================================================================== #
|
410
|
+
def self.map(
|
411
|
+
i, &block
|
412
|
+
)
|
413
|
+
::BeautifulUrl::BeautifulUrl.new(i, &block).return_as_string
|
414
|
+
end; self.instance_eval { alias [] map } # === BeautifulUrl[]
|
415
|
+
self.instance_eval { alias convert map } # === BeautifulUrl.convert
|
416
|
+
self.instance_eval { alias new map } # === BeautifulUrl.new
|
417
|
+
self.instance_eval { alias return_url_from map } # === BeautifulUrl.return_url_from
|
418
|
+
self.instance_eval { alias return_as_string map } # === BeautifulUrl.return_as_string
|
419
|
+
self.instance_eval { alias parse map } # === BeautifulUrl.parse
|
420
|
+
|
421
|
+
# =========================================================================== #
|
422
|
+
# === BeautifulUrl.fetch_value
|
423
|
+
#
|
424
|
+
# This method simply allows you to return the URL on the commandline. It
|
425
|
+
# will also set the xorg-buffer, if available, so it is ideally used
|
426
|
+
# for commandline-applications, e. g. if the xorg-server is not available.
|
427
|
+
#
|
428
|
+
# Usage example would be:
|
429
|
+
#
|
430
|
+
# BeautifulUrl.fetch_value 'php' # => "/home/x/DATA/PROGRAMMING_LANGUAGES/php/PHP_TUTORIAL.php"
|
431
|
+
#
|
432
|
+
# =========================================================================== #
|
433
|
+
def self.fetch_value(
|
434
|
+
i
|
435
|
+
)
|
436
|
+
result = ::BeautifulUrl::BeautifulUrl.new(i).result?
|
437
|
+
if Object.const_defined? :XorgBuffer
|
438
|
+
XorgBuffer[result]
|
439
|
+
end
|
440
|
+
return result
|
441
|
+
end
|
442
|
+
|
443
|
+
# ========================================================================= #
|
444
|
+
# === BeautifulUrl.is_included?
|
445
|
+
#
|
446
|
+
# Use this method to find out whether an entry is registered or whether
|
447
|
+
# it is not.
|
448
|
+
#
|
449
|
+
# Usage example:
|
450
|
+
#
|
451
|
+
# x = BeautifulUrl.is_included? 'htop'
|
452
|
+
#
|
453
|
+
# ========================================================================= #
|
454
|
+
def self.is_included?(i)
|
455
|
+
# ======================================================================= #
|
456
|
+
# The next check was added in September 2015. It was disabled again
|
457
|
+
# in 2020.
|
458
|
+
# ======================================================================= #
|
459
|
+
# i = i.to_sym unless i.is_a? Symbol
|
460
|
+
_ = ::BeautifulUrl::BeautifulUrl.new(i)
|
461
|
+
_.is_included? # Work on the class-level there.
|
462
|
+
end; self.instance_eval { alias include? is_included? } # === BeautifulUrl.include?
|
463
|
+
self.instance_eval { alias has_this_entry? is_included? } # === BeautifulUrl.has_this_entry?
|
464
|
+
self.instance_eval { alias does_include? is_included? } # === BeautifulUrl.does_include?
|
465
|
+
|
466
|
+
# ========================================================================= #
|
467
|
+
# === BeautifulUrl.replace_localhost
|
468
|
+
# ========================================================================= #
|
469
|
+
def self.replace_localhost(i)
|
470
|
+
::BeautifulUrl::BeautifulUrl.new(i) { :replace_localhost }
|
471
|
+
end
|
472
|
+
|
473
|
+
end
|