techbook_helper 0.1.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/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +3 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bin/techbook +6 -0
- data/lib/techbook_helper/version.rb +3 -0
- data/lib/techbook_helper.rb +254 -0
- data/techbook_helper.gemspec +30 -0
- metadata +85 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9f030fbab34f7c2fede36bca17d7f7dcbfd7aa1e
|
|
4
|
+
data.tar.gz: 1772137618ded850935f1f2216b7e6bb90c03a17
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 591bf4fe848adc26938c4e720d1c9b85725b564a5f226afeaa736ab0ba8779bbe99a6be4b6c3f57b905f710f2b8a6bf5707d622f754617e436632c555515e1e0
|
|
7
|
+
data.tar.gz: 494e5747d9423cea6436ea6911c49544960218585e7a582a8a4a15a984fb8abec9b1e8d1ee2f05d1199a4bbf3f414aac4ee5f6dd596a3fb8acef61e07a6cd44f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Georg Romas
|
|
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/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "techbook_helper"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bin/techbook
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
require "techbook_helper/version"
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
|
|
4
|
+
gem 'colorize'
|
|
5
|
+
require 'colorize'
|
|
6
|
+
|
|
7
|
+
trap "SIGINT" do
|
|
8
|
+
puts " "
|
|
9
|
+
puts "Exiting"
|
|
10
|
+
exit 130
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module TechbookHelper
|
|
14
|
+
class Helper
|
|
15
|
+
|
|
16
|
+
IMAGES_DIR = '_i'
|
|
17
|
+
INDEX_MD = 'index.md'
|
|
18
|
+
GIT_KEEP = '.keep'
|
|
19
|
+
|
|
20
|
+
def say_hello
|
|
21
|
+
|
|
22
|
+
@help_args = ['-h', 'h', '--h', '-help', 'help', '--help']
|
|
23
|
+
@create_args = ['create', '-create', '--create', 'c', '-c', '--c']
|
|
24
|
+
@check_args = ['check', '-check', '--check', 'ch', '-ch', '--ch']
|
|
25
|
+
|
|
26
|
+
@confirm_args = ['y', 'yes', 'ok', 'sure']
|
|
27
|
+
@reject_args = ['n', 'no', 'o no', 'do not', 'exit', 'close']
|
|
28
|
+
|
|
29
|
+
@current_book_name = nil
|
|
30
|
+
|
|
31
|
+
print_help if ARGV.size == 0
|
|
32
|
+
if ARGV.size > 1
|
|
33
|
+
too_many_arg_error
|
|
34
|
+
return
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
ARGV.each do |a|
|
|
38
|
+
handler_arguments a
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def handler_arguments(arg)
|
|
44
|
+
case
|
|
45
|
+
when @help_args.include?(arg)
|
|
46
|
+
puts "Welcome to TechBook helper!".colorize(:color => :white, :background => :black)
|
|
47
|
+
puts 'type cd path_to_your_book_repository and lets go.'
|
|
48
|
+
puts_line
|
|
49
|
+
print_help
|
|
50
|
+
when @create_args.include?(arg)
|
|
51
|
+
create
|
|
52
|
+
else
|
|
53
|
+
print_unknown_command(arg)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def create
|
|
58
|
+
|
|
59
|
+
if is_dir_used?
|
|
60
|
+
puts "We find other files in this directory:".red
|
|
61
|
+
puts "'#{Dir['*'].join("', '")}'".blue
|
|
62
|
+
puts "One book – one folder."
|
|
63
|
+
puts "Are you want #{'delete all'.red} and create new empty book?"
|
|
64
|
+
puts "(yes/no)?"
|
|
65
|
+
unless yes_no_choice
|
|
66
|
+
puts_ok
|
|
67
|
+
return
|
|
68
|
+
end
|
|
69
|
+
clear_current_dir
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
unless check_git_dir
|
|
73
|
+
puts 'Looks like git not initialized in current directory'.yellow
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
current_dir = Dir.pwd
|
|
77
|
+
puts 'Ok, lest do it.'
|
|
78
|
+
puts "Confirm you wana create TechBook template in directory #{current_dir.green}"
|
|
79
|
+
print '(yes/no) '
|
|
80
|
+
|
|
81
|
+
if yes_no_choice
|
|
82
|
+
select_book_name
|
|
83
|
+
else
|
|
84
|
+
puts_ok
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def clear_current_dir
|
|
90
|
+
puts 'Clear files in current directory'.red
|
|
91
|
+
|
|
92
|
+
Dir['*'].each do |file|
|
|
93
|
+
if File.directory? file
|
|
94
|
+
FileUtils.rm_rf file
|
|
95
|
+
else
|
|
96
|
+
File.delete file
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
10.times{print '. '; sleep 0.3;}
|
|
101
|
+
puts ' '
|
|
102
|
+
puts 'Done'
|
|
103
|
+
sleep(0.4)
|
|
104
|
+
puts_line
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def select_book_name
|
|
108
|
+
puts "One more question. What the name of your book?"
|
|
109
|
+
print_promt
|
|
110
|
+
while user_input = STDIN.gets.chomp
|
|
111
|
+
case
|
|
112
|
+
when user_input.nil? || user_input.size == 0
|
|
113
|
+
puts "I am not sure this is good idea to create book with empty name"
|
|
114
|
+
puts "Please, try again"
|
|
115
|
+
print_promt
|
|
116
|
+
else
|
|
117
|
+
puts "Build template for book name \"#{user_input}\""
|
|
118
|
+
build_template user_input
|
|
119
|
+
|
|
120
|
+
puts 'Are you want to create top level chapters? (y/n)'
|
|
121
|
+
if yes_no_choice
|
|
122
|
+
create_root_chapters
|
|
123
|
+
else
|
|
124
|
+
puts_ok
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
break
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def build_chapter(name)
|
|
133
|
+
if @current_book_name.nil?
|
|
134
|
+
puts "Do not know which book to work with".red
|
|
135
|
+
return
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
Dir.mkdir(File.join(@current_book_name, name))
|
|
139
|
+
puts "Create chapter #{name}"
|
|
140
|
+
sleep(0.4)
|
|
141
|
+
File.open(File.join(@current_book_name, name, INDEX_MD), 'w').close
|
|
142
|
+
puts 'Index page'
|
|
143
|
+
sleep(0.5)
|
|
144
|
+
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def build_template(name)
|
|
148
|
+
Dir.mkdir(name)
|
|
149
|
+
puts 'Create root directory'
|
|
150
|
+
sleep(0.4)
|
|
151
|
+
File.open(File.join(name, INDEX_MD), 'w').close
|
|
152
|
+
puts 'Index page'
|
|
153
|
+
sleep(0.4)
|
|
154
|
+
Dir.mkdir(File.join(name, IMAGES_DIR))
|
|
155
|
+
sleep(0.4)
|
|
156
|
+
puts 'Create images directory'
|
|
157
|
+
puts_line
|
|
158
|
+
puts 'Book template complete. You can edit it, commit and push to the server... manually for now ;)'
|
|
159
|
+
puts_line
|
|
160
|
+
sleep(0.5)
|
|
161
|
+
|
|
162
|
+
@current_book_name = name
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def create_root_chapters
|
|
166
|
+
puts 'Top level chapters creation'
|
|
167
|
+
puts_line
|
|
168
|
+
puts 'For exit type "exit"'
|
|
169
|
+
puts 'Enter chapter name (ex: "1 Specification", "2 Money and low")'
|
|
170
|
+
print_promt
|
|
171
|
+
while user_input = STDIN.gets.chomp
|
|
172
|
+
case
|
|
173
|
+
when user_input.nil? || user_input.size == 0
|
|
174
|
+
puts "Chapter with empty name? Are you kidding me?"
|
|
175
|
+
puts "Please, give me something more intelligent"
|
|
176
|
+
print_promt
|
|
177
|
+
when @reject_args.include?(user_input)
|
|
178
|
+
puts_ok
|
|
179
|
+
break
|
|
180
|
+
else
|
|
181
|
+
puts "Create chapter \"#{user_input}\""
|
|
182
|
+
build_chapter user_input
|
|
183
|
+
puts 'For exit type "exit"'
|
|
184
|
+
puts 'Enter chapter name'
|
|
185
|
+
print_promt
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def check_git_dir
|
|
192
|
+
Dir.exist?('.git')
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def is_dir_used?
|
|
196
|
+
files_array = Dir['*']
|
|
197
|
+
return true unless files_array.empty?
|
|
198
|
+
return false
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def print_help
|
|
202
|
+
puts 'Command you can use:'
|
|
203
|
+
puts '%-10s – %10s' % ['create'.green, 'Will create new book template in current directory']
|
|
204
|
+
puts '%-10s – %10s' % [' ', 'Aliases c, -c, --c, -create, --create']
|
|
205
|
+
puts '%-10s – %10s' % ['check'.green, 'Go through dirs in current folder and check known problems']
|
|
206
|
+
puts '%-10s – %10s' % [' ', 'Aliases ch, -ch, --ch, -check, --check']
|
|
207
|
+
puts_line
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def print_unknown_command(command)
|
|
211
|
+
puts "Unknown command: #{command}"
|
|
212
|
+
puts_line
|
|
213
|
+
print_help
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def too_many_arg_error
|
|
217
|
+
puts 'Too many arguments.'.red.on_black
|
|
218
|
+
puts_line
|
|
219
|
+
print_help
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def yes_no_choice
|
|
223
|
+
print_promt
|
|
224
|
+
answer = false
|
|
225
|
+
while user_input = STDIN.gets.chomp
|
|
226
|
+
case
|
|
227
|
+
when @confirm_args.include?(user_input)
|
|
228
|
+
answer = true
|
|
229
|
+
break
|
|
230
|
+
when @reject_args.include?(user_input)
|
|
231
|
+
answer = false
|
|
232
|
+
break
|
|
233
|
+
else
|
|
234
|
+
puts "Please, answer the question – yes or no"
|
|
235
|
+
print_promt
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
answer
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def print_promt
|
|
242
|
+
print ':> '.green
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def puts_line
|
|
246
|
+
puts '--------------------------'
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def puts_ok
|
|
250
|
+
puts 'I respect your choice'
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
end
|
|
254
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'techbook_helper/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "techbook_helper"
|
|
8
|
+
spec.version = TechbookHelper::VERSION
|
|
9
|
+
spec.authors = ["Georg Romas"]
|
|
10
|
+
spec.email = ["y.romas@crestwavetech.ru"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Build start book template for TechBook from CrestWave technologies}
|
|
13
|
+
spec.description = %q{This is helper to start wright technical book stored in git with and published on TechBook developed by CrestWave technologies}
|
|
14
|
+
spec.homepage = "https://rubygems.org/gems/techbook_helper"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
#spec.bindir = "bin"
|
|
19
|
+
#spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
20
|
+
spec.executables = ['techbook']
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
23
|
+
|
|
24
|
+
# if spec.respond_to?(:metadata)
|
|
25
|
+
# spec.metadata['allowed_push_host'] = "https://github.com/roma86/TechBook_helper.git"
|
|
26
|
+
# end
|
|
27
|
+
|
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
30
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: techbook_helper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Georg Romas
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.8'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.8'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description: This is helper to start wright technical book stored in git with and
|
|
42
|
+
published on TechBook developed by CrestWave technologies
|
|
43
|
+
email:
|
|
44
|
+
- y.romas@crestwavetech.ru
|
|
45
|
+
executables:
|
|
46
|
+
- techbook
|
|
47
|
+
extensions: []
|
|
48
|
+
extra_rdoc_files: []
|
|
49
|
+
files:
|
|
50
|
+
- .gitignore
|
|
51
|
+
- Gemfile
|
|
52
|
+
- LICENSE.txt
|
|
53
|
+
- README.md
|
|
54
|
+
- Rakefile
|
|
55
|
+
- bin/console
|
|
56
|
+
- bin/setup
|
|
57
|
+
- bin/techbook
|
|
58
|
+
- lib/techbook_helper.rb
|
|
59
|
+
- lib/techbook_helper/version.rb
|
|
60
|
+
- techbook_helper.gemspec
|
|
61
|
+
homepage: https://rubygems.org/gems/techbook_helper
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata: {}
|
|
65
|
+
post_install_message:
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - '>='
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - '>='
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 2.4.6
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 4
|
|
84
|
+
summary: Build start book template for TechBook from CrestWave technologies
|
|
85
|
+
test_files: []
|