org_mode 0.0.4 → 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.
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/README.mkd +25 -6
- data/bin/org-mode +12 -1
- data/features/cmdline_rcfile.feature +23 -0
- data/features/cmdline_update.feature +2 -1
- data/features/fixtures/orgmode/gtd-minimal.org +1 -0
- data/features/fixtures/orgmode/gtd.org +1 -0
- data/features/fixtures/orgmoderc +10 -0
- data/features/steps.rb +19 -0
- data/features/support/env.rb +6 -0
- data/features/support/org_mode_script.rb +7 -1
- data/lib/org_mode.rb +3 -5
- data/lib/org_mode/commands.rb +1 -0
- data/lib/org_mode/commands/agenda.rb +8 -3
- data/lib/org_mode/commands/open.rb +16 -0
- data/lib/org_mode/commands/update.rb +16 -6
- data/lib/org_mode/configuration.rb +143 -0
- data/lib/org_mode/configuration/defaultrc.rb +10 -0
- data/lib/org_mode/file_tools.rb +45 -0
- data/lib/org_mode/load_or_setup_default_configuration.rb +16 -0
- data/lib/org_mode/loader.rb +1 -1
- data/lib/org_mode/version.rb +1 -1
- data/org_mode.gemspec +1 -0
- data/spec/configuration/default.rb +6 -0
- data/spec/configuration/orgmoderc +6 -0
- data/spec/configuration/orgmoderc-error +11 -0
- data/spec/configuration_spec.rb +14 -0
- data/spec/lib/org_mode/commands/update_spec.rb +12 -0
- data/spec/lib/org_mode/configuration_spec.rb +72 -0
- data/spec/lib/org_mode/file_tools_spec.rb +37 -0
- metadata +45 -7
- data/features/cmdline_noparams.feature +0 -11
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.mkd
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# Org-Mode file parser and writer
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
One of the killer features of emacs was org-mode. A real eye
|
4
|
+
opener what text-based to-do lists can do for you.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
So this ruby-gem is result of this personal org-mode dissonance.
|
6
|
+
This ruby-gem carries within all you need to work efficiently with a set of
|
7
|
+
org-mode files.
|
10
8
|
|
11
9
|
## Goal
|
12
10
|
|
@@ -14,6 +12,27 @@ Making lightweight/fast ruby org-mode executable to parse/reformat/analyse and
|
|
14
12
|
report on my org-files or the one in my buffer. And following the Unix philosopy
|
15
13
|
making a seperate process of it.
|
16
14
|
|
15
|
+
# Usage
|
16
|
+
|
17
|
+
A shell script is carried along.
|
18
|
+
|
19
|
+
org-mode <org-file>
|
20
|
+
|
21
|
+
## Agenda
|
22
|
+
|
23
|
+
Displays scheduled items. Parses all the files configured in `.org-moderc`
|
24
|
+
|
25
|
+
## Update
|
26
|
+
|
27
|
+
org-mode update <org-file>
|
28
|
+
|
29
|
+
parses and updates an org file. It does the following:
|
30
|
+
|
31
|
+
* archive done items
|
32
|
+
* reformats/re-indents the complete file
|
33
|
+
* assigns a sha-1 of the title-content for further updates and
|
34
|
+
quick reference
|
35
|
+
|
17
36
|
## What I want
|
18
37
|
|
19
38
|
* flexible parsers
|
data/bin/org-mode
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby -Ilib
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
-
require 'commander/import'
|
5
4
|
require 'org_mode/version'
|
6
5
|
|
6
|
+
require 'org_mode/load_or_setup_default_configuration'
|
7
|
+
|
8
|
+
require 'commander/import'
|
7
9
|
require 'org_mode/commands'
|
8
10
|
|
9
11
|
program :version, OrgMode::VERSION
|
10
12
|
program :description, 'Formats and extracts information out of org-mode files'
|
11
13
|
program :help_formatter, :compact
|
12
14
|
|
15
|
+
default_command :agenda
|
16
|
+
|
13
17
|
command :agenda do |c|
|
14
18
|
c.syntax = 'org-mode agenda [options] *org-mode-files'
|
15
19
|
c.summary = 'Displays information on scheduled items'
|
@@ -28,3 +32,10 @@ command :update do |c|
|
|
28
32
|
c.when_called OrgMode::Commands::Update, :execute
|
29
33
|
end
|
30
34
|
|
35
|
+
command :open do |c|
|
36
|
+
c.syntax = 'org-mode open'
|
37
|
+
c.summary = 'open all org-files'
|
38
|
+
c.description = 'Opens configured org-files in a vim session'
|
39
|
+
c.example 'description', 'command example'
|
40
|
+
c.when_called OrgMode::Commands::Open, :execute
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Feature: Org-mode loads and writes an rcfile
|
2
|
+
org-mode tool should load a rc file on startup
|
3
|
+
|
4
|
+
Scenario: an rc file exist
|
5
|
+
Given date is "1-1-2012 15:00"
|
6
|
+
And we have an environment containing:
|
7
|
+
| ORG_MODE_RC_DIR | features/fixtures |
|
8
|
+
| ORG_MODE_RC_FNAME | orgmoderc |
|
9
|
+
When the script is called with "agenda"
|
10
|
+
Then the output should contain "Agenda"
|
11
|
+
And the output should contain "TODO"
|
12
|
+
And the output should contain "Scheduled task defined in orgmoderc"
|
13
|
+
|
14
|
+
Scenario: no rc file exists
|
15
|
+
Given date is "1-1-2012 15:00"
|
16
|
+
And we have an environment containing:
|
17
|
+
| ORG_MODE_RC_DIR | features/tmp |
|
18
|
+
| ORG_MODE_RC_FNAME | orgmoderc-non-existent |
|
19
|
+
And I have an empty tmp dir 'features/tmp'
|
20
|
+
When the script is called with "agenda"
|
21
|
+
Then the output should contain "Agenda"
|
22
|
+
And the output should not contain "Scheduled task defined in orgmoderc"
|
23
|
+
And the output should contain "TODO Configure orgmoderc file in"
|
@@ -4,6 +4,7 @@ Feature: org-mode update <orgfile>
|
|
4
4
|
standarized way. This also enables certain
|
5
5
|
filters to be applied.
|
6
6
|
|
7
|
+
@focus
|
7
8
|
Scenario: should present meaningfull agenda information
|
8
9
|
Given we have an org-file with the following content
|
9
10
|
"""
|
@@ -15,7 +16,7 @@ Feature: org-mode update <orgfile>
|
|
15
16
|
some other content that will be indented
|
16
17
|
"""
|
17
18
|
When the script is called with "update"
|
18
|
-
Then the
|
19
|
+
Then the orgfile should be rewritten as
|
19
20
|
"""
|
20
21
|
a header
|
21
22
|
|
@@ -0,0 +1 @@
|
|
1
|
+
* TODO Scheduled task defined in orgmoderc <1-1-2012 Wed 15:15>
|
@@ -0,0 +1 @@
|
|
1
|
+
* TODO Existing orgmode file
|
data/features/steps.rb
CHANGED
@@ -19,6 +19,22 @@ When /^the script is called with "([^"]*)"( should fail)?$/ do |argv, should_fai
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
Then /^the orgfile should be rewritten as$/ do |string|
|
23
|
+
File.open( @org_file.path ).read.should == string
|
24
|
+
end
|
25
|
+
|
26
|
+
Given /^we have an environment containing:$/ do |table|
|
27
|
+
# table is a Cucumber::Ast::Table
|
28
|
+
table.raw.each do |k,v|
|
29
|
+
ENV[k] = v
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Given /^I have an empty tmp dir 'features\/tmp'$/ do
|
34
|
+
%x[rm -r features/tmp]
|
35
|
+
%x[mkdir features/tmp]
|
36
|
+
end
|
37
|
+
|
22
38
|
Given /^date is "([^"]*)"$/ do |date_string|
|
23
39
|
Timecop.freeze(Date.parse(date_string))
|
24
40
|
end
|
@@ -33,6 +49,9 @@ end
|
|
33
49
|
Then /^the output should contain "([^""]*)"$/ do |pattern|
|
34
50
|
@stdout.should match(pattern)
|
35
51
|
end
|
52
|
+
Then /^the output should not contain "([^""]*)"$/ do |pattern|
|
53
|
+
@stdout.should_not match(pattern)
|
54
|
+
end
|
36
55
|
|
37
56
|
Then /^the error should be$/ do |string|
|
38
57
|
@script_error.stderr.chomp.should == string
|
data/features/support/env.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'tempfile'
|
2
2
|
require 'ruby-debug'
|
3
3
|
require 'popen4'
|
4
|
+
require 'facets/kernel/blank'
|
4
5
|
|
5
6
|
class OrgModeScriptError < StandardError;
|
6
7
|
attr_accessor :stdout, :stderr, :status, :cmd
|
@@ -37,7 +38,8 @@ end
|
|
37
38
|
def org_mode_script(cmd, *params)
|
38
39
|
|
39
40
|
# build command
|
40
|
-
cmd = %[bin/org-mode #{cmd} #{params * ' '}]
|
41
|
+
cmd = %[#{org_mode_env} bin/org-mode #{cmd} #{params * ' '}]
|
42
|
+
puts cmd
|
41
43
|
|
42
44
|
stdout, stderr = [ nil,nil ]
|
43
45
|
status = POpen4.popen4(cmd) do |pout,perr|
|
@@ -51,3 +53,7 @@ def org_mode_script(cmd, *params)
|
|
51
53
|
|
52
54
|
return [stdout.chomp, stderr, status]
|
53
55
|
end
|
56
|
+
|
57
|
+
def org_mode_env
|
58
|
+
['ORG_MODE_RC_DIR', 'ORG_MODE_RC_FNAME'].reject(&:blank?).map {|e| "#{e}='#{ENV[e]}'"} * ' '
|
59
|
+
end
|
data/lib/org_mode.rb
CHANGED
@@ -13,7 +13,6 @@
|
|
13
13
|
require "org_mode/version"
|
14
14
|
|
15
15
|
module OrgMode
|
16
|
-
|
17
16
|
class Node
|
18
17
|
attr_accessor :title, :content, :stars, :date, :date_start_time, :date_end_time, :todo_state
|
19
18
|
attr_accessor :parent, :children
|
@@ -46,7 +45,6 @@ module OrgMode
|
|
46
45
|
def done?
|
47
46
|
todo_state == 'DONE'
|
48
47
|
end
|
49
|
-
|
50
48
|
end
|
51
49
|
|
52
50
|
module FileInterface
|
@@ -68,8 +66,9 @@ module OrgMode
|
|
68
66
|
|
69
67
|
include FileInterface
|
70
68
|
|
71
|
-
# For universial
|
72
|
-
# file
|
69
|
+
# For universial acces
|
70
|
+
# on file level, the root_nodes
|
71
|
+
# are the nodes children
|
73
72
|
alias :children :root_nodes
|
74
73
|
alias :children= :root_nodes=
|
75
74
|
|
@@ -110,6 +109,5 @@ module OrgMode
|
|
110
109
|
def root_nodes
|
111
110
|
nodes.select(&:root_node?)
|
112
111
|
end
|
113
|
-
|
114
112
|
end
|
115
113
|
end
|
data/lib/org_mode/commands.rb
CHANGED
@@ -16,11 +16,16 @@ module OrgMode::Commands
|
|
16
16
|
# Returns the restult to stdout
|
17
17
|
def execute(args, options)
|
18
18
|
|
19
|
-
|
19
|
+
files_to_parse = args
|
20
|
+
if files_to_parse.empty?
|
21
|
+
files_to_parse = $config.org_mode_files
|
22
|
+
end
|
23
|
+
|
24
|
+
file_collection = OrgMode::Loader.load_and_parse_files(files_to_parse)
|
20
25
|
agenda_reporter = OrgMode::Reporters::Agenda.new(file_collection)
|
21
|
-
|
26
|
+
console_presenter = OrgMode::Presenters::Agenda::Console.new(agenda_reporter)
|
22
27
|
|
23
|
-
puts
|
28
|
+
puts console_presenter.open_items_per_day_colorized
|
24
29
|
|
25
30
|
rescue SystemCallError => e
|
26
31
|
puts "Encountered a little problem: #{e}"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module OrgMode::Commands
|
2
|
+
class Open
|
3
|
+
# Private: executes the open command
|
4
|
+
# opens all org-files in vim sessions
|
5
|
+
#
|
6
|
+
# args - list of filenames
|
7
|
+
# options - switches set by the app
|
8
|
+
#
|
9
|
+
# Returns nothing
|
10
|
+
def execute(args, options)
|
11
|
+
$config.org_mode_files
|
12
|
+
|
13
|
+
exec %[vim], *$config.org_mode_files
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -2,19 +2,29 @@ require 'org_mode/parser'
|
|
2
2
|
require 'org_mode/loader'
|
3
3
|
require 'org_mode/formatters/textual'
|
4
4
|
require 'org_mode/processors/archive_done'
|
5
|
+
require 'org_mode/file_tools'
|
5
6
|
|
6
7
|
module OrgMode::Commands
|
7
8
|
class Update
|
9
|
+
|
8
10
|
def execute(args, options)
|
9
|
-
|
11
|
+
# use supplied file-name
|
12
|
+
# or use files out of configuration
|
13
|
+
args = OrgMode::Configuration.org_mode_files if args.blank?
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
args.each do |file_path|
|
16
|
+
OrgMode::FileTools.backup(file_path)
|
17
|
+
|
18
|
+
org_file = OrgMode::Loader.load_and_parse_file(file_path)
|
14
19
|
|
15
|
-
|
20
|
+
if options.archive_done
|
21
|
+
org_file = OrgMode::Processors::ArchiveDone.new(org_file).process
|
22
|
+
end
|
16
23
|
|
17
|
-
|
24
|
+
org_formatter = OrgMode::Formatters::Textual.new(org_file)
|
25
|
+
|
26
|
+
OrgMode::FileTools.spit_into_file(org_formatter.format, file_path)
|
27
|
+
end
|
18
28
|
|
19
29
|
rescue StandardError => e
|
20
30
|
puts "Encountered a little problem: #{e}"
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'configuration'
|
3
|
+
require 'core_ext/string'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
module OrgMode
|
7
|
+
module FileOperations
|
8
|
+
def spit_into_file(path, content)
|
9
|
+
f = ::File.open(path, 'w+')
|
10
|
+
f.write(content)
|
11
|
+
f.flush
|
12
|
+
f.close
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class DefaultOrgfile
|
17
|
+
extend FileOperations
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def content(tmpl_vars={})
|
21
|
+
return <<-EOF.strip_indent(10)
|
22
|
+
This is your default orgmode agenda file, the orgmode script
|
23
|
+
finds this file since it's configured in #{tmpl_vars.fetch(:target_path)}
|
24
|
+
|
25
|
+
* TODO Configure orgmoderc file in #{tmpl_vars.fetch(:target_path)} <#{DateTime.now.strftime('%Y-%m-%d %a')}>
|
26
|
+
EOF
|
27
|
+
end
|
28
|
+
|
29
|
+
def write_to(path, tmpl_vars={})
|
30
|
+
spit_into_file(path, content(tmpl_vars))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class DefaultRcFile
|
36
|
+
extend FileOperations
|
37
|
+
|
38
|
+
class << self
|
39
|
+
def content
|
40
|
+
@content ||= ::File.open(default_rc_path).read
|
41
|
+
end
|
42
|
+
|
43
|
+
def write_to(target_path)
|
44
|
+
spit_into_file(target_path, content)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def default_rc_path
|
50
|
+
::File.dirname(__FILE__) + '/configuration/defaultrc.rb'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class DefaultConfiguration
|
56
|
+
|
57
|
+
def write_to(target_path)
|
58
|
+
dirname = ::File.dirname(target_path)
|
59
|
+
config_dir = "#{dirname}/.orgmode"
|
60
|
+
%x[mkdir #{config_dir}]
|
61
|
+
|
62
|
+
DefaultOrgfile.write_to("#{config_dir}/gtd.org", :target_path=>target_path)
|
63
|
+
DefaultRcFile.write_to(target_path)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.write_to(target_path)
|
67
|
+
new.write_to(target_path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Configuration
|
72
|
+
class Error < StandardError; end
|
73
|
+
class ScriptError < Error; end
|
74
|
+
class IOError < Error; end
|
75
|
+
class NonExistant < Error; end
|
76
|
+
|
77
|
+
## Class method caller
|
78
|
+
class << self
|
79
|
+
def load(base_dir=nil, file_name=nil)
|
80
|
+
@singleton = new(base_dir,file_name)
|
81
|
+
@config = @singleton.read_and_evaluate
|
82
|
+
end
|
83
|
+
|
84
|
+
def path
|
85
|
+
@singleton.path
|
86
|
+
end
|
87
|
+
|
88
|
+
def backup_dir
|
89
|
+
@singleton.base_dir + '.orgmode/backups'
|
90
|
+
end
|
91
|
+
|
92
|
+
# forward all to our singleton
|
93
|
+
def method_missing(f,*a)
|
94
|
+
if @config.respond_to?(f)
|
95
|
+
return @config.send(f, *a)
|
96
|
+
end
|
97
|
+
super
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
# Instance
|
103
|
+
attr_reader :file_name, :base_dir, :path
|
104
|
+
|
105
|
+
# Initializes loader and generates file-path
|
106
|
+
def initialize(a_base_dir=nil, a_file_name=nil)
|
107
|
+
@base_dir = Pathname.new(a_base_dir || ENV['HOME'])
|
108
|
+
@file_name = Pathname.new(a_file_name || '.orgmoderc')
|
109
|
+
@path = @base_dir + @file_name
|
110
|
+
end
|
111
|
+
|
112
|
+
# Reads a config file and avaluates
|
113
|
+
# it.
|
114
|
+
#
|
115
|
+
# Returns a Configuration object
|
116
|
+
def read_and_evaluate
|
117
|
+
contents = ::File.open(path).read
|
118
|
+
instance_eval <<-RUBY, path, 0
|
119
|
+
::Configuration.for('org-mode') do
|
120
|
+
#{contents}
|
121
|
+
end
|
122
|
+
RUBY
|
123
|
+
|
124
|
+
::Configuration.for('org-mode')
|
125
|
+
|
126
|
+
rescue ::Errno::ENOENT => e
|
127
|
+
raise NonExistant, "config file does not exist"
|
128
|
+
rescue ::IOError, ::SystemCallError => e
|
129
|
+
raise IOError, "problem loading config: #{e}"
|
130
|
+
rescue ::ScriptError => e
|
131
|
+
raise ScriptError, "problem loading config: #{e}"
|
132
|
+
end
|
133
|
+
|
134
|
+
# Creates a minimal example configuration
|
135
|
+
#
|
136
|
+
# Returns the default config
|
137
|
+
def self.create_default_config(base_dir=nil,file_name=nil)
|
138
|
+
new_config = Configuration.new(base_dir,file_name)
|
139
|
+
DefaultConfiguration.write_to( new_config.path )
|
140
|
+
return new_config.read_and_evaluate
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# specify which files to load per default
|
2
|
+
# using the agenda function
|
3
|
+
org_mode_files %W{
|
4
|
+
#{ENV['ORG_MODE_RC_DIR'] || ENV['HOME']}/.orgmode/gtd.org
|
5
|
+
}
|
6
|
+
|
7
|
+
# Remember Daniel San, you have all of ruby to you disposal
|
8
|
+
# make it happen ...
|
9
|
+
|
10
|
+
# vim: ft=ruby
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module OrgMode::FileTools
|
4
|
+
extend self
|
5
|
+
extend FileUtils
|
6
|
+
|
7
|
+
def backup(file)
|
8
|
+
mkdir_p backup_dir unless File.exist?(backup_dir)
|
9
|
+
cp file, add_unique_extention(backup_path(file))
|
10
|
+
end
|
11
|
+
|
12
|
+
def spit_into_file(buffer, file)
|
13
|
+
File.open(file, 'w') do |f|
|
14
|
+
f.write(buffer)
|
15
|
+
f.flush
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def backup_path(file)
|
20
|
+
backup_dir + ::File.basename(file)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def backup_dir
|
25
|
+
OrgMode::Configuration.backup_dir
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def add_unique_extention(file)
|
31
|
+
"%s.%d" % [ file, (_unique_extention(file)) ]
|
32
|
+
end
|
33
|
+
|
34
|
+
def _unique_extention(file)
|
35
|
+
uid = _extract_unique_extentions(file).max
|
36
|
+
uid ? uid + 1 : 0
|
37
|
+
end
|
38
|
+
|
39
|
+
def _extract_unique_extentions(file)
|
40
|
+
Dir["#{ file }.*"].
|
41
|
+
select {|p| /\.\d+$/ }.
|
42
|
+
map { |p| p.match(/(\d+)$/)[1].to_i }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'org_mode/configuration'
|
2
|
+
|
3
|
+
def load_or_setup_default_configuration
|
4
|
+
dirname, fname = ENV['ORG_MODE_RC_DIR'], ENV['ORG_MODE_RC_FNAME']
|
5
|
+
$config = OrgMode::Configuration.
|
6
|
+
load(dirname, fname)
|
7
|
+
rescue OrgMode::Configuration::NonExistant => e
|
8
|
+
$config = OrgMode::Configuration.
|
9
|
+
create_default_config(dirname, fname)
|
10
|
+
rescue OrgMode::Configuration::Error => e
|
11
|
+
puts "Problem loading configuration: #{e}"
|
12
|
+
puts "Fix it first, and run me again ..."
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
load_or_setup_default_configuration
|
data/lib/org_mode/loader.rb
CHANGED
@@ -2,7 +2,7 @@ class OrgMode::Loader
|
|
2
2
|
# Public: loads and parses multiple files
|
3
3
|
#
|
4
4
|
# Returns OrgMode::FileCollection
|
5
|
-
def self.load_and_parse_files
|
5
|
+
def self.load_and_parse_files paths
|
6
6
|
org_mode_files = paths.map {|f| load_and_parse_file(f) }
|
7
7
|
OrgMode::FileCollection.new(org_mode_files)
|
8
8
|
end
|
data/lib/org_mode/version.rb
CHANGED
data/org_mode.gemspec
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'configuration'
|
2
|
+
|
3
|
+
describe "org-mode configuration" do
|
4
|
+
before do
|
5
|
+
load 'spec/configuration/default.rb'
|
6
|
+
end
|
7
|
+
let (:config) { Configuration.for('org-mode') }
|
8
|
+
|
9
|
+
it "should load the configuration file" do
|
10
|
+
config.org_mode_files.should == [
|
11
|
+
"spec/configuration/example-org-file-00.org",
|
12
|
+
"spec/configuration/example-org-file-01.org" ]
|
13
|
+
end
|
14
|
+
end
|
@@ -1,17 +1,29 @@
|
|
1
1
|
require 'org_mode/commands/update'
|
2
2
|
require 'lib/org_mode/commands/helpers'
|
3
3
|
|
4
|
+
# Fake out functionality
|
5
|
+
# not needed
|
6
|
+
module OrgMode::FileTools
|
7
|
+
def spit_into_file(buffer, file)
|
8
|
+
puts buffer
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
describe OrgMode::Commands::Update do
|
5
13
|
before do
|
6
14
|
@cmd = OrgMode::Commands::Update.new
|
7
15
|
end
|
8
16
|
|
9
17
|
context '#execute' do
|
18
|
+
before do
|
19
|
+
OrgMode::FileTools.should_receive(:backup).and_return(true)
|
20
|
+
end
|
10
21
|
context 'without options' do
|
11
22
|
it 'reformats a file correctly' do
|
12
23
|
org_file = write_into_tempfile <<-eos.strip_indent(10)
|
13
24
|
* TODO Scheduled task <1-1-2012 Wed 15:15>
|
14
25
|
eos
|
26
|
+
|
15
27
|
execute_and_compare_stdout_with @cmd, [org_file.path], stub(:archive_done => false), <<-eos.strip_indent(10)
|
16
28
|
* TODO <2012-01-01 Sun 15:15> Scheduled task
|
17
29
|
eos
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'lib/org_mode/configuration'
|
2
|
+
|
3
|
+
describe OrgMode::Configuration do
|
4
|
+
context "no configuration present" do
|
5
|
+
let (:config) {
|
6
|
+
OrgMode::Configuration.
|
7
|
+
load('spec/configuration', 'orgmoderc-non-existant') }
|
8
|
+
|
9
|
+
it "raises an error" do
|
10
|
+
lambda {
|
11
|
+
config.org_mode_files
|
12
|
+
}.should raise_error(OrgMode::Configuration::NonExistant)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
context "configuration present" do
|
16
|
+
let (:config) {
|
17
|
+
OrgMode::Configuration.
|
18
|
+
load('spec/configuration', 'orgmoderc') }
|
19
|
+
|
20
|
+
it "should set correct parameters" do
|
21
|
+
config.org_mode_files.should == %W{
|
22
|
+
spec/configuration/example-org-file-00.org
|
23
|
+
spec/configuration/example-org-file-01.org
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be accessible through the class" do
|
28
|
+
OrgMode::Configuration.org_mode_files.should == %W{
|
29
|
+
spec/configuration/example-org-file-00.org
|
30
|
+
spec/configuration/example-org-file-01.org
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context "wrong configuration present" do
|
35
|
+
let (:config) {
|
36
|
+
OrgMode::Configuration.
|
37
|
+
load('spec/configuration', 'orgmoderc-error') }
|
38
|
+
|
39
|
+
it "should raise an error" do
|
40
|
+
lambda {
|
41
|
+
config.org_mode_files
|
42
|
+
}.should raise_error(OrgMode::Configuration::ScriptError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context ".create_default_config" do
|
47
|
+
it "should write it" do
|
48
|
+
OrgMode::DefaultConfiguration.should_receive(:write_to)
|
49
|
+
OrgMode::Configuration.create_default_config
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe OrgMode::DefaultConfiguration do
|
55
|
+
let (:default_config) { OrgMode::DefaultConfiguration.new }
|
56
|
+
|
57
|
+
it "writes the content if asked for" do
|
58
|
+
%x[rm -r spec/tmp]
|
59
|
+
%x[mkdir spec/tmp]
|
60
|
+
target_path = 'spec/tmp/orgmoderc'
|
61
|
+
|
62
|
+
default_config.write_to(target_path)
|
63
|
+
|
64
|
+
File.exist?('spec/tmp/.orgmode').should be_true
|
65
|
+
File.exist?('spec/tmp/.orgmode/gtd.org').should be_true
|
66
|
+
File.exist?('spec/tmp/orgmoderc').should be_true
|
67
|
+
|
68
|
+
File.open('spec/tmp/.orgmode/gtd.org').read.should ==
|
69
|
+
OrgMode::DefaultOrgfile.
|
70
|
+
content(:target_path => 'spec/tmp/orgmoderc')
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'org_mode/file_tools'
|
2
|
+
|
3
|
+
|
4
|
+
describe OrgMode::FileTools do
|
5
|
+
context "#backup" do
|
6
|
+
before do
|
7
|
+
# assume backup dir exist
|
8
|
+
File.stub(:exist? => true)
|
9
|
+
end
|
10
|
+
it "copies to the correct dir" do
|
11
|
+
OrgMode::FileTools.stub(:_extract_unique_extentions => [1,2,3,4,5,8])
|
12
|
+
OrgMode::FileTools.stub(:backup_dir => '/tmp/backups/' )
|
13
|
+
OrgMode::FileTools.should_receive(:cp).with('blah', '/tmp/backups/blah.9').and_return(true)
|
14
|
+
|
15
|
+
OrgMode::FileTools.backup('blah')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "#_unique_extention" do
|
20
|
+
context "with existing files" do
|
21
|
+
it 'determines a correct unique extention' do
|
22
|
+
Dir.stub(:[]).and_return(['blah.1', 'blah.2', 'blah.3'])
|
23
|
+
OrgMode::FileTools.send(:_unique_extention, 'blah').
|
24
|
+
should == 4
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context "with no files" do
|
29
|
+
it 'determines a correct unique extention' do
|
30
|
+
Dir.stub(:[]).and_return([])
|
31
|
+
OrgMode::FileTools.send(:_unique_extention, 'blah').
|
32
|
+
should == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: org_mode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.4
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Boy Maas
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|
@@ -92,6 +92,21 @@ dependencies:
|
|
92
92
|
version: "0.5"
|
93
93
|
type: :runtime
|
94
94
|
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: configuration
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 9
|
104
|
+
segments:
|
105
|
+
- 1
|
106
|
+
- 3
|
107
|
+
version: "1.3"
|
108
|
+
type: :runtime
|
109
|
+
version_requirements: *id006
|
95
110
|
description: Org-mode parser, presenter, and reformatter. Read more about it on the github pages.
|
96
111
|
email:
|
97
112
|
- boy.maas@gmail.com
|
@@ -109,9 +124,12 @@ files:
|
|
109
124
|
- bin/org-mode
|
110
125
|
- features/cmdline_agenda.feature
|
111
126
|
- features/cmdline_handles_errors_cracefully.feature
|
112
|
-
- features/
|
127
|
+
- features/cmdline_rcfile.feature
|
113
128
|
- features/cmdline_todos.feature
|
114
129
|
- features/cmdline_update.feature
|
130
|
+
- features/fixtures/orgmode/gtd-minimal.org
|
131
|
+
- features/fixtures/orgmode/gtd.org
|
132
|
+
- features/fixtures/orgmoderc
|
115
133
|
- features/steps.rb
|
116
134
|
- features/support/env.rb
|
117
135
|
- features/support/org_mode_script.rb
|
@@ -120,8 +138,13 @@ files:
|
|
120
138
|
- lib/org_mode.rb
|
121
139
|
- lib/org_mode/commands.rb
|
122
140
|
- lib/org_mode/commands/agenda.rb
|
141
|
+
- lib/org_mode/commands/open.rb
|
123
142
|
- lib/org_mode/commands/update.rb
|
143
|
+
- lib/org_mode/configuration.rb
|
144
|
+
- lib/org_mode/configuration/defaultrc.rb
|
145
|
+
- lib/org_mode/file_tools.rb
|
124
146
|
- lib/org_mode/formatters/textual.rb
|
147
|
+
- lib/org_mode/load_or_setup_default_configuration.rb
|
125
148
|
- lib/org_mode/loader.rb
|
126
149
|
- lib/org_mode/node_utils.rb
|
127
150
|
- lib/org_mode/parser.rb
|
@@ -130,10 +153,16 @@ files:
|
|
130
153
|
- lib/org_mode/reporters/agenda.rb
|
131
154
|
- lib/org_mode/version.rb
|
132
155
|
- org_mode.gemspec
|
156
|
+
- spec/configuration/default.rb
|
157
|
+
- spec/configuration/orgmoderc
|
158
|
+
- spec/configuration/orgmoderc-error
|
159
|
+
- spec/configuration_spec.rb
|
133
160
|
- spec/data/org-file-01-simple-node-structure.org
|
134
161
|
- spec/lib/org_mode/commands/agenda_spec.rb
|
135
162
|
- spec/lib/org_mode/commands/helpers.rb
|
136
163
|
- spec/lib/org_mode/commands/update_spec.rb
|
164
|
+
- spec/lib/org_mode/configuration_spec.rb
|
165
|
+
- spec/lib/org_mode/file_tools_spec.rb
|
137
166
|
- spec/lib/org_mode/formatters/textual_spec.rb
|
138
167
|
- spec/lib/org_mode/parser_spec.rb
|
139
168
|
- spec/lib/org_mode/processors/archive_done_spec.rb
|
@@ -172,23 +201,32 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
201
|
requirements: []
|
173
202
|
|
174
203
|
rubyforge_project: org_mode
|
175
|
-
rubygems_version: 1.8.
|
204
|
+
rubygems_version: 1.8.15
|
176
205
|
signing_key:
|
177
206
|
specification_version: 3
|
178
207
|
summary: Parses and does all kinds of tricks with org-mode files
|
179
208
|
test_files:
|
180
209
|
- features/cmdline_agenda.feature
|
181
210
|
- features/cmdline_handles_errors_cracefully.feature
|
182
|
-
- features/
|
211
|
+
- features/cmdline_rcfile.feature
|
183
212
|
- features/cmdline_todos.feature
|
184
213
|
- features/cmdline_update.feature
|
214
|
+
- features/fixtures/orgmode/gtd-minimal.org
|
215
|
+
- features/fixtures/orgmode/gtd.org
|
216
|
+
- features/fixtures/orgmoderc
|
185
217
|
- features/steps.rb
|
186
218
|
- features/support/env.rb
|
187
219
|
- features/support/org_mode_script.rb
|
220
|
+
- spec/configuration/default.rb
|
221
|
+
- spec/configuration/orgmoderc
|
222
|
+
- spec/configuration/orgmoderc-error
|
223
|
+
- spec/configuration_spec.rb
|
188
224
|
- spec/data/org-file-01-simple-node-structure.org
|
189
225
|
- spec/lib/org_mode/commands/agenda_spec.rb
|
190
226
|
- spec/lib/org_mode/commands/helpers.rb
|
191
227
|
- spec/lib/org_mode/commands/update_spec.rb
|
228
|
+
- spec/lib/org_mode/configuration_spec.rb
|
229
|
+
- spec/lib/org_mode/file_tools_spec.rb
|
192
230
|
- spec/lib/org_mode/formatters/textual_spec.rb
|
193
231
|
- spec/lib/org_mode/parser_spec.rb
|
194
232
|
- spec/lib/org_mode/processors/archive_done_spec.rb
|
@@ -1,11 +0,0 @@
|
|
1
|
-
Feature: noparams or reformat
|
2
|
-
Whenever the org-mode script is run without params
|
3
|
-
it should just display help
|
4
|
-
|
5
|
-
Scenario: script with no params should display help
|
6
|
-
When the script is called with "" should fail
|
7
|
-
Then the error should be
|
8
|
-
"""
|
9
|
-
invalid command. Use --help for more information
|
10
|
-
"""
|
11
|
-
|