evertils 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/evertils +7 -38
- data/evertils.gemspec +1 -1
- data/lib/evertils/config.rb +55 -0
- data/lib/evertils/controller.rb +69 -0
- data/lib/{controllers → evertils/controllers}/convert.rb +1 -1
- data/lib/evertils/controllers/firstrun.rb +24 -0
- data/lib/{controllers → evertils/controllers}/generate.rb +11 -27
- data/lib/{controllers → evertils/controllers}/get.rb +3 -3
- data/lib/{controllers → evertils/controllers}/status.rb +2 -2
- data/lib/{helper.rb → evertils/helper.rb} +3 -3
- data/lib/{helpers → evertils/helpers}/api-enml-handler.rb +3 -10
- data/lib/{helpers → evertils/helpers}/evernote-markdown.rb +14 -14
- data/lib/{helpers → evertils/helpers}/formatting.rb +29 -27
- data/lib/evertils/request.rb +31 -0
- data/lib/evertils/router.rb +56 -0
- data/lib/{type.rb → evertils/type.rb} +8 -2
- data/lib/{types → evertils/types}/daily.rb +2 -5
- data/lib/{types → evertils/types}/monthly-task-summary.rb +2 -11
- data/lib/{types → evertils/types}/monthly.rb +3 -6
- data/lib/{types → evertils/types}/priority-queue.rb +3 -5
- data/lib/{types → evertils/types}/weekly.rb +4 -8
- data/lib/{utils.rb → evertils/utils.rb} +4 -4
- data/lib/evertils/version.rb +3 -0
- data/lib/evertils.rb +39 -0
- metadata +33 -34
- data/lib/command.rb +0 -179
- data/lib/config.rb +0 -65
- data/lib/controller.rb +0 -117
- data/lib/log.rb +0 -111
- data/lib/logs.rb +0 -34
- data/lib/request.rb +0 -23
- data/lib/router.rb +0 -67
- data/lib/version.rb +0 -3
- /data/lib/{configs → evertils/configs}/templates/daily.enml +0 -0
- /data/lib/{configs/templates/mts.enml → evertils/configs/templates/monthly-task-summaries.enml} +0 -0
- /data/lib/{configs → evertils/configs}/templates/monthly.enml +0 -0
- /data/lib/{configs → evertils/configs}/templates/pq.enml +0 -0
- /data/lib/{configs → evertils/configs}/templates/weekly.enml +0 -0
- /data/lib/{controllers → evertils/controllers}/new.rb +0 -0
- /data/lib/{helpers → evertils/helpers}/evernote-enml.rb +0 -0
- /data/lib/{helpers → evertils/helpers}/results.rb +0 -0
- /data/lib/{helpers → evertils/helpers}/time.rb +0 -0
- /data/lib/{kernel.rb → evertils/kernel.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e842768fbe2f278375d2237fd4f574b5384bc0e
|
4
|
+
data.tar.gz: 2206bb78084adf5ea0f47d5efdb70be1e8ca808f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6219f5fcce8ada651fac7abcfa8b7f2e194bb3946e1045600bb74729d5f745473075ab14c46122d74cc9c34617725f4eb2490cac2e1b1dca222f251e95ea1943
|
7
|
+
data.tar.gz: c5dc1a67ae390280ddf15ce6709735bf8e1ea698c187589ace2d0e6791a4c3fdcc0c565be78cb020588033e62c7645ee35eea6b909b4ddb4fb7e1e7714f6b66c
|
data/bin/evertils
CHANGED
@@ -1,46 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require 'optparse'
|
7
|
-
require 'rbconfig'
|
8
|
-
require 'evernote-thrift'
|
9
|
-
require 'net/http'
|
10
|
-
require 'uri'
|
11
|
-
require 'fileutils'
|
12
|
-
require 'cgi'
|
13
|
-
require 'notifaction'
|
14
|
-
require 'digest/md5'
|
15
|
-
require 'mime/types'
|
16
|
-
require 'evertils/common'
|
17
|
-
require 'yaml'
|
18
|
-
require 'nokogiri'
|
3
|
+
# fix load path
|
4
|
+
lib = File.expand_path('../../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
19
6
|
|
20
|
-
|
21
|
-
require_relative '../lib/kernel'
|
22
|
-
require_relative '../lib/version'
|
23
|
-
require_relative '../lib/type'
|
24
|
-
require_relative '../lib/helpers/time'
|
25
|
-
require_relative '../lib/helpers/results'
|
26
|
-
require_relative '../lib/helpers/api-enml-handler'
|
27
|
-
require_relative '../lib/log'
|
28
|
-
require_relative '../lib/config'
|
29
|
-
require_relative '../lib/request'
|
30
|
-
require_relative '../lib/utils'
|
31
|
-
require_relative '../lib/logs'
|
32
|
-
require_relative '../lib/command'
|
33
|
-
require_relative '../lib/controller'
|
34
|
-
require_relative '../lib/router'
|
35
|
-
require_relative '../lib/helpers/formatting'
|
36
|
-
require_relative '../lib/helpers/evernote-enml'
|
37
|
-
require_relative '../lib/helper'
|
7
|
+
require 'evertils'
|
38
8
|
|
39
9
|
# Modify configuration options here
|
40
|
-
|
41
|
-
|
42
|
-
$config.bootstrap!
|
10
|
+
app = Evertils::Cfg.new
|
11
|
+
app.bootstrap!
|
43
12
|
|
44
13
|
# Config file located, route the request
|
45
|
-
req = Evertils::Router.new
|
14
|
+
req = Evertils::Router.new(app)
|
46
15
|
req.route
|
data/evertils.gemspec
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Evertils
|
2
|
+
class Cfg
|
3
|
+
# Perform first run tasks and create or read config file values
|
4
|
+
def bootstrap!
|
5
|
+
populate_config
|
6
|
+
|
7
|
+
return if valid_config?
|
8
|
+
|
9
|
+
# no config file found, lets create one using the firstrun controller
|
10
|
+
require 'client/controller/firstrun'
|
11
|
+
|
12
|
+
controller = Evertils::Controller::Firstrun.new
|
13
|
+
controller.default
|
14
|
+
|
15
|
+
populate_config
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a hash of all module constants and their values
|
19
|
+
def options
|
20
|
+
keys = Evertils.constants.select { |name| constant?(name) }
|
21
|
+
hash = {}
|
22
|
+
|
23
|
+
keys.each { |key| hash[key] = Evertils.const_get(key) }
|
24
|
+
hash
|
25
|
+
end
|
26
|
+
|
27
|
+
# Populates the internal hash which stores any values set in the config file
|
28
|
+
def populate_config
|
29
|
+
file = File.expand_path("~/.evertils/config.yml")
|
30
|
+
fmt = Evertils::Helper.load('Formatting')
|
31
|
+
|
32
|
+
@yml = fmt.symbolize(::YAML.load_file(file))
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
# Get a specific value from the config file data
|
37
|
+
# Params:
|
38
|
+
# +name+:: String/symbol key value
|
39
|
+
def get(name)
|
40
|
+
@yml[name.to_sym]
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Check if configuration data exists
|
46
|
+
def valid_config?
|
47
|
+
!@yml.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
# Checks if string is a constant
|
51
|
+
def constant?(name)
|
52
|
+
name == name.upcase
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Evertils
|
2
|
+
module Controller
|
3
|
+
class Base
|
4
|
+
# Access the configuration object instance externally
|
5
|
+
attr_accessor :config
|
6
|
+
# Access the request object instance externally
|
7
|
+
attr_accessor :request
|
8
|
+
|
9
|
+
# Exit code to indicate everything is ok!
|
10
|
+
OK = 0
|
11
|
+
# Exit code to indicate a force quit (exit) call, meaning the program
|
12
|
+
# quit with an error
|
13
|
+
QUIT = 1
|
14
|
+
# Exit code to indicate that the program exited with a non-zero exit code,
|
15
|
+
# but not one that resulted in a force quit
|
16
|
+
QUIT_SOFT = 2
|
17
|
+
|
18
|
+
# Setup internal variables that will be used in subclasses
|
19
|
+
# Params:
|
20
|
+
# +config+:: Instance of Evertils::Cfg to enable access to config file
|
21
|
+
# +request+:: Instance of Evertils::Request, enables access to request
|
22
|
+
# parameters
|
23
|
+
def initialize(config, request)
|
24
|
+
@config = config
|
25
|
+
@request = request
|
26
|
+
|
27
|
+
pre_exec
|
28
|
+
end
|
29
|
+
|
30
|
+
# Perform pre-run tasks
|
31
|
+
def pre_exec
|
32
|
+
@format = Evertils::Helper.load('Formatting')
|
33
|
+
end
|
34
|
+
|
35
|
+
# Handle the request
|
36
|
+
def exec
|
37
|
+
if @request.param.nil?
|
38
|
+
send(@method.to_sym)
|
39
|
+
else
|
40
|
+
send(@method.to_sym, @request.flags.first)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Perform post-run cleanup tasks, such as deleting old logs
|
45
|
+
def post_exec
|
46
|
+
end
|
47
|
+
|
48
|
+
# Determines if the command can execute
|
49
|
+
# Params:
|
50
|
+
# +command+:: Symbol containing the command we want to execute
|
51
|
+
def can_exec?(command)
|
52
|
+
# no command was passed, check if controller has a default method
|
53
|
+
if command.nil? && respond_to?(:default)
|
54
|
+
@method = :default
|
55
|
+
elsif respond_to? command
|
56
|
+
# check the controller for the requested method
|
57
|
+
@method = command
|
58
|
+
else
|
59
|
+
raise NoMethodError, "Invalid method: #{command}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Default method called by exec if no argument is passed
|
64
|
+
def sample
|
65
|
+
Notify.warning("Method not implemented")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Evertils
|
2
|
+
module Controller
|
3
|
+
class Firstrun < Controller::Base
|
4
|
+
# Create the configuration file if it does not exist
|
5
|
+
def default
|
6
|
+
if File.exist?("#{Dir.home}/.evertils/config.yml")
|
7
|
+
Notify.error('Configuration already exists, this is not the first run! Exiting.', show_time: false)
|
8
|
+
end
|
9
|
+
|
10
|
+
File.open("#{Dir.home}/.evertils/config.yml", "w") do |f|
|
11
|
+
f.write <<-'CONTENTS'
|
12
|
+
templates:
|
13
|
+
Monthly:
|
14
|
+
"templates/monthly.enml"
|
15
|
+
Daily:
|
16
|
+
"templates/daily.enml"
|
17
|
+
|
18
|
+
provider: Evernote
|
19
|
+
CONTENTS
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -7,51 +7,35 @@ require_relative '../types/monthly'
|
|
7
7
|
module Evertils
|
8
8
|
module Controller
|
9
9
|
class Generate < Controller::Base
|
10
|
-
attr_accessor :force, :start, :name
|
11
|
-
|
12
|
-
def pre_exec
|
13
|
-
@methods_require_internet.push(:daily, :weekly, :monthly, :mts)
|
14
|
-
|
15
|
-
OptionParser.new do |opt|
|
16
|
-
opt.banner = "#{Evertils::PACKAGE_NAME} generate timeframe [...-flags]"
|
17
|
-
|
18
|
-
opt.on("-n", "--name=NAME", "A name to pass to the script (not all commands support this flag)") do |name|
|
19
|
-
@name = name
|
20
|
-
end
|
21
|
-
end.parse!
|
22
|
-
|
23
|
-
super
|
24
|
-
end
|
25
|
-
|
26
10
|
# generate daily notes
|
27
11
|
def daily
|
28
|
-
note = Type::Daily.new
|
12
|
+
note = Type::Daily.new(@config)
|
29
13
|
note.create
|
30
14
|
end
|
31
15
|
|
32
16
|
# generate weekly notes
|
33
17
|
def weekly
|
34
|
-
note = Type::Weekly.new
|
18
|
+
note = Type::Weekly.new(@config)
|
35
19
|
note.create
|
36
20
|
end
|
37
21
|
|
38
22
|
# generate monthly notes
|
39
23
|
def monthly
|
40
|
-
note = Type::Monthly.new
|
24
|
+
note = Type::Monthly.new(@config)
|
41
25
|
note.create
|
42
26
|
end
|
43
27
|
|
44
28
|
# generate monthly task summary templates
|
45
|
-
def mts
|
46
|
-
Notify.error('Name argument is required', {}) if
|
29
|
+
def mts(arg)
|
30
|
+
Notify.error('Name argument is required', {}) if arg.nil?
|
47
31
|
|
48
|
-
note = Type::MonthlyTaskSummary.new(@
|
32
|
+
note = Type::MonthlyTaskSummary.new(@config, arg[1])
|
49
33
|
note.create
|
50
34
|
end
|
51
35
|
|
52
36
|
# generate priority queue notes
|
53
37
|
def pq
|
54
|
-
note = Type::PriorityQueue.new
|
38
|
+
note = Type::PriorityQueue.new(@config)
|
55
39
|
note.create
|
56
40
|
end
|
57
41
|
|
@@ -61,16 +45,16 @@ module Evertils
|
|
61
45
|
# - weekly (if today is Monday and there isn't a weekly log already)
|
62
46
|
# - monthly (if today is the 1st and there isn't a monthly log already)
|
63
47
|
def morning
|
64
|
-
pq = Type::PriorityQueue.new
|
48
|
+
pq = Type::PriorityQueue.new(@config)
|
65
49
|
pq.create
|
66
50
|
|
67
|
-
daily = Type::Daily.new
|
51
|
+
daily = Type::Daily.new(@config)
|
68
52
|
daily.create
|
69
53
|
|
70
|
-
weekly = Type::Weekly.new
|
54
|
+
weekly = Type::Weekly.new(@config)
|
71
55
|
weekly.create if weekly.should_create?
|
72
56
|
|
73
|
-
monthly = Type::Monthly.new
|
57
|
+
monthly = Type::Monthly.new(@config)
|
74
58
|
monthly.create if monthly.should_create?
|
75
59
|
end
|
76
60
|
end
|
@@ -6,7 +6,7 @@ module Evertils
|
|
6
6
|
def pre_exec
|
7
7
|
# command flag parser
|
8
8
|
OptionParser.new do |opt|
|
9
|
-
opt.banner = "
|
9
|
+
opt.banner = "evertils new note [...-flags]"
|
10
10
|
|
11
11
|
opt.on("-t", "--title=TITLE", "Set a custom title") do |title|
|
12
12
|
@title = title
|
@@ -35,7 +35,7 @@ module Evertils
|
|
35
35
|
Notify.info("Printing list of notes")
|
36
36
|
|
37
37
|
metadata.notes.each do |note|
|
38
|
-
|
38
|
+
Notify.spit note.title
|
39
39
|
end
|
40
40
|
else
|
41
41
|
Notify.error("Could not pull data for notebook #{$request.custom[0]}", {})
|
@@ -46,7 +46,7 @@ module Evertils
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def info
|
49
|
-
|
49
|
+
@config.options.each_pair do |key, value|
|
50
50
|
Notify.spit("#{key}: #{value}")
|
51
51
|
end
|
52
52
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module Evertils
|
2
2
|
module Helper
|
3
|
-
def self.load(klass, args
|
3
|
+
def self.load(klass, *args)
|
4
4
|
begin
|
5
5
|
klass_instance = Evertils::Helper.const_get(klass)
|
6
6
|
|
7
7
|
if klass_instance
|
8
|
-
if args.
|
8
|
+
if args.empty?
|
9
9
|
klass_instance.new
|
10
10
|
else
|
11
11
|
klass_instance.new(args)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
rescue => e
|
15
|
-
Notify.error(e.
|
15
|
+
Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -3,8 +3,8 @@ module Evertils
|
|
3
3
|
class ApiEnmlHandler
|
4
4
|
#
|
5
5
|
# @since 0.3.7
|
6
|
-
def initialize(
|
7
|
-
|
6
|
+
def initialize(config = nil)
|
7
|
+
@config = config
|
8
8
|
self
|
9
9
|
end
|
10
10
|
|
@@ -26,14 +26,7 @@ module Evertils
|
|
26
26
|
|
27
27
|
# remove <br> tags
|
28
28
|
note_xml.search('br').each(&:remove)
|
29
|
-
|
30
|
-
enml = note_xml.inner_html.to_s
|
31
|
-
|
32
|
-
# append custom sections to the end of the content if they exist
|
33
|
-
return enml if $config.custom_sections.nil?
|
34
|
-
|
35
|
-
enml += to_enml($config.custom_sections[NOTEBOOK_PRIORITY_QUEUE])
|
36
|
-
enml
|
29
|
+
note_xml.inner_html.to_s
|
37
30
|
end
|
38
31
|
|
39
32
|
#
|
@@ -32,7 +32,7 @@ module Evertils
|
|
32
32
|
@indent = 0
|
33
33
|
@errors = []
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
# Invokes the HTML parsing by using a string. Returns the markdown code in @output.
|
37
37
|
# To garantuee well-formed xml for REXML a <root> element will be added, but has no effect.
|
38
38
|
# After parsing all elements, the 'reference style'-links will be inserted.
|
@@ -45,7 +45,7 @@ module Evertils
|
|
45
45
|
insert_links()
|
46
46
|
@output
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
# Parsing an element and its children (recursive) and writing its markdown code to @output
|
50
50
|
# 1. do indent for nested list items
|
51
51
|
# 2. add the markdown opening tag for this element
|
@@ -58,18 +58,18 @@ module Evertils
|
|
58
58
|
@output << indent() if name.eql?(:li)
|
59
59
|
# 2.
|
60
60
|
@output << opening(element, parent)
|
61
|
-
|
61
|
+
|
62
62
|
# 3a.
|
63
63
|
if (element.has_text? and element.children.size < 2)
|
64
64
|
@output << text_node(element, parent)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
# 3b.
|
68
68
|
if element.has_elements?
|
69
69
|
element.children.each do |child|
|
70
70
|
# increase indent if nested list
|
71
71
|
@indent += 1 if element.name=~/(ul|ol)/ and parent.eql?(:li)
|
72
|
-
|
72
|
+
|
73
73
|
if child.node_type.eql?(:element)
|
74
74
|
parse_element(child, element.name.to_sym)
|
75
75
|
else
|
@@ -79,12 +79,12 @@ module Evertils
|
|
79
79
|
@output << child.to_s
|
80
80
|
end
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
# decrease indent if end of nested list
|
84
84
|
@indent -= 1 if element.name=~/(ul|ol)/ and parent.eql?(:li)
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
# 4.
|
89
89
|
@output << ending(element, parent)
|
90
90
|
end
|
@@ -124,7 +124,7 @@ module Evertils
|
|
124
124
|
""
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
# Returns the closing markdown tag, like opening()
|
129
129
|
def ending(type, parent)
|
130
130
|
case type.name.to_sym
|
@@ -160,7 +160,7 @@ module Evertils
|
|
160
160
|
""
|
161
161
|
end
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
# Perform indent: two space, @indent times - quite simple! :)
|
165
165
|
def indent
|
166
166
|
str = ""
|
@@ -169,7 +169,7 @@ module Evertils
|
|
169
169
|
end
|
170
170
|
str
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
# Return the content of element, which should be just text.
|
174
174
|
# If its a code block to indent of 4 spaces.
|
175
175
|
# For block quotation add a leading '>'
|
@@ -182,7 +182,7 @@ module Evertils
|
|
182
182
|
element.text
|
183
183
|
end
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
# Insert the mentioned reference style links.
|
187
187
|
def insert_links
|
188
188
|
@output << "\n"
|
@@ -190,14 +190,14 @@ module Evertils
|
|
190
190
|
@output << " [#{index+1}]: #{@links[index]}\n"
|
191
191
|
end
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
# Print out all errors, that occured and have been written to @errors.
|
195
195
|
def print_errors
|
196
196
|
@errors.each do |error|
|
197
|
-
|
197
|
+
Notify.error(error)
|
198
198
|
end
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
# Perform a benchmark on a given string n-times.
|
202
202
|
def speed_benchmark(string, n)
|
203
203
|
initialize()
|
@@ -29,9 +29,9 @@ module Evertils
|
|
29
29
|
|
30
30
|
IO.readlines(load_template(type), :encoding => 'UTF-8').join("").delete!("\n")
|
31
31
|
rescue Errno::ENOENT => e
|
32
|
-
Notify.error(e.
|
32
|
+
Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false)
|
33
33
|
rescue ArgumentError => e
|
34
|
-
Notify.error(e.
|
34
|
+
Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -51,9 +51,22 @@ module Evertils
|
|
51
51
|
}
|
52
52
|
end
|
53
53
|
|
54
|
-
#
|
55
|
-
|
56
|
-
|
54
|
+
# Recursively symbolize keys in a hash
|
55
|
+
# Params:
|
56
|
+
# +h+:: The hash you want to symbolize
|
57
|
+
def symbolize(h)
|
58
|
+
case h
|
59
|
+
when Hash
|
60
|
+
Hash[
|
61
|
+
h.map do |k, v|
|
62
|
+
[k.respond_to?(:to_sym) ? k.to_sym : k, symbolize(v)]
|
63
|
+
end
|
64
|
+
]
|
65
|
+
when Enumerable
|
66
|
+
h.map { |v| symbolize(v) }
|
67
|
+
else
|
68
|
+
h
|
69
|
+
end
|
57
70
|
end
|
58
71
|
|
59
72
|
private
|
@@ -61,34 +74,23 @@ module Evertils
|
|
61
74
|
#
|
62
75
|
# @since 0.3.1
|
63
76
|
def load_template(type)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
:"Monthly Task Summaries" => "mts",
|
69
|
-
:"Priority Queue" => "pq"
|
70
|
-
}
|
71
|
-
|
72
|
-
default = "#{Evertils::TEMPLATE_DIR}#{template_type_map[type]}.enml"
|
77
|
+
file_name = type.to_s.downcase.gsub(/\s/, '-')
|
78
|
+
installed_dir = Gem::Specification.find_by_name('evertils').gem_dir
|
79
|
+
local_installed_dir = "#{Dir.home}/.evertils/templates/"
|
80
|
+
template_file = "#{installed_dir}/#{file_name}.enml"
|
73
81
|
|
74
|
-
|
82
|
+
if Dir.exist? local_installed_dir
|
83
|
+
template_file = "#{local_installed_dir}#{file_name}.enml"
|
75
84
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
rval = $config.custom_path
|
81
|
-
|
82
|
-
if tmpl.include?('~')
|
83
|
-
rval += tmpl.gsub!(/~/, Dir.home)
|
84
|
-
else
|
85
|
-
rval += tmpl
|
85
|
+
# local config dir exists but the requested template does not, use
|
86
|
+
# the default template for this type
|
87
|
+
unless File.exist? template_file
|
88
|
+
template_file = "#{installed_dir}/#{file_name}.enml"
|
86
89
|
end
|
87
90
|
end
|
88
91
|
|
89
|
-
|
92
|
+
template_file
|
90
93
|
end
|
91
|
-
|
92
94
|
end
|
93
95
|
end
|
94
96
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Evertils
|
2
|
+
class Request
|
3
|
+
# Access controller variable property externally
|
4
|
+
attr_reader :controller
|
5
|
+
# Access command variable property externally
|
6
|
+
attr_reader :command
|
7
|
+
# Access custom variable property externally
|
8
|
+
attr_reader :custom
|
9
|
+
# Access flags variable property externally
|
10
|
+
attr_reader :flags
|
11
|
+
# Access raw_flags variable property externally
|
12
|
+
attr_reader :raw_flags
|
13
|
+
# Access param variable property externally
|
14
|
+
attr_reader :param
|
15
|
+
|
16
|
+
# Create the request object, parse ARGV for values
|
17
|
+
def initialize
|
18
|
+
raise ArgumentError, "ARGV is empty" if ARGV.empty?
|
19
|
+
|
20
|
+
@flags = ARGV.select { |f| f.start_with?('-') }.map { |f| f.split('=').map(&:to_sym) } || []
|
21
|
+
@raw_flags = ARGV.select { |f| f.start_with?('-') } || []
|
22
|
+
@controller = ARGV[0].to_sym unless ARGV[0].start_with?('-')
|
23
|
+
@command = ARGV[1].to_sym unless ARGV[1].nil?
|
24
|
+
|
25
|
+
return unless ARGV.size > 2
|
26
|
+
|
27
|
+
@custom = ARGV[2..ARGV.size].reject { |p| p.start_with?('-') }.map(&:to_sym) || []
|
28
|
+
@param = ARGV[2]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Evertils
|
2
|
+
class Router
|
3
|
+
# Create the router object
|
4
|
+
# Params:
|
5
|
+
# +config_instance+:: An instance of Evertils::Cfg
|
6
|
+
def initialize(config_instance)
|
7
|
+
@config = config_instance
|
8
|
+
end
|
9
|
+
|
10
|
+
# Prepare for routing
|
11
|
+
def pre_exec
|
12
|
+
@request = Request.new
|
13
|
+
|
14
|
+
begin
|
15
|
+
# include the controller
|
16
|
+
require "evertils/controllers/#{@request.controller}"
|
17
|
+
# include helpers
|
18
|
+
require "evertils/helpers/#{@request.controller}" if File.exist? "evertils/helpers/#{@request.controller}"
|
19
|
+
rescue LoadError
|
20
|
+
Notify.error("Controller not found: #{@request.controller}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Perform command routing
|
25
|
+
def route
|
26
|
+
pre_exec
|
27
|
+
|
28
|
+
# Create object context and pass it the required command line arguments
|
29
|
+
begin
|
30
|
+
unless @request.controller.nil?
|
31
|
+
controller = Evertils::Controller.const_get @request.controller.capitalize
|
32
|
+
|
33
|
+
# create an instance of the requested controller
|
34
|
+
context = controller.new(@config, @request)
|
35
|
+
|
36
|
+
if context.can_exec? @request.command
|
37
|
+
# Set things up
|
38
|
+
context.pre_exec
|
39
|
+
|
40
|
+
# Run the requested action
|
41
|
+
context.exec
|
42
|
+
|
43
|
+
# Run cleanup commands
|
44
|
+
context.post_exec
|
45
|
+
end
|
46
|
+
end
|
47
|
+
rescue NoMethodError => e
|
48
|
+
Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false)
|
49
|
+
rescue RuntimeError => e
|
50
|
+
Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false)
|
51
|
+
rescue NameError => e
|
52
|
+
Notify.error("#{e}\n#{e.backtrace.join("\n")}", show_time: false)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|