k_builder 0.0.40 → 0.0.51
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/STORIES.md +22 -2
- data/USAGE.md +24 -24
- data/lib/k_builder.rb +1 -0
- data/lib/k_builder/base_builder.rb +60 -3
- data/lib/k_builder/file_segments.rb +32 -0
- data/lib/k_builder/layered_folders.rb +2 -2
- data/lib/k_builder/named_folders.rb +17 -1
- data/lib/k_builder/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 528f2587aacba6aa1d13d32737aa081b3ebb5364d3bc7e4628a2935a3746ff15
|
4
|
+
data.tar.gz: bb780d8e64e7c814e0b51c8561537a2cbdc31a1ab81f5ee4c78e8d3bb3fa1e89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d1dfa3e5875b691576390c970d8005036244566277fee71bbaebe5fc8e63e43588b87780c7616d8e5e07df838dcc3f2ccbf2d4edad8689d2308b8ce41e780e0
|
7
|
+
data.tar.gz: 2eda2bb2b6caa396b0a7ffa0052d22e1bd98fc2931fbb3eb1352ff0b2e0c4fe86880c70e947f456d862d7279bf862f948ffb1c8eea9f9581b29257eb75ded468
|
data/STORIES.md
CHANGED
@@ -10,14 +10,34 @@ As a Polyglot Developer, I want to be up and running in any development language
|
|
10
10
|
|
11
11
|
As a Polyglot Developer, I want to be up and running in any development language with consistency, so I am productive and using best practices [EPIC]
|
12
12
|
|
13
|
-
|
13
|
+
As a Developer, I need builders to be easier to use, so I am more efficient
|
14
14
|
|
15
|
-
|
15
|
+
- Logging needs to be more informative
|
16
|
+
- Template errors need to log the template and the filename
|
17
|
+
- add_file with template_file: needs to support optional filename that is the same as the template_file (or use a token, eg. $TF_PATH$, $TF_NAME$, $TF_FILE$
|
18
|
+
- add_file, the files being generated are not being logged
|
16
19
|
|
17
20
|
## Stories and tasks
|
18
21
|
|
22
|
+
### Stories - completed
|
23
|
+
|
24
|
+
As a Developer, I want have multiple template, so I can group my templates by area of specialty
|
25
|
+
|
26
|
+
- Refactor global and app templates to a layered folder array using (First In, Last Out) priority
|
27
|
+
- Support subfolders of any template folder (maybe)
|
28
|
+
|
29
|
+
As a Developer, I want have multiple output folders, so I can write to multiple locations
|
30
|
+
|
31
|
+
- Refactor output folder so that there are multiple named output folders, with :default working the same way as the existing system
|
32
|
+
- Support subfolders of any output folder
|
33
|
+
- Support output folder change of focus
|
34
|
+
|
19
35
|
### Tasks - completed
|
20
36
|
|
37
|
+
WatchBuilder - Build Watcher (as a builder) - [k_builder-watch](https://github.com/klueless-io/k_builder-watch)
|
38
|
+
|
39
|
+
Refactor BaseBuilder
|
40
|
+
|
21
41
|
Setup RubyGems and RubyDoc
|
22
42
|
|
23
43
|
- Build and deploy gem to [rubygems.org](https://rubygems.org/gems/k_builder)
|
data/USAGE.md
CHANGED
@@ -55,26 +55,26 @@ TEXT
|
|
55
55
|
|
56
56
|
builder = KBuilder::Builder.init
|
57
57
|
|
58
|
-
builder
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
58
|
+
builder.add_file('main.rb', template_file: 'class.rb', name: 'main').add_file(
|
59
|
+
'person.rb',
|
60
|
+
template_file: 'model.rb', name: 'person', fields: %i[first_name last_name]
|
61
|
+
).add_file(
|
62
|
+
'address.rb',
|
63
|
+
template_file: 'model.rb',
|
64
|
+
name: 'address',
|
65
|
+
fields: %i[street1 street2 post_code state]
|
66
|
+
).add_file(
|
67
|
+
'configuration.log.txt',
|
68
|
+
template: template,
|
69
|
+
a: builder.template_folder,
|
70
|
+
b: builder.global_template_folder,
|
71
|
+
c: builder.target_folder
|
72
|
+
).add_file(
|
73
|
+
'css/index.css',
|
74
|
+
template: '{{#each colors}} .{{.}} { color: {{.}} } {{/each}}',
|
75
|
+
colors: %w[red blue green],
|
76
|
+
pretty: true
|
77
|
+
)
|
78
78
|
```
|
79
79
|
|
80
80
|
#### Folder Structure (after)
|
@@ -85,7 +85,7 @@ Folder structure after running the builder
|
|
85
85
|
|
86
86
|
#### main.rb
|
87
87
|
|
88
|
-

|
89
89
|
|
90
90
|
#### person.rb
|
91
91
|
|
@@ -93,12 +93,12 @@ Folder structure after running the builder
|
|
93
93
|
|
94
94
|
#### address.rb
|
95
95
|
|
96
|
-

|
97
97
|
|
98
98
|
#### configuration.log.txt
|
99
99
|
|
100
|
-

|
101
101
|
|
102
102
|
#### css/index.css
|
103
103
|
|
104
|
-

|
data/lib/k_builder.rb
CHANGED
@@ -81,8 +81,9 @@ module KBuilder
|
|
81
81
|
# @option opts [String] :to Recipient email
|
82
82
|
# @option opts [String] :body The email's body
|
83
83
|
def add_file(file, **opts)
|
84
|
-
full_file = target_file(file)
|
84
|
+
full_file = opts.key?(:folder_key) ? target_file(file, folder: opts[:folder_key]) : target_file(file)
|
85
85
|
|
86
|
+
# Need logging options that can log these internal details
|
86
87
|
FileUtils.mkdir_p(File.dirname(full_file))
|
87
88
|
|
88
89
|
content = process_any_content(**opts)
|
@@ -94,6 +95,42 @@ module KBuilder
|
|
94
95
|
|
95
96
|
self
|
96
97
|
end
|
98
|
+
alias touch add_file # it is expected that you would not supply any options, just a file name
|
99
|
+
|
100
|
+
# Add content to the clipboard
|
101
|
+
#
|
102
|
+
# @option opts [String] :content Supply the content that you want to write to the file
|
103
|
+
# @option opts [String] :template Supply the template that you want to write to the file, template will be processed ('nobody') From address
|
104
|
+
# @option opts [String] :content_file File with content, file location is based on where the program is running
|
105
|
+
# @option opts [String] :template_file File with handlebars templated content that will be transformed, file location is based on the configured template_path
|
106
|
+
#
|
107
|
+
# Extra options will be used as data for templates, e.g
|
108
|
+
# @option opts [String] :to Recipient email
|
109
|
+
# @option opts [String] :body The email's body
|
110
|
+
def add_clipboard(**opts)
|
111
|
+
content = process_any_content(**opts)
|
112
|
+
|
113
|
+
begin
|
114
|
+
IO.popen('pbcopy', 'w') { |f| f << content }
|
115
|
+
rescue Errno::ENOENT => e
|
116
|
+
if e.message == 'No such file or directory - pbcopy'
|
117
|
+
# May want to use this GEM in the future
|
118
|
+
# https://github.com/janlelis/clipboard
|
119
|
+
puts 'Clipboard paste is currently only supported on MAC'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
self
|
124
|
+
end
|
125
|
+
alias clipboard_copy add_clipboard
|
126
|
+
|
127
|
+
def vscode(*file_parts, folder: current_folder_key)
|
128
|
+
file = target_file(*file_parts, folder: folder)
|
129
|
+
|
130
|
+
rc "code #{file}"
|
131
|
+
|
132
|
+
self
|
133
|
+
end
|
97
134
|
|
98
135
|
# ----------------------------------------------------------------------
|
99
136
|
# Attributes: Think getter/setter
|
@@ -134,8 +171,28 @@ module KBuilder
|
|
134
171
|
end
|
135
172
|
|
136
173
|
# Get target file
|
137
|
-
|
138
|
-
|
174
|
+
#
|
175
|
+
# If you provide a relative folder, then it will be relative to the :folder parameter
|
176
|
+
#
|
177
|
+
# If the :folder is not set, then it will be relative to the current folder
|
178
|
+
#
|
179
|
+
# @examples
|
180
|
+
# target_file('abc.txt')
|
181
|
+
# target_file('xyz/abc.txt')
|
182
|
+
# target_file('xyz', 'abc.txt')
|
183
|
+
#
|
184
|
+
# If you provide an absolute folder, then it will ignore the :folder parameter
|
185
|
+
#
|
186
|
+
# @examples
|
187
|
+
# target_file('/abc.txt')
|
188
|
+
# target_file('/xyz/abc.txt')
|
189
|
+
# target_file('/xyz', 'abc.txt')
|
190
|
+
def target_file(*file_parts, folder: current_folder_key)
|
191
|
+
# Absolute path
|
192
|
+
return File.join(*file_parts) if Pathname.new(file_parts.first).absolute?
|
193
|
+
|
194
|
+
# Relative to :folder
|
195
|
+
File.join(target_folder(folder), *file_parts)
|
139
196
|
end
|
140
197
|
|
141
198
|
# Template folder & Files
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KBuilder
|
4
|
+
# Splits a file into its base parts (file, path, file_name, extension and file_name_only)
|
5
|
+
#
|
6
|
+
# Provides the interpolate helper to rebuild a different filename using those segments
|
7
|
+
class FileSegments
|
8
|
+
attr_reader :file
|
9
|
+
attr_reader :path
|
10
|
+
attr_reader :file_name
|
11
|
+
attr_reader :ext
|
12
|
+
attr_reader :file_name_only
|
13
|
+
|
14
|
+
def initialize(file)
|
15
|
+
@file = file
|
16
|
+
@path = File.dirname(file)
|
17
|
+
@file_name = File.basename(file)
|
18
|
+
@ext = File.extname(file)
|
19
|
+
@file_name_only = File.basename(file, @ext)
|
20
|
+
end
|
21
|
+
|
22
|
+
def interpolate(target_file)
|
23
|
+
# p str.gsub( /#{var}/, 'foo' ) # => "a test foo"
|
24
|
+
target_file
|
25
|
+
.gsub(/\$T_FILE\$/i, file)
|
26
|
+
.gsub(/\$T_PATH\$/i, path)
|
27
|
+
.gsub(/\$T_FILE_NAME\$/i, file_name)
|
28
|
+
.gsub(/\$T_EXT\$/i, ext)
|
29
|
+
.gsub(/\$T_FILE_NAME_ONLY\$/i, file_name_only)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -68,8 +68,8 @@ module KBuilder
|
|
68
68
|
@ordered_folders = orig.ordered_folders.clone
|
69
69
|
end
|
70
70
|
|
71
|
-
def add(folder_key,
|
72
|
-
folder = super(folder_key,
|
71
|
+
def add(folder_key, *folder_parts)
|
72
|
+
folder = super(folder_key, *folder_parts)
|
73
73
|
|
74
74
|
ordered_keys.prepend(folder_key)
|
75
75
|
ordered_folders.prepend(folder)
|
@@ -54,8 +54,10 @@ module KBuilder
|
|
54
54
|
@current = folder_key
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
# Add support for file_parts
|
58
|
+
def add(folder_key, *folder_parts)
|
58
59
|
# get a predefined folder by symbol
|
60
|
+
folder = join_folder_parts(folder_parts)
|
59
61
|
if folder.is_a?(Symbol)
|
60
62
|
folder = get(folder)
|
61
63
|
elsif folder.start_with?('~')
|
@@ -93,6 +95,20 @@ module KBuilder
|
|
93
95
|
|
94
96
|
private
|
95
97
|
|
98
|
+
def join_folder_parts(folder_parts)
|
99
|
+
raise KBuilder::Error, 'No folder part provided' if folder_parts.nil? || folder_parts.length.zero?
|
100
|
+
|
101
|
+
# If only one part, and that can be a folder or :folder_key, then just return it
|
102
|
+
return folder_parts.first if folder_parts.length == 1
|
103
|
+
|
104
|
+
folder_parts = folder_parts.map.with_index do |folder_part, index|
|
105
|
+
folder_part = get(folder_part) if index.zero? && folder_part.is_a?(Symbol)
|
106
|
+
folder_part
|
107
|
+
end
|
108
|
+
|
109
|
+
File.join(folder_parts)
|
110
|
+
end
|
111
|
+
|
96
112
|
def guard_folder_key(folder_key)
|
97
113
|
raise KBuilder::Error, "Folder not found, this folder key not found: #{folder_key}" unless folders.key?(folder_key)
|
98
114
|
end
|
data/lib/k_builder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.51
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: handlebars-helpers
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/k_builder/base_configuration.rb
|
58
58
|
- lib/k_builder/configuration.rb
|
59
59
|
- lib/k_builder/data_helper.rb
|
60
|
+
- lib/k_builder/file_segments.rb
|
60
61
|
- lib/k_builder/layered_folders.rb
|
61
62
|
- lib/k_builder/named_folders.rb
|
62
63
|
- lib/k_builder/version.rb
|