evertils 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40ea220d69b7b5db784276e1f73c8f4b1a20c1d8
4
- data.tar.gz: a6f7643cbfa69044f127df963c824c7f6c01bdc5
3
+ metadata.gz: 831cd9afe4aacb4705e8671c810a86a75a457995
4
+ data.tar.gz: 854c215462444912c7a921e3ad96c419091455d9
5
5
  SHA512:
6
- metadata.gz: f2b0e059335d2c8290c9ee63cf823758fc8b307b9b6faf4b1d7a4b66f3e3b7240af0b7bf564543ca4751c43f5450f854a17a007a34142048ceccd0ec2f1a1fc9
7
- data.tar.gz: c58541d8ea0879d621556d8e84c25b2f88c7b26c7dc5fcaf45163c07c60a39286ca249159e4618ee749b69a233425e9555c84b6f9501812ad9ff803d08c88785
6
+ metadata.gz: 53dad8596ca329e245b131ee9d96b2eb7dd5e186b72a3a04659e1784fa713e349f8ffd2c6956d41b75ec9e352c8b16a70739480448c8cd3537d15646f04599f4
7
+ data.tar.gz: d6a3bed7465363d47d0b26668ddf7e52709b58feeff9d4902ec0064dc2aa4a0aaf4d76ca7fab99922b1d835f34e5dee82b03580a30001a071fcb6b4cdde1891e
data/bin/evertils CHANGED
@@ -14,6 +14,7 @@ require "notifaction"
14
14
  require 'digest/md5'
15
15
  require 'mime/types'
16
16
  require 'evertils/common'
17
+ require 'yaml'
17
18
 
18
19
  # include required files
19
20
  require_relative "../lib/kernel.rb"
data/evertils.gemspec CHANGED
@@ -1,3 +1,6 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
1
4
  require './lib/version'
2
5
 
3
6
  Gem::Specification.new do |s|
data/lib/config.rb CHANGED
@@ -11,6 +11,8 @@ module Evertils
11
11
  DEBUG = false
12
12
 
13
13
  class Cfg
14
+ attr_accessor :custom_sections, :custom_templates
15
+
14
16
  def bootstrap!
15
17
  begin
16
18
  # configure Notifaction gem
@@ -20,6 +22,8 @@ module Evertils
20
22
  rescue => e
21
23
  Notify.error("#{e.to_s}\n#{e.backtrace.join("\n")}")
22
24
  end
25
+
26
+ load_user_customizations
23
27
  end
24
28
 
25
29
  def constant?(name)
@@ -37,5 +41,32 @@ module Evertils
37
41
  end
38
42
  hash
39
43
  end
44
+
45
+ #
46
+ # @since 0.3.1
47
+ def load_user_customizations
48
+ conf = recursive_symbolize_keys(YAML::load_file(Dir.home + '/.evertils/config.yml'))
49
+
50
+ @custom_sections = conf[:sections] if conf[:sections]
51
+ @custom_templates = conf[:templates] if conf[:templates]
52
+ end
53
+
54
+ #
55
+ # @since 0.3.1
56
+ def recursive_symbolize_keys(hash)
57
+ hash.inject({}){|result, (key, value)|
58
+ new_key = case key
59
+ when String then key.to_sym
60
+ else key
61
+ end
62
+ new_value = case value
63
+ when Hash then recursive_symbolize_keys(value)
64
+ else value
65
+ end
66
+ result[new_key] = new_value
67
+ result
68
+ }
69
+ end
70
+
40
71
  end
41
72
  end
@@ -24,7 +24,7 @@ module Evertils
24
24
  @start = DateTime.parse(date)
25
25
  end
26
26
 
27
- opt.on("-n", "--name=NAME", "A name to pass to the script (not all command support this flag)") do |name|
27
+ opt.on("-n", "--name=NAME", "A name to pass to the script (not all commands support this flag)") do |name|
28
28
  @name = name
29
29
  end
30
30
  end.parse!
@@ -36,6 +36,7 @@ module Evertils
36
36
  def daily
37
37
  title = @format.date_templates[NOTEBOOK_DAILY]
38
38
  body = @format.template_contents
39
+ body += to_enml($config.custom_sections[NOTEBOOK_DAILY]) if $config.custom_sections[NOTEBOOK_DAILY]
39
40
  parent_notebook = NOTEBOOK_DAILY
40
41
 
41
42
  @model.create_note(title, body, parent_notebook)
@@ -45,6 +46,7 @@ module Evertils
45
46
  def weekly
46
47
  title = @format.date_templates[NOTEBOOK_WEEKLY]
