diff --git a/lib/keyboard_reactor/output.rb b/lib/keyboard_reactor/output.rb index 6e0e4f3..621e4c0 100644 --- a/lib/keyboard_reactor/output.rb +++ b/lib/keyboard_reactor/output.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/keyboard_reactor/version.rb b/lib/keyboard_reactor/version.rb index 33858f1..2621188 100644 --- a/lib/keyboard_reactor/version.rb +++ b/lib/keyboard_reactor/version.rb @@ -1,3 +1,3 @@ module KeyboardReactor - VERSION = '0.0.4' + VERSION = '0.0.5' end diff --git a/spec/fixtures/ergodox_ez.json b/spec/fixtures/ergodox_ez.json index f18f746..20f3c96 100644 --- a/spec/fixtures/ergodox_ez.json +++ b/spec/fixtures/ergodox_ez.json @@ -1,5 +1,5 @@ { - "type": "ergodox_ez", + "kind": "ergodox_ez", "description": "ErgoDox EZ default layout", "properties": {}, "layers": [ diff --git a/spec/keyboard_reactor/output_spec.rb b/spec/keyboard_reactor/output_spec.rb index 1251da9..7fa7221 100644 --- a/spec/keyboard_reactor/output_spec.rb +++ b/spec/keyboard_reactor/output_spec.rb @@ -12,21 +12,22 @@ 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 @@ -34,7 +35,7 @@ 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 @@ -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 @@ -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