k_builder 0.0.53 → 0.0.55

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
  SHA256:
3
- metadata.gz: 122c7daee609c40dbd918d5bb98640c3850d3cb0c54eeabee10e4d4082c036f3
4
- data.tar.gz: 3c2041cd23f31b624860a141858f0c54ac995cf49b277bd591acb94a37cb1456
3
+ metadata.gz: 3f0600bab4a6de1743b8be1d7f14f4cc20e997edc60201e920fd3102086472bf
4
+ data.tar.gz: ad10a064ebf45d8e73aac310b7c6725193f3cf36bacc847f0fe2e312919c0b1b
5
5
  SHA512:
6
- metadata.gz: ae5aa592ffe9845c5438a80761a2ee8dccf358d4d32cfa6f84926038d64433c9e041911ba464c29811617b871a3c174baadb23d2dadb57bf76bcd9de44487ff9
7
- data.tar.gz: c009caabf877b46d424e529bce376477835153338eef1b6bd2fd833fdbfb3b7cca157238823efd86aa44513c0ba5bd7e7fab5571a9799666ba9ab81624e4cb7f
6
+ metadata.gz: b3c82683757bf60d630b3e9e6827b57abbaca1bbd83b132e7dd1433961f8946acd651beb5eebf8614cbcd5ad544ea7aa8b7bfd7a7c48feadf87a3e0d8c651acf
7
+ data.tar.gz: d8c7778a7501ccf7a76611bf15aae7d3824658e48e5249c2a1f7879fad7b18ae354323fe92794171737b1ddd386e38ab254f9f399895acd8af86014f3688e98c
data/k_builder.gemspec CHANGED
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
40
40
 
41
41
  spec.add_dependency 'handlebars-helpers', '~> 0'
42
42
  spec.add_dependency 'k_log', '~> 0'
43
+ spec.add_dependency 'k_type', '~> 0'
43
44
  spec.add_dependency 'k_util', '~> 0'
44
45
  # spec.add_dependency "anyway_config" , ">= 2.0.0"
45
46
  # spec.add_dependency "config" , ">= 3.0.0"
data/lib/k_builder.rb CHANGED
@@ -1,30 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'k_log'
4
+ require 'k_util'
5
+ require 'k_type'
3
6
  require 'k_builder/version'
4
7
  require 'k_builder/base_builder'
5
8
  require 'k_builder/base_configuration'
6
9
  require 'k_builder/configuration'
7
10
  require 'k_builder/file_segments'
8
- require 'k_builder/named_folders'
9
- require 'k_builder/layered_folders'
10
- require 'k_log'
11
- require 'k_util'
12
11
 
13
12
  require 'handlebars/helpers/template'
14
13
 
15
14
  module KBuilder
16
15
  # raise KBuilder::Error, 'Sample message'
17
16
  class Error < StandardError; end
18
-
19
- # Need to move this into a KLog factory
20
- def self.configure_logger
21
- logger = Logger.new($stdout)
22
- logger.level = Logger::DEBUG
23
- logger.formatter = KLog::LogFormatter.new
24
- KLog::LogUtil.new(logger)
25
- end
26
17
  end
27
18
 
28
- L = KBuilder.configure_logger
29
-
30
- puts "KBuilder::Version: #{KBuilder::VERSION}" if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
19
+ if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
20
+ namespace = 'KBuilder::Version'
21
+ file_path = $LOADED_FEATURES.find { |f| f.include?('k_builder/version') }
22
+ version = KBuilder::VERSION.ljust(9)
23
+ puts "#{namespace.ljust(40)} : #{version.ljust(9)} : #{file_path}"
24
+ end
@@ -21,6 +21,8 @@ module KBuilder
21
21
 
22
22
  # Configuration class
23
23
  class Configuration < BaseConfiguration
24
+ include KLog::Logging
25
+
24
26
  attr_accessor :target_folders
25
27
  attr_accessor :template_folders
26
28
 
@@ -29,8 +31,8 @@ module KBuilder
29
31
  # @target_folder = Dir.getwd
30
32
  # @template_folder = File.join(Dir.getwd, '.templates')
31
33
  # @global_template_folder = nil
32
- @target_folders = NamedFolders.new
33
- @template_folders = LayeredFolders.new
34
+ @target_folders = KType::NamedFolders.new
35
+ @template_folders = KType::LayeredFolders.new
34
36
  end
35
37
 
36
38
  def initialize_copy(orig)
