commentbox 0.3.2 → 0.3.4

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 +22 -7
  3. data/lib/commentbox.rb +6 -3
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c9924ff53c559dcf315eb35ecc7587b702a1a7bd561a126910f9b1d51a073b1
4
- data.tar.gz: aa7434f90f115cecdca5a6b1f1735c82622127ac47343bb052c59f3b7a760373
3
+ metadata.gz: d6e6ad58ee774761f75736dfa59521066e1891734a2cbec74735934787bd217b
4
+ data.tar.gz: ed56c9fc4b444ad98d8efb8ff466b4febae04120f6fdec4de3f44a886e61b455
5
5
  SHA512:
6
- metadata.gz: b38c2d5f76c2554890d9fc309e313d8339ec9d4b150817d275b23ef16d3e50dc5841b9d77d3724048f3f4fc91ceaaa2b313dc52171d6ecda2cdf0554622a7187
7
- data.tar.gz: d888803e4c6a6a53ca7896d4f3fce2664f7109f5ae877e1bc00858789583ae0e4981ed7cd0e53ddd13a5c6e3c966e09e68f25b15169d8017682efe616e3ec0d2
6
+ metadata.gz: a696f49cdbc12e075d0a02743bd7c7ac5ead6ee337f9849b9e9ae3070393f8b6f2609943c137ab8216d7a1a19555d34fc441ad8d60572ac5d12e1bb26a090a9b
7
+ data.tar.gz: 8b2a64f47c07f8784afb7fbb5b3ab7cde81083e158559dc3b41eabd37f1777dc58a445818e0a482b123626beac7679dc113c5f728b8ca383cf0133049cc7c6ad
data/bin/cbwiz CHANGED
@@ -1,11 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # cbwiz - an executable tool for the commentbox ruby gem by Lenny
4
+ # it's read: Comment Box WhIZzer
5
+ # github.com/lennyitb/commentbox
6
+
3
7
  require 'commentbox'
4
8
 
5
- $HELP_MSG = %q(Usage: cbwiz [options] [text]
9
+ $HELP_MSG = %q(Usage: cbwiz [-t] text [options]
6
10
  Options:
7
11
  -t, --text [text] Text to be commented. Optional flag for first argument
8
- -a, --align [l1, l2...] Alignment of text: left, center, right
12
+ -a, --align [l1 l2...] Alignment of text: left, center, right
9
13
  -s, --style [style] Style of comment box: stub, window, parallax, zigzag, or money
10
14
  -p, --padding [padding] Padding of comment box
11
15
  -o, --offset [offset] Offset of comment box
@@ -19,16 +23,22 @@ def help_and_exit
19
23
  puts $HELP_MSG
20
24
  exit
21
25
  end
22
-
23
26
  if ARGV.empty?
24
- help_and_exit
27
+ puts "/* cbwiz - no arguments given. for help, use: cbwiz -h */"
28
+ exit
25
29
  end
30
+
26
31
  # if the :text parameter is first, the -t flag is optional
27
32
  mode = :text
28
33
  options = {}
29
34
  # for each argument:
30
- # if it's a switch, set the `mode` symbol
31
- # if it's a value, set/append to the coresponding `mode` key in `options`
35
+ # - if it's a switch, set the `mode` symbol
36
+ # - if it's a value, set/append to the coresponding `mode` key in `options`
37
+
38
+ # usually this type of code wouldn't be the best practice, but not only does it work well here--
39
+ # it's also a situation where the order of the arguments is an important piece, that we can't
40
+ # really get away from by writitng unnecicarily declarative code. With each iterative pass,
41
+ # we're either updating the mode, or using the value of mode we set before.
32
42
  ARGV.each do |arg|
33
43
  case arg
34
44
  when '-h', '--help', 'help', '-?', '--?'
@@ -53,14 +63,19 @@ ARGV.each do |arg|
53
63
  # although it remains possible to explicitly specify true
54
64
  options[:spacelines] = false
55
65
  else
66
+ # every argv that gets here is not a switch
56
67
  if options[mode].nil?
57
68
  options[mode] = arg
58
69
  else
59
- # hacky line to make sure anything with multiple arguments comes out as a flat array
70
+ # hacky line to make sure any switch with multiple arguments comes out as a flat array like so:
71
+ # -a left center right
72
+ # >> { alignment: ['left', 'center', 'right'] }
60
73
  options[mode] = ([ options[mode] ] << arg).flatten
61
74
  end
62
75
  end
63
76
  end
77
+ # make sure the :text key is a string
78
+ if options[:text].is_a? Array then options[:text] = options[:text].join(' ') end
64
79
  # finally, unescape newlines in text
65
80
  options[:text] = options[:text].gsub('\n', "\n")
66
81
 
data/lib/commentbox.rb CHANGED
@@ -1,4 +1,7 @@
1
1
 
2
+ # commentbox: a ruby gem for generating C/C++ formatted comment boxes
3
+ # github.com/lennyitb/commentbox
4
+
2
5
  module CommentBoxStyles
3
6
  DefaultParams = {
4
7
  style: :stub,
@@ -7,7 +10,7 @@ module CommentBoxStyles
7
10
  offset: 2,
8
11
  min_width: 0,
9
12
  spacelines: true,
10
- alignment: :left
13
+ alignment: :left
11
14
  }
12
15
  Styles = {
13
16
  stub: {
@@ -124,8 +127,8 @@ class CommentBox
124
127
  if params.is_a? String then params = {text: params} end
125
128
 
126
129
  # fill in a bunch of instance variables from params or default values
127
- @padding = params[:padding].to_i || @@default_params[:padding]
128
- @offset = params[:offset].to_i || @@default_params[:offset]
130
+ @padding = (params[:padding] || @@default_params[:padding]).to_i
131
+ @offset = (params[:offset] || @@default_params[:offset]).to_i
129
132
  # one of the options for this is false, so it's not gonna play nice with ||
130
133
  @spacelines = (params[:spacelines] != nil) ? params[:spacelines] : @@default_params[:spacelines]
131
134
  @stretch = (params[:stretch] || @@default_params[:stretch]).to_i
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commentbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
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-13 00:00:00.000000000 Z
11
+ date: 2023-01-20 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