Skip to content

Commit

Permalink
Merge 8a9e6d2 into 01d236d
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Pikesley committed Sep 19, 2016
2 parents 01d236d + 8a9e6d2 commit 3c562d9
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 64 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
autoprefixer-rails (6.4.1)
autoprefixer-rails (6.4.1.1)
execjs
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
Expand Down Expand Up @@ -85,12 +85,12 @@ GEM
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
i18n (0.7.0)
jasmine (2.5.0)
jasmine-core (~> 2.5)
jasmine (2.5.1)
jasmine-core (>= 2.5.1, < 3.0.0)
phantomjs
rack (>= 1.2.1)
rake
jasmine-core (2.5.0)
jasmine-core (2.5.2)
json (1.8.3)
kramdown (1.12.0)
listen (3.1.5)
Expand All @@ -108,7 +108,7 @@ GEM
minitest (5.9.0)
multi_json (1.12.1)
nenv (0.3.0)
nineteen-eighty-two (0.1.2)
nineteen-eighty-two (0.1.4)
erubis
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
Expand Down
10 changes: 6 additions & 4 deletions lib/uncle_clive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ class App < Sinatra::Base
get '/:text' do
headers( 'Access-Control-Allow-Origin' => '*' )

text = cleave params[:text], separator: params.fetch('line-separator', '---')

respond_to do |wants|
wants.json do
Nineteen::Eighty::Two::Formats::JSON.format params[:text]
Nineteen::Eighty::Two::Formats::JSON.format text
end

wants.svg do
Nineteen::Eighty::Two::Formats::SVG.format params[:text], {colour: "##{params.fetch('colour', '000000')}"}
Nineteen::Eighty::Two::Formats::SVG.format text, {colour: "##{params.fetch('colour', '000000')}"}
end

wants.text do
Nineteen::Eighty::Two::Formats::Text.format params[:text], {on: '()', off: ' '}
Nineteen::Eighty::Two::Formats::Text.format text, {on: '()', off: ' '}
end

wants.html do
@content = Nineteen::Eighty::Two::Formats::HTMLTable.format params[:text]
@content = Nineteen::Eighty::Two::Formats::HTMLTable.format text
erb :table, layout: :default
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/uncle_clive/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module UncleClive
CONFIG = YAML.load_file('config/config.yml') || {}

module Helpers
def hello
'Hello'
def cleave string, separator: '---'
items = string.split separator
return items.first if items.length == 1
items
end
end
end
18 changes: 14 additions & 4 deletions spec/uncle_clive/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ module UncleClive
describe Helpers do
let(:helpers) { TestHelper.new }

it 'says hello' do
expect(helpers.hello).to eq 'Hello'
end

it 'has a config' do
expect(CONFIG).to be_a Hash
end

context 'cleave' do
it 'splits text' do
expect(helpers.cleave 'multi---line').to eq ['multi', 'line']
end

it 'returns a single string where appropriate' do
expect(helpers.cleave 'singleton').to eq 'singleton'
end

it 'splits on a custom separator' do
expect(helpers.cleave 'split_me', separator: '_').to eq ['split','me']
end
end
end
end
17 changes: 17 additions & 0 deletions spec/uncle_clive/html_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module UncleClive
describe App do
context 'HTML' do
specify 'single line' do
get '/html'
expect(last_response).to be_ok
expect(last_response.body).to match /<tr><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><\/tr>/
end

specify 'multi-line' do
get '/ab---cd'
expect(last_response).to be_ok
expect(last_response.body.split("\n").count).to eq 81
end
end
end
end
54 changes: 54 additions & 0 deletions spec/uncle_clive/json_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module UncleClive
JSON_HEADERS = { 'HTTP_ACCEPT' => 'application/json' }

