pangrid 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/pangrid/frontend/webrick.rb +24 -5
- data/lib/pangrid/plugin.rb +5 -3
- data/lib/pangrid/plugins/acrosslite.rb +4 -0
- data/lib/pangrid/plugins/csv.rb +3 -0
- data/lib/pangrid/plugins/excel.rb +3 -0
- data/lib/pangrid/plugins/exolve.rb +64 -0
- data/lib/pangrid/plugins/json.rb +78 -0
- data/lib/pangrid/plugins/qxw.rb +3 -0
- data/lib/pangrid/plugins/reddit.rb +4 -0
- data/lib/pangrid/plugins/text.rb +3 -0
- data/lib/pangrid/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be115d7cba3bf82d65d241afb1fedb1becfa8085d447590960447fc479b57d90
|
4
|
+
data.tar.gz: 5520cd33d623bb0f55f11d0eb3fe4c9e2187dc437e3675bd2b97d40bb60cef08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 607c19e615b28a3ad2117765ebba9d5003aaec081e04b0dac4793fdc3a32e88d99b9fbe6c40b3739c116b20a0bcb7e263f00c223dca6898b35f65729c358fed9
|
7
|
+
data.tar.gz: 6df6cf0d9a78dbaef9213722a80538e0da262dcdb2026e862da07f0235154d2688f2bfc26397b67bd9a2e8a9975ff2a8a3c453fd6427a098d6dc912c011a1643
|
@@ -26,11 +26,30 @@ class Servlet < WEBrick::HTTPServlet::AbstractServlet
|
|
26
26
|
rescue Exception => e
|
27
27
|
out = e.inspect
|
28
28
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
|
30
|
+
response.header['Access-Control-Allow-Origin'] = '*'
|
31
|
+
|
32
|
+
case request.path
|
33
|
+
when "/"
|
34
|
+
template = IO.read(TEMPLATE)
|
35
|
+
response.status = 200
|
36
|
+
response.content_type = "text/html"
|
37
|
+
response.body = template % out
|
38
|
+
when "/blob"
|
39
|
+
response.status = 200
|
40
|
+
response.content_type = "application/octet-stream"
|
41
|
+
response.body = out
|
42
|
+
when "/json"
|
43
|
+
if request.query["to"] == "json"
|
44
|
+
response.status = 200
|
45
|
+
response.content_type = "text/json"
|
46
|
+
response.body = out
|
47
|
+
else
|
48
|
+
response.status = 200
|
49
|
+
response.content_type = "text/json"
|
50
|
+
response.body = '{ "error" : "non-json format requested" }'
|
51
|
+
end
|
52
|
+
end
|
34
53
|
end
|
35
54
|
end
|
36
55
|
|
data/lib/pangrid/plugin.rb
CHANGED
@@ -35,6 +35,8 @@ class Plugin
|
|
35
35
|
FAILED = []
|
36
36
|
MISSING_DEPS = {}
|
37
37
|
|
38
|
+
DESCRIPTION = ""
|
39
|
+
|
38
40
|
def self.inherited(subclass)
|
39
41
|
name = class_to_name(subclass.name)
|
40
42
|
#puts "Registered #{subclass} as #{name}"
|
@@ -62,13 +64,13 @@ class Plugin
|
|
62
64
|
|
63
65
|
def self.list_all
|
64
66
|
puts "-------------------------------------------------------"
|
65
|
-
puts "Available plugins:"
|
67
|
+
puts "Available plugins (F = from, T = to):"
|
66
68
|
puts "-------------------------------------------------------"
|
67
69
|
REGISTRY.keys.sort.each do |name|
|
68
70
|
plugin = REGISTRY[name]
|
69
71
|
provides = [:read, :write].select {|m| plugin.method_defined? m}
|
70
|
-
provides = provides.map {|m| {read: '
|
71
|
-
puts "
|
72
|
+
provides = provides.map {|m| {read: 'F', write: 'T'}[m]}.join
|
73
|
+
puts " #{name} [#{provides}]".ljust(30) + plugin.const_get(:DESCRIPTION)
|
72
74
|
end
|
73
75
|
if !MISSING_DEPS.empty?
|
74
76
|
puts
|
@@ -75,6 +75,8 @@ class AcrossLiteBinary < Plugin
|
|
75
75
|
# crossword, checksums
|
76
76
|
attr_accessor :xw, :cs
|
77
77
|
|
78
|
+
DESCRIPTION = "AcrossLite binary format (.puz)"
|
79
|
+
|
78
80
|
HEADER_FORMAT = "v A12 v V2 A4 v2 A12 c2 v3"
|
79
81
|
HEADER_CHECKSUM_FORMAT = "c2 v3"
|
80
82
|
EXT_HEADER_FORMAT = "A4 v2"
|
@@ -359,6 +361,8 @@ class AcrossLiteText < Plugin
|
|
359
361
|
|
360
362
|
attr_accessor :xw, :rebus
|
361
363
|
|
364
|
+
DESCRIPTION = "AcrossLite text format"
|
365
|
+
|
362
366
|
def initialize
|
363
367
|
@xw = XWord.new
|
364
368
|
end
|
data/lib/pangrid/plugins/csv.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Exolve (https://github.com/viresh-ratnakar/exolve) is a browser-based
|
2
|
+
# crossword solver that allows you to embed the crossword and solving software
|
3
|
+
# in a single HTML file.
|
4
|
+
|
5
|
+
module Pangrid
|
6
|
+
|
7
|
+
module ExolveWriter
|
8
|
+
def write(xw)
|
9
|
+
headers = format_headers(xw)
|
10
|
+
across, down = xw.number
|
11
|
+
grid = format_grid(xw)
|
12
|
+
ac = format_clues(across, xw.across_clues)
|
13
|
+
dn = format_clues(down, xw.down_clues)
|
14
|
+
across = ["exolve-across:"] + indent(ac)
|
15
|
+
down = ["exolve-down:"] + indent(dn)
|
16
|
+
grid = ["exolve-grid:"] + indent(grid)
|
17
|
+
body = headers + grid + across + down
|
18
|
+
out = ["exolve-begin"] + indent(body) + ["exolve-end"]
|
19
|
+
out.join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
def format_headers(xw)
|
23
|
+
headers = [
|
24
|
+
'id', 'replace-with-unique-id',
|
25
|
+
'title', xw.title,
|
26
|
+
'setter', xw.author,
|
27
|
+
'width', xw.width,
|
28
|
+
'height', xw.height,
|
29
|
+
'copyright', xw.copyright,
|
30
|
+
'prelude', xw.preamble
|
31
|
+
]
|
32
|
+
headers.each_slice(2).select {|k, v| v}.map {|k, v| "exolve-#{k}: #{v}"}
|
33
|
+
end
|
34
|
+
|
35
|
+
def format_clues(numbers, clues)
|
36
|
+
numbers.zip(clues).map {|n, c| "#{n.to_s.rjust(2)}. #{c}"}
|
37
|
+
end
|
38
|
+
|
39
|
+
def indent(lines)
|
40
|
+
lines.map {|x| " " + x}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ExolveFilled < Plugin
|
45
|
+
include ExolveWriter
|
46
|
+
|
47
|
+
DESCRIPTION = "Exolve writer with solutions"
|
48
|
+
|
49
|
+
def format_grid(xw)
|
50
|
+
xw.to_array(:black => '.', :null => '0').map(&:join)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class ExolveBlank < Plugin
|
55
|
+
include ExolveWriter
|
56
|
+
|
57
|
+
DESCRIPTION = "Exolve writer without solutions"
|
58
|
+
|
59
|
+
def format_grid(xw)
|
60
|
+
xw.to_array(:black => '.', :null => '0') {|c| 0}.map(&:join)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end # module Pangrid
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Json
|
2
|
+
#
|
3
|
+
# cell = { x : int, y : int, contents : string }
|
4
|
+
#
|
5
|
+
# xword = { rows : int,
|
6
|
+
# cols : int,
|
7
|
+
# cells : [cell],
|
8
|
+
# across : [string]
|
9
|
+
# down : [string]
|
10
|
+
# }
|
11
|
+
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
module Pangrid
|
15
|
+
|
16
|
+
class Json < Plugin
|
17
|
+
|
18
|
+
DESCRIPTION = "Simple JSON format"
|
19
|
+
|
20
|
+
def write(xw)
|
21
|
+
cells = []
|
22
|
+
(0 ... xw.height).each do |y|
|
23
|
+
(0 ... xw.width).each do |x|
|
24
|
+
cell = xw.solution[y][x]
|
25
|
+
s = case cell.solution
|
26
|
+
when :black; '#'
|
27
|
+
when :null; ''
|
28
|
+
when Rebus; cell.solution.inspect
|
29
|
+
else; cell.solution
|
30
|
+
end
|
31
|
+
|
32
|
+
cells.push({ x: x, y: y, contents: s })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
h = {
|
37
|
+
rows: xw.height,
|
38
|
+
cols: xw.width,
|
39
|
+
cells: cells,
|
40
|
+
across: xw.across_clues,
|
41
|
+
down: xw.down_clues
|
42
|
+
}
|
43
|
+
|
44
|
+
::JSON.generate(h)
|
45
|
+
end
|
46
|
+
|
47
|
+
def read(data)
|
48
|
+
json = ::JSON.parse(data)
|
49
|
+
xw = XWord.new
|
50
|
+
|
51
|
+
xw.height = json['rows']
|
52
|
+
xw.width = json['cols']
|
53
|
+
xw.solution = Array.new(xw.height) { Array.new(xw.width) }
|
54
|
+
json['cells'].each do |c|
|
55
|
+
cell = Cell.new
|
56
|
+
s = c['contents']
|
57
|
+
cell.solution =
|
58
|
+
case s
|
59
|
+
when ""; :null
|
60
|
+
when "#"; :black
|
61
|
+
else
|
62
|
+
if s.length == 1
|
63
|
+
s
|
64
|
+
else
|
65
|
+
Rebus.new s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
x, y = c['x'], c['y']
|
69
|
+
xw.solution[y][x] = cell
|
70
|
+
end
|
71
|
+
xw.across_clues = json['across']
|
72
|
+
xw.down_clues = json['down']
|
73
|
+
xw
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/lib/pangrid/plugins/qxw.rb
CHANGED
@@ -34,6 +34,8 @@ end
|
|
34
34
|
class RedditFilled < Plugin
|
35
35
|
include RedditWriter
|
36
36
|
|
37
|
+
DESCRIPTION = "Reddit format (with filled squares)"
|
38
|
+
|
37
39
|
def write(xw)
|
38
40
|
write_xw(xw)
|
39
41
|
end
|
@@ -48,6 +50,8 @@ end
|
|
48
50
|
class RedditBlank < Plugin
|
49
51
|
include RedditWriter
|
50
52
|
|
53
|
+
DESCRIPTION = "Reddit format (with blank squares)"
|
54
|
+
|
51
55
|
def write(xw)
|
52
56
|
write_xw(xw)
|
53
57
|
end
|
data/lib/pangrid/plugins/text.rb
CHANGED
data/lib/pangrid/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pangrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin DeMello
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: martindemello@gmail.com
|
@@ -29,6 +29,8 @@ files:
|
|
29
29
|
- lib/pangrid/plugins/acrosslite.rb
|
30
30
|
- lib/pangrid/plugins/csv.rb
|
31
31
|
- lib/pangrid/plugins/excel.rb
|
32
|
+
- lib/pangrid/plugins/exolve.rb
|
33
|
+
- lib/pangrid/plugins/json.rb
|
32
34
|
- lib/pangrid/plugins/qxw.rb
|
33
35
|
- lib/pangrid/plugins/reddit.rb
|
34
36
|
- lib/pangrid/plugins/text.rb
|
@@ -56,8 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
58
|
- !ruby/object:Gem::Version
|
57
59
|
version: '0'
|
58
60
|
requirements: []
|
59
|
-
|
60
|
-
rubygems_version: 2.5.1
|
61
|
+
rubygems_version: 3.0.3
|
61
62
|
signing_key:
|
62
63
|
specification_version: 4
|
63
64
|
summary: A crossword file format converter
|