eskimo 2.0.0 → 2.1.0
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/lib/eskimo.rb +2 -0
- data/lib/eskimo/component.rb +6 -0
- data/lib/eskimo/components/gutter.rb +33 -0
- data/lib/eskimo/components/spacer.rb +33 -0
- data/lib/eskimo/version.rb +1 -1
- data/spec/components/gutter_spec.rb +25 -0
- data/spec/components/spacer_spec.rb +42 -0
- metadata +19 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cda13727446ff4b079dfa76a1203d4545739b8a73a635cd515a00072914f889c
|
4
|
+
data.tar.gz: 913d763b28a632677d530e2c8d7d31e2c3c7c363f57b9e63be420a3fd5ebc5cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb6ba86cfc76d02e4e82bfc3ea9ea191a6752de8fd569d9f9eda6c155154c402ae05c22f7c8870a192f4b5c918ec6d011bb277f8992983c536d0b74fd2743104
|
7
|
+
data.tar.gz: 1a0739266cd09f9d002272a27968219c89556a24d4412050c73239be6f15ba4aa7ede74e19ca5bdf1ad71c5cfc98a8549bd941d0405149fe95dd46fd4b7d478f
|
data/lib/eskimo.rb
CHANGED
@@ -11,11 +11,13 @@ require 'eskimo/renderer'
|
|
11
11
|
|
12
12
|
require 'eskimo/components/did_you_mean'
|
13
13
|
require 'eskimo/components/either'
|
14
|
+
require 'eskimo/components/gutter'
|
14
15
|
require 'eskimo/components/highlight'
|
15
16
|
require 'eskimo/components/highlight_column'
|
16
17
|
require 'eskimo/components/indent'
|
17
18
|
require 'eskimo/components/line_break'
|
18
19
|
require 'eskimo/components/soft_break'
|
20
|
+
require 'eskimo/components/spacer'
|
19
21
|
require 'eskimo/components/squeeze'
|
20
22
|
require 'eskimo/components/strip'
|
21
23
|
require 'eskimo/components/strip_left'
|
data/lib/eskimo/component.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Eskimo
|
4
|
+
module Components
|
5
|
+
# Prepend each line with a character or symbol.
|
6
|
+
#
|
7
|
+
# Gutter.new(char: '| ') do
|
8
|
+
# [ "Hello", "\n", "World!" ]
|
9
|
+
# end
|
10
|
+
# # => "| Hello"
|
11
|
+
# # "| World!"
|
12
|
+
class Gutter < Component
|
13
|
+
attr_reader :char, :spacing
|
14
|
+
|
15
|
+
def initialize(char:, spacing: 0, &children)
|
16
|
+
@char = char
|
17
|
+
@spacing = spacing
|
18
|
+
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def render(**)
|
23
|
+
spacer = Array.new(spacing, char)
|
24
|
+
|
25
|
+
[
|
26
|
+
*spacer,
|
27
|
+
super.lines.map { |s| s.prepend(char) }.join,
|
28
|
+
*spacer
|
29
|
+
].join("\n")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Eskimo
|
4
|
+
module Components
|
5
|
+
# Space consecutive components with soft breaks.
|
6
|
+
#
|
7
|
+
# Spacer.new([
|
8
|
+
# "Hello",
|
9
|
+
# "World!"
|
10
|
+
# ])
|
11
|
+
# # => "Hello"
|
12
|
+
# # "World!"
|
13
|
+
#
|
14
|
+
# The soft breaks for each conditional component will be preserved only
|
15
|
+
# if they do render some content.
|
16
|
+
class Spacer
|
17
|
+
def initialize(children)
|
18
|
+
if !children.is_a?(Array) || block_given?
|
19
|
+
raise ArgumentError.new("Spacer works only with an Array of components")
|
20
|
+
end
|
21
|
+
|
22
|
+
@children = children
|
23
|
+
end
|
24
|
+
|
25
|
+
def render(**props)
|
26
|
+
rendered = @children.map(&props[:render])
|
27
|
+
|
28
|
+
without_blanks = rendered.reject(&:empty?)
|
29
|
+
without_blanks.join("\n")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/eskimo/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Eskimo::Components::Gutter do
|
6
|
+
it 'prepends each line with the character' do
|
7
|
+
expect(
|
8
|
+
renderer.apply do
|
9
|
+
ESK::Gutter.new(char: '| ') do
|
10
|
+
"hello\nworld"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
).to eq("| hello\n| world")
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'inserts surrounding whitespace' do
|
17
|
+
expect(
|
18
|
+
renderer.apply do
|
19
|
+
ESK::Gutter.new(char: '| ', spacing: 2) do
|
20
|
+
"hello\nworld"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
).to eq("| \n| \n| hello\n| world\n| \n| ")
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Eskimo::Components::Spacer do
|
6
|
+
it 'inserts newlines between components' do
|
7
|
+
expect(
|
8
|
+
renderer.apply do
|
9
|
+
ESK::Spacer.new([
|
10
|
+
"Hello",
|
11
|
+
"World!"
|
12
|
+
])
|
13
|
+
end
|
14
|
+
).to eq("Hello\nWorld!")
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'ignores falsey components' do
|
18
|
+
expect(
|
19
|
+
renderer.apply do
|
20
|
+
ESK::Spacer.new([
|
21
|
+
"Hello",
|
22
|
+
false && 'hi',
|
23
|
+
false && 'ho',
|
24
|
+
"World!",
|
25
|
+
false && 'yup'
|
26
|
+
])
|
27
|
+
end
|
28
|
+
).to eq("Hello\nWorld!")
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'bails if not given an array of children' do
|
32
|
+
expect { ESK::Spacer.new('') }.to raise_error(ArgumentError,
|
33
|
+
"Spacer works only with an Array of components"
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'bails if given a block' do
|
38
|
+
expect { ESK::Spacer.new([]) {} }.to raise_error(ArgumentError,
|
39
|
+
"Spacer works only with an Array of components"
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eskimo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmad Amireh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|
@@ -90,11 +90,13 @@ files:
|
|
90
90
|
- lib/eskimo/component.rb
|
91
91
|
- lib/eskimo/components/did_you_mean.rb
|
92
92
|
- lib/eskimo/components/either.rb
|
93
|
+
- lib/eskimo/components/gutter.rb
|
93
94
|
- lib/eskimo/components/highlight.rb
|
94
95
|
- lib/eskimo/components/highlight_column.rb
|
95
96
|
- lib/eskimo/components/indent.rb
|
96
97
|
- lib/eskimo/components/line_break.rb
|
97
98
|
- lib/eskimo/components/soft_break.rb
|
99
|
+
- lib/eskimo/components/spacer.rb
|
98
100
|
- lib/eskimo/components/squeeze.rb
|
99
101
|
- lib/eskimo/components/strip.rb
|
100
102
|
- lib/eskimo/components/strip_left.rb
|
@@ -109,11 +111,13 @@ files:
|
|
109
111
|
- spec/component_spec.rb
|
110
112
|
- spec/components/did_you_mean_spec.rb
|
111
113
|
- spec/components/either_spec.rb
|
114
|
+
- spec/components/gutter_spec.rb
|
112
115
|
- spec/components/highlight_column_spec.rb
|
113
116
|
- spec/components/highlight_spec.rb
|
114
117
|
- spec/components/indent_spec.rb
|
115
118
|
- spec/components/line_break_spec.rb
|
116
119
|
- spec/components/soft_break_spec.rb
|
120
|
+
- spec/components/spacer_spec.rb
|
117
121
|
- spec/components/squeeze_spec.rb
|
118
122
|
- spec/components/strip_left_spec.rb
|
119
123
|
- spec/components/strip_right_spec.rb
|
@@ -150,22 +154,24 @@ signing_key:
|
|
150
154
|
specification_version: 4
|
151
155
|
summary: Declarative text formatting
|
152
156
|
test_files:
|
153
|
-
- spec/
|
154
|
-
- spec/
|
155
|
-
- spec/components/truncate_rear_spec.rb
|
156
|
-
- spec/components/indent_spec.rb
|
157
|
+
- spec/spec_helper.rb
|
158
|
+
- spec/component_spec.rb
|
157
159
|
- spec/components/did_you_mean_spec.rb
|
160
|
+
- spec/components/strip_left_spec.rb
|
158
161
|
- spec/components/line_break_spec.rb
|
159
|
-
- spec/components/style_spec.rb
|
160
162
|
- spec/components/squeeze_spec.rb
|
161
|
-
- spec/components/
|
163
|
+
- spec/components/style_spec.rb
|
164
|
+
- spec/components/highlight_spec.rb
|
162
165
|
- spec/components/either_spec.rb
|
163
|
-
- spec/components/
|
164
|
-
- spec/components/
|
166
|
+
- spec/components/soft_break_spec.rb
|
167
|
+
- spec/components/spacer_spec.rb
|
165
168
|
- spec/components/wrap_spec.rb
|
169
|
+
- spec/components/gutter_spec.rb
|
170
|
+
- spec/components/highlight_column_spec.rb
|
171
|
+
- spec/components/truncate_spec.rb
|
166
172
|
- spec/components/strip_right_spec.rb
|
167
|
-
- spec/components/
|
173
|
+
- spec/components/indent_spec.rb
|
174
|
+
- spec/components/strip_spec.rb
|
175
|
+
- spec/components/truncate_rear_spec.rb
|
168
176
|
- spec/support/component_suite.rb
|
169
|
-
- spec/spec_helper.rb
|
170
177
|
- spec/renderer_spec.rb
|
171
|
-
- spec/component_spec.rb
|