cvgen 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cvgen/exec.rb +55 -9
- data/lib/cvgen.rb +18 -0
- metadata +31 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18022dda5028a3a2ab5a1bf085040bc307ab6c26
|
4
|
+
data.tar.gz: c98151f8b89d41abd3d001ea7a72c5d9eaa12c47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d764de95524cbac896e7853e9059b861290febb9b9b76d5afa341eb4095fb1e828374870d1d838298827f96d9f78205c1225c28ecdd661658ccd39390029d08
|
7
|
+
data.tar.gz: cd2df1f140864eb9b867c2b806a21b839a5f7af8c6bc4126ff242606d93394ddcd12faa82429e8c1190d6ade3972264f6382b69a7c9aba5e2296eb898802f4bd
|
data/lib/cvgen/exec.rb
CHANGED
@@ -1,26 +1,72 @@
|
|
1
1
|
require 'cvgen'
|
2
2
|
require 'yaml'
|
3
|
+
require 'optparse'
|
3
4
|
|
4
5
|
module CVGen
|
5
6
|
module Exec
|
6
7
|
|
7
8
|
def self.call
|
8
|
-
|
9
|
+
config = parse_command_line_args
|
10
|
+
watch = config.delete('watch')
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
input_file, output_file = ARGV[0], ARGV[1]
|
13
|
+
|
14
|
+
create_output(input_file, output_file, config)
|
15
|
+
|
16
|
+
if watch
|
17
|
+
trap(:INT) { exit }
|
18
|
+
|
19
|
+
require 'listen'
|
20
|
+
Listen.to('.', :only => Regexp.new(input_file)) do |modified, added, removed|
|
21
|
+
#assume the only possibility is modification of source file
|
22
|
+
create_output(input_file, output_file, config)
|
23
|
+
end.start
|
24
|
+
|
25
|
+
puts 'Listening for changes, Ctrl-C to exit'
|
26
|
+
sleep
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.create_output(input_file, output_file, config)
|
31
|
+
input = File.read(input_file)
|
32
|
+
merge_options(config, YAML.load_file('config.yml')) if File.exist? 'config.yml'
|
12
33
|
|
13
34
|
if input.start_with? "---\n"
|
14
|
-
|
15
|
-
|
35
|
+
input.slice!(0..3)
|
36
|
+
front, input = input.split /^(?:\.{3}|-{3})\s*$/, 2
|
37
|
+
|
38
|
+
front = YAML.load(front)
|
39
|
+
|
40
|
+
merge_options(config, front)
|
16
41
|
end
|
17
42
|
|
18
|
-
|
43
|
+
pdf_data = CVGen.generate input, config
|
44
|
+
IO.binwrite(output_file, pdf_data)
|
45
|
+
end
|
19
46
|
|
20
|
-
|
47
|
+
def self.merge_options(into, from)
|
48
|
+
if into[FEATURES_OPTION] && from[FEATURES_OPTION]
|
49
|
+
into[FEATURES_OPTION].concat(from.delete(FEATURES_OPTION))
|
50
|
+
end
|
21
51
|
|
52
|
+
into.merge!(from)
|
22
53
|
end
|
23
54
|
|
24
|
-
|
55
|
+
def self.parse_command_line_args
|
56
|
+
config = {}
|
57
|
+
|
58
|
+
OptionParser.new do |opts|
|
59
|
+
opts.on("-e", "--enable FEATURES", Array, "List of features to enable") do |features|
|
60
|
+
config[FEATURES_OPTION] = features
|
61
|
+
end
|
25
62
|
|
26
|
-
|
63
|
+
opts.on("-w", "--watch", "Watch for changes and automatically regenerate pdf") do
|
64
|
+
config['watch'] = true
|
65
|
+
end
|
66
|
+
end.parse!
|
67
|
+
|
68
|
+
config
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
data/lib/cvgen.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
require 'cvgen/parser'
|
2
2
|
require 'cvgen/converter'
|
3
3
|
|
4
|
+
require 'erubis'
|
5
|
+
|
4
6
|
module CVGen
|
5
7
|
|
8
|
+
FEATURES_OPTION = 'features'.freeze
|
9
|
+
|
6
10
|
def self.generate source, opts={}
|
11
|
+
|
12
|
+
source = Erubis::Eruby.new(source).evaluate(ErbContext.new(opts.fetch(FEATURES_OPTION, [])))
|
13
|
+
|
7
14
|
root, warnings = Parser.parse(source, opts)
|
8
15
|
$stderr.puts warnings if warnings
|
9
16
|
output, c_warnings = Converter.convert(root, opts)
|
@@ -11,4 +18,15 @@ module CVGen
|
|
11
18
|
output
|
12
19
|
end
|
13
20
|
|
21
|
+
class ErbContext < BasicObject
|
22
|
+
|
23
|
+
def initialize(features)
|
24
|
+
@features = features
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(method, *args)
|
28
|
+
@features.include?(method.to_s)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
14
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cvgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Wildig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: erubis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: listen
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.8'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.8'
|
55
83
|
description: Because everybody hates word processors
|
56
84
|
email: matt@mattwildig.co.uk
|
57
85
|
executables:
|
@@ -83,9 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
111
|
version: '0'
|
84
112
|
requirements: []
|
85
113
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.4.
|
114
|
+
rubygems_version: 2.4.5
|
87
115
|
signing_key:
|
88
116
|
specification_version: 4
|
89
117
|
summary: Generate CVs in PDF format from Markdown-like source
|
90
118
|
test_files: []
|
91
|
-
has_rdoc:
|