branding 0.0.1 → 0.0.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 +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +4 -2
- data/lib/branding/canvas.rb +24 -4
- data/lib/branding/cli.rb +6 -7
- data/lib/branding/logo.rb +5 -2
- data/lib/branding/railtie.rb +26 -7
- data/lib/branding/version.rb +1 -1
- data/spec/branding_spec.rb +1 -1
- data/spec/fixtures/test3x3.png +0 -0
- data/spec/png_spec.rb +6 -8
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98c7c50a74686570bba45b496c478e1e3e34dbcc
|
4
|
+
data.tar.gz: 631b8ac04bd4f9aea66443e4c5224535bc32025d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 575a40f1e189d2ceee0614e12e4773e8c73c4c90c46ca39cad7a3fcc781190f0a65ae59cdfaa23f69bb4483958c883cca484de3c70cbddcc3953d5b009fc3fad
|
7
|
+
data.tar.gz: 8526484d7c9776793bed44e8de82efb7f56f30c02c40dc4c963f01beb58733dc899c3edca79d5ba193bbfd279a3f54a39390f9e015df8dc5b7948eae3d929bfa
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -6,17 +6,19 @@ Proud of your code? Add some bling to your terminal.
|
|
6
6
|
|
7
7
|
* No dependencies!
|
8
8
|
* Pure Ruby PNG decoding in < 200 LoC
|
9
|
+
* Hi-Res mode for 2x pixel density!
|
10
|
+
* Hi-Color mode for 720 colors!!
|
9
11
|
* Loads of fun!
|
10
12
|
|
11
13
|
## Quality
|
12
14
|
|
13
|
-
Much quality
|
15
|
+
Much quality.
|
14
16
|
|
15
17
|
## How it works
|
16
18
|
|
17
19
|
Branding will detect your Rails application's favicon. It adds a small
|
18
20
|
initializer in development and testing environments that draws the favicon with
|
19
|
-
ANSI control characters.
|
21
|
+
ANSI control characters whenever you run tests, a rake task or boot the console.
|
20
22
|
|
21
23
|
## Installation
|
22
24
|
|
data/lib/branding/canvas.rb
CHANGED
@@ -4,14 +4,34 @@ module Branding
|
|
4
4
|
class Canvas
|
5
5
|
attr_reader :width, :height, :rows, :cols
|
6
6
|
|
7
|
-
def
|
7
|
+
def self.terminal_size
|
8
|
+
# TODO: make sure we can get this on linux
|
9
|
+
begin
|
10
|
+
`stty size`.split.map(&:to_i)
|
11
|
+
rescue
|
12
|
+
[40, 100]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(width:, height:)
|
8
17
|
@width, @height = width, height
|
9
|
-
@rows, @cols =
|
18
|
+
@rows, @cols = self.class.terminal_size
|
10
19
|
@pixel_buffer = []
|
11
20
|
end
|
12
21
|
|
13
|
-
def load(pixels)
|
14
|
-
|
22
|
+
def load(pixels, algo: :normal)
|
23
|
+
case algo
|
24
|
+
when :normal
|
25
|
+
klass = Pixel
|
26
|
+
when :hires
|
27
|
+
klass = Pixel2x
|
28
|
+
when :hicolor
|
29
|
+
raise 'Hi-Color coming soon!'
|
30
|
+
else
|
31
|
+
raise "Unknown pixel algo `#{algo}`"
|
32
|
+
end
|
33
|
+
|
34
|
+
klass.load_strategy(pixels, width: width, height: height) do |pixel|
|
15
35
|
@pixel_buffer << pixel
|
16
36
|
end
|
17
37
|
end
|
data/lib/branding/cli.rb
CHANGED
@@ -6,13 +6,15 @@ module Branding
|
|
6
6
|
def initialize(args)
|
7
7
|
@options = OpenStruct.new
|
8
8
|
|
9
|
-
@options.command = :print_logo
|
10
9
|
@options.file = args.last
|
11
10
|
|
12
11
|
@parser = OptionParser.new do |opts|
|
13
12
|
opts.banner = 'Usage: branding FILE'
|
14
|
-
opts.on('-
|
15
|
-
|
13
|
+
opts.on('-p PIXEL',
|
14
|
+
'--pixel=PIXEL',
|
15
|
+
[:normal, :hires, :hicolor],
|
16
|
+
'The pixel rendering algorithm (`normal`, `hires`, or `hicolor`)') do |pixel_algo|
|
17
|
+
@options.algo = pixel_algo.to_sym
|
16
18
|
end
|
17
19
|
|
18
20
|
opts.on_tail('-h', '--help', 'Show this message') do
|
@@ -26,11 +28,8 @@ module Branding
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def run
|
29
|
-
send(@options.command)
|
30
|
-
end
|
31
|
-
|
32
|
-
def print_logo
|
33
31
|
logo = Branding::Logo.new(@options.file)
|
32
|
+
logo.algo = @options.algo
|
34
33
|
logo.print
|
35
34
|
end
|
36
35
|
end
|
data/lib/branding/logo.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
module Branding
|
2
|
-
class Logo
|
2
|
+
class Logo # :nodoc:
|
3
|
+
attr_accessor :algo
|
4
|
+
|
3
5
|
def initialize(path)
|
6
|
+
@algo = :normal
|
4
7
|
@img = PNG.from_file(path)
|
5
8
|
@canvas = Canvas.new(width: @img.width, height: @img.height)
|
6
9
|
end
|
7
10
|
|
8
11
|
def print
|
9
|
-
@canvas.load(@img.pixels)
|
12
|
+
@canvas.load(@img.pixels, algo: @algo)
|
10
13
|
@canvas.print
|
11
14
|
nil
|
12
15
|
end
|
data/lib/branding/railtie.rb
CHANGED
@@ -3,21 +3,40 @@ module Branding
|
|
3
3
|
|
4
4
|
unless Rails.env.production?
|
5
5
|
initializer('branding.print_logo') do
|
6
|
-
|
7
|
-
|
6
|
+
begin
|
7
|
+
rows, cols = Canvas.terminal_size
|
8
|
+
ideal_width = cols / 6
|
9
|
+
|
10
|
+
logo = Branding::Logo.new(Branding::Railtie.best_icon(ideal_width))
|
11
|
+
logo.algo = :hires
|
12
|
+
logo.print
|
13
|
+
print "\n"
|
14
|
+
rescue
|
15
|
+
# We don't want to do anything if this causes an exception. Your time
|
16
|
+
# is too valuable to be dealing with busted amusement gems.
|
17
|
+
end
|
8
18
|
end
|
9
19
|
end
|
10
20
|
|
11
21
|
##
|
12
22
|
# find the best suited icon in a rails app
|
13
|
-
def self.
|
23
|
+
def self.best_icon(ideal_width)
|
24
|
+
paths = icon_paths.sort_by do |path|
|
25
|
+
png = PNG.from_file(path)
|
26
|
+
(ideal_width - png.width).abs
|
27
|
+
end
|
28
|
+
|
29
|
+
if paths.empty?
|
30
|
+
else
|
31
|
+
paths.first
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.icon_paths
|
14
36
|
paths = ["#{Rails.root}/public/", "#{Rails.root}/app/assets/images/"]
|
15
37
|
file_patterns = ['favicon*.png', 'apple-touch-icon*.png']
|
16
38
|
patterns = paths.product(file_patterns).map(&:join)
|
17
|
-
|
18
|
-
matches = Dir.glob(patterns)
|
19
|
-
|
20
|
-
matches.sort_by{|path| File.stat(path).size }.first
|
39
|
+
Dir.glob(patterns)
|
21
40
|
end
|
22
41
|
end
|
23
42
|
end
|
data/lib/branding/version.rb
CHANGED
data/spec/branding_spec.rb
CHANGED
Binary file
|
data/spec/png_spec.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Branding::PNG do
|
4
|
-
it 'returns a pixel
|
4
|
+
it 'returns a pixel list' do
|
5
5
|
png = Branding::PNG.from_file(fixture_file('test3x3.png'))
|
6
|
-
expect(png.pixels).to eq(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
]
|
12
|
-
)
|
6
|
+
expect(png.pixels).to eq([
|
7
|
+
0x111111ff, 0xc6c6c6ff, 0xffffffff,
|
8
|
+
0xc6c6c6ff, 0x111111ff, 0xc6c6c6ff,
|
9
|
+
0xffffffff, 0xc6c6c6ff, 0x111111ff
|
10
|
+
])
|
13
11
|
end
|
14
12
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: branding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Natchev
|
@@ -90,6 +90,7 @@ extra_rdoc_files: []
|
|
90
90
|
files:
|
91
91
|
- ".gitignore"
|
92
92
|
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
93
94
|
- ".travis.yml"
|
94
95
|
- Gemfile
|
95
96
|
- LICENSE.txt
|
@@ -107,6 +108,7 @@ files:
|
|
107
108
|
- lib/branding/railtie.rb
|
108
109
|
- lib/branding/version.rb
|
109
110
|
- spec/branding_spec.rb
|
111
|
+
- spec/fixtures/test3x3.png
|
110
112
|
- spec/pixel_spec.rb
|
111
113
|
- spec/png_spec.rb
|
112
114
|
- spec/spec_helper.rb
|
@@ -136,6 +138,7 @@ specification_version: 4
|
|
136
138
|
summary: Print your logo to the terminal.
|
137
139
|
test_files:
|
138
140
|
- spec/branding_spec.rb
|
141
|
+
- spec/fixtures/test3x3.png
|
139
142
|
- spec/pixel_spec.rb
|
140
143
|
- spec/png_spec.rb
|
141
144
|
- spec/spec_helper.rb
|