1hdoc 0.1.3
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/README.md +117 -0
- data/bin/1hdoc +7 -0
- data/lib/1hdoc/application.rb +94 -0
- data/lib/1hdoc/core/committer.rb +27 -0
- data/lib/1hdoc/core/configuration.rb +20 -0
- data/lib/1hdoc/core/log_builder.rb +46 -0
- data/lib/1hdoc/core/log_viewer.rb +49 -0
- data/lib/1hdoc/core/utilities.rb +27 -0
- data/lib/1hdoc/integration.rb +36 -0
- data/lib/1hdoc/version.rb +3 -0
- data/lib/1hdoc.rb +16 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6858c51ee5e5515c03900f8060fe672a4f899a45
|
4
|
+
data.tar.gz: 7f5b95cdb98bf60fc42dab7dfb20ab7c61eea76a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43b32f3517660ac29cc340bb208117e3560037c2a0d32243a93dcb4c3d9fbe05833482aa96e024e7cec1daaa5eaac2cd80753074af6db4207957f5cdc32da809
|
7
|
+
data.tar.gz: cfc91d0e61f6c9fb00c96e65dbc3158eace822362f9c14195d603c56b1e77b866e28994f8d0967ab736ec8081ee288f2379bb005d42c617be23fd6d4573ca7ae
|
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# 1hdoc
|
2
|
+
[](https://codeclimate.com/github/domcorvasce/1hdoc)
|
3
|
+
[](https://codeclimate.com/github/domcorvasce/1hdoc/coverage)
|
4
|
+
[](https://travis-ci.org/domcorvasce/1hdoc)
|
5
|
+
|
6
|
+
Keep track of your progress during #100DaysOfCode event.
|
7
|
+
## Warning
|
8
|
+
It's still in development so you could meet some bugs.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Install **1hdoc** from RubyGems:
|
13
|
+
|
14
|
+
```shell
|
15
|
+
gem install 1hdoc
|
16
|
+
```
|
17
|
+
|
18
|
+
or clone this repository and build the gem manually:
|
19
|
+
|
20
|
+
```shell
|
21
|
+
git clone https://github.com/domcorvasce/1hdoc
|
22
|
+
cd 1hdoc
|
23
|
+
|
24
|
+
gem build 1hdoc.gemspec
|
25
|
+
gem install *.gem
|
26
|
+
```
|
27
|
+
|
28
|
+
## Getting Started
|
29
|
+
|
30
|
+
You can get a list of available commands typing:
|
31
|
+
|
32
|
+
```shell
|
33
|
+
1hdoc --help
|
34
|
+
```
|
35
|
+
|
36
|
+
### Configure the necessary
|
37
|
+
|
38
|
+
Here we are! Now you've to initialize all necessary files which are:
|
39
|
+
|
40
|
+
- the [#100DaysOfCode's repository](https://github.com/Kallaway/100-days-of-code)
|
41
|
+
- the .1hdoc.yml configuration file
|
42
|
+
|
43
|
+
Open your Terminal and type:
|
44
|
+
|
45
|
+
```shell
|
46
|
+
1hdoc --init
|
47
|
+
```
|
48
|
+
|
49
|
+
### Change repo's remote origin
|
50
|
+
|
51
|
+
A final thing, you should edit the repo's remote origin so I can
|
52
|
+
push to your account.
|
53
|
+
|
54
|
+
First of all, open GitHub or whatever you use and create a new empty repository.
|
55
|
+
|
56
|
+
Now move to the **100-days-of-code** repo's folder and type:
|
57
|
+
|
58
|
+
```shell
|
59
|
+
git remote remove origin
|
60
|
+
git remote add origin YOUR_REPO_URL
|
61
|
+
```
|
62
|
+
|
63
|
+
Hooray! We're done.
|
64
|
+
|
65
|
+
### Register your progress
|
66
|
+
|
67
|
+
Have you ended Day 2?
|
68
|
+
|
69
|
+
Great! Let's 1hdoc track your progress. Type:
|
70
|
+
|
71
|
+
```shell
|
72
|
+
1hdoc --commit
|
73
|
+
```
|
74
|
+
|
75
|
+
By default, 1hdoc will push to the repo automatically after you
|
76
|
+
register your progress.
|
77
|
+
|
78
|
+
You can change this behavior by assigning `false` to `auto_push` option in
|
79
|
+
`~/.1hdoc.yml`:
|
80
|
+
|
81
|
+
```yaml
|
82
|
+
workspace: ~/Workspace/Mine/100-days-of-code
|
83
|
+
auto_push: false
|
84
|
+
```
|
85
|
+
|
86
|
+
### Manually push to the repo
|
87
|
+
|
88
|
+
If you turn off `auto_push` you can push to the repo typing:
|
89
|
+
|
90
|
+
```shell
|
91
|
+
1hdoc --sync
|
92
|
+
```
|
93
|
+
|
94
|
+
### See progress
|
95
|
+
|
96
|
+
Obviously you can see your progress:
|
97
|
+
|
98
|
+
```shell
|
99
|
+
1hdoc --log
|
100
|
+
1hdoc --log=2 # only day 2
|
101
|
+
```
|
102
|
+
|
103
|
+
## Contribute
|
104
|
+
|
105
|
+
Everyone can contribute to this project:
|
106
|
+
|
107
|
+
- Fixing bugs
|
108
|
+
- Fixing my bad english
|
109
|
+
- Proposing new features
|
110
|
+
- Improving code
|
111
|
+
- and doing a plethora of other things..
|
112
|
+
|
113
|
+
Feel free to open an issue and propose a pull request.
|
114
|
+
|
115
|
+
## License
|
116
|
+
|
117
|
+
**1hdoc** is released under terms of _GNU/GPL v3_ license.
|
data/bin/1hdoc
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Provides an interface for interact with the program.
|
4
|
+
class Application
|
5
|
+
include Integration
|
6
|
+
|
7
|
+
AVAILABLE_COMMANDS = [
|
8
|
+
['-i', '--init', 'Initialize necessary files.'],
|
9
|
+
['-c', '--commit', 'Register your progress and sync it.'],
|
10
|
+
['-s', '--sync', 'Manually synchronize your online repository.'],
|
11
|
+
['-v', '--version', 'Show program version.']
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
def initialize(option_parser = OptionParser)
|
15
|
+
@option_parser = option_parser
|
16
|
+
@config_file = File.expand_path('~/.1hdoc.yml')
|
17
|
+
|
18
|
+
return init unless File.exist?(@config_file)
|
19
|
+
|
20
|
+
@config_options = Configuration.new(@config_file).options
|
21
|
+
@log_path = File.join(@config_options['workspace'], 'log.yml')
|
22
|
+
@repo = 'https://github.com/domcorvasce/100-days-of-code'
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Parse defined options.
|
27
|
+
def run
|
28
|
+
options = initialize_options
|
29
|
+
options.parse!
|
30
|
+
rescue @option_parser::InvalidOption
|
31
|
+
puts options
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def initialize_options
|
37
|
+
@option_parser.new do |opts|
|
38
|
+
opts.banner = 'Usage: 1hdoc -h'
|
39
|
+
|
40
|
+
AVAILABLE_COMMANDS.each do |command|
|
41
|
+
opts.on(*command) { send(command[1].sub('--', '')) }
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on('-l', '--log=[DAY]', 'Show the entire log or per day') do |day|
|
45
|
+
show_log(day)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Initialize necessary files such as the configuration file.
|
52
|
+
def init
|
53
|
+
print 'Type the full path for your new repo (ex. ~/works/my_repo): '
|
54
|
+
workspace = $stdin.gets.chomp
|
55
|
+
|
56
|
+
Configuration.init(@config_file, 'workspace' => File.expand_path(workspace),
|
57
|
+
'auto_push' => true)
|
58
|
+
Committer.init(@repo, workspace)
|
59
|
+
|
60
|
+
puts 'Here we are! You are ready to start.'
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Track user's progress for the current day.
|
65
|
+
def commit
|
66
|
+
log_handler = LogBuilder.new(@log_path)
|
67
|
+
committer = Committer.new(@config_options['workspace'])
|
68
|
+
|
69
|
+
return puts 'You are done for today :)' unless log_handler.record_not_exist?
|
70
|
+
|
71
|
+
latest_day = log_handler.add(register_daily_commit)
|
72
|
+
committer.commit("Add Day #{latest_day}")
|
73
|
+
|
74
|
+
sync if @config_options['auto_push']
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Show the entire log or per day.
|
79
|
+
def show_log(target_day)
|
80
|
+
log_viewer = LogViewer.new(@log_path)
|
81
|
+
puts log_viewer.show(target_day.to_i)
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Manually push the daily commit to user's repository.
|
86
|
+
def sync
|
87
|
+
push_commit(@config_options['workspace'])
|
88
|
+
end
|
89
|
+
|
90
|
+
def version
|
91
|
+
puts '1hdoc ver' + VERSION
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Provides an interface for Git in order to manage user's repo.
|
4
|
+
class Committer
|
5
|
+
##
|
6
|
+
# Initialize the workspace.
|
7
|
+
def self.init(repository, path, git = Git)
|
8
|
+
path = File.expand_path(path)
|
9
|
+
|
10
|
+
$stderr.puts 'Cloning #100DaysOfCode repository..'
|
11
|
+
git.clone(repository, path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(path, git = Git)
|
15
|
+
@repo = git.open(path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def commit(message)
|
19
|
+
@repo.add(all: true)
|
20
|
+
@repo.commit(message)
|
21
|
+
end
|
22
|
+
|
23
|
+
def push
|
24
|
+
@repo.push
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Manage configuration files.
|
4
|
+
class Configuration
|
5
|
+
attr_reader :options
|
6
|
+
include Utilities
|
7
|
+
|
8
|
+
##
|
9
|
+
# Initialize a new configuration file and write given options.
|
10
|
+
def self.init(path, options)
|
11
|
+
File.open(File.expand_path(path), 'w') do |configuration_file|
|
12
|
+
configuration_file.puts(options.to_yaml)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(path, config_parser = YAML)
|
17
|
+
@options = parse_file(expand_path(path), config_parser)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Provides methods for manage user's log such as adding records.
|
4
|
+
class LogBuilder
|
5
|
+
attr_reader :log
|
6
|
+
include Utilities
|
7
|
+
|
8
|
+
def initialize(path, file_parser = YAML)
|
9
|
+
@path = expand_path(path)
|
10
|
+
@log = parse_file(@path, file_parser)
|
11
|
+
|
12
|
+
@today_date = Time.now.strftime('%Y-%m-%d')
|
13
|
+
@record = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# Check if there is no record for the current day.
|
18
|
+
def record_not_exist?
|
19
|
+
last_day = @log.keys.last
|
20
|
+
last_day.nil? || @log[last_day]['published_on'] != @today_date
|
21
|
+
end
|
22
|
+
|
23
|
+
def add(data)
|
24
|
+
day = fetch_current_day
|
25
|
+
|
26
|
+
@record[day] = stringify_symbols(data)
|
27
|
+
@record[day]['published_on'] = @today_date
|
28
|
+
|
29
|
+
append_to_log
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def append_to_log
|
35
|
+
File.open(@path, 'a') do |log|
|
36
|
+
log.puts @record.to_yaml.sub('---', '')
|
37
|
+
end
|
38
|
+
|
39
|
+
fetch_current_day
|
40
|
+
end
|
41
|
+
|
42
|
+
def fetch_current_day
|
43
|
+
(@log.keys.last || 0) + 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Show the user's log in a human-readable way.
|
4
|
+
class LogViewer
|
5
|
+
include Utilities
|
6
|
+
|
7
|
+
def initialize(path, file_parser = YAML)
|
8
|
+
@path = expand_path(path)
|
9
|
+
@log = parse_file(@path, file_parser)
|
10
|
+
end
|
11
|
+
|
12
|
+
def show(target_day = 0)
|
13
|
+
result = ''
|
14
|
+
|
15
|
+
@log.each do |past_day, information|
|
16
|
+
next if target_day != 0 && target_day != past_day
|
17
|
+
result << format_log(past_day, information)
|
18
|
+
end
|
19
|
+
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
##
|
26
|
+
# Format log's data in order to get something like:
|
27
|
+
# ```
|
28
|
+
# - Day 1 -
|
29
|
+
# ** Progress **
|
30
|
+
# Fixed CSS, worked on canvas functionality for the app.
|
31
|
+
#
|
32
|
+
# ** Thoughts **
|
33
|
+
# I really struggled with CSS.
|
34
|
+
#
|
35
|
+
# -- Link to work: http://www.example.com/
|
36
|
+
# ```
|
37
|
+
def format_log(day, data)
|
38
|
+
%(
|
39
|
+
|- Day #{day} -
|
40
|
+
|
|
41
|
+
| ** Progress ** \n #{data['progress']}
|
42
|
+
|
|
43
|
+
| ** Thoughts ** \n #{data['thoughts']}
|
44
|
+
|
|
45
|
+
| -- Link to work: #{data['link']}
|
46
|
+
).gsub(/ +\|/, '')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Implements methods and constants used by many independents classes.
|
4
|
+
module Utilities
|
5
|
+
##
|
6
|
+
# Load log from a YAML file.
|
7
|
+
def parse_file(path, file_parser)
|
8
|
+
raise Errno::ENOENT, "Unable to find #{path}" unless File.exist?(path)
|
9
|
+
file_parser.load_file(path) || {}
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# Transform symbol's keys in string ones.
|
14
|
+
def stringify_symbols(hash_object)
|
15
|
+
hash_object.keys.each do |key|
|
16
|
+
next unless key.is_a?(Symbol)
|
17
|
+
hash_object[key.to_s] = hash_object.delete(key)
|
18
|
+
end
|
19
|
+
|
20
|
+
hash_object
|
21
|
+
end
|
22
|
+
|
23
|
+
def expand_path(path)
|
24
|
+
File.expand_path(path, File.dirname($PROGRAM_NAME))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Provides methods used across various commands.
|
4
|
+
module Integration
|
5
|
+
QUESTIONS = {
|
6
|
+
progress: 'Your progress:',
|
7
|
+
thoughts: 'Your thoughts:',
|
8
|
+
link: 'Link to work:'
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def push_commit(workspace)
|
12
|
+
committer = Committer.new(workspace)
|
13
|
+
committer.push
|
14
|
+
$stderr.puts 'Daily commit pushed with success!'
|
15
|
+
rescue Exception => exception
|
16
|
+
$stderr.puts exception.message
|
17
|
+
end
|
18
|
+
|
19
|
+
def register_daily_commit
|
20
|
+
record = {}
|
21
|
+
|
22
|
+
QUESTIONS.each do |key, question|
|
23
|
+
record[key] = ask(question)
|
24
|
+
end
|
25
|
+
|
26
|
+
record
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def ask(message)
|
32
|
+
puts message
|
33
|
+
gets.chomp
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/1hdoc.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# stdlib
|
2
|
+
require 'yaml'
|
3
|
+
require 'optparse'
|
4
|
+
require 'git'
|
5
|
+
|
6
|
+
# 1hdoc core
|
7
|
+
require_relative '1hdoc/core/utilities'
|
8
|
+
require_relative '1hdoc/core/configuration'
|
9
|
+
require_relative '1hdoc/core/committer'
|
10
|
+
require_relative '1hdoc/core/log_builder'
|
11
|
+
require_relative '1hdoc/core/log_viewer'
|
12
|
+
|
13
|
+
# 1hdoc inteface
|
14
|
+
require_relative '1hdoc/version'
|
15
|
+
require_relative '1hdoc/integration'
|
16
|
+
require_relative '1hdoc/application'
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: 1hdoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dom Corvasce
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
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: rdoc
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: git
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
description: 'Keep track of your progress during #100DaysOfCode event.'
|
70
|
+
email: dom.corvasce@yandex.com
|
71
|
+
executables:
|
72
|
+
- 1hdoc
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
76
|
+
files:
|
77
|
+
- README.md
|
78
|
+
- bin/1hdoc
|
79
|
+
- lib/1hdoc.rb
|
80
|
+
- lib/1hdoc/application.rb
|
81
|
+
- lib/1hdoc/core/committer.rb
|
82
|
+
- lib/1hdoc/core/configuration.rb
|
83
|
+
- lib/1hdoc/core/log_builder.rb
|
84
|
+
- lib/1hdoc/core/log_viewer.rb
|
85
|
+
- lib/1hdoc/core/utilities.rb
|
86
|
+
- lib/1hdoc/integration.rb
|
87
|
+
- lib/1hdoc/version.rb
|
88
|
+
homepage: https://github.com/domcorvasce/1hdoc
|
89
|
+
licenses:
|
90
|
+
- GPL-3.0
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options:
|
94
|
+
- "--charset=UTF-8"
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.9'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements:
|
108
|
+
- git >= 1.6
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.6.8
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: "#100DaysOfCode CLI tracker"
|
114
|
+
test_files: []
|