lgtm_hd 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9df1287eca4fdb9e7b610538f46cea75e67996eb
4
- data.tar.gz: b32c25c952a847d7828edcc19a69e6fa750bf13d
3
+ metadata.gz: 4cb60a766e51ba4e5afa496f4ece6c1ed2178213
4
+ data.tar.gz: 32f930d5fd406cb6fcb8530343910a6d7d796e69
5
5
  SHA512:
6
- metadata.gz: fdeee3dacf8123d2adc5d634f4505fa3b352e17151ef791e62a0e8ec6ba5246b6dce4898a50689b92780a72c30630bbd4bfb390c8e765438fbb69cca49d5ccf5
7
- data.tar.gz: 9cbca052787a3900d888edc6d4e09c8cb46db1cdcf1182a262328d01b7420378c8f4258c8e6b0e5774b84c17426dd110a94ffc22b474251c1bb87ab9b134354e
6
+ metadata.gz: e55c1aadd8ac434d1bf3223d60dcb0a53520c77996bf6b2a6797f6ebeabb1b7d10cc799cea044fed065a706ee35088c6ede16625c25c9614be943431b9dfc71a
7
+ data.tar.gz: f20e482210fa657059447b2cd52f1479be3b2bc13aee251f1b18dc4fa6e636eb59702b2edd9041124f5968cfe490b0d449bce3727542da44c3eadf4b5ab47284
data/lgtm_hd.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- ROOT_DIR = __dir__
4
+
5
5
  require 'lgtm_hd/version'
6
6
  require 'rubygems/dependency_installer.rb'
7
7
 
data/lib/lgtm_hd.rb CHANGED
@@ -65,7 +65,7 @@ module LgtmHD
65
65
  end
66
66
 
67
67
  def captionFont
68
- '' << ROOT_DIR << Configuration::FONT_PATH
68
+ '' << LgtmHD.root << Configuration::FONT_PATH
69
69
  end
70
70
 
71
71
  def captionFontSize
@@ -116,4 +116,8 @@ module LgtmHD
116
116
  end
117
117
 
118
118
  end # End of Class
119
+
120
+ def self.root
121
+ File.expand_path '../..', __FILE__
122
+ end
119
123
  end # End of Module
data/lib/lgtm_hd/cli.rb CHANGED
@@ -18,42 +18,77 @@ module LgtmHD
18
18
  program :name, LgtmHD::Configuration::PROGRAM_NAME
19
19
  program :version, LgtmHD::VERSION
20
20
  program :description, LgtmHD::Configuration::DESCRIPTION
21
- default_command :export
21
+ default_command :transform
22
22
 
23
23
  command :transform do |c|
24
24
  c.syntax = 'lgtm_hd transform <source_uri> <output_uri> [options]'
25
- c.summary = 'Generate a LGTM image from source_uri (local path or URL) into output_uri (local)'
25
+ c.summary = 'Generate a LGTM image from source_uri (local path or URL) into output folder'
26
26
  c.description = ''
27
27
  c.example '', 'lgtm_hd export http://domain.com/image.png /path/to/lgtm.png'
28
28
  c.option '--clipboard', 'Copy the end result (LGTM image) to OS\'s clipboard'
29
+ c.option '--interactive', 'In case you forgot all these super complexive args and options'
29
30
 
30
31
  c.action do |args, options|
31
- # TODO add validation for args
32
- uri = URI.parse(args[0])
33
- tmp_file_name = Time.now.strftime('%Y-%m-%d_%H-%M-%S') << LgtmHD::Configuration::TEMP_FILE_PREFIX
32
+ to_clipboard = options.clipboard
34
33
 
