letter_generator 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +34 -38
- data/README.md +4 -1
- data/features/build_letter.feature +20 -0
- data/features/generate_letter.feature +57 -2
- data/features/init_generator.feature +20 -4
- data/features/step_definitions.rb +61 -1
- data/letter_generator.gemspec +1 -0
- data/lib/letter_generator.rb +16 -1
- data/lib/letter_generator/addressee.rb +13 -0
- data/lib/letter_generator/application_config.rb +2 -0
- data/lib/letter_generator/generator.rb +8 -2
- data/lib/letter_generator/generators/tex_file_generator.rb +26 -0
- data/lib/letter_generator/letter_template.rb +3 -0
- data/lib/letter_generator/{letter_content.rb → metadata.rb} +5 -13
- data/lib/letter_generator/metadata_file.rb +9 -0
- data/lib/letter_generator/metadata_parser.rb +13 -0
- data/lib/letter_generator/metadata_proxy.rb +19 -0
- data/lib/letter_generator/output_file.rb +17 -0
- data/lib/letter_generator/runner.rb +43 -7
- data/lib/letter_generator/sender.rb +13 -0
- data/lib/letter_generator/templates_directory.rb +4 -0
- data/lib/letter_generator/version.rb +1 -1
- data/templates/Rakefile.tt +11 -0
- metadata +28 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55d5ae0c7254e841009e0dd163e80202fa384d52
|
4
|
+
data.tar.gz: 4c5041205e6b05a46702591c19cde0cdbe5fae8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f653c799552e577574c641bbf2bcf4f41ef7eb5f1a52ad73ae5b292b1488264e42ffeba2e9a2ab4df18db32b7ae3eacf5123714aef292965177a90c0b03b378
|
7
|
+
data.tar.gz: e0018a17dae08777113de6f664419ed3d39dbf85dbd54c1775ea3dbb190cb38eba66a242b4622dbabcfbf6192ec8addc68a00fed895e0fb8f677b800255de2af
|
data/Gemfile.lock
CHANGED
@@ -10,9 +10,10 @@ GIT
|
|
10
10
|
PATH
|
11
11
|
remote: .
|
12
12
|
specs:
|
13
|
-
letter_generator (0.
|
13
|
+
letter_generator (0.1.1)
|
14
14
|
activesupport
|
15
15
|
fedux_org-stdlib
|
16
|
+
rake
|
16
17
|
thor
|
17
18
|
tilt
|
18
19
|
|
@@ -55,9 +56,9 @@ GEM
|
|
55
56
|
concord (0.1.5)
|
56
57
|
adamantium (~> 0.2.0)
|
57
58
|
equalizer (~> 0.0.9)
|
58
|
-
coveralls (0.7.
|
59
|
+
coveralls (0.7.11)
|
59
60
|
multi_json (~> 1.10)
|
60
|
-
rest-client (
|
61
|
+
rest-client (>= 1.6.8, < 2)
|
61
62
|
simplecov (~> 0.9.1)
|
62
63
|
term-ansicolor (~> 1.3)
|
63
64
|
thor (~> 0.19.1)
|
@@ -73,8 +74,8 @@ GEM
|
|
73
74
|
dotenv (1.0.2)
|
74
75
|
equalizer (0.0.9)
|
75
76
|
erubis (2.7.0)
|
76
|
-
excon (0.44.
|
77
|
-
fedux_org-stdlib (0.11.
|
77
|
+
excon (0.44.4)
|
78
|
+
fedux_org-stdlib (0.11.16)
|
78
79
|
activesupport
|
79
80
|
ffi (1.9.6)
|
80
81
|
filegen (0.4.3)
|
@@ -87,8 +88,7 @@ GEM
|
|
87
88
|
ruby-progressbar (~> 1.4)
|
88
89
|
gherkin (2.12.2)
|
89
90
|
multi_json (~> 1.3)
|
90
|
-
github-markup (1.3.
|
91
|
-
posix-spawn (~> 0.3.8)
|
91
|
+
github-markup (1.3.3)
|
92
92
|
httparty (0.13.3)
|
93
93
|
json (~> 1.8)
|
94
94
|
multi_xml (>= 0.5.2)
|
@@ -103,11 +103,9 @@ GEM
|
|
103
103
|
launchy (2.4.3)
|
104
104
|
addressable (~> 2.3)
|
105
105
|
libv8 (3.16.14.7)
|
106
|
-
license_finder (1
|
106
|
+
license_finder (2.0.1)
|
107
107
|
bundler
|
108
108
|
httparty
|
109
|
-
sequel
|
110
|
-
sqlite3
|
111
109
|
thor
|
112
110
|
xml-simple
|
113
111
|
memoizable (0.4.2)
|
@@ -124,10 +122,10 @@ GEM
|
|
124
122
|
equalizer (~> 0.0.9)
|
125
123
|
ice_nine (~> 0.11.0)
|
126
124
|
procto (~> 0.0.2)
|
127
|
-
multi_json (1.
|
125
|
+
multi_json (1.11.0)
|
128
126
|
multi_test (0.1.2)
|
129
127
|
multi_xml (0.5.5)
|
130
|
-
mutant (0.7.
|
128
|
+
mutant (0.7.8)
|
131
129
|
abstract_type (~> 0.0.7)
|
132
130
|
adamantium (~> 0.2.0)
|
133
131
|
anima (~> 0.2.0)
|
@@ -142,14 +140,13 @@ GEM
|
|
142
140
|
parser (~> 2.2.0.2)
|
143
141
|
procto (~> 0.0.2)
|
144
142
|
unparser (~> 0.2.2)
|
145
|
-
mutant-rspec (0.7.
|
146
|
-
mutant (~> 0.7.
|
147
|
-
rspec-core (>= 3.0.0, < 3.
|
148
|
-
netrc (0.10.
|
149
|
-
parallel (1.
|
143
|
+
mutant-rspec (0.7.8)
|
144
|
+
mutant (~> 0.7.8)
|
145
|
+
rspec-core (>= 3.0.0, < 3.3.0)
|
146
|
+
netrc (0.10.3)
|
147
|
+
parallel (1.4.1)
|
150
148
|
parser (2.2.0.3)
|
151
149
|
ast (>= 1.1, < 3.0)
|
152
|
-
posix-spawn (0.3.9)
|
153
150
|
powerpack (0.1.0)
|
154
151
|
procto (0.0.2)
|
155
152
|
pry (0.10.1)
|
@@ -166,21 +163,22 @@ GEM
|
|
166
163
|
rake (10.4.2)
|
167
164
|
redcarpet (3.2.2)
|
168
165
|
ref (1.0.5)
|
169
|
-
rest-client (1.7.
|
166
|
+
rest-client (1.7.3)
|
170
167
|
mime-types (>= 1.16, < 3.0)
|
171
168
|
netrc (~> 0.7)
|
172
|
-
rspec (3.
|
173
|
-
rspec-core (~> 3.
|
174
|
-
rspec-expectations (~> 3.
|
175
|
-
rspec-mocks (~> 3.
|
176
|
-
rspec-core (3.1
|
177
|
-
rspec-support (~> 3.
|
178
|
-
rspec-expectations (3.
|
169
|
+
rspec (3.2.0)
|
170
|
+
rspec-core (~> 3.2.0)
|
171
|
+
rspec-expectations (~> 3.2.0)
|
172
|
+
rspec-mocks (~> 3.2.0)
|
173
|
+
rspec-core (3.2.1)
|
174
|
+
rspec-support (~> 3.2.0)
|
175
|
+
rspec-expectations (3.2.0)
|
179
176
|
diff-lcs (>= 1.2.0, < 2.0)
|
180
|
-
rspec-support (~> 3.
|
181
|
-
rspec-mocks (3.1
|
182
|
-
|
183
|
-
|
177
|
+
rspec-support (~> 3.2.0)
|
178
|
+
rspec-mocks (3.2.1)
|
179
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
180
|
+
rspec-support (~> 3.2.0)
|
181
|
+
rspec-support (3.2.2)
|
184
182
|
rubocop (0.29.1)
|
185
183
|
astrolabe (~> 1.3)
|
186
184
|
parser (>= 2.2.0.1, < 3.0)
|
@@ -189,16 +187,14 @@ GEM
|
|
189
187
|
ruby-progressbar (~> 1.4)
|
190
188
|
ruby-progressbar (1.7.1)
|
191
189
|
rugged (0.21.4)
|
192
|
-
|
193
|
-
simplecov (0.9.1)
|
190
|
+
simplecov (0.9.2)
|
194
191
|
docile (~> 1.1.0)
|
195
192
|
multi_json (~> 1.0)
|
196
|
-
simplecov-html (~> 0.
|
197
|
-
simplecov-html (0.
|
193
|
+
simplecov-html (~> 0.9.0)
|
194
|
+
simplecov-html (0.9.0)
|
198
195
|
slop (3.6.0)
|
199
196
|
smart_colored (1.1.1)
|
200
197
|
sparkr (0.4.1)
|
201
|
-
sqlite3 (1.3.10)
|
202
198
|
stackprof (0.2.7)
|
203
199
|
term-ansicolor (1.3.0)
|
204
200
|
tins (~> 1.0)
|
@@ -209,9 +205,9 @@ GEM
|
|
209
205
|
therubyrhino_jar (>= 1.7.3)
|
210
206
|
therubyrhino_jar (1.7.4)
|
211
207
|
thor (0.19.1)
|
212
|
-
thread_safe (0.3.
|
208
|
+
thread_safe (0.3.5)
|
213
209
|
tilt (2.0.1)
|
214
|
-
tins (1.3.
|
210
|
+
tins (1.3.5)
|
215
211
|
tmrb (1.2.7)
|
216
212
|
thor
|
217
213
|
travis-lint (2.0.0)
|
@@ -228,7 +224,7 @@ GEM
|
|
228
224
|
procto (~> 0.0.2)
|
229
225
|
versionomy (0.4.4)
|
230
226
|
blockenspiel (>= 0.4.5)
|
231
|
-
xml-simple (1.1.
|
227
|
+
xml-simple (1.1.5)
|
232
228
|
yard (0.8.7.6)
|
233
229
|
|
234
230
|
PLATFORMS
|
data/README.md
CHANGED
@@ -20,6 +20,9 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
|
24
|
+
### Generate letter.tex
|
25
|
+
|
23
26
|
To invoke the letter generator, you can use `lg` or `letter_generator`.
|
24
27
|
|
25
28
|
You need to place an ERB-template at any of this places
|
@@ -58,7 +61,7 @@ Generate letter based on template:
|
|
58
61
|
letter_generator generate
|
59
62
|
```
|
60
63
|
|
61
|
-
After this a tex file named "letter.tex" exists.
|
64
|
+
After this a tex file named "letter-mina-muster.tex" exists.
|
62
65
|
|
63
66
|
## Contributing
|
64
67
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Feature: Generate pdf Letter
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given the default letter template exist in working directory
|
5
|
+
And the data file "data" with:
|
6
|
+
"""
|
7
|
+
from:
|
8
|
+
name: Max Mustermann
|
9
|
+
street: Musterstrasse 1
|
10
|
+
city: Musterstadt
|
11
|
+
to:
|
12
|
+
name: Hans im Glück
|
13
|
+
street: Gluecksstrasse 1
|
14
|
+
city: Glueckstadt
|
15
|
+
subject: Subject
|
16
|
+
"""
|
17
|
+
|
18
|
+
Scenario: Non-existing pdf
|
19
|
+
When I successfully run `letter_generator build`
|
20
|
+
Then a file named "build/letter-hans-im-gluck.pdf" should exist
|
@@ -1,9 +1,64 @@
|
|
1
1
|
Feature: Generate Letter
|
2
2
|
|
3
3
|
Background:
|
4
|
-
Given the default letter template
|
4
|
+
Given the default letter template exist in working directory
|
5
|
+
And the data file "data" with:
|
6
|
+
"""
|
7
|
+
from:
|
8
|
+
name: Max Mustermann
|
9
|
+
street: Musterstrasse 1
|
10
|
+
city: Musterstadt
|
11
|
+
to:
|
12
|
+
name: Hans im Glück
|
13
|
+
street: Gluecksstrasse 1
|
14
|
+
city: Glueckstadt
|
15
|
+
subject: Subject
|
16
|
+
"""
|
5
17
|
|
6
18
|
Scenario: Non-existing letter
|
7
19
|
Given a letter named "letter" does not exist
|
8
20
|
When I successfully run `letter_generator generate`
|
9
|
-
Then a letter named "letter" should exist
|
21
|
+
Then a letter named "letter-hans-im-gluck" should exist
|
22
|
+
|
23
|
+
Scenario: Template in current working directory
|
24
|
+
Given a letter named "letter" does not exist
|
25
|
+
And a local letter template named "letter" with:
|
26
|
+
"""
|
27
|
+
Hello world
|
28
|
+
"""
|
29
|
+
When I successfully run `letter_generator generate`
|
30
|
+
Then the letter "letter-hans-im-gluck" should contain:
|
31
|
+
"""
|
32
|
+
Hello world
|
33
|
+
"""
|
34
|
+
|
35
|
+
Scenario: Multiple addressees
|
36
|
+
Given a letter named "letter" does not exist
|
37
|
+
And the data file "data" with:
|
38
|
+
"""
|
39
|
+
from:
|
40
|
+
name: Max Mustermann
|
41
|
+
street: Musterstrasse 1
|
42
|
+
city: Musterstadt
|
43
|
+
to:
|
44
|
+
- name: Hans im Glück
|
45
|
+
street: Gluecksstrasse 1
|
46
|
+
city: Glueckstadt
|
47
|
+
- name: Maxi Mustermann
|
48
|
+
street: Gluecksstrasse 2
|
49
|
+
city: Glueckstadt
|
50
|
+
subject: Subject
|
51
|
+
"""
|
52
|
+
And a local letter template named "letter" with:
|
53
|
+
"""
|
54
|
+
<%= to.name %>
|
55
|
+
"""
|
56
|
+
When I successfully run `letter_generator generate`
|
57
|
+
Then the letter "letter-hans-im-gluck" should contain:
|
58
|
+
"""
|
59
|
+
Hans im Glück
|
60
|
+
"""
|
61
|
+
And the letter "letter-maxi-mustermann" should contain:
|
62
|
+
"""
|
63
|
+
Maxi Mustermann
|
64
|
+
"""
|
@@ -1,12 +1,13 @@
|
|
1
1
|
Feature: Init generator
|
2
2
|
|
3
|
-
Background:
|
4
|
-
|
3
|
+
#Background:
|
4
|
+
# Given the default letter template
|
5
5
|
|
6
|
-
Scenario:
|
6
|
+
Scenario: Init local directory
|
7
7
|
Given a data file named "data" does not exist
|
8
8
|
When I successfully run `letter_generator init`
|
9
|
-
Then
|
9
|
+
Then the local letter template "letter" should exist
|
10
|
+
Then the data file "data" should contain:
|
10
11
|
"""
|
11
12
|
from:
|
12
13
|
name:
|
@@ -18,3 +19,18 @@ Feature: Init generator
|
|
18
19
|
city:
|
19
20
|
subject:
|
20
21
|
"""
|
22
|
+
|
23
|
+
Scenario: Init user directory
|
24
|
+
Given a data file named "data" does not exist
|
25
|
+
When I successfully run `letter_generator init --for user`
|
26
|
+
Then the user letter template "letter" should exist
|
27
|
+
|
28
|
+
Scenario: Init working directory (default)
|
29
|
+
Given a data file named "data" does not exist
|
30
|
+
When I successfully run `letter_generator init --for working-directory`
|
31
|
+
Then the local letter template "letter" should exist
|
32
|
+
|
33
|
+
Scenario: Init working directory (explicit)
|
34
|
+
Given a data file named "data" does not exist
|
35
|
+
When I successfully run `letter_generator init --for working-directory`
|
36
|
+
Then the local letter template "letter" should exist
|
@@ -1,3 +1,39 @@
|
|
1
|
+
Before do
|
2
|
+
@aruba_timeout_seconds = 120
|
3
|
+
step 'a valid pry configuration file'
|
4
|
+
step 'a mocked home directory'
|
5
|
+
end
|
6
|
+
|
7
|
+
Given(/^a valid pry configuration file$/) do
|
8
|
+
ENV['PRYRC'] = File.join(ENV['HOME'], '.pryrc')
|
9
|
+
end
|
10
|
+
|
11
|
+
# Clean environment
|
12
|
+
Around do |_, block|
|
13
|
+
old_env = ENV.to_h
|
14
|
+
block.call
|
15
|
+
ENV.replace old_env
|
16
|
+
end
|
17
|
+
|
18
|
+
When(/^I start debugging/) do
|
19
|
+
# rubocop:disable Lint/Debugger
|
20
|
+
require 'pry'
|
21
|
+
binding.pry
|
22
|
+
# rubocop:enable Lint/Debugger
|
23
|
+
|
24
|
+
''
|
25
|
+
end
|
26
|
+
|
27
|
+
When(/^I run `([^`]+)` in debug mode$/) do |cmd|
|
28
|
+
in_current_dir do
|
29
|
+
# rubocop:disable Lint/Debugger
|
30
|
+
require 'pry'
|
31
|
+
binding.pry
|
32
|
+
# rubocop:enable Lint/Debugger
|
33
|
+
system(cmd)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
1
37
|
Given(/^a letter named "(.*?)" does not exist$/) do |name|
|
2
38
|
in_current_dir do
|
3
39
|
FileUtils.rm_f name
|
@@ -8,6 +44,14 @@ Then(/^a letter named "(.*?)" should exist$/) do |name|
|
|
8
44
|
step %(a file named "#{name}.tex" should exist)
|
9
45
|
end
|
10
46
|
|
47
|
+
Given(/^the data file "(.*?)" with:$/) do |name, string|
|
48
|
+
step %(a file named "#{name}.yaml" with:), string
|
49
|
+
end
|
50
|
+
|
51
|
+
Given(/^the default letter template exist in working directory$/) do
|
52
|
+
step %(a local letter template named "letter" with:), File.read(File.expand_path('../../templates/letter.tex.tt', __FILE__))
|
53
|
+
end
|
54
|
+
|
11
55
|
Given(/^the default letter template$/) do
|
12
56
|
step %(a letter template named "letter" with:), File.read(File.expand_path('../../templates/letter.tex.tt', __FILE__))
|
13
57
|
end
|
@@ -16,6 +60,10 @@ Given(/^a letter template named "(.*?)" with:$/) do |name, string|
|
|
16
60
|
step %(a file named "~/.config/letter_generator/templates/#{name}.tex.tt" with:), string
|
17
61
|
end
|
18
62
|
|
63
|
+
Given(/^a local letter template named "(.*?)" with:$/) do |name, string|
|
64
|
+
step %(a file named "templates/#{name}.tex.tt" with:), string
|
65
|
+
end
|
66
|
+
|
19
67
|
Given(/^a config file named "(.*?)" with:$/) do |name, string|
|
20
68
|
step %(a file named "~/.config/letter_generator/#{name}" with:), string
|
21
69
|
end
|
@@ -24,6 +72,18 @@ Given(/^a data file named "(.*?)" does not exist$/) do |name|
|
|
24
72
|
in_current_dir { FileUtils.rm_f File.expand_path("#{name}.yaml") }
|
25
73
|
end
|
26
74
|
|
27
|
-
Then(/^
|
75
|
+
Then(/^the data file "(.*?)" should contain:$/) do |name, string|
|
28
76
|
step %(the file "#{name}.yaml" should contain:), string
|
29
77
|
end
|
78
|
+
|
79
|
+
Then(/^the letter "(.*?)" should contain:$/) do |name, string|
|
80
|
+
step %(the file "#{name}.tex" should contain:), string
|
81
|
+
end
|
82
|
+
|
83
|
+
Then(/^the local letter template "(.*?)" should exist$/) do |name|
|
84
|
+
step %(a file named "templates/#{name}.tex.tt" should exist)
|
85
|
+
end
|
86
|
+
|
87
|
+
Then(/^the user letter template "(.*?)" should exist$/) do |name|
|
88
|
+
step %(a file named "~/.config/letter_generator/templates/#{name}.tex.tt" should exist)
|
89
|
+
end
|
data/letter_generator.gemspec
CHANGED
data/lib/letter_generator.rb
CHANGED
@@ -1,21 +1,36 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'thor/actions'
|
3
|
+
require 'thor/group'
|
3
4
|
require 'tilt'
|
4
5
|
require 'psych'
|
6
|
+
require 'rake/file_list'
|
5
7
|
require 'active_support'
|
6
8
|
require 'active_support/core_ext'
|
7
9
|
require 'fedux_org_stdlib/file_template'
|
10
|
+
require 'fedux_org_stdlib/directory_finder'
|
8
11
|
require 'fedux_org_stdlib/app_config'
|
9
12
|
require 'fedux_org_stdlib/logging/logger'
|
13
|
+
require 'fedux_org_stdlib/core_ext/string/characterize'
|
10
14
|
|
15
|
+
require 'letter_generator/generators/tex_file_generator'
|
16
|
+
require 'letter_generator/templates_directory'
|
11
17
|
require 'letter_generator/letter_template'
|
12
18
|
require 'letter_generator/logger'
|
13
19
|
require 'letter_generator/application_config'
|
14
20
|
require 'letter_generator/main'
|
21
|
+
|
22
|
+
LetterGenerator.enable_debug_mode if ENV.key? 'DEBUG'
|
23
|
+
|
15
24
|
require 'letter_generator/version'
|
16
25
|
require 'letter_generator/logger'
|
26
|
+
require 'letter_generator/sender'
|
27
|
+
require 'letter_generator/addressee'
|
28
|
+
require 'letter_generator/output_file'
|
29
|
+
require 'letter_generator/metadata_file'
|
30
|
+
require 'letter_generator/metadata_parser'
|
31
|
+
require 'letter_generator/metadata_proxy'
|
17
32
|
require 'letter_generator/generator'
|
18
|
-
require 'letter_generator/
|
33
|
+
require 'letter_generator/metadata'
|
19
34
|
require 'letter_generator/runner'
|
20
35
|
|
21
36
|
module LetterGenerator
|
@@ -2,6 +2,8 @@ module LetterGenerator
|
|
2
2
|
class ApplicationConfig < FeduxOrgStdlib::AppConfig
|
3
3
|
option :template, LetterTemplate.new.file
|
4
4
|
option :debugging_libraries, %w(pry byebug)
|
5
|
+
option :debug_mode, false
|
6
|
+
option :templates_directory, TemplatesDirectory.new.directory
|
5
7
|
|
6
8
|
def _application_name
|
7
9
|
'letter_generator'
|
@@ -10,8 +10,14 @@ module LetterGenerator
|
|
10
10
|
@template = Tilt::ErubisTemplate.new(template_file)
|
11
11
|
end
|
12
12
|
|
13
|
-
def run(
|
14
|
-
|
13
|
+
def run(metadata, file)
|
14
|
+
metadata.to.each do |addressee|
|
15
|
+
path = file.path_for(addressee.name)
|
16
|
+
content = template.render(MetadataProxy.new(addressee, metadata))
|
17
|
+
|
18
|
+
FileUtils.mkdir_p(File.dirname(path))
|
19
|
+
File.write(path, content)
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module LetterGenerator
|
2
|
+
module Generators
|
3
|
+
class TexFileGenerator < Thor::Group
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
def self.exit_on_failure?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
class_option :output_file, required: true, desc: 'Outputfile'
|
11
|
+
argument :input_file, required: true
|
12
|
+
|
13
|
+
def generate
|
14
|
+
metadata_file = MetadataFile.new
|
15
|
+
|
16
|
+
metadata_parser = MetadataParser.new
|
17
|
+
metadata = metadata_parser.parse(metadata_file.path)
|
18
|
+
|
19
|
+
output_file = OutputFile.new(options[:output_file])
|
20
|
+
|
21
|
+
generator = Generator.new(input_file)
|
22
|
+
generator.run(metadata, output_file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,29 +1,21 @@
|
|
1
1
|
module LetterGenerator
|
2
|
-
class
|
2
|
+
class Metadata
|
3
3
|
private
|
4
4
|
|
5
5
|
attr_reader :data
|
6
6
|
|
7
7
|
public
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
|
11
|
-
|
12
|
-
if file
|
13
|
-
@data = Psych.load_file(file).deep_symbolize_keys
|
14
|
-
else
|
15
|
-
@data = {}
|
16
|
-
end
|
17
|
-
rescue
|
18
|
-
@data = {}
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
19
11
|
end
|
20
12
|
|
21
13
|
def from
|
22
|
-
@from ||=
|
14
|
+
@from ||= Sender.new(data[:from])
|
23
15
|
end
|
24
16
|
|
25
17
|
def to
|
26
|
-
@to ||=
|
18
|
+
@to ||= [data[:to]].flatten.map { |t| Addressee.new(t) }
|
27
19
|
end
|
28
20
|
|
29
21
|
def opening
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module LetterGenerator
|
2
|
+
class MetadataProxy < Delegator
|
3
|
+
attr_reader :to
|
4
|
+
|
5
|
+
def initialize(to, obj)
|
6
|
+
@to = to
|
7
|
+
@delegate_sd_obj = obj
|
8
|
+
end
|
9
|
+
|
10
|
+
def __getobj__
|
11
|
+
@delegate_sd_obj
|
12
|
+
end
|
13
|
+
|
14
|
+
def __setobj__(obj)
|
15
|
+
@delegate_sd_obj = obj
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module LetterGenerator
|
2
|
+
class OutputFile
|
3
|
+
private
|
4
|
+
|
5
|
+
attr_reader :template
|
6
|
+
|
7
|
+
public
|
8
|
+
|
9
|
+
def initialize(template)
|
10
|
+
@template = Tilt::ErubisTemplate.new{ template }
|
11
|
+
end
|
12
|
+
|
13
|
+
def path_for(object)
|
14
|
+
Pathname.new(File.expand_path(template.render(object.to_s.characterize)))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,21 +6,57 @@ module LetterGenerator
|
|
6
6
|
true
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
class_option :debug_mode, type: :boolean, default: LetterGenerator.config.debug_mode, desc: 'Enabled debug mode'
|
10
10
|
|
11
|
+
option :output_file, default: 'letter-<%= to_s %>.tex', desc: 'Outputfile'
|
11
12
|
desc 'generate', 'Generate template'
|
12
13
|
def generate
|
13
|
-
|
14
|
-
template = LetterTemplate.new
|
14
|
+
enable_debug_mode
|
15
15
|
|
16
|
-
|
17
|
-
generator.run(content, options[:output_file])
|
16
|
+
invoke 'letter_generator:generators:tex_file_generator', [LetterTemplate.new.file], output_file: options[:output_file]
|
18
17
|
end
|
19
18
|
|
20
|
-
|
19
|
+
option :build_directory, default: 'build', desc: 'Build directory'
|
20
|
+
desc 'build', 'Build letter'
|
21
|
+
def build
|
22
|
+
enable_debug_mode
|
23
|
+
|
24
|
+
invoke :generate, [], output_file: File.join(options[:build_directory], 'letter-<%= to_s %>.tex')
|
25
|
+
|
26
|
+
Dir.chdir File.expand_path(options[:build_directory]) do
|
27
|
+
Rake::FileList.new('*.tex').each do |f|
|
28
|
+
run %(pdflatex #{f})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'init', 'Init configuration'
|
34
|
+
option :for, default: 'working-directory', enum: %(user working-directory), desc: 'Initialize user configuration'
|
21
35
|
def init
|
36
|
+
enable_debug_mode
|
37
|
+
|
22
38
|
source_paths << File.expand_path('../../../templates', __FILE__)
|
23
|
-
|
39
|
+
letter_template = LetterTemplate.new
|
40
|
+
|
41
|
+
template_path = File.expand_path(File.join('templates', File.basename(letter_template.file)))
|
42
|
+
|
43
|
+
case options[:for].to_s.to_sym
|
44
|
+
when :user || :u
|
45
|
+
copy_file letter_template.file, File.join(File.dirname(LetterGenerator.config.preferred_configuration_file), 'templates', File.basename(letter_template.file))
|
46
|
+
when :'working-directory' || :wd
|
47
|
+
|
48
|
+
template 'data', File.expand_path('data.yaml')
|
49
|
+
copy_file letter_template.file, template_path
|
50
|
+
else
|
51
|
+
fail ArgumentError, "#{options[:for]} is not a valid value for \"for\"."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
no_commands do
|
56
|
+
# Enable debug mode
|
57
|
+
def enable_debug_mode
|
58
|
+
LetterGenerator.enable_debug_mode if options[:debug_mode] == true
|
59
|
+
end
|
24
60
|
end
|
25
61
|
end
|
26
62
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
template_files = Rake::FileList.new('*.tt')
|
2
|
+
tex_files = template_files.ext 'tex'
|
3
|
+
pdf_files = tex_files.ext 'pdf'
|
4
|
+
|
5
|
+
rule pdf_files => tex_files do |t|
|
6
|
+
sh %(pdflatex #{t.source})
|
7
|
+
end
|
8
|
+
|
9
|
+
rule tex_files => template_files do |t|
|
10
|
+
Generators::TexFileGenerator.invoke(t.source, output_files: t.name)
|
11
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: letter_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- dev@fedux.org
|
@@ -102,6 +116,7 @@ files:
|
|
102
116
|
- bin/letter_generator
|
103
117
|
- bin/lg
|
104
118
|
- cucumber.yml
|
119
|
+
- features/build_letter.feature
|
105
120
|
- features/generate_letter.feature
|
106
121
|
- features/init_generator.feature
|
107
122
|
- features/step_definitions.rb
|
@@ -111,19 +126,28 @@ files:
|
|
111
126
|
- features/support/reporting.rb
|
112
127
|
- letter_generator.gemspec
|
113
128
|
- lib/letter_generator.rb
|
129
|
+
- lib/letter_generator/addressee.rb
|
114
130
|
- lib/letter_generator/application_config.rb
|
115
131
|
- lib/letter_generator/generate.rb
|
116
132
|
- lib/letter_generator/generator.rb
|
117
|
-
- lib/letter_generator/
|
133
|
+
- lib/letter_generator/generators/tex_file_generator.rb
|
118
134
|
- lib/letter_generator/letter_template.rb
|
119
135
|
- lib/letter_generator/logger.rb
|
120
136
|
- lib/letter_generator/main.rb
|
137
|
+
- lib/letter_generator/metadata.rb
|
138
|
+
- lib/letter_generator/metadata_file.rb
|
139
|
+
- lib/letter_generator/metadata_parser.rb
|
140
|
+
- lib/letter_generator/metadata_proxy.rb
|
141
|
+
- lib/letter_generator/output_file.rb
|
121
142
|
- lib/letter_generator/runner.rb
|
143
|
+
- lib/letter_generator/sender.rb
|
144
|
+
- lib/letter_generator/templates_directory.rb
|
122
145
|
- lib/letter_generator/version.rb
|
123
146
|
- spec/support/aruba.rb
|
124
147
|
- spec/support/reporting.rb
|
125
148
|
- spec/support/rspec.rb
|
126
149
|
- spec/support/string.rb
|
150
|
+
- templates/Rakefile.tt
|
127
151
|
- templates/data.tt
|
128
152
|
- templates/letter.tex.tt
|
129
153
|
homepage: https://github.com/maxmeyer/letter_generator
|
@@ -151,6 +175,7 @@ signing_key:
|
|
151
175
|
specification_version: 4
|
152
176
|
summary: Generate letters
|
153
177
|
test_files:
|
178
|
+
- features/build_letter.feature
|
154
179
|
- features/generate_letter.feature
|
155
180
|
- features/init_generator.feature
|
156
181
|
- features/step_definitions.rb
|