vedeu 0.6.9 → 0.6.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/lib/vedeu/all.rb +3 -3
  4. data/lib/vedeu/api/external.rb +194 -0
  5. data/lib/vedeu/api/internal.rb +173 -0
  6. data/lib/vedeu/application/controller.rb +3 -2
  7. data/lib/vedeu/bindings/application.rb +1 -1
  8. data/lib/vedeu/bindings/drb.rb +2 -3
  9. data/lib/vedeu/bindings/movement.rb +1 -1
  10. data/lib/vedeu/buffers/all.rb +0 -2
  11. data/lib/vedeu/colours/translator.rb +2 -1
  12. data/lib/vedeu/common.rb +4 -2
  13. data/lib/vedeu/configuration/api.rb +1 -1
  14. data/lib/vedeu/configuration/cli.rb +1 -1
  15. data/lib/vedeu/cursors/repository.rb +1 -1
  16. data/lib/vedeu/editor/insert.rb +12 -13
  17. data/lib/vedeu/geometry/position.rb +1 -1
  18. data/lib/vedeu/models/cell.rb +35 -21
  19. data/lib/vedeu/models/escape.rb +18 -1
  20. data/lib/vedeu/models/page.rb +20 -10
  21. data/lib/vedeu/models/row.rb +18 -8
  22. data/lib/vedeu/models/views/char.rb +9 -7
  23. data/lib/vedeu/models/views/view.rb +1 -1
  24. data/lib/vedeu/output/compressor.rb +22 -14
  25. data/lib/vedeu/output/output.rb +1 -10
  26. data/lib/vedeu/output/renderers/escape_sequence.rb +8 -4
  27. data/lib/vedeu/output/renderers/file.rb +7 -23
  28. data/lib/vedeu/output/renderers/html.rb +47 -26
  29. data/lib/vedeu/output/renderers/json.rb +11 -16
  30. data/lib/vedeu/output/renderers/null.rb +1 -1
  31. data/lib/vedeu/output/renderers/renderer_options.rb +2 -1
  32. data/lib/vedeu/output/renderers/terminal.rb +7 -15
  33. data/lib/vedeu/output/renderers/text.rb +1 -1
  34. data/lib/vedeu/output/viewport.rb +154 -143
  35. data/lib/vedeu/repositories/collection.rb +2 -2
  36. data/lib/vedeu/repositories/model.rb +25 -26
  37. data/lib/vedeu/repositories/registerable.rb +9 -8
  38. data/lib/vedeu/repositories/repository.rb +21 -16
  39. data/lib/vedeu/repositories/store.rb +6 -4
  40. data/lib/vedeu/runtime/bootstrap.rb +7 -5
  41. data/lib/vedeu/runtime/main_loop.rb +2 -0
  42. data/lib/vedeu/runtime/router.rb +155 -149
  43. data/lib/vedeu/templating/decoder.rb +8 -5
  44. data/lib/vedeu/templating/encoder.rb +6 -4
  45. data/lib/vedeu/templating/template.rb +2 -2
  46. data/lib/vedeu/templating/view_template.rb +8 -7
  47. data/lib/vedeu/terminal/buffer.rb +132 -0
  48. data/lib/vedeu/terminal/terminal.rb +0 -5
  49. data/lib/vedeu/version.rb +1 -1
  50. data/lib/vedeu.rb +2 -2
  51. data/out_ +50 -0
  52. data/test/lib/vedeu/api/external_test.rb +62 -0
  53. data/test/lib/vedeu/{internal_api_test.rb → api/internal_test.rb} +6 -2
  54. data/test/lib/vedeu/application/controller_test.rb +3 -3
  55. data/test/lib/vedeu/bindings/application_test.rb +2 -2
  56. data/test/lib/vedeu/models/cell_test.rb +48 -17
  57. data/test/lib/vedeu/models/escape_test.rb +29 -7
  58. data/test/lib/vedeu/models/page_test.rb +70 -50
  59. data/test/lib/vedeu/models/row_test.rb +40 -20
  60. data/test/lib/vedeu/output/compressor_test.rb +12 -12
  61. data/test/lib/vedeu/output/output_test.rb +17 -23
  62. data/test/lib/vedeu/output/renderers/escape_sequence_test.rb +15 -11
  63. data/test/lib/vedeu/output/renderers/html_test.rb +66 -68
  64. data/test/lib/vedeu/output/renderers/json_test.rb +36 -83
  65. data/test/lib/vedeu/output/renderers/terminal_test.rb +22 -2
  66. data/test/lib/vedeu/output/viewport_test.rb +201 -197
  67. data/test/lib/vedeu/runtime/router_test.rb +144 -140
  68. data/test/lib/vedeu/terminal/buffer_test.rb +307 -0
  69. data/test/support/examples/material_colours_app.rb +2 -2
  70. data/test/support/templates/html_renderer.vedeu +24 -0
  71. metadata +14 -17
  72. data/lib/vedeu/api.rb +0 -190
  73. data/lib/vedeu/buffers/virtual_buffer.rb +0 -136
  74. data/lib/vedeu/buffers/virtual_buffers.rb +0 -77
  75. data/lib/vedeu/internal_api.rb +0 -173
  76. data/lib/vedeu/terminal/content.rb +0 -88
  77. data/test/lib/vedeu/api_test.rb +0 -58
  78. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +0 -148
  79. data/test/lib/vedeu/buffers/virtual_buffers_test.rb +0 -73
  80. data/test/lib/vedeu/terminal/content_test.rb +0 -108
