imgzet 0.2.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.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/bin/imgzet +6 -0
- data/lib/imgzet.rb +1 -0
- data/lib/imgzet/cli.rb +98 -0
- data/lib/imgzet/version.rb +7 -0
- metadata +119 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1316861742a789e3e3b14a4d97afafc06df21fddb3c630e08738d169d1e164e5
|
|
4
|
+
data.tar.gz: '068f9c9332146766729e8bda25a0b842af5072b93d99db3ebe3fcdecc2e62fd6'
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0d5bf424947c7239ec07d1cd8018d314ca6d7a0d02fb6c5805e7d884012dc076d74c3f504f74a93dc9b4e578ad19b148bf137db6eb0b30da31d293b6167e79e7
|
|
7
|
+
data.tar.gz: 1ec402fb3c5aff2eaf9848fd7b58601e3edbbde44520723b4015a52c2f9067d78fa2a21495d3803f5f0a2e017614836386d885ca10baeeeb243de98dc1c0aded
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Anatoli Makarevich
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/bin/imgzet
ADDED
data/lib/imgzet.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "imgzet/version"
|
data/lib/imgzet/cli.rb
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
6
|
+
$LOAD_PATH << File.expand_path(__dir__)
|
|
7
|
+
|
|
8
|
+
module Imgzet
|
|
9
|
+
# CLI class is responsible for handling command-line arguments.
|
|
10
|
+
#
|
|
11
|
+
class CLI
|
|
12
|
+
# CLI is used when running imgzet from command line (check bin/imgzet) file.
|
|
13
|
+
#
|
|
14
|
+
def run(args = [])
|
|
15
|
+
if !Dir.exists?("notes") || !Dir.exists?("images") || !Dir.exists?("input")
|
|
16
|
+
puts "Create notes, images and input folders"
|
|
17
|
+
return
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if args.first == "names"
|
|
21
|
+
# TODO: go over notes and generate slugs from headlines
|
|
22
|
+
else
|
|
23
|
+
Dir["input/*"].each do |input|
|
|
24
|
+
next if input == "."
|
|
25
|
+
next if input == ".."
|
|
26
|
+
|
|
27
|
+
if File.directory?(input)
|
|
28
|
+
process_input_foler(input)
|
|
29
|
+
else
|
|
30
|
+
process_input_file(input)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
0
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def process_input_foler(folder)
|
|
41
|
+
slug = temp_slug()
|
|
42
|
+
|
|
43
|
+
note_file = File.join("notes", "#{slug}.md")
|
|
44
|
+
image_folder = File.join("images", slug)
|
|
45
|
+
|
|
46
|
+
Dir.mkdir(image_folder)
|
|
47
|
+
|
|
48
|
+
images = []
|
|
49
|
+
Dir[File.join(folder, "**/*")].sort_by { |f| File.mtime(f) }.each do |image|
|
|
50
|
+
image_file_name = "#{temp_slug}-#{File.extname(image)}"
|
|
51
|
+
image_file = File.join(image_folder, image_file_name)
|
|
52
|
+
FileUtils.cp(image, image_file)
|
|
53
|
+
images.push(image_file)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
File.open(note_file, "w") do |f|
|
|
57
|
+
template = File.read(File.join(Dir.pwd, "note_template.md"))
|
|
58
|
+
template.gsub!("IMG", images.map { |image_file|
|
|
59
|
+
""
|
|
60
|
+
}.join("\n"))
|
|
61
|
+
|
|
62
|
+
f.puts(template)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
FileUtils.rm_rf(folder)
|
|
66
|
+
|
|
67
|
+
system `code .`
|
|
68
|
+
system `code #{note_file}`
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def process_input_file(input_image_file)
|
|
72
|
+
slug = temp_slug()
|
|
73
|
+
|
|
74
|
+
note_file = File.join("notes", "#{slug}.md")
|
|
75
|
+
image_file = File.join("images", "#{slug}#{File.extname(input_image_file)}")
|
|
76
|
+
|
|
77
|
+
FileUtils.cp(input_image_file, image_file)
|
|
78
|
+
File.open(note_file, "w") do |f|
|
|
79
|
+
template = File.read(File.join(Dir.pwd, "note_template.md"))
|
|
80
|
+
template.gsub!("IMG", "")
|
|
81
|
+
|
|
82
|
+
f.puts(template)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
FileUtils.rm(input_image_file)
|
|
86
|
+
|
|
87
|
+
system `code .`
|
|
88
|
+
system `code #{note_file}`
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def temp_slug
|
|
92
|
+
random_slug = 6.times.map { ("a".."z").to_a.sample }.join
|
|
93
|
+
timestamp = Time.now.strftime("%Y%m%d%H%M")
|
|
94
|
+
|
|
95
|
+
"#{timestamp}-temp-#{random_slug}"
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: imgzet
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Anatoli Makarevich
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-01-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rmagick
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '4'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 2.2.3
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 2.2.3
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: byebug
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '12.3'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '12.3'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
83
|
+
description: CLI tool to organize notes, inspired by Imgzettelkasten
|
|
84
|
+
email:
|
|
85
|
+
- makaroni4@gmail.com
|
|
86
|
+
executables:
|
|
87
|
+
- imgzet
|
|
88
|
+
extensions: []
|
|
89
|
+
extra_rdoc_files: []
|
|
90
|
+
files:
|
|
91
|
+
- LICENSE.txt
|
|
92
|
+
- bin/imgzet
|
|
93
|
+
- lib/imgzet.rb
|
|
94
|
+
- lib/imgzet/cli.rb
|
|
95
|
+
- lib/imgzet/version.rb
|
|
96
|
+
homepage: https://github.com/makaroni4/imgzet
|
|
97
|
+
licenses:
|
|
98
|
+
- MIT
|
|
99
|
+
metadata: {}
|
|
100
|
+
post_install_message:
|
|
101
|
+
rdoc_options: []
|
|
102
|
+
require_paths:
|
|
103
|
+
- lib
|
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - ">="
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '0'
|
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
requirements: []
|
|
115
|
+
rubygems_version: 3.0.3
|
|
116
|
+
signing_key:
|
|
117
|
+
specification_version: 4
|
|
118
|
+
summary: CLI tool to organize notes, inspired by Imgzettelkasten
|
|
119
|
+
test_files: []
|