describe App do
context 'JSON' do
specify 'single line' do
get '/json', nil, JSON_HEADERS
expect(last_response).to be_ok
expect(JSON.parse last_response.body).to eq (
{
'id' => 'json',
'data' => [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
}
)
end

specify 'multi-line' do
get '/ab---cd', nil, JSON_HEADERS
expect(last_response).to be_ok
expect(JSON.parse last_response.body).to eq (
{
'id' => "[ab, cd]",
'data' => [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
}
)
end
end
end
end
37 changes: 37 additions & 0 deletions spec/uncle_clive/svg_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module UncleClive
SVG_HEADERS = { 'HTTP_ACCEPT' => 'image/svg+xml' }

describe App do
context 'SVG' do
context 'single line' do
it 'serves SVG' do
get '/svg', nil, SVG_HEADERS
expect(last_response).to be_ok
expect(last_response.body.split("\n")[9]).to eq " <rect x='2' y='2' width='3' height='1' class='on' />"
end

it 'changes the colour' do
get '/svg?colour=fa8100', nil, SVG_HEADERS
expect(last_response).to be_ok
expect(last_response.body.split("\n")[4]).to eq " fill: #fa8100;"
end
end

context 'multi-line' do
it 'serves SVG' do
get '/ab---cd', nil, SVG_HEADERS
expect(last_response).to be_ok
lines = last_response.body.split("\n")
expect(lines[0]).to eq"<svg viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'>"
expect((lines).count).to eq 38
end

it 'changes the colour' do
get '/ab---cd?colour=abcdef', nil, SVG_HEADERS
expect(last_response).to be_ok
expect(last_response.body.split("\n")[4]).to eq " fill: #abcdef;"
end
end
end
end
end
19 changes: 19 additions & 0 deletions spec/uncle_clive/text_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module UncleClive
TEXT_HEADERS = { 'HTTP_ACCEPT' => 'text/plain' }

describe App do
context 'text' do
specify 'single line' do
get '/text', nil, TEXT_HEADERS
expect(last_response).to be_ok
expect(last_response.body.split("\n")[2]).to eq " ()()() ()()() () () ()()() "
end

specify 'multi-line' do
get 'ab---cd', nil, TEXT_HEADERS
expect(last_response).to be_ok
expect(last_response.body.split("\n").count).to eq 16
end
end
end
end
75 changes: 26 additions & 49 deletions spec/uncle_clive/uncle_clive_spec.rb
Original file line number Diff line number Diff line change
@@ -1,60 +1,37 @@
module UncleClive
JSON_HEADERS = { 'HTTP_ACCEPT' => 'application/json' }
TEXT_HEADERS = { 'HTTP_ACCEPT' => 'text/plain' }
SVG_HEADERS = { 'HTTP_ACCEPT' => 'image/svg+xml' }

describe App do
it 'has a homepage' do
get '/'
expect(last_response).to be_ok
expect(last_response.body).to match /Sinclair Spectrum Font as a Service/
end

context 'spectrum font' do
it 'serves JSON' do
get '/json', nil, JSON_HEADERS
expect(last_response).to be_ok
expect(JSON.parse last_response.body).to eq (
{
'id' => 'json',
'data' => [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
}
)
end

it 'serves HTML' do
get '/html'
expect(last_response).to be_ok
expect(last_response.body).to match /<tr><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><td class='off'> <\/td><\/tr>/
end

it 'serves text' do
get '/text', nil, TEXT_HEADERS
expect(last_response).to be_ok
expect(last_response.body.split("\n")[2]).to eq " ()()() ()()() () () ()()() "
end

context 'SVG' do
it 'serves SVG' do
get '/svg', nil, SVG_HEADERS
expect(last_response).to be_ok
expect(last_response.body.split("\n")[9]).to eq "<rect x='2' y='2' width='3' height='1' class='on' />"
end

it 'changes the colour' do
get '/svg?colour=fa8100', nil, SVG_HEADERS
expect(last_response).to be_ok
expect(last_response.body.split("\n")[4]).to eq " fill: #fa8100;"
end
end
it 'can take a custom line-separator' do
get '/ab:cd?line-separator=:', nil, { 'HTTP_ACCEPT' => 'application/json' }
expect(last_response).to be_ok
expect(JSON.parse last_response.body).to eq (
{
'id' => "[ab, cd]",
'data' => [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
}
)
end
end
end

0 comments on commit 3c562d9

Please sign in to comment.