howzit 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Howzit
4
+ # String Extensions
5
+ module StringUtils
6
+ # Just strip out color codes when requested
7
+ def uncolor
8
+ gsub(/\e\[[\d;]+m/, '')
9
+ end
10
+
11
+ # Adapted from https://github.com/pazdera/word_wrap/,
12
+ # copyright (c) 2014, 2015 Radek Pazdera
13
+ # Distributed under the MIT License
14
+ def wrap(width)
15
+ width ||= 80
16
+ output = []
17
+ indent = ''
18
+
19
+ text = gsub(/\t/, ' ')
20
+
21
+ text.lines do |line|
22
+ line.chomp! "\n"
23
+ if line.length > width
24
+ indent = if line.uncolor =~ /^(\s*(?:[+\-*]|\d+\.) )/
25
+ ' ' * Regexp.last_match[1].length
26
+ else
27
+ ''
28
+ end
29
+ new_lines = line.split_line(width)
30
+
31
+ while new_lines.length > 1 && new_lines[1].length + indent.length > width
32
+ output.push new_lines[0]
33
+
34
+ new_lines = new_lines[1].split_line(width, indent)
35
+ end
36
+ output += [new_lines[0], indent + new_lines[1]]
37
+ else
38
+ output.push line
39
+ end
40
+ end
41
+ output.map!(&:rstrip)
42
+ output.join("\n")
43
+ end
44
+
45
+ def wrap!(width)
46
+ replace(wrap(width))
47
+ end
48
+
49
+ # Truncate string to nearest word
50
+ # @param len <number> max length of string
51
+ def trunc(len)
52
+ split(/ /).each_with_object('') do |x, ob|
53
+ break ob unless ob.length + ' '.length + x.length <= len
54
+
55
+ ob << (" #{x}")
56
+ end.strip
57
+ end
58
+
59
+ def trunc!(len)
60
+ replace trunc(len)
61
+ end
62
+
63
+ def split_line(width, indent = '')
64
+ line = dup
65
+ at = line.index(/\s/)
66
+ last_at = at
67
+
68
+ while !at.nil? && at < width
69
+ last_at = at
70
+ at = line.index(/\s/, last_at + 1)
71
+ end
72
+
73
+ if last_at.nil?
74
+ [indent + line[0, width], line[width, line.length]]
75
+ else
76
+ [indent + line[0, last_at], line[last_at + 1, line.length]]
77
+ end
78
+ end
79
+
80
+ def available?
81
+ if File.exist?(File.expand_path(self))
82
+ File.executable?(File.expand_path(self))
83
+ else
84
+ system "which #{self}", out: File::NULL
85
+ end
86
+ end
87
+
88
+ def render_template(vars)
89
+ content = dup
90
+ vars.each do |k, v|
91
+ content.gsub!(/\[%#{k}(:.*?)?\]/, v)
92
+ end
93
+
94
+ content.gsub(/\[%(.*?):(.*?)\]/, '\2')
95
+ end
96
+
97
+ def render_template!(vars)
98
+ replace render_template(vars)
99
+ end
100
+
101
+ def extract_metadata
102
+ if File.exist?(self)
103
+ leader = IO.read(self).split(/^#/)[0].strip
104
+ leader.length > 0 ? leader.get_metadata : {}
105
+ else
106
+ {}
107
+ end
108
+ end
109
+
110
+ def get_metadata
111
+ data = {}
112
+ scan(/(?mi)^(\S[\s\S]+?): ([\s\S]*?)(?=\n\S[\s\S]*?:|\Z)/).each do |m|
113
+ data[m[0].strip.downcase] = m[1]
114
+ end
115
+ normalize_metadata(data)
116
+ end
117
+
118
+ def normalize_metadata(meta)
119
+ data = {}
120
+ meta.each do |k, v|
121
+ case k
122
+ when /^templ\w+$/
123
+ data['template'] = v
124
+ when /^req\w+$/
125
+ data['required'] = v
126
+ else
127
+ data[k] = v
128
+ end
129
+ end
130
+ data
131
+ end
132
+ end
133
+ end
134
+
135
+ class ::String
136
+ include Howzit::StringUtils
137
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ # Primary module for this gem.
3
+ module Howzit
4
+ # Current Howzit version.
5
+ VERSION = '1.2.5'.freeze
6
+ end
data/lib/howzit.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'howzit/version'
2
+ require 'howzit/buildnotes'
3
+ require 'howzit/stringutils'
4
+ require 'optparse'
5
+ require 'shellwords'
6
+ require 'pathname'
7
+ require 'readline'
8
+ require 'tempfile'
9
+ require 'yaml'
10
+
11
+ CONFIG_DIR = '~/.config/howzit'
12
+ CONFIG_FILE = 'howzit.yaml'
13
+ IGNORE_FILE = 'ignore.yaml'
14
+ MATCHING_OPTIONS = %w[partial exact fuzzy beginswith].freeze
data/spec/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_from: ../.rubocop.yml
2
+
3
+ Style/StringLiterals:
4
+ Enabled: false
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Howzit::BuildNotes do
4
+ subject(:ruby_gem) { Howzit::BuildNotes.new }
5
+
6
+ describe ".new" do
7
+ it "makes a new instance" do
8
+ expect(ruby_gem).to be_a Howzit::BuildNotes
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start
4
+
5
+ if ENV['CI'] == 'true'
6
+ require 'codecov'
7
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
8
+ else
9
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
10
+ end
11
+
12
+ require 'howzit'
13
+
14
+ RSpec.configure do |c|
15
+ c.expect_with(:rspec) { |e| e.syntax = :expect }
16
+ c.before(:each) do
17
+ allow(FileUtils).to receive(:remove_entry_secure).with(anything)
18
+ end
19
+ end
data/update_readmes.rb ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ readme = IO.read('README.md')
4
+ blog_project = '/Users/ttscoff/Sites/dev/bt/source/_projects/howzit.md'
5
+ blog_changelog = '/Users/ttscoff/Sites/dev/bt/source/_projects/changelogs/howzit.md'
6
+
7
+ project = readme.match(/<!--BEGIN PROJECT-->(.*?)<!--END PROJECT-->/m)[0]
8
+ changelog = readme.match(/<!--BEGIN CHANGELOG-->(.*?)<!--END CHANGELOG-->/m)[1]
9
+ blog_project_content = IO.read(blog_project)
10
+ blog_project_content.sub!(/<!--BEGIN PROJECT-->(.*?)<!--END PROJECT-->/m, project)
11
+ File.open(blog_project, 'w') { |f| f.puts blog_project_content }
12
+ File.open(blog_changelog, 'w') { |f| f.puts changelog.strip }
13
+ puts "Updated project file and changelog for BrettTerpstra.com"
metadata ADDED
@@ -0,0 +1,305 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: howzit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.5
5
+ platform: ruby
6
+ authors:
7
+ - Brett Terpstra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bump
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.5'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.5'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.28'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.28'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.9'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.9'
153
+ - !ruby/object:Gem::Dependency
154
+ name: codecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.1'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.1'
167
+ - !ruby/object:Gem::Dependency
168
+ name: fuubar
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '2.0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '2.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: yard
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 0.9.5
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 0.9.5
195
+ - !ruby/object:Gem::Dependency
196
+ name: redcarpet
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '3.2'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '3.2'
209
+ - !ruby/object:Gem::Dependency
210
+ name: github-markup
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '1.3'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '1.3'
223
+ - !ruby/object:Gem::Dependency
224
+ name: mdless
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '1.0'
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: 1.0.28
233
+ type: :runtime
234
+ prerelease: false
235
+ version_requirements: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - "~>"
238
+ - !ruby/object:Gem::Version
239
+ version: '1.0'
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: 1.0.28
243
+ description: Command line project documentation and task runner
244
+ email:
245
+ - me@brettterpstra.com
246
+ executables:
247
+ - howzit
248
+ extensions: []
249
+ extra_rdoc_files: []
250
+ files:
251
+ - ".editorconfig"
252
+ - ".gitignore"
253
+ - ".rspec"
254
+ - ".rubocop.yml"
255
+ - ".travis.yml"
256
+ - ".yardopts"
257
+ - CHANGELOG.md
258
+ - Gemfile
259
+ - Guardfile
260
+ - LICENSE.txt
261
+ - README.md
262
+ - Rakefile
263
+ - bin/howzit
264
+ - fish/completions/bld.fish
265
+ - fish/completions/fisher.fish
266
+ - fish/completions/howzit.fish
267
+ - fish/functions/bld.fish
268
+ - howzit.gemspec
269
+ - lib/.rubocop.yml
270
+ - lib/howzit.rb
271
+ - lib/howzit/buildnotes.rb
272
+ - lib/howzit/stringutils.rb
273
+ - lib/howzit/version.rb
274
+ - spec/.rubocop.yml
275
+ - spec/ruby_gem_spec.rb
276
+ - spec/spec_helper.rb
277
+ - update_readmes.rb
278
+ homepage: https://github.com/ttscoff/howzit
279
+ licenses:
280
+ - MIT
281
+ metadata: {}
282
+ post_install_message:
283
+ rdoc_options: []
284
+ require_paths:
285
+ - lib
286
+ required_ruby_version: !ruby/object:Gem::Requirement
287
+ requirements:
288
+ - - ">="
289
+ - !ruby/object:Gem::Version
290
+ version: 2.0.1
291
+ required_rubygems_version: !ruby/object:Gem::Requirement
292
+ requirements:
293
+ - - ">="
294
+ - !ruby/object:Gem::Version
295
+ version: '0'
296
+ requirements: []
297
+ rubygems_version: 3.2.16
298
+ signing_key:
299
+ specification_version: 4
300
+ summary: Provides a way to access Markdown project notes by topic with query capabilities
301
+ and the ability to execute the tasks it describes.
302
+ test_files:
303
+ - spec/.rubocop.yml
304
+ - spec/ruby_gem_spec.rb
305
+ - spec/spec_helper.rb