L2 0.6.0 → 0.6.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: b264818a3f5af77f0ca579737bf36aa09205a685a9b05dfc18ed753c9c1344c7
4
- data.tar.gz: 75f7caa168b4a6e224780ddf1d2da6400a24fbd7aacc9de586e9c8aa7f77406c
3
+ metadata.gz: c1297f11f7f7386804c92d8ee1a29e348fe934a0fc99835bd2bff946288015ca
4
+ data.tar.gz: c3aa0855ec601c2bbc17b64c82a86b195bc75b2a1a0194aef4f5d548a3698218
5
5
  SHA512:
6
- metadata.gz: b063d07d782e5f08754ec0fe99dea119434924ecbc6f047537f606ec15c4691d2e3f483de936d2623e32e44e02fce6772a86427b4fefbd0d66cb201df6c62c88
7
- data.tar.gz: '055648ed84a8db941adb87aca18e670ce6b4b17f4cb5b9eca67d803c385a48fbc0ad6730b724186594878a139e38decddf9b09d158255f324f69de33e41dabe6'
6
+ metadata.gz: c0cd7475c62bb0ab8ad7bc5dda8f5f9fb489043e8bc99cba212fae3a46ffb47b8b7ff640459628ea14bd73619b2a6ee42e117eab8e11ab2e69b216949f695bac
7
+ data.tar.gz: e4b8f6586abfffa587a1c846536291405d17887d5d8e367ffb85ecb3a6e052e8b683983031c2bbf0078d3aeb86333e1edb63c31cb29e4472c184cbbe65287c9a
data/lib/L2/banner.rb ADDED
@@ -0,0 +1,50 @@
1
+
2
+ module L2
3
+ module Banner
4
+ def self.title title
5
+ width = WIDTH - title.length - 4
6
+ self.line(WIDTH/8)
7
+ puts title.rjust(width / 2)
8
+ self.line(WIDTH/8)
9
+ end
10
+
11
+ def self.infob *messages
12
+ puts(separator_pretty(:blue))
13
+ messages.each { |message| puts(pretty("INFO: #{ message }", :white, :blue)) }
14
+ puts(separator_pretty(:blue))
15
+ end
16
+
17
+ def self.successb *messages
18
+ puts(separator_pretty(:green))
19
+ messages.each { |message| puts(pretty("SUCCESS: #{ message }", :black, :green)) }
20
+ puts(separator_pretty(:green))
21
+ end
22
+
23
+ def self.warningb *messages
24
+ puts(separator_pretty(:yellow))
25
+ messages.each { |message| puts(pretty("WARNING: #{ message }", :black, :yellow)) }
26
+ puts(separator_pretty(:yellow))
27
+ end
28
+
29
+ def self.dangerb *messages
30
+ puts(separator_pretty(:red))
31
+ messages.each { |message| puts(pretty("ERROR: #{ message }", :yellow, :red)) }
32
+ puts(pretty("PATH: #{ caller[0] }", :yellow, :red))
33
+ puts(separator_pretty(:red))
34
+ end
35
+
36
+ def self.fatal *messages
37
+ puts(separator_pretty(:red))
38
+ messages.each { |message| puts("\e[5m#{pretty(message, :white, :red)}\e[0m") }
39
+ puts(pretty("PATH: #{ caller[0] }", :white, :red))
40
+ puts(separator_pretty(:red))
41
+ end
42
+
43
+
44
+ def self.deprecation message
45
+ puts(separator_pretty(:red))
46
+ puts(pretty("DEPRECATED METHOD: #{ caller[0] }, #{ message }", :white, :red))
47
+ puts(separator_pretty(:red))
48
+ end
49
+ end
50
+ end
data/lib/L2/config.rb ADDED
@@ -0,0 +1,64 @@
1
+
2
+
3
+ module L2
4
+ module Config
5
+
6
+ ICONS = {
7
+ checkmark: "✓",
8
+ bullet: "•",
9
+ star: "★"
10
+ }.freeze
11
+
12
+ # standard color palette for texts
13
+ COLORS = {
14
+ skyblue: '96',
15
+ default: '38',
16
+ yellow: '1;33',
17
+ white: '1;37',
18
+ green: '32',
19
+ black: '30',
20
+ blue: '36',
21
+ red: '31'
22
+ }.freeze
23
+
24
+ # standard color palette for backgrounds
25
+ BG_COLORS = {
26
+ default: '0',
27
+ yellow: '103',
28
+ white: '107',
29
+ green: '42',
30
+ black: '40',
31
+ blue: '44',
32
+ red: '41'
33
+ }.freeze
34
+
35
+
36
+ # calculate the console width
37
+ # tputcols is not available on windows
38
+ #WIDTH = `tput cols`.to_i rescue WIDTH = 1;
39
+ WIDTH = begin
40
+ term = ENV['TERM']
41
+ term ? `tput cols`.to_i : 1
42
+ rescue
43
+ 1
44
+ end
45
+
46
+ def self.colorize(text, colour = :default, bg_colour = :default)
47
+ colour_code = COLORS[colour]
48
+ bg_colour_code = BG_COLORS[bg_colour]
49
+ return "\e[#{bg_colour_code};#{colour_code}m#{text}\e[0m".squeeze(';')
50
+ end
51
+
52
+
53
+ def self.pretty(message, colour = :default, bg_colour = :default)
54
+ width = 1
55
+
56
+ unless bg_colour == :default
57
+ width = WIDTH - message.length - 4
58
+ width = 1 if width.negative?
59
+ end
60
+
61
+ return colorize("\ \ #{ message } #{"\ " * width}", colour, bg_colour)
62
+ end
63
+ end
64
+ end
data/lib/L2/list.rb ADDED
@@ -0,0 +1,19 @@
1
+
2
+ require "l2/Config"
3
+
4
+ module L2
5
+ module List
6
+
7
+ def self.bullet *items
8
+ items.each { |item| puts(" #{Config::ICONS[:bullet]} #{ item }" )}
9
+ end
10
+
11
+ def self.check *items
12
+ items.each { |item| puts(" #{Config::ICONS[:checkmark]} #{ item }" )}
13
+ end
14
+
15
+ def self.star *items
16
+ items.each { |item| puts(" #{Config::ICONS[:star]} #{ item }" )}
17
+ end
18
+ end
19
+ end
data/lib/L2/msg.rb ADDED
@@ -0,0 +1,35 @@
1
+
2
+ require "l2/Config"
3
+
4
+ module L2
5
+ module Msg
6
+ def self.simple messages
7
+ messages.each { |message| puts(message) }
8
+ end
9
+
10
+ def self.msg messages
11
+ self.m(messages)
12
+ end
13
+
14
+ def self.info messages
15
+ messages.each { |message| puts(Config.pretty("INFO: #{ message }", :blue)) }
16
+ end
17
+
18
+ def self.success messages
19
+ messages.each { |message| puts(Config.pretty("SUCCESS: #{ message }", :green)) }
20
+ end
21
+
22
+ def self.warning messages
23
+ messages.each { |message| puts(Config.pretty("WARNING: #{ message }", :yellow)) }
24
+ end
25
+
26
+ def self.danger messages
27
+ messages.each { |message| puts(Config.pretty("ERROR: #{ message }", :red)) }
28
+ end
29
+
30
+ def self.alert messages
31
+ messages.each { |message| puts("\e[5m#{message}\e[0m") }
32
+ end
33
+
34
+ end
35
+ end
data/lib/L2/space.rb ADDED
@@ -0,0 +1,19 @@
1
+
2
+ require "l2/Config"
3
+
4
+ module L2
5
+ module Space
6
+
7
+ def self.br count=1
8
+ puts("\n" * count);
9
+ end
10
+
11
+ def self.line count=8
12
+ puts('-·- ' * count)
13
+ end
14
+
15
+ def self.color color
16
+ Config.pretty("", :black, color)
17
+ end
18
+ end
19
+ end
data/lib/L2/table.rb ADDED
@@ -0,0 +1,55 @@
1
+
2
+ require "l2/Config"
3
+
4
+ module L2
5
+ module Table
6
+ def self.simple data
7
+
8
+ return if Gem.win_platform?
9
+ return unless data.size > 0
10
+
11
+ if data.class.name == "ActiveRecord::Relation"
12
+ data = data.to_a.map(&:serializable_hash)
13
+ end
14
+
15
+ # get the available characters in terminal width
16
+ #terminal_width = `tput cols`.to_i
17
+ terminal_width = Config::WIDTH
18
+
19
+ # get the number of columns to print base on the data hash
20
+ cols = data.first.keys.count + 1
21
+
22
+ # get the available space for every column
23
+ col_width = (terminal_width / cols) - 1
24
+
25
+ # validate that we have minimum space to render the table
26
+ return if col_width <= 0
27
+
28
+ # separator for every column and row
29
+ separator = ('| ' << ('- ' * (col_width / 2)))
30
+
31
+ # add extra blank spaces to adjust the col_width only if col_width not a even number
32
+ separator += (' ') if (col_width - separator.size).odd?
33
+
34
+ # print data as table :)
35
+ data.each_with_index do |row, index|
36
+
37
+ # only for table header
38
+ if index == 0
39
+
40
+ # print table titles
41
+ puts '| ' << row.keys.map { |key| key.to_s.upcase.ljust(col_width) }.join('| ')
42
+
43
+ # print header separators, only for visible columns
44
+ puts separator * (cols - 1)
45
+
46
+ end
47
+
48
+ # join hash values as a line and justify every value to print value
49
+ # in its own column
50
+ puts '| ' << row.values.map { |value| value.to_s.ljust(col_width) }.join('| ')
51
+
52
+ end
53
+ end
54
+ end
55
+ end
data/lib/L2/version.rb ADDED
@@ -0,0 +1,34 @@
1
+ =begin
2
+
3
+ Copyright (c) 2022, Lesli Technologies, S. A.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ Lesli Ruby Messages - Message utilities for the Ruby console
19
+
20
+ Powered by https://www.lesli.tech
21
+ Building a better future, one line of code at a time.
22
+
23
+ @contact <hello@lesli.tech>
24
+ @website <https://www.lesli.tech>
25
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
26
+ @author The Lesli Development Team
27
+
28
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
29
+ // ·
30
+ =end
31
+
32
+ module L2
33
+ VERSION = "0.6.2"
34
+ end
data/lib/L2.rb CHANGED
@@ -30,10 +30,10 @@ Building a better future, one line of code at a time.
30
30
  =end