47
48
  body = @format.template_contents
49
+ body += to_enml($config.custom_sections[NOTEBOOK_WEEKLY]) if $config.custom_sections[NOTEBOOK_WEEKLY]
48
50
  parent_notebook = NOTEBOOK_WEEKLY
49
51
 
50
52
  if !@force
@@ -64,6 +66,7 @@ module Evertils
64
66
  def monthly
65
67
  title = @format.date_templates[NOTEBOOK_MONTHLY]
66
68
  body = @format.template_contents
69
+ body += to_enml($config.custom_sections[NOTEBOOK_MONTHLY]) if $config.custom_sections[NOTEBOOK_MONTHLY]
67
70
  parent_notebook = NOTEBOOK_MONTHLY
68
71
 
69
72
  note = @model.create_note(title, body, parent_notebook)
@@ -79,11 +82,12 @@ module Evertils
79
82
 
80
83
  title = "#{@name} #{DateTime.now.strftime('%m-%Y')}"
81
84
  body = @format.template_contents
85
+ body += to_enml($config.custom_sections[NOTEBOOK_MTS]) if $config.custom_sections[NOTEBOOK_MTS]
82
86
  parent_notebook = NOTEBOOK_MTS
83
87
 
84
88
  # create the note from template
85
89
  mts_note = @model.create_note(title, body, parent_notebook)
86
-
90
+
87
91
  # tag it
88
92
  # TODO: maybe move this out of controller?
89
93
  tag_manager = Evertils::Common::Manager::Tag.new
@@ -94,6 +98,15 @@ module Evertils
94
98
  # client_tag = tag_manager.find_or_create(@name)
95
99
  # mts_note.tag(client_tag.prop(:name))
96
100
  end
101
+
102
+ private
103
+
104
+ #
105
+ # @since 0.3.1
106
+ def to_enml(hash)
107
+ enml = Evertils::Helper::EvernoteENML::with_list(hash)
108
+ end
109
+
97
110
  end
98
111
  end
99
112
  end
@@ -38,15 +38,15 @@ module Evertils
38
38
  puts note.title
39
39
  end
40
40
  else
41
- Notify.error("Could not pull data for notebook #{$request.custom[0]}")
41
+ Notify.error("Could not pull data for notebook #{$request.custom[0]}", {})
42
42
  end
43
43
  else
44
- Notify.error("Notebook name is a required argument, i.e.\n#{Evertils::PACKAGE_NAME} get notebook agendas")
44
+ Notify.error("Notebook name is a required argument, i.e.\n#{Evertils::PACKAGE_NAME} get notebook agendas", {})
45
45
  end
46
46
  end
47
47
 
48
48
  def info
49
- @model.info.each_pair do |key, value|
49
+ $config.options.each_pair do |key, value|
50
50
  Notify.spit("#{key}: #{value}")
51
51
  end
52
52
  end
@@ -3,6 +3,7 @@ module Evertils
3
3
  class EvernoteENML
4
4
  attr_reader :element, :embeddable_element
5
5
 
6
+ # TODO: refactor this whole class so you can create ENML elements with it
6
7
  def initialize(file = nil)
7
8
  @file = file
8
9
  @element = enml_element
@@ -12,22 +13,44 @@ module Evertils
12
13
  end
13
14
  end
14
15
 
15
- private
16
- def enml_element
17
- if @file
18
- read_file = File.open(@file, 'rb') { |io| io.read }
19
-
20
- el = ::Evernote::EDAM::Type::Resource.new()
21
- el.mime = MIME::Types.type_for(@file)[0].content_type
22
- el.data = ::Evernote::EDAM::Type::Data.new()
23
- el.data.size = read_file.size
24
- el.data.bodyHash = Digest::MD5.hexdigest(read_file)
25
- el.data.body = read_file
26
- el.attributes = ::Evernote::EDAM::Type::ResourceAttributes.new()
27
- el.attributes.fileName = @file # temporary for now, the actual file name
28
- el
16
+ def self.with_list(arr)
17
+ enml_bucket = []
18
+
19
+ if arr.respond_to? :each_pair
20
+ arr.each_pair do |title, data|
21
+ enml_bucket.push("<br /><div><span style=\"font-size: 18px;\">#{title}</span></div>")
22
+
23
+ enml_bucket.push('<ul>')
24
+
25
+ data.each do |item|
26
+ enml_bucket.push("<li>#{item}</li>")
27
+ end
28
+
29
+ enml_bucket.push('</ul>')
29
30
  end