@@ -42,20 +44,20 @@ module KBuilder
42
44
 
43
45
  # rubocop:disable Metrics/AbcSize
44
46
  def debug
45
- L.subheading 'kbuilder base configuration'
47
+ log.subheading 'kbuilder base configuration'
46
48
 
47
- L.section_heading 'target_folders'
49
+ log.section_heading 'target_folders'
48
50
  target_folders.folders.each_key do |key|
49
51
  folder = target_folders.folders[key]
50
- L.kv key.to_s, folder
52
+ log.kv key.to_s, folder
51
53
  end
52
- L.info ''
54
+ log.info ''
53
55
 
54
- L.section_heading 'template folders (search order)'
56
+ log.section_heading 'template folders (search order)'
55
57
 
56
58
  template_folders.ordered_keys.each do |key|
57
59
  folder = template_folders.folders[key]
58
- L.kv key.to_s, folder
60
+ log.kv key.to_s, folder
59
61
  end
60
62
  ''
61
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KBuilder
4
- VERSION = '0.0.53'
4
+ VERSION = '0.0.55'
5
5
  end
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.53
4
+ version: 0.0.55
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-04-01 00:00:00.000000000 Z
11
+ date: 2021-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: handlebars-helpers
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: k_type
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: k_util
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -85,8 +99,6 @@ files:
85
99
  - lib/k_builder/base_configuration.rb
86
100
  - lib/k_builder/configuration.rb
87
101
  - lib/k_builder/file_segments.rb
88
- - lib/k_builder/layered_folders.rb
89
- - lib/k_builder/named_folders.rb
90
102
  - lib/k_builder/version.rb
91
103
  - usage/_out1.png