@@ -9,7 +9,7 @@ module Vedeu
9
9
  let(:described) { Vedeu::Renderers::EscapeSequence }
10
10
  let(:instance) { described.new(options) }
11
11
  let(:options) { {} }
12
- let(:output) {}
12
+ let(:output) { Vedeu::Models::Page.new }
13
13
 
14
14
  describe '#initialize' do
15
15
  it { instance.must_be_instance_of(described) }
@@ -21,13 +21,15 @@ module Vedeu
21
21
 
22
22
  it { subject.must_be_instance_of(String) }
23
23
 
24
- context 'when there is no output' do
25
- it { subject.must_equal('') }
24
+ context 'when there is an empty buffer' do
25
+ let(:expected) { '' }
26
+
27
+ it { subject.must_equal(expected) }
26
28
  end
27
29
 
28
- context 'when there is output' do
30
+ context 'when there is content on the buffer' do
29
31
  let(:output) {
30
- [
32
+ Vedeu::Models::Page.coerce([
31
33
  Vedeu::Views::Char.new(value: 't',
32
34
  colour: {
33
35
  background: '#ff0000',
@@ -48,14 +50,16 @@ module Vedeu
48
50
  background: '#00ffff',
49
51
  foreground: '#000000'
50
52
  }),
51
- ]
53
+ ])
52
54
  }
53
55
 
54
- it { subject.must_equal(
55
- "\\e[38;2;255;255;255m\\e[48;2;255;0;0mt\n" \
56
- "\\e[38;2;0;0;0m\\e[48;2;255;255;0me\n" \
57
- "\\e[38;2;0;0;0m\\e[48;2;0;255;0ms\n" \
58
- "\\e[38;2;0;0;0m\\e[48;2;0;255;255mt\n")
56
+ it {
57
+ subject.must_equal(
58
+ "\\e[38;2;255;255;255m\\e[48;2;255;0;0mt" \
59
+ "\\e[38;2;0;0;0m\\e[48;2;255;255;0me" \
60
+ "\\e[38;2;0;0;0m\\e[48;2;0;255;0ms" \
61
+ "\\e[38;2;0;0;0m\\e[48;2;0;255;255mt"
62
+ )
59
63
  }
60
64
  end
61
65
  end
@@ -10,86 +10,84 @@ module Vedeu
10
10
  let(:instance) { described.new(options) }
11
11
  let(:options) {
12
12
  {
13
- content: content,
14
- write_file: write_file,
13
+ content: content,
14
+ end_tag: end_tag,
15
+ end_row_tag: end_row_tag,
16
+ filename: filename,
17
+ start_tag: start_tag,
18
+ start_row_tag: start_row_tag,
19
+ template: template,
20
+ timestamp: timestamp,
21
+ write_file: write_file,
15
22
  }
16
23
  }
17
- let(:content) { [''] }
18
- let(:write_file) { false }
19
-
20
- before { ::File.stubs(:write) }
24
+ let(:content) { '' }
25
+ let(:end_tag) { '</td>' }
26
+ let(:end_row_tag) { '</tr>' }
27
+ let(:filename) { 'out' }
28
+ let(:start_tag) { '<td' }
29
+ let(:start_row_tag) { '<tr>' }
30
+ let(:template) {
31
+ ::File.dirname(__FILE__) + '/../../../../support/templates/html_renderer.vedeu'
32
+ }
33
+ let(:timestamp) { false }
34
+ let(:write_file) { false }
35
+ let(:buffer) { Vedeu::Terminal::Buffer }
36
+
37
+ before do
38
+ ::File.stubs(:write)
39
+ Vedeu.stubs(:height).returns(2)
40
+ Vedeu.stubs(:width).returns(4)
41
+ Vedeu::Terminal::Buffer.reset
42
+ end
21
43
 
22
44
  describe '#initialize' do
23
45
  it { instance.must_be_instance_of(described) }
24
46
  it { instance.instance_variable_get('@options').must_equal(options) }
47
+ it { instance.instance_variable_get('@output').must_equal(nil) }
25
48
  end
26
49
 
27
- # describe '#render' do
28
- # before { ::File.stubs(:open) }
29
-
30
- # subject { instance.render(content) }
31
-
32
- # it { subject.must_be_instance_of(String) }
33
-
34
- # context 'when the :write_file option is true' do
35
- # let(:write_file) { true }
36
-
37
- # context 'when a path is given' do
38
- # let(:path) { '/tmp/test_vedeu_html_renderer.html' }
39
-
40
- # # it do
41
- # # ::File.expects(:open)
42
- # # subject
43
- # # end
44
- # end
45
-
46
- # context 'when a path is not given' do
47
- # let(:path) {}
48
- # let(:_time) { Time.new(2015, 4, 12, 16, 55) }
49
-
50
- # before { Time.stubs(:now).returns(_time) }
51
-
52
- # # it do
53
- # # ::File.expects(:open)#.with('/tmp/vedeu_html_1428854100.html', 'w')
54
- # # subject
55
- # # end
56
- # end
57
- # end
58
-
59
- # context 'when the :write_file options is false' do
60
- # let(:write_file) { false }
61
-
62
- # # @todo Add more tests.
63
- # # it { skip }
64
- # end
65
- # end
66
-
67
- describe '#html_body' do
68
- let(:content) {
69
- [
70
- [
71
- Vedeu::Views::Char.new(value: 't'),
72
- Vedeu::Views::Char.new(value: 'e'),
73
- Vedeu::Views::Char.new(value: 's'),
74
- Vedeu::Views::Char.new(value: 't'),
75
- ]
76
- ]
50
+ describe '#render' do
51
+ let(:output) {
52
+ Vedeu::Models::Page.coerce([
53
+ Vedeu::Views::Char.new(value: 'a',
54
+ colour: {
55
+ background: '#ff0000',
56
+ foreground: '#ffffff' }),
57
+ ])
58
+ }
59
+ let(:expected) {
60
+ "<html>\n" \
61
+ " <head>\n" \
62
+ " <style type='text/css'>\n" \
63
+ " body {\n" \
64
+ " background:#000;\n" \
65
+ " }\n" \
66
+ " td {\n" \
67
+ " border:1px #171717 solid;\n" \
68
+ " font-size:12px;\n" \
69
+ " font-family:monospace;\n" \
70
+ " height:18px;\n" \
71
+ " margin:1px;\n" \
72
+ " text-align:center;\n" \
73
+ " vertical-align:center;\n" \
74
+ " width:18px;\n" \
75
+ " }\n" \
76
+ " </style>\n" \
77
+ " </head>\n" \
78
+ " <body>\n" \
79
+ " <table>\n" \
80
+ " <tr>\n" \
81
+ "<td style='border:1px #ff0000 solid;background:#ff0000;color:#ffffff;'>a</td></tr>\n" \
82
+ " </table>\n" \
83
+ " </body>\n" \
84
+ "</html>\n"
77
85
  }
78
86
 
79
- subject { instance.html_body }
87
+ subject { instance.render(output) }
80
88
 
81
89
  it { subject.must_be_instance_of(String) }
82
-
83
- it do
84
- subject.must_equal(
85
- "<tr>\n" \
86
- "<td style=''>t</td>\n" \
87
- "<td style=''>e</td>\n" \
88
- "<td style=''>s</td>\n" \
89
- "<td style=''>t</td>\n" \
90
- "</tr>\n"
91
- )
92
- end
90
+ it { subject.must_equal(expected) }
93
91
  end
94
92
 
95
93
  end # HTML
@@ -9,9 +9,14 @@ module Vedeu
9
9
  let(:described) { Vedeu::Renderers::JSON }
10
10
  let(:instance) { described.new(options) }
11
11
  let(:options) { {} }
12
- let(:output) {}
12
+ let(:output) { Vedeu::Models::Page.new }
13
13
 
14
- before { ::File.stubs(:write) }
14
+ before do
15
+ ::File.stubs(:write)
16
+ Vedeu.stubs(:height).returns(1)
17
+ Vedeu.stubs(:width).returns(1)
18
+ Vedeu::Terminal::Buffer.reset
19
+ end
15
20
 
16
21
  describe '#initialize' do
17
22
  it { instance.must_be_instance_of(described) }
@@ -19,90 +24,38 @@ module Vedeu
19
24
  end
20
25
 
21
26
  describe '#render' do
27
+ let(:output) {
28
+ Vedeu::Models::Page.coerce([
29
+ Vedeu::Views::Char.new(value: 'a',
30
+ colour: {
31
+ background: '#ff0000',
32
+ foreground: '#ffffff' }),
33
+ ])
34
+ }
35
+ let(:expected) {
36
+ "[\n" \
37
+ " {\n" \
38
+ " \"border\": \"\",\n" \
39
+ " \"colour\": {\n" \
40
+ " \"background\": \"\\u001b[48;2;255;0;0m\",\n" \
41
+ " \"foreground\": \"\\u001b[38;2;255;255;255m\"\n" \
42
+ " },\n" \
43
+ " \"parent\": {\n" \
44
+ " },\n" \
45
+ " \"position\": {\n" \
46
+ " \"y\": null,\n" \
47
+ " \"x\": null\n" \
48
+ " },\n" \
49
+ " \"style\": \"\",\n" \
50
+ " \"value\": \"a\"\n" \
51
+ " }\n" \
52
+ "]"
53
+ }
54
+
22
55
  subject { instance.render(output) }
23
56
 
24
57
  it { subject.must_be_instance_of(String) }
25
-
26
- context 'when the output is empty' do
27
- it { subject.must_equal('') }
28
- end
29
-
30
- context 'when the output is not empty' do
31
- let(:colour) {
32
- Vedeu::Colours::Colour.new(foreground: '#ff0000',
33
- background: '#ffffff')
34
- }
35
- let(:output) {
36
- [
37
- [
38
- Vedeu::Views::Char.new(value: 'a',
39
- colour: colour,
40
- parent: parent,
41
- position: Vedeu::Geometry::Position[5, 3])
42
- ]
43
- ]
44
- }
45
- let(:parent) {}
46
- let(:expected) {
47
- <<-eos
48
- [
49
- {
50
- \"border\": \"\",
51
- \"colour\": {
52
- \"background\": \"\\u001b[48;2;255;255;255m\",
53
- \"foreground\": \"\\u001b[38;2;255;0;0m\"
54
- },
55
- \"parent\": {
56
- },
57
- \"position\": {
58
- \"y\": 5,
59
- \"x\": 3
60
- },
61
- \"style\": \"\",
62
- \"value\": \"a\"
63
- }
64
- ]
65
- eos
66
- }
67
-
68
- it { subject.must_equal(expected.chomp) }
69
-
70
- context 'when a parent is available' do
71
- let(:parent) {
72
- Vedeu::Views::Stream.new(
73
- colour: Vedeu::Colours::Colour.coerce(background: '',
74
- foreground: '')
75
- )
76
- }
77
-
78
- let(:expected) {
79
- <<-eos
80
- [
81
- {
82
- \"border\": \"\",
83
- \"colour\": {
84
- \"background\": \"\\u001b[48;2;255;255;255m\",
85
- \"foreground\": \"\\u001b[38;2;255;0;0m\"
86
- },
87
- \"parent\": {
88
- \"background\": \"\",
89
- \"foreground\": \"\",
90
- \"style\": \"\"
91
- },
92
- \"position\": {
93
- \"y\": 5,
94
- \"x\": 3
95
- },
96
- \"style\": \"\",
97
- \"value\": \"a\"
98
- }
99
- ]
100
- eos
101
- }
102
-
103
- it { subject.must_equal(expected.chomp) }
104
- end
105
- end
58
+ it { subject.must_equal(expected) }
106
59
  end
107
60
 
108
61
  end # JSON
@@ -9,7 +9,27 @@ module Vedeu
9
9
  let(:described) { Vedeu::Renderers::Terminal }
10
10
  let(:instance) { described.new(options) }
11
11
  let(:options) { {} }
12
- let(:output) {}
12
+ let(:output) {
13
+ Vedeu::Models::Page.coerce([
14
+ [
15
+ Vedeu::Models::Cell.new(position: [1, 1]),
16
+ Vedeu::Views::Char.new(value: 'a', position: [1, 2]),
17
+ Vedeu::Models::Cell.new(position: [1, 3]),
18
+ ], [
19
+ Vedeu::Models::Cell.new(position: [2, 1]),
20
+ Vedeu::Views::Char.new(value: 'b', position: [2, 2]),
21
+ Vedeu::Models::Cell.new(position: [2, 3]),
22
+ ], [
23
+ Vedeu::Models::Cell.new(position: [3, 1]),
24
+ Vedeu::Views::Char.new(value: 'c', position: [3, 2]),
25
+ Vedeu::Models::Cell.new(position: [3, 3]),
26
+ ],
27
+ ])
28
+ }
29
+
30
+ before do
31
+ Vedeu::Terminal.stubs(:output).returns(output)
32
+ end
13
33
 
14
34
  describe '#initialize' do
15
35
  it { instance.must_be_instance_of(described) }
@@ -19,7 +39,7 @@ module Vedeu
19
39
  describe '#render' do
20
40
  subject { instance.render(output) }
21
41
 
22
- it { subject.must_be_instance_of(Array) }
42
+ it { subject.must_be_instance_of(Vedeu::Models::Page) }
23
43
  end
24
44
 
25
45
  end # Terminal