jog 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jog (0.0.2)
5
+ activesupport
6
+ thor
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.3)
12
+ i18n (~> 0.6)
13
+ multi_json (~> 1.0)
14
+ i18n (0.6.0)
15
+ multi_json (1.3.4)
16
+ thor (0.14.6)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ jog!
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ Jog
2
+ ===
3
+
4
+ *In-progress.*
5
+
6
+ Simple command-line tool for logging what you've been up to in plain text files.
7
+
8
+ Create / edit log entry for today
9
+ ---------------------------------
10
+
11
+ ```shell
12
+ > jog today
13
+ ```
14
+
15
+ By default, this will create a blank file at `~/jog/YYYY/MM/DD.txt'` and open it with Vim. If the file already exists, it will be opened in your editor.
16
+
17
+ Configuration
18
+ -------------
19
+
20
+ When run, `jog` will walk up your directory tree from your current working directory looking for `.jogrc` and `.jogtemplate`. If it can't find them, it will look in your home directory. If they don't exist there, it will use the built-in defaults.
21
+
22
+ To view your current configuration, run `jog config`:
23
+
24
+ ```shell
25
+ > jog config
26
+ Config
27
+ ------
28
+ {:root=>"/Users/tyson/Dropbox/log",
29
+ :editor=>"mate -w",
30
+ :path_format=>"%Y/%B/%d.txt"}
31
+
32
+ Template
33
+ --------
34
+ ---
35
+ Date: <%= Time.now.strftime( "%B %-d, %Y" ) %>
36
+ Time: <%= Time.now.strftime( "%-I:%M%P %Z" ) %>
37
+ ---
38
+ ```
39
+
40
+ ### `.jogrc` Example
41
+
42
+ root: ~/Dropbox/log
43
+ editor: vim -f
44
+ path_format: '%Y/%B/%d.txt'
45
+
46
+ ### `.dontemplate` Example
47
+
48
+ ---
49
+ Date: <%= Time.now.strftime( "%B %-d, %Y" ) %>
50
+ Time: <%= Time.now.strftime( "%-I:%M%P %Z" ) %>
51
+ ---
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
data/bin/jog ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.push File.expand_path("../../lib", __FILE__)
4
+ require 'jog'
5
+ require 'jog/cli'
6
+
7
+ begin
8
+ Jog::CLI.start(ARGV)
9
+ rescue Jog::Config::InvalidConfig => e
10
+ puts e.message
11
+ exit 1
12
+ end
data/jog.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jog/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jog"
7
+ s.version = Jog::VERSION
8
+ s.authors = ["Tyson Tate"]
9
+ s.email = ["tyson@tysontate.com"]
10
+ s.homepage = "http://github.com/tysontate/jog"
11
+ s.summary = "Command-line tool that makes it easy to log your work."
12
+ s.description = "Jog is a simple command-line tool that simplifies the process of logging what you've worked on, storing plain-text files in a sensible file structue."
13
+
14
+ s.rubyforge_project = "jog"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency "thor"
21
+ s.add_runtime_dependency "activesupport"
22
+ end
data/lib/jog/cli.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'thor'
2
+ require 'pp'
3
+
4
+ module Jog
5
+ class CLI < Thor
6
+ desc "today", "Edit the log entry for today"
7
+ def today
8
+ Jog.edit( Jog.get_or_create_file( Time.now ) )
9
+ end
10
+
11
+ desc "config", "Print the current configuration"
12
+ def config
13
+ puts "Config"
14
+ puts "------"
15
+ pp Jog.config
16
+ puts
17
+ puts "Template"
18
+ puts "--------"
19
+ puts Jog.template
20
+ end
21
+ end
22
+ end
data/lib/jog/config.rb ADDED
@@ -0,0 +1,82 @@
1
+ require 'active_support/concern'
2
+ require 'ostruct'
3
+
4
+ module Jog
5
+ module Config
6
+ extend ActiveSupport::Concern
7
+ class InvalidConfig < StandardError; end
8
+
9
+ module ClassMethods
10
+ CONFIG_NAME = ".jogrc"
11
+ TEMPLATE_NAME = ".jogtemplate"
12
+ CONFIG_VARS = %w{root editor path_format}
13
+ DEFAULT_CONFIG = {
14
+ root: '~/jog',
15
+ editor: 'vim -f',
16
+ path_format: '%Y/%B/%d.txt'
17
+ }
18
+ DEFAULT_TEMPLATE = nil
19
+
20
+ def config
21
+ @config ||= load_config
22
+ end
23
+
24
+ def template
25
+ @template ||= load_template
26
+ end
27
+
28
+ protected
29
+
30
+ def load_config
31
+ config = DEFAULT_CONFIG.dup
32
+ if path = config_path
33
+ File.readlines( path ).each do |line|
34
+ next unless match = /([a-z_]+): (.+)/.match( line )
35
+ key, value = [match[1], match[2]]
36
+ unless CONFIG_VARS.include?( key )
37
+ raise InvalidConfig.new( "\"#{key}\" is not a valid configuration variable (from #{path})" )
38
+ end
39
+ config[key.to_sym] = value
40
+ end
41
+ end
42
+ config[:root] = File.expand_path( config[:root] )
43
+ config
44
+ end
45
+
46
+ def load_template
47
+ if path = template_path
48
+ File.read( path )
49
+ else
50
+ DEFAULT_TEMPLATE.dup
51
+ end
52
+ end
53
+
54
+ def config_path
55
+ allowed_paths( CONFIG_NAME ).find do |path|
56
+ File.exists?( path )
57
+ end
58
+ end
59
+
60
+ def template_path
61
+ allowed_paths( TEMPLATE_NAME ).find do |path|
62
+ File.exists?( path )
63
+ end
64
+ end
65
+
66
+ # Returns an array of allowed paths for the given folder / file name, in
67
+ # the order they should be searched.
68
+ def allowed_paths( basename )
69
+ dir = Dir.pwd
70
+ paths = []
71
+ while dir != File::SEPARATOR do
72
+ paths << File.join( dir, basename )
73
+ dir = File.split( dir ).first
74
+ end
75
+ ["/", "~/"].each do |root|
76
+ paths << File.expand_path( "#{root}#{CONFIG_NAME}" )
77
+ end
78
+ paths
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module Jog
2
+ VERSION = "0.0.2"
3
+ end
data/lib/jog.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'jog/version'
2
+ require 'jog/config'
3
+ require 'fileutils'
4
+ require 'erb'
5
+
6
+ module Jog
7
+ include Config
8
+
9
+ class << self
10
+ def get_or_create_file( time )
11
+ subpath = time.strftime( Jog.config[:path_format] )
12
+ full_path = File.expand_path( File.join( Jog.config[:root], subpath ) )
13
+ path, _ = File.split( full_path )
14
+
15
+ unless File.exists?( full_path )
16
+ FileUtils.mkdir_p( path )
17
+ if Jog.template
18
+ File.open( full_path, 'w' ) do |file|
19
+ text = ERB.new( Jog.template ).result
20
+ file.write( text )
21
+ end
22
+ else
23
+ FileUtils.touch( path )
24
+ end
25
+ end
26
+ full_path
27
+ end
28
+
29
+ def edit( path )
30
+ system "#{Jog.config[:editor]} #{path}"
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tyson Tate
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70230803245000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70230803245000
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70230803244520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70230803244520
36
+ description: Jog is a simple command-line tool that simplifies the process of logging
37
+ what you've worked on, storing plain-text files in a sensible file structue.
38
+ email:
39
+ - tyson@tysontate.com
40
+ executables:
41
+ - jog
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - Gemfile.lock
48
+ - README.md
49
+ - Rakefile
50
+ - bin/jog
51
+ - jog.gemspec
52
+ - lib/jog.rb
53
+ - lib/jog/cli.rb
54
+ - lib/jog/config.rb
55
+ - lib/jog/version.rb
56
+ homepage: http://github.com/tysontate/jog
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: jog
76
+ rubygems_version: 1.8.11
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Command-line tool that makes it easy to log your work.
80
+ test_files: []