k_builder 0.0.69 → 0.0.74

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: 344376d8ceaffc96fb8ebc4c0add3456bc6a1ff97f7d1b017286a6f4ea523c09
4
- data.tar.gz: 51eb8ddb6f7e3b578442423f0dfd9c08759012caa33003d1ecec0849d435b342
3
+ metadata.gz: ba7eb819303b0c16a00de3d75a74276acbe7813d205a8b380395156b375977ed
4
+ data.tar.gz: 37fdae6f2e90fbe8f26f368a0565a8916f6911e2fa5696a4d7973f662397a27a
5
5
  SHA512:
6
- metadata.gz: 0dde58c5926b4ecdf4952ee40b4babc4111cf8e9578ee2bacb29f6f6a14915e954631b4ef1c09d4148002357640f7323879325ac61cc7da9c8e5d40bb0168971
7
- data.tar.gz: 1a6b81315dd4a09c7bd48e83e5f3fb3b35a2b179a3fdd4a79d1d6e87e9645d86ae054ecc1332eed8a5e24e4628117b53c30b445264975ad93dc03e8f9d6daf8e
6
+ metadata.gz: 4dbb5a5c8322b7d79331fc542f39d01ed6ac6540937468b59b89e95d34a3104b452bac4578f4862435e1e727081c53df5e031e9a0429ac34c13d178c5c43ead2
7
+ data.tar.gz: 8f86d00742b9d61bc3938a135535317688e098edc0f362e837dd2a958cfa8ae6c546d92c8d0ad5a94f499f6352e96cefe28f6d0215b07f13e13a0c9339a0e8fa
data/a.txt ADDED
File without changes
data/hooks/pre-commit CHANGED
@@ -8,8 +8,8 @@ require 'English'
8
8
 
9
9
  exit 0 if ARGV.include?('--no-verify')
10
10
 
11
- warning_keywords = %w[console.log]
12
- keywords = %w[binding.pry console.dir byebug debugger]
11
+ warning_keywords = %w[]
12
+ keywords = %w[binding.pry console.dir byebug]
13
13
  files_changed = `git diff-index --name-only HEAD --`.split
14
14
 
15
15
  # puts '----------------------------------------------------------------------'
data/hooks/update-version CHANGED
@@ -30,4 +30,4 @@ end
30
30
  output.push('')
31
31
 
32
32
  printf "%-25<label>s : %<version>s\n", label: 'GEM VERSION', version: version
33
- File.open('lib/k_builder/version.rb', 'w+') { |f| f.write(output.join("\n")) }
33
+ File.write('lib/k_builder/version.rb', output.join("\n"))
data/k_builder.gemspec CHANGED
@@ -38,11 +38,11 @@ Gem::Specification.new do |spec|
38
38
  spec.require_paths = ['lib']
39
39
  # spec.extensions = ['ext/k_builder/extconf.rb']
40
40
  spec.add_dependency 'handlebars-helpers', '~> 0'
41
+ spec.add_dependency 'k_config', '~> 0'
41
42
  spec.add_dependency 'k_log', '~> 0'
42
43
  spec.add_dependency 'k_type', '~> 0'
43
44
  spec.add_dependency 'k_util', '~> 0'
44
45
  spec.add_dependency 'rubocop', '~> 1.8'
45
46
 
46
- # spec.add_dependency "anyway_config" , ">= 2.0.0"
47
- # spec.add_dependency "config" , ">= 3.0.0"
47
+ spec.metadata['rubygems_mfa_required'] = 'true'
48
48
  end
@@ -54,7 +54,7 @@ module KBuilder
54
54
 
55
55
  # assigns a builder hash and defines builder methods
56
56
  def initialize(configuration = nil)
57
- configuration = KBuilder.configuration if configuration.nil?
57
+ configuration = KConfig.configuration if configuration.nil?
58
58
 
59
59
  @configuration = configuration
60
60
 
@@ -130,7 +130,7 @@ module KBuilder
130
130
  }
131
131
  end
132
132
 
133
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
133
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
134
134
  def add_file(file, **opts)
135
135
  # move to command
136
136
  full_file = target_file(file, **opts) # opts.key?(:folder_key) || opts.key?(:folder) ? target_file(file, folder: opts[:folder], folder_key: opts[:folder_key]) : target_file(file)
