justprep 1.0.1 → 1.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4729fa9db5b45ee64efff9c7f0aaddbeddf6d654cfe031d1a7039a13c8deca0
4
- data.tar.gz: a2806b5e251bf062763aec4b5c1806919051a3251e42d7c03f61a557f53b9465
3
+ metadata.gz: 7e0bc299adb71964c6298e1a195b380dd37c4cf716c2c58cb6ffab9320f74a5d
4
+ data.tar.gz: a22fcb32d3c7c5b516dade83e17670696ef0aa0619efcbb8c1361b580100b814
5
5
  SHA512:
6
- metadata.gz: b27ccd199ac3f53759e0c07e039c3d5d3d4212166c5f4d6cec0fde22fb4f0281746ca7a61b690cb882280e4bdb0e45f7aee446a3696aadc40db20b9617a1117a
7
- data.tar.gz: 436b0657a5d2a66d1db74cdfb953f7a83f2b69889653bb0ad0204365a79117f8adcf086aabc7f256123adefcac8861db339362de7d46c4d4e271974e507a799f
6
+ metadata.gz: 9c2a9c4b7da6f3ad617f6799084808596c868a710dcb6a639dd742709c3aef18c414d32d654c3f74821d1d10af03c80f27414c0dd7007294b28b731d741eeb9b
7
+ data.tar.gz: 70b4bc355484300078eac81ec0ce5f450373346dd5809338f03ddaae83f1823f07bb39a8dfa76c67a043960805c14ad54830b036722e855ec62f766c2611bf6a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- justprep (1.0.1)
4
+ justprep (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/bin/justprep CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'justprep'
3
+ require_relative '../lib/justprep.rb'
4
4
 
5
- Justprep.execute
5
+ Justprep.new.execute
data/justfile CHANGED
@@ -1,6 +1,5 @@
1
1
  # github.com/MadBomber/justprep/**/ruby/justfile
2
2
  #
3
- # gem install bump
4
3
 
5
4
  set positional-arguments := true
6
5
 
@@ -14,6 +13,10 @@ set positional-arguments := true
14
13
  just -l --list-prefix 'just ' --list-heading ''
15
14
  echo
16
15
 
16
+ # Run the minitest examples on the Ruby code
17
+ test: build
18
+ rake test
19
+
17
20
 
18
21
  # Build the current gem
19
22
  @build:
@@ -24,26 +27,3 @@ set positional-arguments := true
24
27
  @install:
25
28
  rake install:local
26
29
 
27
-
28
- #################################################
29
- ## Recipes that deal with the source code version
30
- ## Version manager is handled by the "bump" gem
31
-
32
- # Set the version: major . minor . patch
33
- @set version:
34
- bump set {{version}} --no-commit --replace-in ../crystal/version.cr
35
-
36
-
37
- # Show current version
38
- @show:
39
- bump current
40
-
41
-
42
- # Bump the level: major . minor . patch
43
- bump level='patch':
44
- #!/bin/bash
45
- if [[ "{{level}}" =~ ^(major|minor|patch)$ ]]; then
46
- bump {{level}} --no-commit --replace-in ../crystal/version.cr
47
- else
48
- echo "ERROR: level must be one of: major, minor, patch"
49
- fi
data/justprep.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/justprep/version"
3
+ load "lib/justprep/common/constants.crb"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "justprep"
7
- spec.version = Justprep::VERSION
7
+ spec.version = VERSION
8
8
  spec.authors = ["Dewayne VanHoozer"]
9
9
  spec.email = ["dvanhoozer@gmail.com"]
10
10
 
@@ -0,0 +1,5 @@
1
+ VERSION = "1.2.2"
2
+
3
+ JUSTPREP_FILENAME_IN = ENV.fetch("JUSTPREP_FILENAME_IN", "main.just")
4
+ JUSTPREP_FILENAME_OUT = ENV.fetch("JUSTPREP_FILENAME_OUT", "justfile")
5
+ JUSTPREP_KEYWORDS = ENV.fetch("JUSTPREP_KEYWORDS", "import include require with").split
@@ -0,0 +1,31 @@
1
+ # common/error_messages.crb
2
+
3
+ # Parameters:
4
+ # line_number .. Integer (zero-based index)
5
+ # a_line ....... String
6
+ #
7
+ # Returns:
8
+ # nil
9
+ #
10
+ def error_file_does_not_exist(line_number, a_line)
11
+ STDERR.puts
12
+ STDERR.puts "ERROR: File Does Not Exist"
13
+
14
+ # Crystal types thinks line_number can be nil or Int32
15
+ line_out = sprintf("% d ", line_number.nil? ? 0 : line_number)
16
+ STDERR.puts (" "*line_out.size)+"|"
17
+ STDERR.puts "#{line_out}| #{a_line}"
18
+ STDERR.print (" "*line_out.size)+"|"
19
+
20
+ x = a_line.index(" ")
21
+ begin_filename = x.nil? ? a_line.size + 2 : x + 2
22
+ end_filename = a_line.size
23
+ len_filename = end_filename - begin_filename + 1
24
+
25
+ len_filename = 13 if len_filename < 0
26
+
27
+ STDERR.puts (" "*begin_filename) + ("^"*len_filename)
28
+ STDERR.puts
29
+
30
+ return nil
31
+ end
@@ -0,0 +1,15 @@
1
+ # common/expand_file_path.crb
2
+
3
+ # use an external shell to expand system environment variables
4
+ def expand_file_path(a_path_string)
5
+ a_path_string = a_path_string.strip
6
+
7
+ if a_path_string.to_s.starts_with? "~"
8
+ a_path_string = "${HOME}" + a_path_string.to_s[1, a_path_string.to_s.size-1]
9
+ end
10
+
11
+ a_path_string = `echo "#{a_path_string}"`.chomp
12
+
13
+ return a_path_string
14
+ end
15
+
@@ -0,0 +1,24 @@
1
+ # common/handle_command_line_parameters.crb
2
+
3
+
4
+ # take care of ARGV
5
+ #
6
+ # Returns
7
+ # nil when there are no command line parameters
8
+ # otherwise it terminates the process
9
+ #
10
+ def handle_command_line_parameters
11
+ if ARGV.size > 0
12
+ ARGV.each do |param|
13
+ if "--version" == param
14
+ puts "jusrprep v#{VERSION} (#{IMPLEMENTATION})"
15
+ elsif ["-h", "--help"].includes?(param)
16
+ usage
17
+ else
18
+ STDERR.puts "justprep does not support: #{param}"
19
+ end
20
+ end
21
+
22
+ exit(1)
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ # common/just_find_it.crb
2
+
3
+ # look for first occurace of mainfile
4
+ # returns nil when none are found.
5
+ def just_find_it(here = FileUtils.pwd)
6
+ mainfile_path = here + "/" + JUSTPREP_FILENAME_IN
7
+ return mainfile_path if File.exists?(mainfile_path)
8
+
9
+ parts = here.to_s.split("/")
10
+ parts.pop
11
+
12
+ return nil if parts.empty?
13
+ return just_find_it(parts.join('/'))
14
+ end
@@ -0,0 +1,46 @@
1
+ # common/usage.crb
2
+
3
+ def usage
4
+ usage_text = "
5
+ justprep v#{VERSION} (#{IMPLEMENTATION})
6
+
7
+ A pre-processor to the just command line utility
8
+ By Dewayne VanHoozer <dvanhoozer@gmail.com>
9
+
10
+ USAGE:
11
+ justprep [flags] && just
12
+
13
+ FLAGS:
14
+ --version Shows the current version
15
+ -h, --help Displays this usage message
16
+
17
+ DESCRIPTION:
18
+ Looks for a file named #{JUSTPREP_FILENAME_IN} in the current
19
+ directory hierarchy. If found it replaces all lines that
20
+ have the keywords (#{JUSTPREP_KEYWORDS.join(", ")}) followed
21
+ by file path with the contents of the specified file.
22
+
23
+ SYSTEM ENVIRONMENT VARIABLES:
24
+ Default Value
25
+ JUSTPREP_FILENAME_IN .... main.just
26
+ JUSTPREP_FILENAME_OUT ... justfile
27
+ JUSTPREP_KEYWORDS ....... 'import include require with'
28
+
29
+ SUGGESTION:
30
+ Create an alias for your command shell. For example
31
+ alias jj='justprep && just'
32
+
33
+ THANKS TO:
34
+ Casey Rodarmor <casey@rodarmor.com>
35
+ for Just because just is just a handy utility with just an
36
+ odd name but an extreamly useful product. :)
37
+
38
+ Greg Lutostanski <greg.luto@gmail.com>
39
+ for the homebrew formula and the github actions to compile
40
+ a new Crystal release.
41
+
42
+ "
43
+ puts usage_text
44
+
45
+ return usage_text
46
+ end
@@ -0,0 +1,18 @@
1
+ # common/crystal_methods.rb
2
+
3
+ # Monkey oatch Ruby classes to match method names
4
+ # used by Crystal
5
+
6
+ # TODO: find other classes in which Ruby/Crystal differ
7
+
8
+ class Array
9
+ alias_method :includes?, :include?
10
+ end
11
+
12
+ class Pathname
13
+ alias_method :exists?, :exist?
14
+ end
15
+
16
+ class String
17
+ alias_method :starts_with?, :start_with?
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Justprep
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
data/lib/justprep.rb CHANGED
@@ -15,180 +15,102 @@
15
15
  # JUSTPREP_KEYWORDS ... 'import include require with'
16
16
  #
17
17
 
18
- require "pathname"
19
- require_relative "justprep/version"
20
-
21
- module Justprep
22
- class << self
23
- JUSTPREP_FILENAME_IN = ENV.fetch('JUSTPREP_FILENAME_IN', 'main.just')
24
- JUSTPREP_FILENAME_OUT = ENV.fetch('JUSTPREP_FILENAME_OUT', 'justfile')
25
- JUSTPREP_KEYWORDS = ENV.fetch('JUSTPREP_KEYWORDS', 'import include require with').split
26
-
27
-
28
- # review the text looking for module references
29
- def find_modules(text)
30
- modules = []
31
-
32
- JUSTPREP_KEYWORDS.each do |keyword|
33
- modules << text.select{|x| x.start_with?("#{keyword} ") || x.strip == keyword}
34
- end
35
-
36
- return modules.flatten!
37
- end
18
+ IMPLEMENTATION = "Ruby"
38
19
 
20
+ require "fileutils"
21
+ require "pathname"
22
+ require_relative "justprep/crystal_methods"
39
23
 
40
- # somg;e-level inclusion
41
- def include_content_from(file_path)
42
- content = []
43
- content << "\n# >>> #{file_path}"
44
- content << file_path.readlines.map{|x| x.chomp} # TODO: support recursion??
45
- content << "# <<< #{file_path}\n"
46
-
47
- return content.flatten
24
+ # The common directory contains files which are usable in
25
+ # both the Ruby gem and compiled Crystal implementations
26
+ # The files have the extension ".crb"
27
+ #
28
+ COMMON_DIR = Pathname.new(__FILE__) + '../justprep/common'
29
+
30
+ # Loading these common methods as global kernel-level
31
+ load COMMON_DIR + "constants.crb"
32
+ load COMMON_DIR + "error_messages.crb"
33
+ load COMMON_DIR + "expand_file_path.crb"
34
+ load COMMON_DIR + "handle_command_line_parameters.crb"
35
+ load COMMON_DIR + "just_find_it.crb"
36
+ load COMMON_DIR + "usage.crb"
37
+
38
+ class Justprep
39
+ def initialize
40
+ handle_command_line_parameters # may terminate the process
48
41
  end
49
42
 
50
43
 
51
- # look for first occurace of mainfile
52
- def just_find_it(here=Pathname.pwd)
53
- mainfile = here + JUSTPREP_FILENAME_IN
54
- return mainfile if mainfile.exist?
55
- return nil if here == here.parent
56
- return just_find_it(here.parent)
57
- end
44
+ # single-level inclusion
45
+ def include_content_from(out_file, module_filename)
46
+ module_file = File.open(module_filename, "r")
58
47
 
48
+ out_file.puts "\n# >>> #{module_filename}"
59
49
 
60
- # use an external shell to expand system environment variables
61
- def expand_file_path(a_path_string)
62
- if a_path_string.start_with? '~'
63
- a_path_string = "${HOME}" + a_path_string[1, a_path_string.size-1]
50
+ module_file.readlines.each do |m_line|
51
+ out_file.write m_line
64
52
  end
65
53
 
66
- a_path_string = `echo "#{a_path_string}"`.chomp
54
+ out_file.puts "# <<< #{module_filename}\n"
67
55
 
68
- return a_path_string
69
- end
70
-
71
- # Print usage text
72
- def usage
73
- puts <<~EOS
74
- justprep v#{VERSION} (ruby)
75
- A pre-processor to the just command line utility
76
- By Dewayne VanHoozer <dvanhoozer@gmail.com>
77
-
78
- USAGE:
79
- justprep [flags] && just
80
-
81
- FLAGS:
82
- --version Shows the current version
83
- -h, --help Displays this usage message
84
-
85
- DESCRIPTION:
86
- Looks for a file named #{JUSTPREP_FILENAME_IN} in the current
87
- directory hierarchy. If found it replaces all lines that
88
- have the keywords (#{JUSTPREP_KEYWORDS.join(", ")}) followed
89
- by file path with the contents of the specified file.
90
-
91
- SYSTEM ENVIRONMENT VARIABLES:
92
- Default Value
93
- JUSTPREP_FILENAME_IN .... main.just
94
- JUSTPREP_FILENAME_OUT ... justfile
95
- JUSTPREP_KEYWORDS ....... 'import include require with'
96
-
97
- SUGGESTION:
98
- Create an alias for your command shell. For example
99
- alias jj='justprop && just'
100
-
101
- THANKS TO:
102
- Casey Rodarmor <casey@rodarmor.com>
103
- Just because just is just a handy utility with just an odd name. :)
104
-
105
- EOS
106
- end
107
-
108
-
109
- # take care of ARGV processing
110
- def handle_command_line_parameters
111
- if ARGV.size > 0
112
- ARGV.each do |param|
113
- if "--version" == param
114
- puts "jusrprep v#{VERSION} (ruby)"
115
- elsif ["-h", "--help"].include?(param)
116
- usage
117
- else
118
- STDERR.puts "justprep does not support: #{param}"
119
- exit(1)
120
- end
121
- end
122
- end
56
+ return nil
123
57
  end
124
58
 
125
59
 
126
60
  # Main function called from executable
127
61
  def execute
128
- handle_command_line_parameters
62
+ in_filename = just_find_it
129
63
 
130
- mainfile = just_find_it
131
-
132
- if mainfile.nil?
64
+ if in_filename.nil?
133
65
  STDERR.puts "WARNING: JUSTPREP_FILENAME_IN Not Found: #{JUSTPREP_FILENAME_IN}"
134
66
  exit(0)
135
67
  end
136
68
 
137
- basefile = mainfile.parent + JUSTPREP_FILENAME_OUT
69
+ out_filename = File.dirname(in_filename) + "/" + JUSTPREP_FILENAME_OUT
138
70
 
139
- text = mainfile.readlines.map{|x| x.chomp} # drop the line ending from each line
71
+ in_file = File.open(in_filename, "r")
72
+ out_file = File.open(out_filename, "w")
140
73
 
141
- modules = find_modules text
74
+ line_number = 0
142
75
 
143
- if modules.empty?
144
- basefile.write text
145
- exit(0)
146
- end
76
+ in_file.readlines.map{|x| x.chomp}.each do |a_line|
77
+ line_number += 1
147
78
 
148
- modules.each do |a_line|
149
- an_index = text.index a_line
150
- begin_filename = a_line.index(' ')
79
+ parts = a_line.to_s.split(" ")
151
80
 
152
- if begin_filename.nil?
153
- module_filename = ""
154
- else
155
- module_filename = a_line[begin_filename, a_line.size - begin_filename].chomp.strip
81
+ if 0 == parts.size
82
+ out_file.puts
83
+ next
156
84
  end
157
85
 
158
- if module_filename.empty?
159
- STDERR.puts "ERROR: No path/to/file was provided"
160
- line_out = sprintf('% d ', an_index+1)
161
- STDERR.puts (" "*line_out.size)+"|"
162
- STDERR.puts "#{line_out}| #{a_line}"
163
- STDERR.print (" "*line_out.size)+"|"
164
- STDERR.puts (" "*(a_line.size+2)) + "^"
165
- exit(1)
166
- end
86
+ # NOTE: Leading spaces are not allowed. The keywords
87
+ # MUST be complete left-justified.
88
+ #
89
+ if JUSTPREP_KEYWORDS.include?(parts.first.downcase)
90
+ out_file.puts "# #{a_line}"
167
91
 
168
- if module_filename.include?('~') || module_filename.include?('$')
169
- module_filename = expand_file_path(module_filename)
170
- end
92
+ glob_filename = expand_file_path(parts[1..parts.size].join(" "))
171
93
 
172
- module_path = Pathname.new(module_filename)
94
+ module_filenames = Dir.glob(glob_filename)
173
95
 
174
- if module_path.relative?
175
- module_path = mainfile.parent + module_path
96
+ if 0 == module_filenames.size
97
+ error_file_does_not_exist(line_number, a_line)
98
+ exit(1)
176
99
  end
177
100
 
178
- if module_path.exist?
179
- text[an_index] = include_content_from(module_path)
101
+ module_filenames.each do |module_filename|
102
+ if File.exist?(module_filename)
103
+ include_content_from(out_file, module_filename)
180
104
  else
181
- STDERR.puts "ERROR: File Does Not Exist - #{module_path}"
182
- line_out = sprintf('% d ', an_index+1)
183
- STDERR.puts (" "*line_out.size)+"|"
184
- STDERR.puts "#{line_out}| #{a_line}"
185
- STDERR.print (" "*line_out.size)+"|"
186
- STDERR.puts (" "*(a_line.index(module_filename)+1)) + "^"
105
+ error_file_does_not_exist(line_number, a_line)
187
106
  exit(1)
188
107
  end
189
- end # modules.each do |a_line|
108
+ end
109
+ else
110
+ out_file.puts a_line
111
+ end
112
+ end # in_file.readlines ...
190
113
 
191
- basefile.write text.flatten!.join "\n"
114
+ out_file.close
192
115
  end # def execute
193
- end # class << self
194
- end # module Justprep
116
+ end # class Justprep
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: justprep
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-18 00:00:00.000000000 Z
11
+ date: 2022-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -50,6 +50,13 @@ files:
50
50
  - justfile
51
51
  - justprep.gemspec
52
52
  - lib/justprep.rb
53
+ - lib/justprep/common/constants.crb
54
+ - lib/justprep/common/error_messages.crb
55
+ - lib/justprep/common/expand_file_path.crb
56
+ - lib/justprep/common/handle_command_line_parameters.crb
57
+ - lib/justprep/common/just_find_it.crb
58
+ - lib/justprep/common/usage.crb
59
+ - lib/justprep/crystal_methods.rb
53
60
  - lib/justprep/version.rb
54
61
  - prototype.rb
55
62
  homepage: http://github.com/MadBomber/justprep/tree/main/ruby
@@ -72,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
79
  - !ruby/object:Gem::Version
73
80
  version: '0'
74
81
  requirements: []
75
- rubygems_version: 3.2.24
82
+ rubygems_version: 3.3.15
76
83
  signing_key:
77
84
  specification_version: 4
78
85
  summary: A pre-processor for the 'just' command line utility