commentbox 0.2.1 → 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 +17 -8
  4. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a43575a5fce78f88644c9bb88e0291a89455ab0431d28ce196fd7c9297817f45
4
- data.tar.gz: 4da8a222cdb0bbc9051ac63f42d394754b62d51b1e2582517be3ade0938a7003
3
+ metadata.gz: 5bf8ca4be9a56802c326ec4f5e1562262bf40d334571113c70ca11847c904195
4
+ data.tar.gz: ec433e2a0da5b227827e00f35033a626cb521a67668d2dc79a4061e7ffceb98f
5
5
  SHA512:
6
- metadata.gz: b3c437d82fe9a730adc67f3c54a67d76dd7dd6cc30851d173d24f725ce16cc33a043b105bbe640033455e916a4ad3596e896198e6e1c46a9867e298d3604fcaa
7
- data.tar.gz: 33e51c50a9d063ae040b9071d325e2f32dd1535b19a7266e5af3d25551c3dd00cad85c6f34273e967169e661ad338a7aca047d4e576c3cbf2d35d81957972e95
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: ['||', '||'],
@@ -78,9 +84,11 @@ class CommentBox
78
84
  @@styles = CommentBoxStyles::Styles
79
85
 
80
86
  # class methods for messing with default values
87
+ # make sure everything is symbolized that needs to be
81
88
  def self.default_params; @@default_params end
82
- def self.default_params=(value); @@default_params = value end
83
- def self.set_default_params (value = {}); value.each { |key, val| @@default_params[key] = val } end
89
+ def self.default_params=(value); @@default_params = value.transform_keys(&:to_sym) end
90
+ # def self.default_params[]= (key, value); @@default_params[key.to_sym] = value end
91
+ def self.set_default_params (value = {}); value.each { |key, val| @@default_params[key.to_sym] = val } end
84
92
  def self.styles; @@styles end
85
93
  def self.add_style(value)
86
94
  value.each do |key, val|
@@ -90,7 +98,8 @@ class CommentBox
90
98
  end
91
99
  end
92
100
  # I could attempt to remove a :default? key here but it doesn't matter
93
- @@styles.merge! value
101
+ # this is a terse one but trust me
102
+ @@styles.merge! value.transform_keys(&:to_sym).transform_values { |v| v.transform_keys(&:to_sym) }
94
103
  end
95
104
 
96
105
  # instance setter methods
@@ -115,8 +124,8 @@ class CommentBox
115
124
  if params.is_a? String then params = {text: params} end
116
125
 
117
126
  # fill in a bunch of instance variables from params or default values
118
- @padding = params[:padding] || @@default_params[:padding]
119
- @offset = params[:offset] || @@default_params[:offset]
127
+ @padding = params[:padding].to_i || @@default_params[:padding]
128
+ @offset = params[:offset].to_i || @@default_params[:offset]
120
129
  # one of the options for this is false, so it's not gonna play nice with ||
121
130
  @spacelines = (params[:spacelines] != nil) ? params[:spacelines] : @@default_params[:spacelines]
122
131
  @stretch = (params[:stretch] || @@default_params[:stretch]).to_i
@@ -140,8 +149,8 @@ class CommentBox
140
149
  (0..@text.size - 1).map { |line| fmt_text_line line }, # this is a nested array and must be flattened
141
150
  spaceLine,
142
151
  t_line(:end)
143
- # flatten, add offset to each line if it's not empty, join them together, and remove trailing newline
144
- ].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
145
154
  end
146
155
 
147
156
  private
@@ -197,7 +206,7 @@ private
197
206
  else @text.insert(1,''); @alignment.insert(1,:left) end
198
207
  end
199
208
  end
200
- def t_line (beginOrEnd)
209
+ def t_line (beginOrEnd) #t[erminating]_line: top or bottom (begin or end) of the box
201
210
  if beginOrEnd == :begin
202
211
  bchar = '/*'; echar = @style[:oddcorners][0]
203
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.1
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-02 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