techbook_helper 0.1.2 → 0.1.4
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 +4 -4
- data/lib/techbook_helper/version.rb +1 -1
- data/lib/techbook_helper.rb +154 -74
- metadata +9 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 735046b3475ffb985306c0a9771766f62ba22a12
|
|
4
|
+
data.tar.gz: a8382720023625e56dae1a2bb8c2282e6fc1a223
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1af3df78e9cc5d9a683fe5c0f0e0d7d12060bfb4d9f7809c24b9f9939dcd129bcaaec6444f68225c6e9438a7eaa59835074956fe849e7dedc37ef273c94d119
|
|
7
|
+
data.tar.gz: 3d1bc5b1b3ba9eb90e8e3e4d903239a319c22860af7cfc1d12dfde15c49afe44793b513981c13fca6d194489191ca7435e6dbc7af42833df425df3c3059cb712
|
data/lib/techbook_helper.rb
CHANGED
|
@@ -21,12 +21,13 @@ module TechbookHelper
|
|
|
21
21
|
|
|
22
22
|
@help_args = ['-h', 'h', '--h', '-help', 'help', '--help']
|
|
23
23
|
@create_args = ['create', '-create', '--create', 'c', '-c', '--c']
|
|
24
|
-
@check_args = ['check', '-check', '--check', 'ch', '-ch', '--ch']
|
|
24
|
+
# @check_args = ['check', '-check', '--check', 'ch', '-ch', '--ch']
|
|
25
25
|
|
|
26
|
-
@confirm_args = ['y', 'yes', 'ok', 'sure']
|
|
27
|
-
@reject_args = ['n', 'no', 'o no', 'do not', 'exit', 'close']
|
|
26
|
+
@confirm_args = ['y', 'yes', 'ok', 'sure', 'Yes', 'No']
|
|
27
|
+
@reject_args = ['n', 'no', 'o no', 'do not', 'exit', 'close', 'cancel', 'next']
|
|
28
28
|
|
|
29
29
|
@current_book_name = nil
|
|
30
|
+
@current_book_directory = nil
|
|
30
31
|
|
|
31
32
|
print_help if ARGV.size == 0
|
|
32
33
|
if ARGV.size > 1
|
|
@@ -43,8 +44,8 @@ module TechbookHelper
|
|
|
43
44
|
def handler_arguments(arg)
|
|
44
45
|
case
|
|
45
46
|
when @help_args.include?(arg)
|
|
46
|
-
puts "Welcome to TechBook helper!".
|
|
47
|
-
puts '
|
|
47
|
+
puts "Welcome to TechBook helper!".green
|
|
48
|
+
puts 'cd path_to_your_books_library_or_book and lets go.'
|
|
48
49
|
puts_line
|
|
49
50
|
print_help
|
|
50
51
|
when @create_args.include?(arg)
|
|
@@ -56,40 +57,70 @@ module TechbookHelper
|
|
|
56
57
|
|
|
57
58
|
def create
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
puts 'Ok, lest do it.'
|
|
61
|
+
puts 'Helper will create new book in current directory:'
|
|
62
|
+
puts " #{Dir.pwd} ".blue.on_white
|
|
63
|
+
puts_line
|
|
64
|
+
puts 'What the name of new book?:'
|
|
65
|
+
print_promt
|
|
66
|
+
|
|
67
|
+
while user_input = STDIN.gets.chomp
|
|
68
|
+
case
|
|
69
|
+
when user_input.nil? || user_input.size == 0
|
|
70
|
+
puts 'Hmmm... Book without name at all? Are you kidding me?'
|
|
71
|
+
puts "Please, give me something more intelligent"
|
|
72
|
+
puts "If you want to cancel, just say 'cancel' or 'exit'"
|
|
73
|
+
print_promt
|
|
74
|
+
when @reject_args.include?(user_input)
|
|
75
|
+
puts_ok
|
|
76
|
+
break
|
|
77
|
+
else
|
|
78
|
+
check_book_exist user_input
|
|
79
|
+
break
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def check_book_exist(book_name)
|
|
86
|
+
current_folder_name = File.basename(Dir.pwd)
|
|
87
|
+
@current_book_name = book_name
|
|
88
|
+
@current_book_directory = File.join(Dir.pwd, book_name)
|
|
89
|
+
|
|
90
|
+
if current_folder_name == book_name
|
|
91
|
+
puts 'Attention! Attention please!'.yellow
|
|
92
|
+
puts 'Helper now inside directory with book name you are typed'
|
|
93
|
+
puts 'Dow you want to clear existing files and create book inside current directory?'.red
|
|
94
|
+
|
|
95
|
+
if yes_no_choice
|
|
96
|
+
@current_book_directory = Dir.pwd
|
|
97
|
+
clear_book_dir
|
|
68
98
|
end
|
|
69
|
-
clear_current_dir
|
|
70
99
|
end
|
|
71
100
|
|
|
72
|
-
|
|
73
|
-
puts '
|
|
101
|
+
if Dir.exist?(book_name)
|
|
102
|
+
puts 'Book with same name already exist in current place'.red
|
|
103
|
+
puts 'Want to empty it and create new book?'
|
|
104
|
+
if yes_no_choice
|
|
105
|
+
clear_book_dir
|
|
106
|
+
end
|
|
74
107
|
end
|
|
75
108
|
|
|
76
|
-
|
|
77
|
-
puts 'Ok, lest do it.'
|
|
78
|
-
puts "Confirm you wana create TechBook template in directory #{current_dir.green}"
|
|
79
|
-
print '(yes/no) '
|
|
109
|
+
build_template
|
|
80
110
|
|
|
111
|
+
puts 'Want to create top level chapters?'
|
|
81
112
|
if yes_no_choice
|
|
82
|
-
|
|
83
|
-
else
|
|
84
|
-
puts_ok
|
|
113
|
+
create_root_chapters
|
|
85
114
|
end
|
|
86
115
|
|
|
116
|
+
init_repository
|
|
117
|
+
|
|
87
118
|
end
|
|
88
119
|
|
|
89
|
-
def
|
|
90
|
-
puts
|
|
120
|
+
def clear_book_dir
|
|
121
|
+
puts "Clear book #{@current_book_name}".red
|
|
91
122
|
|
|
92
|
-
Dir[
|
|
123
|
+
Dir["#{@current_book_directory}/*"].each do |file|
|
|
93
124
|
if File.directory? file
|
|
94
125
|
FileUtils.rm_rf file
|
|
95
126
|
else
|
|
@@ -97,75 +128,60 @@ module TechbookHelper
|
|
|
97
128
|
end
|
|
98
129
|
end
|
|
99
130
|
|
|
131
|
+
Dir["#{@current_book_directory}/.*"].each do |file|
|
|
132
|
+
unless File.basename(file) == '.' || File.basename(file) == '..'
|
|
133
|
+
if File.directory? file
|
|
134
|
+
FileUtils.rm_rf file
|
|
135
|
+
else
|
|
136
|
+
File.delete file
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
100
141
|
10.times{print '. '; sleep 0.3;}
|
|
101
|
-
puts ' '
|
|
102
142
|
puts 'Done'
|
|
103
143
|
sleep(0.4)
|
|
104
144
|
puts_line
|
|
105
145
|
end
|
|
106
146
|
|
|
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
147
|
def build_chapter(name)
|
|
133
|
-
if @
|
|
148
|
+
if @current_book_directory.nil?
|
|
134
149
|
puts "Do not know which book to work with".red
|
|
135
150
|
return
|
|
136
151
|
end
|
|
137
152
|
|
|
138
|
-
Dir.mkdir(File.join(@
|
|
153
|
+
Dir.mkdir(File.join(@current_book_directory, name))
|
|
139
154
|
puts "Create chapter \"#{name}\""
|
|
140
155
|
sleep(0.4)
|
|
141
|
-
File.open(File.join(@
|
|
156
|
+
File.open(File.join(@current_book_directory, name, INDEX_MD), 'w').close
|
|
142
157
|
puts 'Index page'
|
|
143
158
|
sleep(0.5)
|
|
144
159
|
|
|
145
160
|
end
|
|
146
161
|
|
|
147
|
-
def build_template
|
|
148
|
-
Dir.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
def build_template
|
|
163
|
+
unless Dir.exist?(@current_book_directory)
|
|
164
|
+
Dir.mkdir(@current_book_directory)
|
|
165
|
+
puts 'Create root directory'
|
|
166
|
+
sleep(0.4)
|
|
167
|
+
end
|
|
168
|
+
File.open(File.join(@current_book_directory, INDEX_MD), 'w').close
|
|
169
|
+
puts 'Create Index page'
|
|
153
170
|
sleep(0.4)
|
|
154
|
-
Dir.mkdir(File.join(
|
|
171
|
+
Dir.mkdir(File.join(@current_book_directory, IMAGES_DIR))
|
|
172
|
+
File.open(File.join(@current_book_directory, IMAGES_DIR, GIT_KEEP), 'w').close
|
|
155
173
|
sleep(0.4)
|
|
156
174
|
puts 'Create images directory'
|
|
157
175
|
puts_line
|
|
158
|
-
puts 'Book template complete
|
|
176
|
+
puts 'Book template complete'
|
|
159
177
|
puts_line
|
|
160
178
|
sleep(0.5)
|
|
161
|
-
|
|
162
|
-
@current_book_name = name
|
|
163
179
|
end
|
|
164
180
|
|
|
165
181
|
def create_root_chapters
|
|
166
182
|
puts 'Top level chapters creation'
|
|
167
183
|
puts_line
|
|
168
|
-
|
|
184
|
+
puts_for_next
|
|
169
185
|
puts 'Enter chapter name (ex: "1 Specification", "2 Money and low")'
|
|
170
186
|
print_promt
|
|
171
187
|
while user_input = STDIN.gets.chomp
|
|
@@ -175,20 +191,64 @@ module TechbookHelper
|
|
|
175
191
|
puts "Please, give me something more intelligent"
|
|
176
192
|
print_promt
|
|
177
193
|
when @reject_args.include?(user_input)
|
|
178
|
-
|
|
194
|
+
puts 'Build chapters complete'
|
|
195
|
+
puts_line
|
|
179
196
|
break
|
|
180
197
|
else
|
|
181
198
|
build_chapter user_input
|
|
182
|
-
|
|
199
|
+
puts_for_next
|
|
183
200
|
puts 'Enter chapter name'
|
|
184
201
|
print_promt
|
|
185
202
|
end
|
|
186
203
|
end
|
|
187
204
|
end
|
|
188
205
|
|
|
206
|
+
def init_repository
|
|
207
|
+
puts 'Create git repository'
|
|
208
|
+
Dir.chdir(@current_book_directory) do
|
|
209
|
+
`git init`
|
|
210
|
+
`git add .`
|
|
211
|
+
`git commit -m "Build book #{@current_book_name} template"`
|
|
212
|
+
end
|
|
213
|
+
10.times{print '. '; sleep 0.1;}
|
|
214
|
+
puts 'Done'
|
|
215
|
+
sleep(0.2)
|
|
216
|
+
puts_line
|
|
217
|
+
|
|
218
|
+
add_git_remote
|
|
219
|
+
end
|
|
189
220
|
|
|
190
|
-
def
|
|
191
|
-
|
|
221
|
+
def add_git_remote
|
|
222
|
+
puts 'Want to add remote url to this book?'
|
|
223
|
+
if yes_no_choice
|
|
224
|
+
puts_for_next
|
|
225
|
+
puts 'Type git remote url:' #https://
|
|
226
|
+
print_promt
|
|
227
|
+
while user_input = STDIN.gets.chomp
|
|
228
|
+
case
|
|
229
|
+
when user_input.nil? || user_input.size == 0
|
|
230
|
+
puts_for_next
|
|
231
|
+
puts 'Do not play with me!'
|
|
232
|
+
puts 'Enter valid url or go to exit!'
|
|
233
|
+
print_promt
|
|
234
|
+
when @reject_args.include?(user_input)
|
|
235
|
+
puts_ok
|
|
236
|
+
break
|
|
237
|
+
when !user_input.start_with?('https://')
|
|
238
|
+
puts_for_next
|
|
239
|
+
puts 'Sorry. We need url start from https://'
|
|
240
|
+
puts 'Please, try again'
|
|
241
|
+
print_promt
|
|
242
|
+
else
|
|
243
|
+
Dir.chdir(@current_book_directory) do
|
|
244
|
+
`git remote add origin #{user_input}`
|
|
245
|
+
end
|
|
246
|
+
puts 'Remote url added to git'.green
|
|
247
|
+
break
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
print_finish_message
|
|
192
252
|
end
|
|
193
253
|
|
|
194
254
|
def is_dir_used?
|
|
@@ -201,8 +261,8 @@ module TechbookHelper
|
|
|
201
261
|
puts 'Command you can use:'
|
|
202
262
|
puts '%-10s – %10s' % ['create'.green, 'Will create new book template in current directory']
|
|
203
263
|
puts '%-10s – %10s' % [' ', 'Aliases c, -c, --c, -create, --create']
|
|
204
|
-
puts '%-10s – %10s' % ['check'.green, 'Go through dirs in current folder and check known problems']
|
|
205
|
-
puts '%-10s – %10s' % [' ', 'Aliases ch, -ch, --ch, -check, --check']
|
|
264
|
+
# puts '%-10s – %10s' % ['check'.green, 'Go through dirs in current folder and check known problems']
|
|
265
|
+
# puts '%-10s – %10s' % [' ', 'Aliases ch, -ch, --ch, -check, --check']
|
|
206
266
|
puts_line
|
|
207
267
|
end
|
|
208
268
|
|
|
@@ -219,6 +279,7 @@ module TechbookHelper
|
|
|
219
279
|
end
|
|
220
280
|
|
|
221
281
|
def yes_no_choice
|
|
282
|
+
print '(Yes/No) '.green
|
|
222
283
|
print_promt
|
|
223
284
|
answer = false
|
|
224
285
|
while user_input = STDIN.gets.chomp
|
|
@@ -230,17 +291,30 @@ module TechbookHelper
|
|
|
230
291
|
answer = false
|
|
231
292
|
break
|
|
232
293
|
else
|
|
233
|
-
puts
|
|
294
|
+
puts 'Please, answer the question – yes or no'
|
|
234
295
|
print_promt
|
|
235
296
|
end
|
|
236
297
|
end
|
|
237
298
|
answer
|
|
238
299
|
end
|
|
239
300
|
|
|
301
|
+
def print_finish_message
|
|
302
|
+
puts 'We are finish.'
|
|
303
|
+
puts "Book '#{@current_book_name}' was created!"
|
|
304
|
+
puts_line
|
|
305
|
+
puts 'Add and edit .md pages, commit and push to remote to publish this book'
|
|
306
|
+
puts 'Thanks'
|
|
307
|
+
1.times{puts ''}
|
|
308
|
+
end
|
|
309
|
+
|
|
240
310
|
def print_promt
|
|
241
311
|
print ':> '.green
|
|
242
312
|
end
|
|
243
313
|
|
|
314
|
+
def puts_for_next
|
|
315
|
+
puts 'For exit and continue type "next"'.yellow
|
|
316
|
+
end
|
|
317
|
+
|
|
244
318
|
def puts_line
|
|
245
319
|
puts '--------------------------'
|
|
246
320
|
end
|
|
@@ -251,3 +325,9 @@ module TechbookHelper
|
|
|
251
325
|
|
|
252
326
|
end
|
|
253
327
|
end
|
|
328
|
+
|
|
329
|
+
# what to check
|
|
330
|
+
# files without md in directories
|
|
331
|
+
# directories without index.md
|
|
332
|
+
# where is _i directory
|
|
333
|
+
# root index file
|
metadata
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: techbook_helper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Georg Romas
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-03-
|
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - ~>
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '1.8'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - ~>
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '1.8'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - ~>
|
|
31
|
+
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '10.0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - ~>
|
|
38
|
+
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '10.0'
|
|
41
41
|
description: This is helper to start wright technical book stored in git with and
|
|
@@ -47,7 +47,7 @@ executables:
|
|
|
47
47
|
extensions: []
|
|
48
48
|
extra_rdoc_files: []
|
|
49
49
|
files:
|
|
50
|
-
- .gitignore
|
|
50
|
+
- ".gitignore"
|
|
51
51
|
- Gemfile
|
|
52
52
|
- LICENSE.txt
|
|
53
53
|
- README.md
|
|
@@ -68,12 +68,12 @@ require_paths:
|
|
|
68
68
|
- lib
|
|
69
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
70
|
requirements:
|
|
71
|
-
- -
|
|
71
|
+
- - ">="
|
|
72
72
|
- !ruby/object:Gem::Version
|
|
73
73
|
version: '0'
|
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
requirements:
|
|
76
|
-
- -
|
|
76
|
+
- - ">="
|
|
77
77
|
- !ruby/object:Gem::Version
|
|
78
78
|
version: '0'
|
|
79
79
|
requirements: []
|