fedux_org-stdlib 0.6.37 → 0.6.38
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fedux_org_stdlib/file_template.rb +51 -24
- data/lib/fedux_org_stdlib/version.rb +1 -1
- data/spec/template_file_spec.rb +73 -13
- data/spec/version_management/rubygem_version_file_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa5e47bfdb9fb2bef0245b9251bc1b6568795422
|
4
|
+
data.tar.gz: b793ab10a4b1184e6e1927907ffdeade19e75f87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6de22d0c95aa66f30bf08205e13b3507a262112d6d330c56c0760e32e0b62e8347c407d6a748a2df0f2b21d474927fc8c19860aaafd8cbebba2deef3a7541d07
|
7
|
+
data.tar.gz: 81c8a7486e8977b7f13650e5f2e2b8be0bfe25ce348915db915b050d90112fd4add22eb0937c7745ffa4e38b5daa05bd775f70473ddb0e0cd67f3b9bf743ac53
|
data/Gemfile.lock
CHANGED
@@ -78,10 +78,10 @@ module FeduxOrgStdlib
|
|
78
78
|
@logger = logger
|
79
79
|
@working_directory = working_directory
|
80
80
|
|
81
|
-
@file ||=
|
81
|
+
@file ||= available_template_file
|
82
82
|
|
83
83
|
unless @file
|
84
|
-
logger.debug "No template file found at #{
|
84
|
+
logger.debug "No template file found at #{allowed_template_file_paths.to_list}, therefor I'm going to use an empty template object instead."
|
85
85
|
@content = ''
|
86
86
|
|
87
87
|
return
|
@@ -98,7 +98,7 @@ module FeduxOrgStdlib
|
|
98
98
|
# @return [String]
|
99
99
|
# The path to the preferred template file
|
100
100
|
def preferred_template_file
|
101
|
-
|
101
|
+
allowed_template_file_paths[1]
|
102
102
|
end
|
103
103
|
|
104
104
|
private
|
@@ -109,16 +109,16 @@ module FeduxOrgStdlib
|
|
109
109
|
# The name of the template file. It defaults to `<template_name>.yaml`. If
|
110
110
|
# you want to use a different file name you need to overwrite this
|
111
111
|
# method.
|
112
|
-
def
|
113
|
-
"#{
|
112
|
+
def template_file
|
113
|
+
"#{template_name}#{template_file_suffix}"
|
114
114
|
end
|
115
115
|
|
116
116
|
# The suffix of the template file
|
117
117
|
#
|
118
118
|
# @return [String]
|
119
119
|
# The suffix of the template file
|
120
|
-
def
|
121
|
-
'
|
120
|
+
def template_file_suffix
|
121
|
+
'*.tt'
|
122
122
|
end
|
123
123
|
|
124
124
|
# The base name of the template
|
@@ -132,12 +132,12 @@ module FeduxOrgStdlib
|
|
132
132
|
# class ClientTemplate; end
|
133
133
|
#
|
134
134
|
# This will result in `client` as base name for the template file.
|
135
|
-
def
|
136
|
-
unless (name =
|
135
|
+
def template_name
|
136
|
+
unless (name = class_name.sub(/Template/, '').underscore.singularize).blank?
|
137
137
|
return name
|
138
138
|
end
|
139
139
|
|
140
|
-
fail Exceptions::ClassNameIsMissing, JSON.dump(klass:
|
140
|
+
fail Exceptions::ClassNameIsMissing, JSON.dump(klass: class_name)
|
141
141
|
end
|
142
142
|
|
143
143
|
# The name of your application
|
@@ -153,8 +153,8 @@ module FeduxOrgStdlib
|
|
153
153
|
# This will be converted to
|
154
154
|
#
|
155
155
|
# my_application
|
156
|
-
def
|
157
|
-
|
156
|
+
def application_name
|
157
|
+
module_name.underscore
|
158
158
|
end
|
159
159
|
|
160
160
|
# The paths where to look for the template file
|
@@ -162,35 +162,62 @@ module FeduxOrgStdlib
|
|
162
162
|
# @return [Array]
|
163
163
|
# A list of paths where the template object should look for its template
|
164
164
|
# file.
|
165
|
-
def
|
165
|
+
def allowed_template_file_paths
|
166
166
|
paths = []
|
167
|
-
|
168
|
-
paths <<
|
169
|
-
paths <<
|
170
|
-
paths <<
|
171
|
-
paths <<
|
167
|
+
|
168
|
+
paths << resolve_path(working_directory, 'templates', template_file)
|
169
|
+
paths << resolve_path('~', '.config', application_name, 'templates', template_file)
|
170
|
+
paths << resolve_path('~', format('.%s', application_name), 'templates', template_file)
|
171
|
+
paths << resolve_path('/etc', application_name, 'templates', template_file)
|
172
|
+
paths << resolve_path(fallback_template_directory, template_file) if fallback_template_directory
|
172
173
|
|
173
174
|
paths
|
174
175
|
end
|
175
176
|
|
177
|
+
def resolve_path(*path)
|
178
|
+
::File.expand_path(::File.join(*path))
|
179
|
+
end
|
180
|
+
|
176
181
|
|
177
182
|
# Use this path as fall back path
|
178
|
-
def
|
183
|
+
def fallback_template_directory; end
|
179
184
|
|
180
|
-
def
|
185
|
+
def class_name
|
181
186
|
self.class.name.to_s.demodulize
|
182
187
|
end
|
183
188
|
|
184
|
-
def
|
189
|
+
def module_name
|
185
190
|
self.class.to_s.deconstantize
|
186
191
|
end
|
187
192
|
|
188
|
-
def
|
189
|
-
|
193
|
+
def available_template_file
|
194
|
+
allowed_template_file_paths.map { |f| Dir.glob(f).first }.find { |f| !f.blank? && ::File.exists?(f) }
|
190
195
|
end
|
191
196
|
|
192
|
-
def self.
|
197
|
+
def self.reserved_key_words
|
193
198
|
(methods | instance_methods | private_methods | private_instance_methods ) - (Class.methods | Class.private_methods ) | [:to_s]
|
194
199
|
end
|
200
|
+
|
201
|
+
def basename
|
202
|
+
File.basename(file, '.tt')
|
203
|
+
end
|
204
|
+
|
205
|
+
def extname
|
206
|
+
File.extname(basename)
|
207
|
+
end
|
208
|
+
|
209
|
+
def extname?(*ext)
|
210
|
+
ext.any? { |e| e == extname }
|
211
|
+
end
|
212
|
+
|
213
|
+
public
|
214
|
+
|
215
|
+
def proposed_extname
|
216
|
+
ext = File.extname(basename)
|
217
|
+
|
218
|
+
return '.erb' if ext.blank?
|
219
|
+
|
220
|
+
ext
|
221
|
+
end
|
195
222
|
end
|
196
223
|
end
|
data/spec/template_file_spec.rb
CHANGED
@@ -3,22 +3,21 @@ require 'spec_helper'
|
|
3
3
|
require 'fedux_org_stdlib/file_template'
|
4
4
|
|
5
5
|
RSpec.describe FileTemplate do
|
6
|
-
|
7
6
|
context '#preferred_template_file' do
|
8
7
|
it 'has a default template file which is the preferred place to store the template' do
|
9
8
|
with_environment 'HOME' => working_directory do
|
10
9
|
template_klass = Class.new(FileTemplate) do
|
11
|
-
def
|
10
|
+
def class_name
|
12
11
|
'TestTemplate'
|
13
12
|
end
|
14
13
|
|
15
|
-
def
|
14
|
+
def module_name
|
16
15
|
'MyApplication'
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
19
|
template = template_klass.new
|
21
|
-
expect(template.preferred_template_file).to eq File.expand_path('~/.config/my_application/templates/test
|
20
|
+
expect(template.preferred_template_file).to eq File.expand_path('~/.config/my_application/templates/test*.tt')
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
@@ -26,17 +25,17 @@ RSpec.describe FileTemplate do
|
|
26
25
|
with_environment 'HOME' => working_directory do
|
27
26
|
template_klass = Class.new(FileTemplate) do
|
28
27
|
|
29
|
-
def
|
28
|
+
def class_name
|
30
29
|
'TestTemplate'
|
31
30
|
end
|
32
31
|
|
33
|
-
def
|
32
|
+
def module_name
|
34
33
|
'MyApplication::MySub'
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
37
|
template = template_klass.new
|
39
|
-
expect(template.preferred_template_file).to eq File.expand_path('~/.config/my_application/my_sub/templates/test
|
38
|
+
expect(template.preferred_template_file).to eq File.expand_path('~/.config/my_application/my_sub/templates/test*.tt')
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
@@ -49,11 +48,11 @@ RSpec.describe FileTemplate do
|
|
49
48
|
EOS
|
50
49
|
|
51
50
|
template_klass = Class.new(FileTemplate) do
|
52
|
-
def
|
51
|
+
def class_name
|
53
52
|
'TestTemplate'
|
54
53
|
end
|
55
54
|
|
56
|
-
def
|
55
|
+
def module_name
|
57
56
|
'MyApplication'
|
58
57
|
end
|
59
58
|
end
|
@@ -70,11 +69,32 @@ RSpec.describe FileTemplate do
|
|
70
69
|
EOS
|
71
70
|
|
72
71
|
template_klass = Class.new(FileTemplate) do
|
73
|
-
def
|
72
|
+
def class_name
|
73
|
+
'TestTemplate'
|
74
|
+
end
|
75
|
+
|
76
|
+
def module_name
|
77
|
+
'MyApplication'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
template = template_klass.new
|
82
|
+
expect(template.content).to include 'hello world'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'supports star operator in suffix: ~/.my_application/templates/test*.tt' do
|
87
|
+
with_environment 'HOME' => working_directory do
|
88
|
+
create_file '.my_application/templates/test.erb.tt', <<-EOS.strip_heredoc
|
89
|
+
<%= hello world %>
|
90
|
+
EOS
|
91
|
+
|
92
|
+
template_klass = Class.new(FileTemplate) do
|
93
|
+
def class_name
|
74
94
|
'TestTemplate'
|
75
95
|
end
|
76
96
|
|
77
|
-
def
|
97
|
+
def module_name
|
78
98
|
'MyApplication'
|
79
99
|
end
|
80
100
|
end
|
@@ -93,11 +113,11 @@ RSpec.describe FileTemplate do
|
|
93
113
|
EOS
|
94
114
|
|
95
115
|
template_klass = Class.new(FileTemplate) do
|
96
|
-
def
|
116
|
+
def class_name
|
97
117
|
'TestTemplate'
|
98
118
|
end
|
99
119
|
|
100
|
-
def
|
120
|
+
def module_name
|
101
121
|
'MyApplication'
|
102
122
|
end
|
103
123
|
end
|
@@ -107,4 +127,44 @@ RSpec.describe FileTemplate do
|
|
107
127
|
end
|
108
128
|
end
|
109
129
|
end
|
130
|
+
|
131
|
+
context '#proposed_extname' do
|
132
|
+
it 'propose a erb as default extname' do
|
133
|
+
with_environment 'HOME' => working_directory do
|
134
|
+
create_file '.my_application/templates/test.tt'
|
135
|
+
|
136
|
+
template_klass = Class.new(FileTemplate) do
|
137
|
+
def class_name
|
138
|
+
'TestTemplate'
|
139
|
+
end
|
140
|
+
|
141
|
+
def module_name
|
142
|
+
'MyApplication'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
template = template_klass.new
|
147
|
+
expect(template.proposed_extname).to eq '.erb'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'extracts the extname from file name' do
|
152
|
+
with_environment 'HOME' => working_directory do
|
153
|
+
create_file '.my_application/templates/test.md.tt'
|
154
|
+
|
155
|
+
template_klass = Class.new(FileTemplate) do
|
156
|
+
def class_name
|
157
|
+
'TestTemplate'
|
158
|
+
end
|
159
|
+
|
160
|
+
def module_name
|
161
|
+
'MyApplication'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
template = template_klass.new
|
166
|
+
expect(template.proposed_extname).to eq '.md'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
110
170
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fedux_org-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|