cliz 0.0.1 → 0.0.7

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cliz +2 -36
  3. data/lib/functions.rb +48 -8
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3703184d1cd9de97801b00a83b47f88f8128f08faeeda1af9f9e26df6d34cc94
4
- data.tar.gz: 8cd9a19cd0082b23d82ee881e887203d761eb1cbeb485433869d45b8f1df1213
3
+ metadata.gz: 3244d06cf94a457489f61c5f74aa87e38809ddf73ae1d4afff4cd1223e3bf20a
4
+ data.tar.gz: 555842ee24707775b95c7cdedac5e1f0a385454951987b6e10317baec436e8c5
5
5
  SHA512:
6
- metadata.gz: b10004b4751bacccfce8ecd80209ce96d8e3e4da17e2f07db65e75533a13e2a96ecda27d8b4ddc5c8a80efd1bab0fe48c67bdbadba51039960011c2f2131a659
7
- data.tar.gz: 0f938d76de017cd9507701b293c88e9f2ce0154f5fc59bd30d8a89ca9890f693cb7ef23bb90b1595e30514f212391a12bacfa4ca864991f3602649a49daa69fc
6
+ metadata.gz: 04da2ae52ffb1b8756e349f8e177751d5040bb4309f8ff00c19deb2d8229fce35f704a0be5335da0ae382c208b15eb314ab3d08b8ca625b64cc41a58889d9a50
7
+ data.tar.gz: 8baec4b0aa47d518723a56be58113c1f5436e0ae75638592c10d045babeccfac395117d0becdd5630b2e6fc5c4fdfd100b229ef63f6c976b70930b72ed7bd703
data/bin/cliz CHANGED
@@ -7,41 +7,7 @@ require_relative '../lib/functions.rb'
7
7
 
8
8
 
9
9
  config = YAML.load(File.read('config.yml'))
10
-
11
- OUTPUT_DIR = config['output_dir']
12
- BASE_DOMAIN = config['base_domain']
13
- DEPLOY_SCRIPT = config['deploy_script']
14
- HTML = %Q{
15
- <!DOCTYPE html>
16
- <html>
17
- <head>
18
- <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
19
- <meta content="utf-8" http-equiv="encoding">
20
- <script type="text/javascript">
21
- window.location.replace("https://cliz.in");
22
- </script>
23
- <meta http-equiv="refresh" content="0; url='https://cliz.in'" />
24
- </head>
25
- <body>
26
- <p>Please follow <a href="https://cliz.in">this link</a>.</p>
27
- </body>
28
- </html>
29
- }
30
-
31
10
  url = ARGV[0]
32
11
  short_suggestion = ARGV[1]
33
- redirect_content = HTML.gsub 'https://cliz.in', url
34
-
35
- short_suggestion ||= generate_short_suggestion OUTPUT_DIR
36
- folder_path = get_a_folder_path OUTPUT_DIR, short_suggestion
37
-
38
-
39
- FileUtils.mkdir_p(folder_path)
40
-
41
- File.open "#{folder_path}/index.html", 'w' do |f|
42
- f.puts redirect_content
43
- end
44
-
45
- system("sh #{DEPLOY_SCRIPT}") if DEPLOY_SCRIPT
46
-
47
- puts File.join BASE_DOMAIN, short_suggestion
12
+ short_url = short config, url, short_suggestion
13
+ puts short_url
data/lib/functions.rb CHANGED
@@ -6,14 +6,11 @@ require 'fileutils'
6
6
  def get_a_folder_path output_directory, short_suggestion = nil
7
7
  folder_path = nil
8
8
 
9
- unless short_suggestion
10
- random_string = generate_short_suggestion output_directory
11
- folder_path = get_a_folder_path output_directory, random_string
12
- else
13
- folder_path = File.join(output_directory, short_suggestion, '/')
14
- if File.directory?(folder_path)
15
- raise ("This short URL is already taken.")
16
- end
9
+ short_suggestion ||= generate_short_suggestion output_directory
10
+ folder_path = File.join(output_directory, short_suggestion, '/')
11
+
12
+ if File.directory?(folder_path)
13
+ raise ("This short URL is already taken.")
17
14
  end
18
15
 
19
16
  folder_path
@@ -32,3 +29,46 @@ def generate_short_suggestion output_directory
32
29
 
33
30
  random_string
34
31
  end
32
+
33
+ def create_index_file url, folder_path
34
+ html = %Q{
35
+ <!DOCTYPE html>
36
+ <html>
37
+ <head>
38
+ <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
39
+ <meta content="utf-8" http-equiv="encoding">
40
+ <script type="text/javascript">
41
+ window.location.replace("https://cliz.in");
42
+ </script>
43
+ <meta http-equiv="refresh" content="0; url='https://cliz.in'" />
44
+ </head>
45
+ <body>
46
+ <p>Please follow <a href="https://cliz.in">this link</a>.</p>
47
+ </body>
48
+ </html>
49
+ }
50
+
51
+ redirect_content = html.gsub 'https://cliz.in', url
52
+ FileUtils.mkdir_p(folder_path)
53
+
54
+ File.open "#{folder_path}/index.html", 'w' do |f|
55
+ f.puts redirect_content
56
+ end
57
+ end
58
+
59
+ def short config, url, short_suggestion = nil
60
+ output_dir = config['output_dir']
61
+ base_domain = config['base_domain']
62
+ deploy_script = config['deploy_script']
63
+ pre_script = config['pre_script']
64
+
65
+ system("sh #{pre_script}") if pre_script
66
+
67
+ short_suggestion ||= generate_short_suggestion output_dir
68
+ folder_path = get_a_folder_path output_dir, short_suggestion
69
+ create_index_file(url, folder_path)
70
+
71
+ system("sh #{deploy_script}") if deploy_script
72
+
73
+ File.join base_domain, short_suggestion
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karthikeyan A K
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-02 00:00:00.000000000 Z
11
+ date: 2021-04-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Cliz - The static URL shortner
14
14
  email: mindaslab@protonmail.com
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  requirements: []
41
- rubygems_version: 3.2.3
41
+ rubygems_version: 3.2.15
42
42
  signing_key:
43
43
  specification_version: 4
44
44
  summary: Cliz - The static URL shortner