31
31
 
32
32
 
33
- require "l2/Msg"
34
- require "l2/List"
35
- require "l2/Table"
36
- require "l2/Space"
33
+ require "L2/msg"
34
+ require "L2/list"
35
+ require "L2/table"
36
+ require "L2/space"
37
37
 
38
38
 
39
39
  # ·
data/readme.md ADDED
@@ -0,0 +1,145 @@
1
+ <p align="center">
2
+ <a href="https://www.lesli.dev" target="_blank">
3
+ <img alt="Lesli Ruby Message logo" width="200px" src="./docs/l2-logo.svg" />
4
+ </a>
5
+ </p>
6
+ <h3 align="center">Message utilities for the Ruby console</h3>
7
+
8
+ Version 0.5.2
9
+
10
+ ## Installation
11
+
12
+ Install the gem and add to the application's Gemfile by executing:
13
+
14
+ $ bundle add l2
15
+
16
+ If bundler is not being used to manage dependencies, install the gem by executing:
17
+
18
+ $ gem install l2
19
+
20
+ Rails apps
21
+
22
+ $ gem "L2", "~> 0.4.0"
23
+
24
+ ## Usage
25
+
26
+
27
+ **Simple message:**
28
+
29
+ ```ruby
30
+ L2.m("hola")
31
+ L2.m("hola", "hello", "hallo", 1, [2], {"a":"b"})
32
+ ```
33
+
34
+
35
+ **Simple message with dividing line:**
36
+
37
+ ```ruby
38
+ L2.msg("hola")
39
+ L2.msg("hola", "hello", "hallo", 1, [2], {"a":"b"})
40
+ ```
41
+
42
+
43
+ **Informative message:**
44
+
45
+ ```ruby
46
+ L2.info("hola")
47
+ L2.info("hola", "hello", "hallo", 1, [2], {"a":"b"})
48
+ ```
49
+
50
+
51
+ **Sucessful message:**
52
+
53
+ ```ruby
54
+ L2.success("hola")
55
+ L2.success("hola", "hello", "hallo", 1, [2], {"a":"b"})
56
+ ```
57
+
58
+
59
+ **Simple message:**
60
+
61
+ ```ruby
62
+ L2.warning("hola")
63
+ L2.warning("hola", "hello", "hallo", 1, [2], {"a":"b"})
64
+ ```
65
+
66
+
67
+ **Error message:**
68
+
69
+ ```ruby
70
+ L2.danger("hola")
71
+ L2.danger("hola", "hello", "hallo", 1, [2], {"a":"b"})
72
+ ```
73
+
74
+
75
+ **Error with flashing message:**
76
+
77
+ ```ruby
78
+ L2.fatal("hola")
79
+ L2.fatal("hola", "hello", "hallo", 1, [2], {"a":"b"})
80
+ ```
81
+
82
+
83
+ **Flashing message:**
84
+
85
+ ```ruby
86
+ L2.alert("hola")
87
+ L2.alert("hola", "hello", "hallo", 1, [2], {"a":"b"})
88
+ ```
89
+
90
+
91
+ **Useful to give instructions in deprecated methods or code:**
92
+
93
+ ```ruby
94
+ L2.deprecation("hola")
95
+ ```
96
+
97
+
98
+ **Print a simple list:**
99
+
100
+ ```ruby
101
+ L2.list("hola", "hello", "hallo", 1, [2], {"a":"b"})
102
+ ```
103
+
104
+
105
+ **Show data as table:**
106
+
107
+ ```ruby
108
+ L2.table([
109
+ { español: "hola", english: "hello", deutsch: "hallo" },
110
+ { español: "hola", english: "hello", deutsch: "hallo" },
111
+ { español: "hola", english: "hello", deutsch: "hallo" }
112
+ ])
113
+ ```
114
+
115
+
116
+ **Display a cow message:**
117
+
118
+ ```ruby
119
+ L2.cow("Hello little cow!")
120
+ ```
121
+
122
+
123
+ ### Development
124
+ ------
125
+
126
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
127
+
128
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
129
+
130
+ ### Contributing
131
+ ------
132
+
133
+ Bug reports and pull requests are welcome on GitHub at https://github.com/LesliTech/l2.
134
+
135
+
136
+ ### License
137
+ ------
138
+
139
+ Software developed in [Guatemala](http://visitguatemala.com/) distributed under the *General Public License v 3.0* you can read the full license [here](http://www.gnu.org/licenses/gpl-3.0.html)
140
+
141
+ <p align="center">
142
+ <a href="https://www.lesli.tech" target="_blank">
143
+ <img alt="LesliTech logo" width="150" src="https://cdn.lesli.tech/leslitech/brand/leslitech-logo.svg" />
144
+ </a>
145
+ </p>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: L2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Lesli Development Team
@@ -18,6 +18,14 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/L2.rb
21
+ - lib/L2/banner.rb
22
+ - lib/L2/config.rb
23
+ - lib/L2/list.rb
24
+ - lib/L2/msg.rb
25
+ - lib/L2/space.rb
26
+ - lib/L2/table.rb
27
+ - lib/L2/version.rb
28
+ - readme.md
21
29
  homepage: https://github.com/LesliTech/L2
22
30
  licenses:
23
31
  - GPL-3.0
@@ -25,7 +33,7 @@ metadata:
25
33
  homepage_uri: https://github.com/LesliTech/L2
26
34
  source_code_uri: https://github.com/LesliTech/L2
27
35
  bug_tracker_uri: https://github.com/LesliTech/L2/issues
28
- changelog_uri: https://github.com/LesliTech/L2/releases/tag/v0.6.0
36
+ changelog_uri: https://github.com/LesliTech/L2/releases/tag/v0.6.2
29
37
  post_install_message:
30
38
  rdoc_options: []
31
39
  require_paths: