eskimo 2.2.0 → 3.0.0.pre.1

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eskimo.rb +2 -29
  3. data/lib/eskimo/version.rb +1 -1
  4. metadata +16 -106
  5. data/lib/eskimo/component.rb +0 -37
  6. data/lib/eskimo/components/did_you_mean.rb +0 -34
  7. data/lib/eskimo/components/either.rb +0 -30
  8. data/lib/eskimo/components/gutter.rb +0 -33
  9. data/lib/eskimo/components/highlight.rb +0 -31
  10. data/lib/eskimo/components/highlight_column.rb +0 -61
  11. data/lib/eskimo/components/indent.rb +0 -25
  12. data/lib/eskimo/components/line_break.rb +0 -18
  13. data/lib/eskimo/components/soft_break.rb +0 -16
  14. data/lib/eskimo/components/spacer.rb +0 -33
  15. data/lib/eskimo/components/squeeze.rb +0 -43
  16. data/lib/eskimo/components/strip.rb +0 -15
  17. data/lib/eskimo/components/strip_left.rb +0 -15
  18. data/lib/eskimo/components/strip_right.rb +0 -15
  19. data/lib/eskimo/components/style.rb +0 -25
  20. data/lib/eskimo/components/truncate.rb +0 -31
  21. data/lib/eskimo/components/truncate_rear.rb +0 -25
  22. data/lib/eskimo/components/wrap.rb +0 -26
  23. data/lib/eskimo/constants.rb +0 -7
  24. data/lib/eskimo/renderer.rb +0 -46
  25. data/spec/component_spec.rb +0 -13
  26. data/spec/components/did_you_mean_spec.rb +0 -21
  27. data/spec/components/either_spec.rb +0 -21
  28. data/spec/components/gutter_spec.rb +0 -25
  29. data/spec/components/highlight_column_spec.rb +0 -63
  30. data/spec/components/highlight_spec.rb +0 -25
  31. data/spec/components/indent_spec.rb +0 -15
  32. data/spec/components/line_break_spec.rb +0 -17
  33. data/spec/components/soft_break_spec.rb +0 -17
  34. data/spec/components/spacer_spec.rb +0 -42
  35. data/spec/components/squeeze_spec.rb +0 -61
  36. data/spec/components/strip_left_spec.rb +0 -15
  37. data/spec/components/strip_right_spec.rb +0 -15
  38. data/spec/components/strip_spec.rb +0 -15
  39. data/spec/components/style_spec.rb +0 -25
  40. data/spec/components/truncate_rear_spec.rb +0 -35
  41. data/spec/components/truncate_spec.rb +0 -35
  42. data/spec/components/wrap_spec.rb +0 -15
  43. data/spec/renderer_spec.rb +0 -62
  44. data/spec/spec_helper.rb +0 -42
  45. data/spec/support/component_suite.rb +0 -15
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::HighlightColumn do
6
- it 'highlights the character' do
7
- style = [ :bold, :red ]
8
-
9
- expect(
10
- renderer.apply {
11
- described_class.new(column: 1, line: 1, style: style) { "number:\nfour" }
12
- }
13
- ).to include("f#{pastel.decorate('o', *style)}ur")
14
- end
15
-
16
- it 'highlights the first character' do
17
- style = [ :bold, :red ]
18
-
19
- expect(
20
- renderer.apply {
21
- described_class.new(column: 0, line: 0, style: style) { "four" }
22
- }
23
- ).to include("#{pastel.decorate('f', *style)}our")
24
- end
25
-
26
- it 'highlights the last character' do
27
- style = [ :bold, :red ]
28
-
29
- expect(
30
- renderer.apply {
31
- described_class.new(column: 3, line: 0, style: style) { "four" }
32
- }
33
- ).to include("fou#{pastel.decorate('r', *style)}")
34
- end
35
-
36
- it 'highlights nothing' do
37
- expect(
38
- renderer.apply {
39
- described_class.new(column: 1234, line: 0) { "four" }
40
- }
41
- ).to eq("four")
42
-
43
- expect(
44
- renderer.apply {
45
- described_class.new(column: 0, line: 1234) { "four" }
46
- }
47
- ).to eq("four")
48
- end
49
-
50
- it 'inserts the arrow' do
51
- expect(
52
- strip_styles(
53
- renderer.apply {
54
- described_class.new(column: 1, line: 0) { "four" }
55
- }
56
- )
57
- ).to eq(
58
- "four" + "\n" +
59
- " ^" + "\n" +
60
- " here" + "\n"
61
- )
62
- end
63
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::Highlight do
6
- it 'styles a substring' do
7
- style = [ :bold, :red ]
8
-
9
- expect(
10
- renderer.apply {
11
- described_class.new(pattern: /ou/, style: style) { 'four' }
12
- }
13
- ).to eq("f#{Pastel.new.decorate('ou', *style)}r")
14
- end
15
-
16
- it 'is a no-op if no match' do
17
- input = 'four'
18
-
19
- expect(
20
- renderer.apply {
21
- described_class.new(pattern: /asdf/) { input }
22
- }
23
- ).to eq(input)
24
- end
25
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::Indent do
6
- it 'indents each line' do
7
- expect(
8
- renderer.apply do
9
- ESK::Indent.new(width: 2) do
10
- "hello\nworld"
11
- end
12
- end
13
- ).to eq(" hello\n world")
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::LineBreak do
6
- it 'inserts a hard linebreak' do
7
- expect(
8
- renderer.apply {
9
- [
10
- 'hello',
11
- ESK::LineBreak.new,
12
- 'world'
13
- ]
14
- }
15
- ).to eq("hello\n \nworld")
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::SoftBreak do
6
- it 'inserts a soft linebreak' do
7
- expect(
8
- renderer.apply {
9
- [
10
- 'hello',
11
- ESK::SoftBreak.new,
12
- 'world'
13
- ]
14
- }
15
- ).to eq("hello\nworld")
16
- end
17
- end
@@ -1,42 +0,0 @@
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
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::Squeeze do
6
- it 'swallows consecutive newlines' do
7
- expect(
8
- renderer.apply do
9
- ESK::Squeeze.new([
10
- ESK::SoftBreak.new,
11
- false && '1',
12
-
13
- ESK::SoftBreak.new,
14
- false && '2',
15
-
16
- ESK::SoftBreak.new,
17
- '3',
18
-
19
- ESK::SoftBreak.new,
20
- '4',
21
- ])
22
- end
23
- ).to eq("\n3\n4")
24
- end
25
-
26
- it 'does not swallow consecutive newlines in inner children' do
27
- expect(
28
- renderer.apply do
29
- ESK::Squeeze.new([
30
- ESK::Indent.new(width: 0) do
31
- [
32
- ESK::SoftBreak.new,
33
- false && '1',
34
-
35
- ESK::SoftBreak.new,
36
- false && '2',
37
-
38
- ESK::SoftBreak.new,
39
- '3',
40
-
41
- ESK::SoftBreak.new,
42
- '4',
43
- ]
44
- end
45
- ])
46
- end
47
- ).to eq("\n\n\n3\n4")
48
- end
49
-
50
- it 'bails if not given an array of children' do
51
- expect { ESK::Squeeze.new('') }.to raise_error(ArgumentError,
52
- "Squeeze works only with an Array of components"
53
- )
54
- end
55
-
56
- it 'bails if given a block' do
57
- expect { ESK::Squeeze.new([]) {} }.to raise_error(ArgumentError,
58
- "Squeeze works only with an Array of components"
59
- )
60
- end
61
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::StripLeft do
6
- it 'strips whitespace from the head' do
7
- expect(
8
- renderer.apply do
9
- ESK::StripLeft.new do
10
- " hello world "
11
- end
12
- end
13
- ).to eq("hello world ")
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::StripRight do
6
- it 'strips whitespace from the rear' do
7
- expect(
8
- renderer.apply do
9
- ESK::StripRight.new do
10
- " hello world "
11
- end
12
- end
13
- ).to eq(" hello world")
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::Strip do
6
- it 'strips surrounding whitespace' do
7
- expect(
8
- renderer.apply do
9
- ESK::Strip.new do
10
- " hello world "
11
- end
12
- end
13
- ).to eq("hello world")
14
- end
15
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::Style do
6
- it 'applies ANSI styling to text' do
7
- expect(
8
- renderer.apply {
9
- [
10
- ESK::Style.new([:bold, :green]) { 'hai' },
11
- ]
12
- }
13
- ).to eq("\e[1;32mhai\e[0m")
14
- end
15
-
16
- it 'accepts a splat' do
17
- expect(
18
- renderer.apply {
19
- [
20
- ESK::Style.new(:bold, :green) { 'hai' },
21
- ]
22
- }
23
- ).to eq("\e[1;32mhai\e[0m")
24
- end
25
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::TruncateRear do
6
- it 'truncates a string from the rear if it exceeds the length' do
7
- expect(
8
- renderer.apply do
9
- ESK::TruncateRear.new(width: 5) do
10
- "hello world"
11
- end
12
- end
13
- ).to eq("hello...")
14
- end
15
-
16
- it 'reserves chars from the width' do
17
- expect(
18
- renderer.apply do
19
- ESK::TruncateRear.new(width: 10, reserve: 5) do
20
- ("hello world")
21
- end
22
- end
23
- ).to eq("hello...")
24
- end
25
-
26
- it 'is a no-op if text fits' do
27
- expect(
28
- renderer.apply do
29
- ESK::TruncateRear.new(width: 62, reserve: 5) do
30
- ("hello world")
31
- end
32
- end
33
- ).to eq("hello world")
34
- end
35
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::Truncate do
6
- it 'truncates a string from the beginning if it exceeds the length' do
7
- expect(
8
- renderer.apply do
9
- ESK::Truncate.new(width: 5) do
10
- ("hello world")
11
- end
12
- end
13
- ).to eq("... world")
14
- end
15
-
16
- it 'reserves chars from the width' do
17
- expect(
18
- renderer.apply do
19
- ESK::Truncate.new(width: 10, reserve: 5) do
20
- ("hello world")
21
- end
22
- end
23
- ).to eq("... world")
24
- end
25
-
26
- it 'is a no-op if text fits' do
27
- expect(
28
- renderer.apply do
29
- ESK::Truncate.new(width: 62, reserve: 5) do
30
- ("hello world")
31
- end
32
- end
33
- ).to eq("hello world")
34
- end
35
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Components::Wrap do
6
- it 'wraps text' do
7
- expect(
8
- renderer.apply do
9
- ESK::Wrap.new(width: 5) do
10
- 'hello world'
11
- end
12
- end
13
- ).to eq("\nhello \nworld")
14
- end
15
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Eskimo::Renderer do
6
- it 'renders nothing' do
7
- expect(subject.apply).to eq('')
8
- end
9
-
10
- it 'renders a string' do
11
- expect(subject.apply { 'hello' }).to eq('hello')
12
- end
13
-
14
- it 'renders a proc' do
15
- expect(subject.apply { lambda do |**| 'hello' end }).to eq('hello')
16
- end
17
-
18
- it 'renders an array of renderables' do
19
- expect(subject.apply { ['h','ello'] }).to eq('hello')
20
- end
21
-
22
- it 'renders a #render renderable' do
23
- class Renderable
24
- def render(**)
25
- 'hello'
26
- end
27
- end
28
-
29
- expect(subject.apply { Renderable.new }).to eq('hello')
30
- end
31
-
32
- it 'ignores falseys' do
33
- expect(subject.apply { nil }).to eq('')
34
- expect(subject.apply { false }).to eq('')
35
- expect(subject.apply { [nil,false] }).to eq('')
36
- end
37
-
38
- it 'passes props to renderers' do
39
- props = nil
40
-
41
- described_class.new(foo: 'bar').apply {
42
- lambda { |injected_props| ''.tap { props = injected_props } }
43
- }
44
-
45
- expect(props).to be_a(Hash)
46
- expect(props).to include(foo: 'bar')
47
- end
48
-
49
- it 'injects a "render" routine for procs' do
50
- expect(
51
- subject.apply { lambda { |render:, **| render['hello'] } }
52
- ).to eq('hello')
53
- end
54
-
55
- it 'bails on unrenderable inputs' do
56
- expect {
57
- subject.apply { :foo }
58
- }.to raise_error(ArgumentError,
59
- "Eskimo: don't know how to render #{:foo.class} => foo"
60
- )
61
- end
62
- end