commentbox 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cbwiz +65 -0
  3. data/lib/commentbox.rb +11 -5
  4. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f33b4420fef198112fd6fe3b52306004024b3a6b70359e545e6e2e45fccfbed1
4
- data.tar.gz: ac9415da017b4b9693674e49bf816661e3bcbf9ec73a0b2480ea3eb2a30dbcea
3
+ metadata.gz: 5bf8ca4be9a56802c326ec4f5e1562262bf40d334571113c70ca11847c904195
4
+ data.tar.gz: ec433e2a0da5b227827e00f35033a626cb521a67668d2dc79a4061e7ffceb98f
5
5
  SHA512:
6
- metadata.gz: ef4424cad553e6c719226f93f3d123cb5a0ed53b2c0314ee21334c9714c865a8b32124033ea06550abd3265bd8a55f6dff555f2c8fa47c8bd170b84c8335c6b2
7
- data.tar.gz: 300273669341b063b2a568c16efa1db79691385decda38adefd921c0af44e3997c7d0699d132c76ee46e426c0e10ee106cb6f59745af246aac6afb7ca347f68f
6
+ metadata.gz: 1aea4172ca5e47d5d2dc79b25249d577e3c4d5d61f9b04e11fa7925ff2d77719dbc43a3418fd198d4e2c92a0b728552049e071933caf50078eceee81c3fd2c87
7
+ data.tar.gz: 3580327e9e93b7043bfdc64fb48a48ce0fbfc8b4372736aa5a49f527a2e955b4706190ddc5c91032eedbb4f2f6e1a866e2be324a53b8f1c1856b301f4dfccf0b
data/bin/cbwiz ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'commentbox'
4
+
5
+ $HELP_MSG = %q(Usage: cb_script.rb [options] [text]
6
+ Options:
7
+ -t, --text [text] Text to be commented. Optional flag for first argument
8
+ -a, --align [l1, l2...] Alignment of text: left, center, right
9
+ -s, --style [style] Style of comment box: stub, window, parallax, zigzag, or money
10
+ -p, --padding [padding] Padding of comment box
11
+ -o, --offset [offset] Offset of comment box
12
+ -w, --stretch [stretch] Stretch of comment box
13
+ -sl, --spacelines Remove space lines (default true)
14
+ -h, --help Display this help message
15
+ )
16
+
17
+ def help_and_exit
18
+ puts $HELP_MSG
19
+ exit
20
+ end
21
+
22
+ if ARGV.empty?
23
+ help_and_exit
24
+ end
25
+ # if the :text parameter is first, the -t flag is optional
26
+ mode = :text
27
+ options = {}
28
+ # for each argument:
29
+ # if it's a switch, set the `mode` symbol
30
+ # if it's a value, set/append to the coresponding `mode` key in `options`
31
+ ARGV.each do |arg|
32
+ case arg
33
+ when '-h', '--help', 'help', '-?', '--?'
34
+ help_and_exit
35
+ when '-t', '--text'
36
+ mode = :text
37
+ when '-a', '--align'
38
+ mode = :align
39
+ when '-s', '--style'
40
+ mode = :style
41
+ when '-p', '--padding'
42
+ mode = :padding
43
+ when '-o', '--offset'
44
+ mode = :offset
45
+ when '-w', '--stretch'
46
+ mode = :stretch
47
+ when '-sl', '--spacelines'
48
+ mode = :spacelines
49
+ # default is true so if it's mentioned, we implicitly assume false
50
+ # although it remains possible to explicitly specify true
51
+ options[:spacelines] = false
52
+ else
53
+ if options[mode].nil?
54
+ options[mode] = arg
55
+ else
56
+ # hacky line to make sure anything with multiple arguments comes out as a flat array
57
+ options[mode] = ([ options[mode] ] << arg).flatten
58
+ end
59
+ end
60
+ end
61
+
62
+
63
+ puts options.to_s
64
+
65
+ puts CommentBox.new options
data/lib/commentbox.rb CHANGED
@@ -16,6 +16,12 @@ module CommentBoxStyles
16
16
  evenlines: ['/ ', ' /'],
17
17
  oddcorners: ['=/','/=']
18
18
  },
19
+ window: {
20
+ hlines: '**',
21
+ oddlines: ['\\*', '*\\'],
22
+ evenlines: ['/+', '+/'],
23
+ oddcorners: ['+/','/+']
24
+ },
19
25
  parallax: {
20
26
  hlines: '==',
21
27
  oddlines: ['||', '||'],
@@ -118,8 +124,8 @@ class CommentBox
118
124
  if params.is_a? String then params = {text: params} end
119
125
 
120
126
  # fill in a bunch of instance variables from params or default values
121
- @padding = params[:padding] || @@default_params[:padding]
122
- @offset = params[:offset] || @@default_params[:offset]
127
+ @padding = params[:padding].to_i || @@default_params[:padding]
128
+ @offset = params[:offset].to_i || @@default_params[:offset]
123
129
  # one of the options for this is false, so it's not gonna play nice with ||
124
130
  @spacelines = (params[:spacelines] != nil) ? params[:spacelines] : @@default_params[:spacelines]
125
131
  @stretch = (params[:stretch] || @@default_params[:stretch]).to_i
@@ -143,8 +149,8 @@ class CommentBox
143
149
  (0..@text.size - 1).map { |line| fmt_text_line line }, # this is a nested array and must be flattened
144
150
  spaceLine,
145
151
  t_line(:end)
146
- # flatten, add offset to each line if it's not empty, join them together, and remove trailing newline
147
- ].flatten.map { |line| line == '' ? '' : (' ' * @offset) << line}.join.chomp
152
+ # flatten, map offset in front of each line if it's not empty, join them together, and remove trailing newline
153
+ ].flatten.map { |line| line == '' ? '' : (' ' * @offset) << line }.join.chomp
148
154
  end
149
155
 
150
156
  private
@@ -200,7 +206,7 @@ private
200
206
  else @text.insert(1,''); @alignment.insert(1,:left) end
201
207
  end
202
208
  end
203
- def t_line (beginOrEnd)
209
+ def t_line (beginOrEnd) #t[erminating]_line: top or bottom (begin or end) of the box
204
210
  if beginOrEnd == :begin
205
211
  bchar = '/*'; echar = @style[:oddcorners][0]
206
212
  else
metadata CHANGED
@@ -1,21 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commentbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonard H. Phelan IV
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-03 00:00:00.000000000 Z
11
+ date: 2023-01-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A little gem for generating pretty multiline comment boxes in C/C++ templates
14
14
  email: lenny@lenny.beer
15
- executables: []
15
+ executables:
16
+ - cbwiz
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
20
+ - bin/cbwiz
19
21
  - lib/commentbox.rb
20
22
  homepage: https://github.com/lennyitb/commentbox
21
23
  licenses:
@@ -36,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
38
  - !ruby/object:Gem::Version
37
39
  version: '0'
38
40
  requirements: []
39
- rubygems_version: 3.3.26
41
+ rubygems_version: 3.4.3
40
42
  signing_key:
41
43
  specification_version: 4
42
44
  summary: Lenny C/C++ template CommentBox class