@@ -146,6 +146,8 @@ module KBuilder
146
146
  run_prettier file if opts.key?(:pretty)
147
147
  # TODO: Add test
148
148
  run_cop(full_file, fix_safe: true) if opts.key?(:cop) || opts.key?(:ruby_cop)
149
+ # TODO: Add test
150
+ run_command(file) if opts.key?(:run)
149
151
 
150
152
  # Need support for rubocop -a
151
153
  open_file(last_output_file) if opts.key?(:open)
@@ -155,7 +157,7 @@ module KBuilder
155
157
 
156
158
  self
157
159
  end
158
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
160
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
159
161
 
160
162
  def play_actions(actions)
161
163
  actions.reject { |action| action[:played] }.each do |action|
@@ -164,6 +166,13 @@ module KBuilder
164
166
  end
165
167
 
166
168
  def play_action(action)
169
+ run_action(action)
170
+ action[:played] = true
171
+ end
172
+
173
+ # certain actions (e.g. set_current_folder) will run independently to play
174
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
175
+ def run_action(action)
167
176
  case action[:action]
168
177
  when :add_file
169
178
  add_file(action[:file], action[:opts])
@@ -177,12 +186,13 @@ module KBuilder
177
186
  set_current_folder(action[:folder_key])
178
187
  when :run_command
179
188
  run_command(action[:command])
189
+ when :run_script
190
+ run_script(action[:script])
180
191
  else
181
192
  log.error "Unknown action: #{action[:action]}"
182
193
  end
183
-
184
- action[:played] = true
185
194
  end
195
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
186
196
 
187
197
  alias touch add_file # it is expected that you would not supply any options, just a file name
188
198
 
@@ -529,6 +539,10 @@ module KBuilder
529
539
  # need to support the fork process options as I was not able to run
530
540
  # k_builder_watch -n because it hid all the following output
531
541
  system(build_command)
542
+
543
+ # FROM k_dsl
544
+ # system "/usr/local/bin/zsh #{output_file}" if execution_context == :system
545
+ # fork { exec("/usr/local/bin/zsh #{output_file}") } if execution_context == :fork
532
546
  end
533
547
  alias rc run_command
534
548
 
@@ -540,6 +554,34 @@ module KBuilder
540
554
  }
541
555
  end
542
556
 
557
+ # NOT TESTED, and not working with opts, this code needs rewrite
558
+ def run_script(script)
559
+ # Deep path create if needed
560
+ tf = target_folder
561
+
562
+ mkdir_p(tf)
563
+
564
+ Dir.chdir(tf) do
565
+ output, status = Open3.capture2(script) # , **opts)
566
+
567
+ unless status.success?
568
+ log.error('Script failed')
569
+ puts script
570
+ return nil
571
+ end
572
+
573
+ return output
574
+ end
575
+ end
576
+
577
+ def run_script_action(script)
578
+ {
579
+ action: :run_script,
580
+ played: false,
581
+ script: script
582
+ }
583
+ end
584
+
543
585
  def file_write(file, content, on_exist: :skip)
544
586
  self.last_output_file = file # if file not found, we still want to record this as the last_output_file
545
587
 
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Attach configuration to the KBuilder module
4
+ module KBuilder
5
+ module ConfigurationExtension
6
+ # Target folders provide a set of named folders that can be written to
7
+ def target_folders=(value)
8
+ @target_folders = value
9
+ end
10
+
11
+ def target_folders
12
+ @target_folders ||= KType::NamedFolders.new
13
+ end
14
+
15
+ # Template folders provides layered folders that templates can exist within
16
+ def template_folders=(value)
17
+ @template_folders = value
18
+ end
19
+
20
+ def template_folders
21
+ @template_folders ||= KType::LayeredFolders.new
22
+ end
23
+
24
+ # Custom debug method for k_builder
25
+ #
26
+ # usage:
27
+ # config.debug(:k_builder_debug)
28
+ def k_builder_debug
29
+ target_folders.debug(title: 'target_folders')
30
+
31
+ template_folders.debug(title: 'template folders (search order)')
32
+ ''
33
+ end
34
+
35
+ # Custom initialize_copy method for k_builder, this is called during clone
36
+ def k_builder_initialize_copy(orig)
37
+ @target_folders = orig.target_folders.clone
38
+ @template_folders = orig.template_folders.clone
39
+ end
40
+ end
41
+ end
42
+
43
+ KConfig::Configuration.register(:k_builder, KBuilder::ConfigurationExtension)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KBuilder
4
- VERSION = '0.0.69'
4
+ VERSION = '0.0.74'
5
5
  end
