nineteen-eighty-two 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nineteen/eighty/two/decorators/run_length_encoder.rb +1 -3
- data/lib/nineteen/eighty/two/formatters/html_table_formatter.rb +30 -38
- data/lib/nineteen/eighty/two/formatters/json_formatter.rb +2 -2
- data/lib/nineteen/eighty/two/formatters/svg_formatter.rb +53 -0
- data/lib/nineteen/eighty/two/formatters/text_formatter.rb +2 -2
- data/lib/nineteen/eighty/two/templates/html/table/cell.eruby +1 -0
- data/lib/nineteen/eighty/two/templates/html/table/row.eruby +1 -0
- data/lib/nineteen/eighty/two/templates/html/table/table.eruby +5 -0
- data/lib/nineteen/eighty/two/templates/svg/cell.eruby +1 -0
- data/lib/nineteen/eighty/two/templates/svg/document.eruby +12 -0
- data/lib/nineteen/eighty/two/version.rb +1 -1
- data/lib/nineteen/eighty/two.rb +16 -0
- data/nineteen-eighty-two.gemspec +3 -1
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 333300256f217b8dfadb4c4cd9e4fb0762f07fd2
|
4
|
+
data.tar.gz: 2fa6d7ac8d22628cc6fb28faf780edd78450e043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d1845d8f10db6883e0d4df8f5a4786d51664ed913a66f18f2db05efd524a6ec008210bf82cd0db1675700fb39ccb82179724cac41e1bcf8ce459c095e8636a6
|
7
|
+
data.tar.gz: 39415ce95392aa2eb1a0ebe5b1364070e1c9f1859f1c7b9a0a024e88cb237d176996a50a6260fd0ae65cbe3ec3469f06b00f4dc7bb1111b4bd4071cdc19f9249
|
@@ -1,55 +1,47 @@
|
|
1
1
|
module Nineteen
|
2
2
|
module Eighty
|
3
3
|
module Two
|
4
|
-
module
|
5
|
-
class
|
4
|
+
module Formats
|
5
|
+
class HTMLTable
|
6
6
|
def self.format text
|
7
|
-
s = '<!-- %s -->' % text
|
8
|
-
s << '<table class="sinclair">'
|
9
|
-
|
10
7
|
lines = Spectrum[text]
|
11
|
-
s << self.build_row(self.make_blanks(lines.first))
|
12
|
-
|
13
|
-
lines.each { |line| s << self.build_row(Nineteen::Eighty::Two::Decorators::RunLengthEncoder.encode line) }
|
14
8
|
|
15
|
-
|
16
|
-
|
9
|
+
t = File.read File.open File.join templates_dir, 'table.eruby'
|
10
|
+
context = {
|
11
|
+
title: text,
|
12
|
+
blanks: blanks(lines.first),
|
13
|
+
rows: lines.map { |l| row(l) }.join("\n")
|
14
|
+
}
|
15
|
+
Erubis::Eruby.new(t).evaluate(context).strip
|
17
16
|
end
|
18
17
|
|
19
|
-
def self.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
a
|
18
|
+
def self.blanks lines
|
19
|
+
t = File.read File.open File.join templates_dir, 'row.eruby'
|
20
|
+
context = {
|
21
|
+
cells: lines.map { |b| cell Span.new(0, 1) }.join
|
22
|
+
}
|
23
|
+
Erubis::Eruby.new(t).evaluate(context).strip
|
26
24
|
end
|
27
25
|
|
28
|
-
def self.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
:colspan => i.values[0]
|
33
|
-
}
|
26
|
+
def self.cell span
|
27
|
+
t = File.read File.open File.join templates_dir, 'cell.eruby'
|
28
|
+
context = {
|
29
|
+
style: span.type == 1 ? 'on' : 'off',
|
34
30
|
}
|
31
|
+
context[:colspan] = span.width if span.width > 1
|
32
|
+
Erubis::Eruby.new(t).evaluate(context).strip
|
35
33
|
end
|
36
34
|
|
37
|
-
def self.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
if bit[:colspan] > 1
|
45
|
-
s << ' colspan="%d"' % bit[:colspan]
|
46
|
-
end
|
47
|
-
s << '> </td>'
|
48
|
-
end
|
49
|
-
|
50
|
-
s << '</tr>'
|
35
|
+
def self.row list
|
36
|
+
t = File.read File.open File.join templates_dir, 'row.eruby'
|
37
|
+
context = {
|
38
|
+
cells: Decorators::RunLengthEncoder.encode(list).map { |i| cell i }.join
|
39
|
+
}
|
40
|
+
Erubis::Eruby.new(t).evaluate(context).strip
|
41
|
+
end
|
51
42
|
|
52
|
-
|
43
|
+
def self.templates_dir
|
44
|
+
File.join File.dirname(__FILE__),'..', 'templates', 'html', 'table'
|
53
45
|
end
|
54
46
|
end
|
55
47
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Nineteen
|
2
|
+
module Eighty
|
3
|
+
module Two
|
4
|
+
module Formats
|
5
|
+
class SVG
|
6
|
+
def self.format text, options = {}
|
7
|
+
t = File.read File.open File.join templates_dir, 'document.eruby'
|
8
|
+
context = {
|
9
|
+
width: text.length * 8,
|
10
|
+
height: 8,
|
11
|
+
fill_colour: options.fetch(:on_colour, '#000000'),
|
12
|
+
body: body(text)
|
13
|
+
}
|
14
|
+
Erubis::Eruby.new(t).evaluate(context)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.body text
|
18
|
+
rows = []
|
19
|
+
Spectrum[text].each_with_index do |line, index|
|
20
|
+
rows.push row(line, index)
|
21
|
+
end
|
22
|
+
rows.join("\n").strip
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.row list, index = 0
|
26
|
+
x = 0
|
27
|
+
cells = []
|
28
|
+
Decorators::RunLengthEncoder.encode(list).each do |item|
|
29
|
+
if item.type == 1
|
30
|
+
t = File.read File.open File.join templates_dir, 'cell.eruby'
|
31
|
+
context = {
|
32
|
+
x: x,
|
33
|
+
y: index,
|
34
|
+
width: item.width,
|
35
|
+
height: 1,
|
36
|
+
style: 'on'
|
37
|
+
}
|
38
|
+
cells.push Erubis::Eruby.new(t).evaluate(context)
|
39
|
+
end
|
40
|
+
x += item.width
|
41
|
+
end
|
42
|
+
|
43
|
+
cells.join("\n").strip
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.templates_dir
|
47
|
+
File.join File.dirname(__FILE__),'..', 'templates', 'svg'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<td class='<%= @style %>'<% if @colspan %> colspan='<%= @colspan %>'<% end %>> </td>
|
@@ -0,0 +1 @@
|
|
1
|
+
<tr><%= @cells %></tr>
|
@@ -0,0 +1 @@
|
|
1
|
+
<rect x='<%= @x %>' y='<%= @y %>' width='<%= @width %>' height='<%= @height %>' class='<%= @style %>' />
|
data/lib/nineteen/eighty/two.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'matrix'
|
3
|
+
require 'erubis'
|
3
4
|
|
4
5
|
require 'nineteen/eighty/two/version'
|
5
6
|
require 'nineteen/eighty/two/spectrum'
|
@@ -9,3 +10,18 @@ require 'nineteen/eighty/two/decorators/run_length_encoder'
|
|
9
10
|
require 'nineteen/eighty/two/formatters/text_formatter'
|
10
11
|
require 'nineteen/eighty/two/formatters/json_formatter'
|
11
12
|
require 'nineteen/eighty/two/formatters/html_table_formatter'
|
13
|
+
require 'nineteen/eighty/two/formatters/svg_formatter'
|
14
|
+
|
15
|
+
class Span < Hash
|
16
|
+
def initialize type, width
|
17
|
+
self[type] = width
|
18
|
+
end
|
19
|
+
|
20
|
+
def type
|
21
|
+
self.keys.first
|
22
|
+
end
|
23
|
+
|
24
|
+
def width
|
25
|
+
self.values.first
|
26
|
+
end
|
27
|
+
end
|
data/nineteen-eighty-two.gemspec
CHANGED
@@ -19,8 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
+
spec.add_dependency 'erubis'
|
23
|
+
|
22
24
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
23
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
-
spec.add_development_dependency 'coveralls', '~> 0.8'
|
27
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
26
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nineteen-eighty-two
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pikesley
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: erubis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,8 +102,14 @@ files:
|
|
88
102
|
- lib/nineteen/eighty/two/decorators/run_length_encoder.rb
|
89
103
|
- lib/nineteen/eighty/two/formatters/html_table_formatter.rb
|
90
104
|
- lib/nineteen/eighty/two/formatters/json_formatter.rb
|
105
|
+
- lib/nineteen/eighty/two/formatters/svg_formatter.rb
|
91
106
|
- lib/nineteen/eighty/two/formatters/text_formatter.rb
|
92
107
|
- lib/nineteen/eighty/two/spectrum.rb
|
108
|
+
- lib/nineteen/eighty/two/templates/html/table/cell.eruby
|
109
|
+
- lib/nineteen/eighty/two/templates/html/table/row.eruby
|
110
|
+
- lib/nineteen/eighty/two/templates/html/table/table.eruby
|
111
|
+
- lib/nineteen/eighty/two/templates/svg/cell.eruby
|
112
|
+
- lib/nineteen/eighty/two/templates/svg/document.eruby
|
93
113
|
- lib/nineteen/eighty/two/version.rb
|
94
114
|
- nineteen-eighty-two.gemspec
|
95
115
|
homepage: http://pikesley.org
|