31
+
32
+ enml_bucket.join
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def enml_element
39
+ if @file
40
+ read_file = File.open(@file, 'rb') { |io| io.read }
41
+
42
+ el = ::Evernote::EDAM::Type::Resource.new()
43
+ el.mime = MIME::Types.type_for(@file)[0].content_type
44
+ el.data = ::Evernote::EDAM::Type::Data.new()
45
+ el.data.size = read_file.size
46
+ el.data.bodyHash = Digest::MD5.hexdigest(read_file)
47
+ el.data.body = read_file
48
+ el.attributes = ::Evernote::EDAM::Type::ResourceAttributes.new()
49
+ el.attributes.fileName = @file # temporary for now, the actual file name
50
+ el
30
51
  end
52
+ end
53
+
31
54
  end
32
55
  end
33
56
  end
@@ -33,8 +33,8 @@ module Evertils
33
33
  :default => "#{Evertils::TEMPLATE_DIR}#{command.downcase}.enml"
34
34
  }
35
35
 
36
- template = tmpls[:default]
37
-
36
+ template = local_template_override?(tmpls[:default])
37
+
38
38
  if command == :Daily
39
39
  if Date.today.friday? && File.exist?(tmpls[:friday])
40
40
  template = tmpls[:friday]
@@ -50,7 +50,7 @@ module Evertils
50
50
  def date_templates(arg_date = DateTime.now)
51
51
  dow = day_of_week(arg_date.strftime('%a'))
52
52
  end_of_week = arg_date + 4 # days
53
-
53
+
54
54
  {
55
55
  :Daily => "Daily Log [#{arg_date.strftime('%B %-d')} - #{dow}]",
56
56
  :Weekly => "Weekly Log [#{arg_date.strftime('%B %-d')} - #{end_of_week.strftime('%B %-d')}]",
@@ -63,6 +63,21 @@ module Evertils
63
63
  def command
64
64
  $request.command.capitalize
65
65
  end
66
+
67
+ private
68
+
69
+ #
70
+ # @since 0.3.1
71
+ def local_template_override?(default)
72
+ tmpl = $config.custom_templates[command]
73
+
74
+ if tmpl.nil?
75
+ default
76
+ else
77
+ tmpl.gsub!(/~/, Dir.home) if tmpl.include?('~')
78
+ end
79
+ end
80
+
66
81
  end
67
82
  end
68
83
  end
data/lib/router.rb CHANGED
@@ -7,7 +7,7 @@ module Evertils
7
7
  begin
8
8
  if !$request.controller.nil?
9
9
  controller = Evertils::Controller.const_get $request.controller.capitalize rescue false
10
-
10
+
11
11
  if !controller
12
12
  raise "Controller not found: #{$request.controller.capitalize}"
13
13
  end
@@ -28,7 +28,7 @@ module Evertils
28
28
  if context.model.nil?
29
29
  context.model = Model::Base.new
30
30
  end
31
-
31
+
32
32
  # If the method exists, set model data accordingly
33
33
  # If it doesn't exist then just fail silently, the model may not
34
34
  # be required by some controllers
@@ -44,7 +44,7 @@ module Evertils
44
44
 
45
45
  # Run the controller
46
46
  # Call a default action for controllers which do not require a third
47
- # argument, i.e. evertils status
47
+ # argument, i.e. evertils status
48
48
  if context.respond_to? :default
49
49
  context.default
50
50
  else
@@ -56,9 +56,9 @@ module Evertils
56
56
  end
57
57
  end
58
58
  rescue RuntimeError => e
59
- Notify.error("#{e.to_s}")
59
+ Notify.error("#{e.to_s}", {})
60
60
  rescue NameError => e
61
- Notify.error("#{e.to_s}\n#{e.backtrace.join("\n")}")
61
+ Notify.error("#{e.to_s}\n#{e.backtrace.join("\n")}", {})
62
62
  end
63
63
  end
64
64
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Evertils
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evertils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Priebe
@@ -14,70 +14,70 @@ dependencies:
14
14
  name: notifaction
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mime-types
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: evertils-common
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.3.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.3.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.10'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '10.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.0'
83
83
  description: Evernote utilities for your CLI workflow
@@ -87,7 +87,7 @@ executables:
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - ".gitignore"
90
+ - .gitignore
91
91
  - Gemfile
92
92
  - README.md
93
93
  - Rakefile
@@ -135,17 +135,17 @@ require_paths:
135
135
  - lib
136
136
  required_ruby_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ">="
138
+ - - '>='
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.0.14
148
+ rubygems_version: 2.0.14.1
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: EN (heart) CLI