data/lib/k_builder.rb CHANGED
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rubocop'
4
+ require 'open3'
4
5
 
6
+ require 'k_config'
5
7
  require 'k_log'
6
8
  require 'k_util'
7
9
  require 'k_type'
8
10
  require 'k_builder/version'
9
11
  require 'k_builder/base_builder'
10
- require 'k_builder/base_configuration'
11
- require 'k_builder/configuration'
12
+ require 'k_builder/configuration_extension'
12
13
  require 'k_builder/file_segments'
13
14
 
14
15
  # should commands be in their own gem?
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.69
4
+ version: 0.0.74
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-10 00:00:00.000000000 Z
11
+ date: 2022-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: handlebars-helpers
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: k_config
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: k_log
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -103,6 +117,7 @@ files:
103
117
  - Sample.drawio
104
118
  - Sample.xml
105
119
  - USAGE.md
120
+ - a.txt
106
121
  - bin/console
107
122
  - bin/k
108
123
  - bin/kgitsync
@@ -112,17 +127,11 @@ files:
112
127
  - hooks/update-version
113
128
  - k_builder.gemspec
114
129
  - lib/k_builder.rb
115
- - lib/k_builder/assets/a.html
116
- - lib/k_builder/assets/b.html
117
- - lib/k_builder/assets/highlight.min.js
118
- - lib/k_builder/assets/highlight_css
119
- - lib/k_builder/assets/ruby.min.js
120
130
  - lib/k_builder/base_builder.rb
121
- - lib/k_builder/base_configuration.rb
122
131
  - lib/k_builder/commands/base_command.rb
123
132
  - lib/k_builder/commands/code_syntax_highlighter_command.rb
124
133
  - lib/k_builder/commands/rubo_cop_command.rb
125
- - lib/k_builder/configuration.rb
134
+ - lib/k_builder/configuration_extension.rb
126
135
  - lib/k_builder/file_segments.rb
127
136
  - lib/k_builder/version.rb
128
137
  - usage/_out1.png
@@ -139,6 +148,7 @@ metadata:
139
148
  homepage_uri: http://appydave.com
140
149
  source_code_uri: https://github.com/klueless-io/k_builder
141
150
  changelog_uri: https://github.com/klueless-io/k_builder/commits/master
151
+ rubygems_mfa_required: 'true'
142
152
  post_install_message:
143
153
  rdoc_options: []
144
154
  require_paths:
@@ -1,235 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>David</title>
8
- <script src="highlight.min.js"></script>
9
- <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/default.min.css"> -->
10
- <script src="https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"></script>
11
- <script src="//cdn.jsdelivr.net/gh/TRSasasusu/highlightjs-highlight-lines.js@1.1.6/highlightjs-highlight-lines.min.js"></script>
12
- <script src="//cdn.jsdelivr.net/npm/highlightjs-line-numbers.js@2.8.0/dist/highlightjs-line-numbers.min.js"></script>
13
-
14
- <link rel="stylesheet" href="highlight_css/a11y-light.css">
15
-
16
- <style>
17
- pre > code {
18
- font-family: "Sans Mono", "Consolas", "Courier", monospace;
19
- }
20
-
21
-
22
- /*
23
- color: white; */
24
-
25
- .animated-box {
26
- font-family: 'Lato';
27
- color: #ffffff;
28
- padding: 30px;
29
- text-align: center;
30
- border-radius: 4px;
31
- }
32
-
33
- .animated-box {
34
- position: relative;
35
- }
36
-
37
- .animated-box:after {
38
- content: '';
39
- position: absolute;
40
- top: 0;
41
- left: 0;
42
- right: 0;
43
- bottom: 0;
44
- border-radius: 4px;
45
- background: linear-gradient(120deg, #00F260, #0575E6, #00F260);
46
- background-size: 300% 300%;
47
- clip-path: polygon(0% 100%, 3px 100%, 3px 3px, calc(100% - 3px) 3px, calc(100% - 3px) calc(100% - 3px), 3px calc(100% - 3px), 3px 100%, 100% 100%, 100% 0%, 0% 0%);
48
- }
49
-
50
- .animated-box.in:after {
51
- animation: frame-enter 1s forwards ease-in-out reverse, gradient-animation 4s ease-in-out infinite;
52
- }
53
-
54
- #box {
55
- position: absolute;
56
- top: 170px;
57
- left: 70px;
58
- width: 600px;
59
- height: 465px;
60
- display: flex;
61
- align-items: center;
62
- justify-content: center;
63
- color: white;
64
- font-family: 'Raleway';
65
- font-size: 2.5rem;
66
- /* background-color: rgba(255,255,225,0); */
67
- }
68
-
69
- .with-linear-gradient {
70
- --borderWidth: 13px;
71
- background: transparent;
72
- position: relative;
73
- border-radius: var(--borderWidth);
74
- }
75
- .with-linear-gradient:after {
76
- content: '';
77
- position: absolute;
78
- top: calc(-1 * var(--borderWidth));
79
- left: calc(-1 * var(--borderWidth));
80
- height: calc(100% + var(--borderWidth) * 2);
81
- width: calc(100% + var(--borderWidth) * 2);
82
- border-radius: calc(2 * var(--borderWidth));
83
- background: linear-gradient(60deg, #f79533, #f37055, #ef4e7b, #a166ab, #5073b8);
84
- z-index: -1;
85
- animation: animatedgradient 3s ease alternate infinite;
86
- background-size: 300% 300%;
87
- }
88
- .animated-box {
89
- position: relative;
90
- }
91
-
92
- .animated-box:after {
93
- content: '';
94
- position: absolute;
95
- top: 0;
96
- left: 0;
97
- right: 0;
98
- bottom: 0;
99
- border-radius: 4px;
100
- background: linear-gradient(120deg, #00F260, #0575E6, #00F260);
101
- background-size: 300% 300%;
102
- clip-path: polygon(0% 100%, 3px 100%, 3px 3px, calc(100% - 3px) 3px, calc(100% - 3px) calc(100% - 3px), 3px calc(100% - 3px), 3px 100%, 100% 100%, 100% 0%, 0% 0%);
103
- }
104
-
105
- .animated-box.in:after {
106
- animation: frame-enter 1s forwards ease-in-out reverse, gradient-animation 4s ease-in-out infinite;
107
- }
108
-
109
-
110
- @keyframes animatedgradient {
111
- 0% {
112
- background-position: 0% 50%;
113
- }
114
- 50% {
115
- background-position: 100% 50%;
116
- }
117
- 100% {
118
- background-position: 0% 50%;
119
- }
120
- }
121
-
122
- */
123
- /* for block of numbers */
124
- .hljs-ln-numbers {
125
- -webkit-touch-callout: none;
126
- -webkit-user-select: none;
127
- -khtml-user-select: none;
128
- -moz-user-select: none;
129
- -ms-user-select: none;
130
- user-select: none;
131
-
132
- text-align: center;
133
- color: #ccc;
134
- border-right: 1px solid #CCC;
135
- vertical-align: top;
136
- padding-right: 5px;
137
-
138
- /* your custom style here */
139
- }
140
-
141
- /* for block of code */
142
- .hljs-ln-code {
143
- padding-left: 100px;
144
- }
145
-
146
- .borderexample {
147
- border-style:solid;
148
- border-color:#287EC7;
149
- }
150
- </style>
151
- </head>
152
- <body>
153
-
154
-
155
-
156
- <div id="myBlock">
157
- <pre><code class="ruby">
158
- # frozen_string_literal: true
159
-
160
- module KBuilder
161
- module Commands
162
- # Base command for single responsibility actions that can be fired
163
- # from methods in the builder.
164
- #
165
- # Uses the command pattern
166
- class BaseCommand
167
- include KLog::Logging
168
-
169
- attr_accessor :builder
170
- attr_accessor :valid
171
-
172
- def initialize(**opts)
173
- @builder = opts[:builder]
174
- @valid = true
175
- end
176
-
177
- def guard(message)
178
- # THIS SHOULD ONLY LOG IF DEBUGGING IS TURNED ON
179
- log.error(message)
180
- @valid = false
181
- end
182
-
183
- def valid?
184
- @valid
185
- end
186
-
187
- def debug(title: nil)
188
- log.section_heading(title) if title
189
- debug_values if respond_to?(:debug_values)
190
- end
191
- end
192
- end
193
- end
194
- </code></pre>
195
- are go
196
- <a id='x' href="" download="name.jpg"></a>
197
-
198
- <div id='box' class='animated-box in' xclass="with-linear-gradient">
199
-
200
- </div>
201
- </body>
202
- <script>hljs.highlightAll();</script>
203
-
204
- <button onclick="takeshot()">
205
- Take Screenshot
206
- </button>
207
-
208
- <div id="output"></div>
209
-
210
- <script>
211
-
212
- const screenshotTarget = document.getElementById('myBlock');
213
-
214
- let div = document.getElementById('myBlock');
215
-
216
- setTimeout(function(){
217
-
218
- html2canvas(div).then(
219
- function (canvas) {
220
- document
221
- .getElementById('output')
222
- .appendChild(canvas);
223
- });
224
-
225
- }, 1000);
226
-
227
- hljs.initHighlightingOnLoad();
228
- hljs.initLineNumbersOnLoad();
229
- hljs.initHighlightLinesOnLoad([
230
- [{start: 1, end: 3, color: '#555'}, {start: 6, end: 6, color: 'yellow'},], // Highlight some lines in the first code block.
231
- [{start: 2, end: 3, color: 'rgba(255, 255, 255, 0.2)'},], // Highlight some lines in the second code block.
232
- ]);
233
-
234
- </script>
235
- </html>
@@ -1,109 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>
5
- How to take screenshot of
6
- a div using JavaScript?
7
- </title>
8
- <script src="highlight.min.js"></script>
9
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/default.min.css">
10
- <script src="https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"></script>
11
-
12
- <!-- Include from the CDN -->
13
- <script src=
14
- "https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js">
15
- </script>
16
-
17
- <!-- Include locally otherwise -->
18
- <!-- <script src='html2canvas.js'></script> -->
19
-
20
- <style>
21
- #photo {
22
- border: 4px solid green;
23
- padding: 4px;
24
- }
25
- </style>
26
- </head>
27
-
28
- <body>
29
- <div id="photo">
30
- <h1>GeeksforGeeks</h1>
31
- Hello everyone! This is a
32
- trial page for taking a
33
- screenshot.
34
- <br><br>
35
- This is a dummy button!
36
- <button> Dummy</button>
37
- <br><br>
38
- Click the button below to
39
- take a screenshot of the div.
40
- <br><br>
41
-
42
- <!-- Define the button
43
- that will be used to
44
- take the screenshot -->
45
- <button onclick="takeshot()">
46
- Take Screenshot
47
- </button>
48
- </div>
49
- <h1>Screenshot:</h1>
50
- <div id="myBlock">
51
- <pre><code class="ruby">
52
- # frozen_string_literal: true
53
-
54
- module KBuilder
55
- module Commands
56
- # Base command for single responsibility actions that can be fired
57
- # from methods in the builder.
58
- #
59
- # Uses the command pattern
60
- class BaseCommand
61
- include KLog::Logging
62
-
63
- attr_accessor :builder
64
- attr_accessor :valid
65
-
66
- def initialize(**opts)
67
- @builder = opts[:builder]
68
- @valid = true
69
- end
70
-
71
- def guard(message)
72
- # THIS SHOULD ONLY LOG IF DEBUGGING IS TURNED ON
73
- log.error(message)
74
- @valid = false
75
- end
76
-
77
- def valid?
78
- @valid
79
- end
80
-
81
- def debug(title: nil)
82
- log.section_heading(title) if title
83
- debug_values if respond_to?(:debug_values)
84
- end
85
- end
86
- end
87
- end
88
- </code></pre>
89
-
90
- <div id="output"></div>
91
-
92
- <script type="text/javascript">
93
-
94
- // Define the function
95
- // to screenshot the div
96
- function takeshot() {
97
- let div = document.getElementById('myBlock');
98
- html2canvas(div).then(
99
- function (canvas) {
100
- document
101
- .getElementById('output')
102
- .appendChild(canvas);
103
- })
104
- }
105
- </script>
106
- </body>
107
- <script>hljs.highlightAll();</script>
108
-
109
- </html>