Skip to content

Commit

Permalink
Merge pull request #6 from sethherr/switch_to_kind
Browse files Browse the repository at this point in the history
Switch to kind
  • Loading branch information
tdegrunt committed Jan 4, 2016
2 parents c9bf2d7 + cff1cf6 commit cdf832e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
22 changes: 11 additions & 11 deletions lib/keyboard_reactor/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ def initialize(keyboard_json = nil, keyboard_hash: nil)
@id = "#{(Time.now.to_f * 100).round}reactor"
end

attr_reader :tmp_dir, :keyboard_hash, :find_type, :id
attr_writer :keyboard_type
attr_reader :tmp_dir, :keyboard_hash, :find_kind, :id
attr_writer :keyboard_kind

def self.relative_path(path)
File.expand_path(path, BASE_DIR)
end

def self.known_types
def self.known_kinds
COLUMNS.keys
end

def firmware_path
self.class.relative_path("firmware/keyboard/#{keyboard_type}")
self.class.relative_path("firmware/keyboard/#{keyboard_kind}")
end

def c_file_path
Expand All @@ -28,21 +28,21 @@ def hex_file_path
@hex_file_path ||= self.class.relative_path("#{firmware_path}/#{@id}.hex")
end

def keyboard_type
@keyboard_type ||= @keyboard_hash['type']
return @keyboard_type.to_s if self.class.known_types.include?(@keyboard_type)
fail "Unknown keyboard type '#{@keyboard_type}', not one of #{self.class.known_types}"
def keyboard_kind
@keyboard_kind ||= @keyboard_hash['kind']
return @keyboard_kind.to_s if self.class.known_kinds.include?(@keyboard_kind)
fail "Unknown keyboard kind '#{@keyboard_kind}', not one of #{self.class.known_kinds}"
end

def layout_template
path = "./keyboard_reactor/templates/#{keyboard_type}.liquid"
path = "./keyboard_reactor/templates/#{keyboard_kind}.liquid"
File.read(self.class.relative_path(path))
end

def c_file
Liquid::Template.parse(layout_template)
.render(
'columns' => COLUMNS[keyboard_type],
'columns' => COLUMNS[keyboard_kind],
'layout' => @keyboard_hash
)
end
Expand All @@ -68,7 +68,7 @@ def delete_existing_compilations
end

def default_hex
@hex_file_path = "#{firmware_path}/#{keyboard_type}.hex"
@hex_file_path = "#{firmware_path}/#{keyboard_kind}.hex"
`cd #{firmware_path.to_s} && make clean && make KEYMAP="default"`
read_hex_file
end
Expand Down
2 changes: 1 addition & 1 deletion lib/keyboard_reactor/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module KeyboardReactor
VERSION = '0.0.4'
VERSION = '0.0.5'
end
2 changes: 1 addition & 1 deletion spec/fixtures/ergodox_ez.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "ergodox_ez",
"kind": "ergodox_ez",
"description": "ErgoDox EZ default layout",
"properties": {},
"layers": [
Expand Down
23 changes: 12 additions & 11 deletions spec/keyboard_reactor/output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@
expect(keyboard_reactor.keyboard_hash['layers'][0]['keymap'].count).to eq 84
end
end
context 'passed keyboard_json wrapped in layout'
end

describe 'find_type' do
it "raises an error if the type isn't known" do
expect { KeyboardReactor::Output.new(keyboard_hash: { 'type' => 'cool keyboard' }).keyboard_type }.to raise_error
describe 'find_kind' do
it "raises an error if the kind isn't known" do
expect { KeyboardReactor::Output.new(keyboard_hash: { 'kind' => 'cool keyboard' }).keyboard_kind }.to raise_error
end
it 'returns the type' do
expect(KeyboardReactor::Output.new(keyboard_hash: { 'type' => 'ergodox_ez' }).keyboard_type).to eq('ergodox_ez')
it 'returns the kind' do
expect(KeyboardReactor::Output.new(keyboard_hash: { 'kind' => 'ergodox_ez' }).keyboard_kind).to eq('ergodox_ez')
end
end

describe 'layout_template' do
%w(ergodox_ez planck preonic).each do |layout_type|
it "finds the layout file for #{layout_type}" do
keyboard_reactor = KeyboardReactor::Output.new(keyboard_hash: { 'type' => layout_type })
%w(ergodox_ez planck preonic).each do |layout_kind|
it "finds the layout file for #{layout_kind}" do
keyboard_reactor = KeyboardReactor::Output.new(keyboard_hash: { 'kind' => layout_kind })
expect(keyboard_reactor.layout_template).to_not be_nil
end
end
end

describe 'read hex file' do
it "fails if a file isn't present" do
keyboard_reactor = KeyboardReactor::Output.new(keyboard_hash: { 'type' => 'ergodox_ez' })
keyboard_reactor = KeyboardReactor::Output.new(keyboard_hash: { 'kind' => 'ergodox_ez' })
keyboard_reactor.delete_existing_compilations
expect { keyboard_reactor.read_hex_file }.to raise_error
end
Expand All @@ -49,7 +50,7 @@

describe 'write_c_file' do
it 'writes a c file' do
keyboard_reactor = KeyboardReactor::Output.new(keyboard_hash: { 'type' => 'ergodox_ez' })
keyboard_reactor = KeyboardReactor::Output.new(keyboard_hash: { 'kind' => 'ergodox_ez' })
c_file = keyboard_reactor.c_file_path
expect(File.exist?(c_file)).to be_false
keyboard_reactor.write_c_file
Expand All @@ -62,7 +63,7 @@
# we're ensuring that we can correctly compile a hex file as a test
it 'writes the default hex file' do
keyboard_reactor = KeyboardReactor::Output.new(keyboard_hash: {})
keyboard_reactor.keyboard_type = 'ergodox_ez'
keyboard_reactor.keyboard_kind = 'ergodox_ez'
firmware_dir = keyboard_reactor.firmware_path
hex_file = "#{firmware_dir}/ergodox_ez.hex"
keyboard_reactor.delete_existing_compilations
Expand Down

0 comments on commit cdf832e

Please sign in to comment.