wb 1.0.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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +21 -0
- data/README.md +154 -0
- data/Rakefile +6 -0
- data/bin/hack +10 -0
- data/bin/setup +8 -0
- data/exe/wb +185 -0
- data/lib/wb.rb +20 -0
- data/lib/wb/cli.rb +29 -0
- data/lib/wb/config.rb +80 -0
- data/lib/wb/config_template.rb +18 -0
- data/lib/wb/day.rb +25 -0
- data/lib/wb/filename.rb +9 -0
- data/lib/wb/note.rb +40 -0
- data/lib/wb/project.rb +14 -0
- data/lib/wb/shell.rb +41 -0
- data/lib/wb/version.rb +5 -0
- data/wb.gemspec +30 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 308d477d5155abf0f41976ad5e9b74b4bd1e7d510d1d85221a0bf9e9470126c5
|
4
|
+
data.tar.gz: c445711c39f5e9b04208351353714146daf65095c76997329bfd176a8888ee33
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 259cbd2a351fc1abf1eaffa06c463e5baa3415605af0ae726d6dfab96fc9be52ce4cf88bc1feae60cb4fe83ec1bcee0d7367bb33ac0931afc64f5f5885f6e104
|
7
|
+
data.tar.gz: f907e1e4c066744452ce81e689995127ad05ca7bd0f11f635d0ec28ae49b3d665251330bc6ebe28403c46bb6a1e0aaaf171f51703017233748c2af8d9362f307
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wb (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
method_source (0.9.0)
|
12
|
+
pry (0.11.3)
|
13
|
+
coderay (~> 1.1.0)
|
14
|
+
method_source (~> 0.9.0)
|
15
|
+
rake (12.3.1)
|
16
|
+
rspec (3.8.0)
|
17
|
+
rspec-core (~> 3.8.0)
|
18
|
+
rspec-expectations (~> 3.8.0)
|
19
|
+
rspec-mocks (~> 3.8.0)
|
20
|
+
rspec-core (3.8.0)
|
21
|
+
rspec-support (~> 3.8.0)
|
22
|
+
rspec-expectations (3.8.1)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-mocks (3.8.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.8.0)
|
28
|
+
rspec-support (3.8.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler
|
35
|
+
pry
|
36
|
+
rake
|
37
|
+
rspec (~> 3.0)
|
38
|
+
wb!
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Juanito Fatas
|
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
@@ -0,0 +1,154 @@
|
|
1
|
+
# WB -- Software Engineers's Workbook
|
2
|
+
|
3
|
+
[Background reading: Lab Notebooking for the Software Engineer](https://blog.nelhage.com/2010/06/lab-notebooking-for-the-software-engineer/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install wb
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Set `wb` up first:
|
12
|
+
|
13
|
+
```
|
14
|
+
$ wb setup # wb init + wb ignore
|
15
|
+
```
|
16
|
+
|
17
|
+
This will create a config yaml at `~/.workbookrc`:
|
18
|
+
|
19
|
+
```yaml
|
20
|
+
# Auto generated by wb 1.0.0
|
21
|
+
workbook:
|
22
|
+
working_hours: "9-17"
|
23
|
+
personal: "~/Dropbox/workbooks/personal.md"
|
24
|
+
work: "~/Dropbox/workbooks/work.md"
|
25
|
+
project:
|
26
|
+
note_folder: ".note"
|
27
|
+
```
|
28
|
+
|
29
|
+
To open a workbook:
|
30
|
+
|
31
|
+
```
|
32
|
+
wb
|
33
|
+
```
|
34
|
+
|
35
|
+
This will open workbook based on the working hour set in `~/.workbookrc`.
|
36
|
+
|
37
|
+
Inside working hour `wb` equals to:
|
38
|
+
|
39
|
+
```
|
40
|
+
wb work
|
41
|
+
```
|
42
|
+
|
43
|
+
Outside working hour `wb` equals to:
|
44
|
+
|
45
|
+
```
|
46
|
+
wb personal
|
47
|
+
```
|
48
|
+
|
49
|
+
Create a new workbook in the project you are working:
|
50
|
+
|
51
|
+
```
|
52
|
+
wb new
|
53
|
+
```
|
54
|
+
|
55
|
+
by default it creates a markdown workbook using today's date:
|
56
|
+
|
57
|
+
```
|
58
|
+
2018-09-24.md
|
59
|
+
```
|
60
|
+
|
61
|
+
The date could be overrided in `~/.workbookrc`, either at `workbook` or `project` level:
|
62
|
+
|
63
|
+
Based on [Ruby's `strftime`](https://ruby-doc.org/stdlib-2.5.1/libdoc/date/rdoc/DateTime.html#method-i-strftime):
|
64
|
+
|
65
|
+
```
|
66
|
+
workbook:
|
67
|
+
date_format: %c
|
68
|
+
```
|
69
|
+
|
70
|
+
```
|
71
|
+
workbook:
|
72
|
+
project:
|
73
|
+
date_format: %D
|
74
|
+
```
|
75
|
+
|
76
|
+
The extension could be overrided in `~/.workbookrc`, either at `workbook` or `project` level:
|
77
|
+
|
78
|
+
```
|
79
|
+
workbook:
|
80
|
+
extension: rdoc
|
81
|
+
```
|
82
|
+
|
83
|
+
```
|
84
|
+
workbook:
|
85
|
+
project:
|
86
|
+
extension: txt
|
87
|
+
```
|
88
|
+
|
89
|
+
Invoking `wb new` again will use your editor `$EDITOR` to open the existing workbook.
|
90
|
+
|
91
|
+
You can also create a workbook with custom name under project by:
|
92
|
+
|
93
|
+
```
|
94
|
+
(on branch fix-nasty-bugs)
|
95
|
+
git rev-parse --abbrev-ref HEAD | xargs wb new
|
96
|
+
|
97
|
+
# will create a new note named under {project.note_folder}:
|
98
|
+
# 2018-09-24-fix-nasty-bugs.md
|
99
|
+
```
|
100
|
+
|
101
|
+
Opening local / global notebooks by:
|
102
|
+
|
103
|
+
```
|
104
|
+
wb open
|
105
|
+
|
106
|
+
0: .note/2018-09-23.md
|
107
|
+
1: .note/2018-09-24.md
|
108
|
+
2: ~/Dropbox/workbooks/personal.md
|
109
|
+
3: ~/Dropbox/workbooks/work.md
|
110
|
+
```
|
111
|
+
|
112
|
+
Type in the notebook number you want to open.
|
113
|
+
|
114
|
+
If you remember the notebook name by heart, supply `NAME` to `wb open`:
|
115
|
+
|
116
|
+
```
|
117
|
+
# both works
|
118
|
+
wb open .note/2018-09-23.md
|
119
|
+
wb open 2018-09-23.md # opens .note/2018-09-23.md
|
120
|
+
wb open personal.md # ~/Dropbox/workbooks/personal.md
|
121
|
+
```
|
122
|
+
|
123
|
+
Full documentation by `wb help`:
|
124
|
+
|
125
|
+
```
|
126
|
+
wb init Initialize wb config yaml file
|
127
|
+
wb ignore Add {project.note_folder} to global gitignore
|
128
|
+
wb setup wb init + wb ignore
|
129
|
+
|
130
|
+
wb config Open wb config file
|
131
|
+
|
132
|
+
wb Open global notebook based on {working_hours}
|
133
|
+
wb personal Open global personal notebook
|
134
|
+
wb work Open global work notebook
|
135
|
+
|
136
|
+
wb open Open from all notes in {project.note_folder} and global notes
|
137
|
+
wb open NAME Open note by NAME
|
138
|
+
|
139
|
+
wb new Create/Open note of name {date_format}.{extension} under {project.note_folder}
|
140
|
+
wb new NAME Create note by {date_format}.NAME under {project.note_folder}
|
141
|
+
```
|
142
|
+
|
143
|
+
Thank you for using `wb`.
|
144
|
+
|
145
|
+
Feedback and improvement are welcome!
|
146
|
+
|
147
|
+
## License, Contributor's Guidelines, and Credits
|
148
|
+
|
149
|
+
- MIT license
|
150
|
+
- [Moya Contributors Guidelines][moya] which TLDR: means we give out push access easily and often.
|
151
|
+
- Notebook idea by [Nelson Elhage](https://blog.nelhage.com/about/)
|
152
|
+
|
153
|
+
[mit]: https://opensource.org/licenses/MIT
|
154
|
+
[moya]: https://github.com/Moya/contributors
|
data/Rakefile
ADDED
data/bin/hack
ADDED
data/bin/setup
ADDED
data/exe/wb
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wb"
|
5
|
+
|
6
|
+
# Exit cleanly from an early interrupt
|
7
|
+
Signal.trap("INT") { abort }
|
8
|
+
|
9
|
+
class HelpCommand
|
10
|
+
def self.name
|
11
|
+
@name ||= "help"
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(*)
|
15
|
+
$stdout.puts(<<~HELP)
|
16
|
+
wb init Initialize wb config yaml file
|
17
|
+
wb ignore Add {project.note_folder} to global gitignore
|
18
|
+
wb setup wb init + wb ignore
|
19
|
+
|
20
|
+
wb config Open wb config file
|
21
|
+
|
22
|
+
wb Open global notebook based on {working_hours}
|
23
|
+
wb personal Open global personal notebook
|
24
|
+
wb work Open global work notebook
|
25
|
+
|
26
|
+
wb open Open from all notes in {project.note_folder} and global notes
|
27
|
+
wb open NAME Open note by NAME
|
28
|
+
|
29
|
+
wb new Create/Open note of name {date_format}.{extension} under {project.note_folder}
|
30
|
+
wb new NAME Create note by {date_format}.NAME under {project.note_folder}
|
31
|
+
HELP
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class InitCommand
|
36
|
+
def self.name
|
37
|
+
@name ||= "init"
|
38
|
+
end
|
39
|
+
|
40
|
+
def run(*)
|
41
|
+
unless File.exist?(WB.default_config)
|
42
|
+
File.open(WB.default_config, "w") do |file|
|
43
|
+
file.puts WB::ConfigTemplate.content
|
44
|
+
end
|
45
|
+
$stdout.puts %Q(#{WB.default_config} created!)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class IgnoreCommand
|
51
|
+
def self.name
|
52
|
+
@name ||= "ignore"
|
53
|
+
end
|
54
|
+
|
55
|
+
def run(*)
|
56
|
+
gitignore_global = File.join(Etc.getpwuid.dir, ".gitignore_global")
|
57
|
+
|
58
|
+
unless IO.read(gitignore_global).include?(breadcrumb)
|
59
|
+
WB::Shell.append(gitignore_global) do |file|
|
60
|
+
file.puts("\n# ignore project notes by #{breadcrumb}")
|
61
|
+
file.puts("/.note/")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def breadcrumb
|
69
|
+
"https://github.com/juanitofatas/wb"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class SetupCommand
|
74
|
+
def self.name
|
75
|
+
@name ||= "setup"
|
76
|
+
end
|
77
|
+
|
78
|
+
def run(*)
|
79
|
+
$stdout.puts "wb init"
|
80
|
+
InitCommand.new.run
|
81
|
+
|
82
|
+
$stdout.puts "wb ignore"
|
83
|
+
IgnoreCommand.new.run
|
84
|
+
|
85
|
+
$stdout.puts "setup completed."
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class DefaultCommand
|
90
|
+
def self.name
|
91
|
+
@name ||= ""
|
92
|
+
end
|
93
|
+
|
94
|
+
def run(*)
|
95
|
+
if WB::Day.working?
|
96
|
+
WB::Shell.open_file(WB.config.work_workbook)
|
97
|
+
else
|
98
|
+
WB::Shell.open_file(WB.config.personal_workbook)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class PersonalCommand
|
104
|
+
def self.name
|
105
|
+
@name ||= "personal"
|
106
|
+
end
|
107
|
+
|
108
|
+
def run(*)
|
109
|
+
WB::Shell.open_file(WB.config.personal_workbook)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class WorkCommand
|
114
|
+
def self.name
|
115
|
+
@name ||= "work"
|
116
|
+
end
|
117
|
+
|
118
|
+
def run(*)
|
119
|
+
WB::Shell.open_file(WB.config.work_workbook)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class OpenCommand
|
124
|
+
def self.name
|
125
|
+
@name ||= "open"
|
126
|
+
end
|
127
|
+
|
128
|
+
def run(filename)
|
129
|
+
if filename
|
130
|
+
note = WB::Note.find_note(filename)
|
131
|
+
if note
|
132
|
+
WB::Shell.open_file(note.path)
|
133
|
+
else
|
134
|
+
$stdout.puts "Cannot find #{filename}, please double check."
|
135
|
+
end
|
136
|
+
else
|
137
|
+
WB::Note.list_notes
|
138
|
+
note_number = WB::Shell.getc
|
139
|
+
note = WB::Note.find_by_number(note_number)
|
140
|
+
if note
|
141
|
+
WB::Shell.open_file(note.path)
|
142
|
+
else
|
143
|
+
$stdout.puts "Cannot pick #{note_number}, please double check."
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class NewCommand
|
150
|
+
def self.name
|
151
|
+
@name ||= "new"
|
152
|
+
end
|
153
|
+
|
154
|
+
def run(name)
|
155
|
+
filename = WB::Project.new_note(name)
|
156
|
+
unless File.exist?(filename)
|
157
|
+
WB::Shell.create_file(filename)
|
158
|
+
end
|
159
|
+
WB::Shell.open_file(filename)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class ConfigCommand
|
164
|
+
def self.name
|
165
|
+
@name ||= "config"
|
166
|
+
end
|
167
|
+
|
168
|
+
def run(*)
|
169
|
+
WB::Shell.open_file(WB.config.path)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
commands = [
|
174
|
+
HelpCommand,
|
175
|
+
InitCommand,
|
176
|
+
IgnoreCommand,
|
177
|
+
SetupCommand,
|
178
|
+
DefaultCommand,
|
179
|
+
PersonalCommand,
|
180
|
+
WorkCommand,
|
181
|
+
OpenCommand,
|
182
|
+
NewCommand,
|
183
|
+
ConfigCommand,
|
184
|
+
]
|
185
|
+
WB::CLI.new(commands).run(arguments: ARGV)
|
data/lib/wb.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "etc"
|
3
|
+
|
4
|
+
require "wb/version"
|
5
|
+
require "wb/config"
|
6
|
+
require "wb/cli"
|
7
|
+
require "wb/project"
|
8
|
+
require "wb/shell"
|
9
|
+
require "wb/day"
|
10
|
+
require "wb/config_template"
|
11
|
+
|
12
|
+
module WB
|
13
|
+
def self.default_config
|
14
|
+
File.join(Etc.getpwuid.dir, ".workbookrc")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.config(path: default_config)
|
18
|
+
@config ||= Config.new(path)
|
19
|
+
end
|
20
|
+
end
|
data/lib/wb/cli.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module WB
|
2
|
+
class CLI
|
3
|
+
def initialize(commands)
|
4
|
+
@commands = commands
|
5
|
+
end
|
6
|
+
|
7
|
+
def run(arguments: ARGV)
|
8
|
+
command = find_command(arguments[0])
|
9
|
+
command.run(arguments[1])
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_reader :commands
|
15
|
+
|
16
|
+
def find_command(name)
|
17
|
+
command = find_command_by_name(name) || default_command
|
18
|
+
command.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_command_by_name(name)
|
22
|
+
commands.find { |command| command.name == name }
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_command
|
26
|
+
commands.find { |command| command.name == "" }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/wb/config.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
require "wb/note"
|
5
|
+
require "wb/filename"
|
6
|
+
|
7
|
+
module WB
|
8
|
+
class Config
|
9
|
+
attr_reader :path
|
10
|
+
|
11
|
+
def initialize(config_path)
|
12
|
+
@path = config_path
|
13
|
+
@config = YAML.safe_load(IO.read(config_path))
|
14
|
+
end
|
15
|
+
|
16
|
+
def notes
|
17
|
+
local_notes = Dir[File.join(WB.config.project_root, "*")]
|
18
|
+
global_notes = [WB.config.personal_workbook, WB.config.work_workbook]
|
19
|
+
|
20
|
+
[*local_notes, *global_notes].each_with_index.map do |note, index|
|
21
|
+
WB::Note.new(note, index)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def working_hours
|
26
|
+
@working_hours ||= workbook.fetch("working_hours").split("-")
|
27
|
+
end
|
28
|
+
|
29
|
+
def personal_workbook
|
30
|
+
@personal_workbook ||= workbook.fetch("personal")
|
31
|
+
end
|
32
|
+
|
33
|
+
def work_workbook
|
34
|
+
@work_workbook ||= workbook.fetch("work")
|
35
|
+
end
|
36
|
+
|
37
|
+
def project_root
|
38
|
+
@project_root ||= project.fetch("note_folder")
|
39
|
+
end
|
40
|
+
|
41
|
+
def project_date_format
|
42
|
+
@project_date_format ||= begin
|
43
|
+
date_format = fetch_config(key: "date_format", default: DEFAULT_DATE_FORMAT)
|
44
|
+
Filename.generate(date_format)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def extension
|
49
|
+
@extension ||= begin
|
50
|
+
fetch_config(key: "extension", default: DEFAULT_EXTENSION_FORMAT)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
attr_reader :config
|
57
|
+
|
58
|
+
DEFAULT_DATE_FORMAT = "%F"
|
59
|
+
private_constant :DEFAULT_DATE_FORMAT
|
60
|
+
|
61
|
+
DEFAULT_EXTENSION_FORMAT = "md"
|
62
|
+
private_constant :DEFAULT_EXTENSION_FORMAT
|
63
|
+
|
64
|
+
def workbook
|
65
|
+
@_workbook ||= config.fetch("workbook")
|
66
|
+
end
|
67
|
+
|
68
|
+
def project
|
69
|
+
@_project ||= workbook.fetch("project")
|
70
|
+
end
|
71
|
+
|
72
|
+
def fetch_config(key:, default:)
|
73
|
+
project.fetch(key) do
|
74
|
+
workbook.fetch(key) do
|
75
|
+
default
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module WB
|
2
|
+
class ConfigTemplate
|
3
|
+
def self.content
|
4
|
+
CONTENT
|
5
|
+
end
|
6
|
+
|
7
|
+
CONTENT = <<~WORKBOOKRC
|
8
|
+
# Auto generated by wb #{WB::VERSION}
|
9
|
+
workbook:
|
10
|
+
working_hours: "9-17"
|
11
|
+
personal: "~/Dropbox/workbooks/personal.md"
|
12
|
+
work: "~/Dropbox/workbooks/work.md"
|
13
|
+
project:
|
14
|
+
note_folder: ".note"
|
15
|
+
WORKBOOKRC
|
16
|
+
private_constant :CONTENT
|
17
|
+
end
|
18
|
+
end
|
data/lib/wb/day.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "time"
|
2
|
+
|
3
|
+
module WB
|
4
|
+
class Day
|
5
|
+
def self.working?
|
6
|
+
now = Time.now
|
7
|
+
date = now.strftime("%Y-%m-%d")
|
8
|
+
from, to = WB.config.working_hours
|
9
|
+
start_time = TimeUtils.get_beginning_of(from, within: date)
|
10
|
+
end_time = TimeUtils.get_end_of(to, within: date)
|
11
|
+
|
12
|
+
now.between?(start_time, end_time)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TimeUtils
|
17
|
+
def self.get_beginning_of(hour, within:)
|
18
|
+
Time.parse("#{within} #{hour}:00:00")
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get_end_of(hour, within:)
|
22
|
+
Time.parse("#{within} #{hour}:59:59")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/wb/filename.rb
ADDED
data/lib/wb/note.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WB
|
4
|
+
class Note
|
5
|
+
attr_reader :path, :number
|
6
|
+
|
7
|
+
def self.all
|
8
|
+
WB.config.notes
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find_by_number(number)
|
12
|
+
all.find { |note| note.number == number }
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find_by_full_path(full_path)
|
16
|
+
all.find { |note| note.path == full_path }
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.find_by_basename(basename)
|
20
|
+
all.find { |note| File.basename(note.path) == basename }
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.find_note(name)
|
24
|
+
find_by_full_path(name) || find_by_basename(name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.list_notes
|
28
|
+
all.each { |note| $stdout.puts note }
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(path, number)
|
32
|
+
@path = path
|
33
|
+
@number = number.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
%Q(#{number}: #{path})
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/wb/project.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WB
|
4
|
+
class Project
|
5
|
+
def self.root
|
6
|
+
WB.config.project_root
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.new_note(name)
|
10
|
+
filename = [WB.config.project_date_format, name].compact.join("-")
|
11
|
+
File.join(root, "#{filename}.#{WB.config.extension}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/wb/shell.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WB
|
4
|
+
class Shell
|
5
|
+
def self.run(*commands)
|
6
|
+
$stdout.puts commands.join(" ")
|
7
|
+
system *commands
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.mkdir_p_touch(path)
|
11
|
+
directory = File.dirname(path)
|
12
|
+
filename = File.basename(path)
|
13
|
+
unless File.exist?(directory)
|
14
|
+
FileUtils.mkdir_p(directory)
|
15
|
+
end
|
16
|
+
FileUtils.touch(filename)
|
17
|
+
$stdout.puts "#{path} created"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create_file(path)
|
21
|
+
mkdir_p_touch(path)
|
22
|
+
path
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.open_file(path, editor: ENV["EDITOR"])
|
26
|
+
run(editor, path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.getc
|
30
|
+
$stdin.getc
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.append(path)
|
34
|
+
file = File.open(path, "a")
|
35
|
+
yield file
|
36
|
+
ensure
|
37
|
+
$stdout.puts "Wrote to #{file.path}"
|
38
|
+
file.close
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/wb/version.rb
ADDED
data/wb.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "wb/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wb"
|
8
|
+
spec.version = WB::VERSION
|
9
|
+
spec.authors = ["Juanito Fatas"]
|
10
|
+
spec.email = ["katehuang0320@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{workbook}
|
13
|
+
spec.description = %q{keep notes}
|
14
|
+
spec.homepage = "https://github.com/JuanitoFatas/wb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juanito Fatas
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-24 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: keep notes
|
70
|
+
email:
|
71
|
+
- katehuang0320@gmail.com
|
72
|
+
executables:
|
73
|
+
- wb
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/hack
|
86
|
+
- bin/setup
|
87
|
+
- exe/wb
|
88
|
+
- lib/wb.rb
|
89
|
+
- lib/wb/cli.rb
|
90
|
+
- lib/wb/config.rb
|
91
|
+
- lib/wb/config_template.rb
|
92
|
+
- lib/wb/day.rb
|
93
|
+
- lib/wb/filename.rb
|
94
|
+
- lib/wb/note.rb
|
95
|
+
- lib/wb/project.rb
|
96
|
+
- lib/wb/shell.rb
|
97
|
+
- lib/wb/version.rb
|
98
|
+
- wb.gemspec
|
99
|
+
homepage: https://github.com/JuanitoFatas/wb
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.7.6
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: workbook
|
123
|
+
test_files: []
|