35
- meme_generator = MemeGenerator.new(*args)
34
+ # ARGS validation!
35
+ if args.length == 2 then
36
+ source_uri = args[0]
37
+ output_uri = args[1]
38
+
39
+ elsif options.interactive # Interactive mode!
40
+ say "-- LGTM Interactive mode --"
41
+ source_uri = ask('Source (URL or Path/to/file): ')
42
+ output_uri = ask('Output Folder (absolute path): ')
43
+ # TODO accept relative path "~/.."
44
+ to_clipboard = agree("Copy to clipboard afterward? [Y/N]")
45
+ else
46
+ raise "Too few or too many arguments provided. Need 2: source and output URIs."
47
+ end
48
+
49
+
50
+ # Validate the inputs
51
+ unless (source_uri =~ URI::regexp or File.exist?(source_uri)) then
52
+ # Part of the reason why I fucking hate #unless. No reason.
53
+ raise "Source is not proper URIs (URL or Path/to/file)"
54
+ end
55
+
56
+ unless File.exist?(output_uri) and File.directory?(output_uri) then
57
+ raise "Output is not a directory or valid path"
58
+ end
59
+
60
+ file_ext = File.extname(source_uri)
61
+ output_uri = File.join(output_uri, "" << LgtmHD::Configuration::OUTPUT_PREFIX << Time.now.strftime('%Y-%m-%d_%H-%M-%S') << file_ext)
62
+
63
+ # Do stuff with our LGTM meme
64
+ say "- Reading and inspecting source"
65
+ meme_generator = MemeGenerator.new(source_uri, output_uri)
66
+ say "- Rendering output"
36
67
  meme_generator.draw
37
68
 
69
+ # Export and play around with the clipboard
70
+ say "- exporting to file"
38
71
  meme_generator.export do |output|
39
72
  say "LGTM image has been generated at #{output}."
40
- if not options.clipboard then return; end
41
- if OS.mac? then
42
- applescript "set the clipboard to (read (POSIX file \"#{output}\") as GIF picture)"
43
- say "I see you are using MacOSX. Content of the file has been copied to your clipboard."
44
-
45
- #{}`osascript -e 'set the clipboard to (read (POSIX file "#{output}") as JPEG picture)'`
46
- # Note on 2017/05/22
47
- # Currently Github allow pasting image directly to comment box.
48
- # However it does not support pure text content produced by pbcopy so we have to use direct Applescript
49
- # No Universal solution as for now.
50
- #
51
- # Apple Script reference: http://www.macosxautomation.com/applescript/imageevents/08.html
52
- else
53
- Clipboard.copy(output)
54
- say "Path to LGTM file has been copied to your clipboard."
55
- end
56
- end
73
+ if to_clipboard then
74
+ if OS.mac? then
75
+ applescript "set the clipboard to (read (POSIX file \"#{output}\") as GIF picture)"
76
+ say "I see you are using MacOSX. Content of the file has been copied to your clipboard."
77
+
78
+ # Apple Script Command reference
79
+ # Sample: `osascript -e 'set the clipboard to (read (POSIX file "#{output}") as JPEG picture)'`
80
+ #
81
+ # Currently Github allow pasting image directly to comment box.
82
+ # However it does not support pure text content produced by pbcopy so we have to use direct Applescript
83
+ # No Universal solution as for now.
84
+ #
85
+ # Apple Script reference: http://www.macosxautomation.com/applescript/imageevents/08.html
86
+ else
87
+ Clipboard.copy(output)
88
+ say "Path to LGTM file has been copied to your clipboard."
89
+ end
90
+ end # end of if to_clipboard
91
+ end # end of meme_generator.export block
57
92
 
58
93
  end
59
94
 
@@ -4,9 +4,8 @@ module LgtmHD
4
4
  PROGRAM_NAME = "lgtm_hd"
5
5
  DESCRIPTION = "Generating images from user input with LGTM text on it, or fetching images from LGTM.in based on user's query. Finally put the image to clipboard."
6
6
 
7
- TEMP_FILE_PREFIX = "lgtm_tmp_"
8
-
9
7
  # Output Image configurations
8
+ OUTPUT_PREFIX = "lgtm_tmp_"
10
9
  OUTPUT_MAX_WIDTH = 500
11
10
  OUTPUT_MAX_HEIGHT = 500
12
11
  OUTPUT_DENSITY = 90 # or 120 point per inch
@@ -1,3 +1,3 @@
1
1
  module LgtmHD
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lgtm_hd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Dinh