92
104
  - usage/_out2.png
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KBuilder
4
- #
5
- # Named folders makes sense for generated/output folders because you may want
6
- # more than one type of location to generate output.
7
- #
8
- # Don't confuse multiple named output folders with sub-paths, when you want to
9
- # build up a file name in a child folder, you can do that as part of building
10
- # the filename.
11
- #
12
- # The idea behind named folders is for when you have two or more totally different
13
- # outputs that (may live in the a similar location) or live in different locations.
14
-
15
- # Layered folders allow files to be found in any of the searchable folders
16
- #
17
- # They derive from and thus work just like named folders in that they allow folders
18
- # to be stored with easy to remember names/alias's.
19
- #
20
- # Where they differ is that they are retrieved in preferential search order that is
21
- # by default (First In, Last Out) priority aka a Stack (Last In, First Out) or
22
- # optionally over ridden via the search_order method
23
- #
24
- # Layered folders makes sense for use with template files and source data/model
25
- # where you can have specific usage files available and if they are not found then
26
- # you can use fall-back files in other folders.
27
- #
28
- # example:
29
- # folders = LayeredFolders.new
30
- # folders.add(:global , '~/global_templates')
31
- # folders.add(:domain , '/my-project/domain_templates')
32
- # folders.add(:app , '/my-project/my-app/.templates')
33
- #
34
- # # Find a file and folder will in folders in this order
35
- # # app_templates, then domain_templates and then finally global templates
36
- # # ['/my-project/my-app/.templates', '/my-project/domain_templates', '~/global_templates']
37
- # #
38
- # # Find a file called template1.txt and return its fully-qualified path
39
- # folders.find_file('template1.txt')
40
- #
41
- # # As above, but returns the folder only, file name and sub-paths are ignored
42
- # folders.find_file_folder('template1.txt')
43
- # folders.find_file_folder('abc/xyz/deep-template.txt')
44
- #
45
- # # If an additional folder is added, say in child configuration that is designed
46
- # # to override some of the global templates, then you can run a search_order
47
- # # method to re-order the templates
48
- #
49
- # folders.add(:global_shim , '~/global_templates_shim')
50
- # folders.search_order(:app, :domain, :global_shim, :global)
51
- #
52
- # class Builder < KBuilder::BaseBuilder
53
- class LayeredFolders < KBuilder::NamedFolders
54
- attr_reader :ordered_keys
55
- attr_reader :ordered_folders
56
-
57
- def initialize
58
- super()
59
-
60
- @ordered_keys = []
61
- @ordered_folders = []
62
- end
63
-
64
- def initialize_copy(orig)
65
- super(orig)
66
-
67
- @ordered_keys = orig.ordered_keys.clone
68
- @ordered_folders = orig.ordered_folders.clone
69
- end
70
-
71
- def add(folder_key, *folder_parts)
72
- folder = super(folder_key, *folder_parts)
73
-
74
- ordered_keys.prepend(folder_key)
75
- ordered_folders.prepend(folder)
76
-
77
- folder
78
- end
79
-
80
- # File name or array of sub-paths plus file
81
- #
82
- # Return the folder that a file is found in
83
- def find_file(file_parts)
84
- folder = find_file_folder(file_parts)
85
- folder.nil? ? nil : File.join(folder, file_parts)
86
- end
87
-
88
- # File name or array of sub-paths plus file
89
- #
90
- # Return the folder that a file is found in
91
- def find_file_folder(file_parts)
92
- ordered_folders.find { |folder| File.exist?(File.join(folder, file_parts)) }
93
- end
94
-
95
- def to_h
96
- {
97
- ordered: {
98
- keys: ordered_keys,
99
- folders: ordered_folders
100
- }
101
- }.merge(@folders)
102
- end
103
- end
104
- end
@@ -1,116 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KBuilder
4
- # Named folders allow folders to be stored with easy to remember names/alias's
5
- # Secondarily, you can also build up file names based on these named folders.
6
- #
7
- # Named folders makes sense for generated/output folders because you may want
8
- # more than one type of location to generate output.
9
- #
10
- # Don't confuse multiple named output folders with sub-paths, when you want to
11
- # build up a file name in a child folder, you can do that as part of building
12
- # the filename.
13
- #
14
- # The idea behind named folders is for when you have two or more totally different
15
- # outputs that (may live in the a similar location) or live in different locations.
16
- # Samples:
17
- # name: :code - generating source code into a project
18
- # name: :slide - generating slide deck into a documentation folder
19
- # name: :webpack - folder where you might generate webpack files, e.g. webpack.config.*.json
20
- #
21
- # example:
22
- # folders = NamedFolders.new
23
- # folders.add(:csharp , '~/dev/csharp/cool-project')
24
- # folders.add(:package_json , :csharp)
25
- # folders.add(:webpack , folders.join(:csharp, 'config'))
26
- # folders.add(:builder , folders.join(:csharp, 'builder'))
27
- # folders.add(:slides , '~/doc/csharp/cool-project')
28
- #
29
- # puts folders.get(:builder)
30
- #
31
- # puts folders.get_filename(:csharp, 'Program.cs')
32
- # puts folders.get_filename(:csharp, 'Models/Order.cs')
33
- # puts folders.get_filename(:csharp, 'Models', 'Order.cs')
34
- #
35
- # Do I need to support :default?
36
- class NamedFolders
37
- attr_reader :folders
38
-
39
- attr_reader :current
40
-
41
- def initialize
42
- @folders = {}
43
- @current = nil
44
- end
45
-
46
- def initialize_copy(orig)
47
- super(orig)
48
-
49
- @folders = orig.folders.clone
50
- end
51
-
52
- def current=(folder_key)
53
- guard_folder_key(folder_key)
54
- @current = folder_key
55
- end
56
-
57
- # Add support for file_parts
58
- def add(folder_key, *folder_parts)
59
- # get a predefined folder by symbol
60
- folder = join_folder_parts(folder_parts)
61
- if folder.is_a?(Symbol)
62
- folder = get(folder)
63
- elsif folder.start_with?('~')
64
- folder = File.expand_path(folder)
65
- end
66
-
67
- @current = folder_key if @current.nil?
68
- folders[folder_key] = folder
69
- end
70
-
71
- # Get a folder
72
- def get(folder_key)
73
- guard_folder_key(folder_key)
74
- folders[folder_key]
75
- end
76
-
77
- # Join the lookup folder key with the subpath folder parts (optionally + filename) and return the folder or filename
78
- #
79
- # Return fully qualified filename
80
- def join(folder_key, *file_folder_parts)
81
- folder = get(folder_key)
82
-
83
- File.join(folder, file_folder_parts)
84
- end
85
- # Get a file name using the lookup folder key and the file name or array of sub-paths plus filename
86
- alias get_filename join
87
-
88
- def folder_keys
89
- @folders.keys
90
- end
91
-
92
- def to_h
93
- @folders
94
- end
95
-
96
- private
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
-
112
- def guard_folder_key(folder_key)
113
- raise KBuilder::Error, "Folder not found, this folder key not found: #{folder_key}" unless folders.key?(folder_key)
114
- end
115
- end
116
- end