From 3fef18bf382b330fce8916ae468ea0091e7841ea Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 2 May 2013 09:23:26 -0500 Subject: [PATCH] Added automatic .go.erb compilation fixes #16 --- Guardfile | 48 ++++++++++++++++++++++++++++ README.md | 23 +++++++++++++ connection_select_column_test.go | 2 ++ connection_select_column_test.go.erb | 2 ++ connection_select_value_test.go | 2 ++ connection_select_value_test.go.erb | 2 ++ data_row_reader_test.go | 2 -- data_row_reader_test.go.erb | 2 ++ 8 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 Guardfile diff --git a/Guardfile b/Guardfile new file mode 100644 index 00000000..4a1dc4de --- /dev/null +++ b/Guardfile @@ -0,0 +1,48 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +context = Struct.new(:path) # default +=begin Context Object +context = Class.new do + def initialize(path) + end + # custom behaviour +end +=end + +locals = Hash.new({}) # default +=begin Local Variables +require 'yaml' +locals, path = {}, 'locals.yml' +def locals.reload + update YAML.load_file(path) +end +locals.reload +=end + +guard 'tilt', :context => context, :locals => locals do + # watch files with two extnames like index.html.erb + watch %r'.+go.erb' +end + +# Guard::Tilt.root = Dir.getwd # (default: Dir.getwd) + +=begin Output Path +class OuputPath < Guard::Tilt::OutputPath + + BASE = File.expand_path 'views' + ROOT = File.expand_path 'public' + + # By default Path#sanitize only strips an extname from itself. + # + # If you want to write the rendered output to another folder you can + # overwrite this method to return another Path object, like this: + def sanitize + super.sub BASE, ROOT + end + + # ... then set the OutputPath class. + Guard::Tilt.output_path = self + +end +=end diff --git a/README.md b/README.md index e2c2b303..86757757 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,29 @@ pgx Experimental PostgreSQL client library for Go +Usage +===== + +TODO + +Development +=========== + +ERB Templating +-------------- + +Sometimes Go code can be repetitive especially with dealing with functions that only differ in the type (e.g. ReadInt16, ReadInt32, ReadInt64). Some of this repetition can be eliminated by using a template preprocessor. pgx uses Ruby erb templates. Files that end in .go.erb are used to produce the corresponding .go files. These files can be automatically processed with guard -- a Ruby file and directory watcher. + +Prerequisites: + +* Ruby +* guard +* guard-tilt + +To automatically process .go.erb files open a shell in the pgx directory and run: + + jack@hk-47~/dev/pgx$ guard + Testing ------- diff --git a/connection_select_column_test.go b/connection_select_column_test.go index cf901d1f..679151cd 100644 --- a/connection_select_column_test.go +++ b/connection_select_column_test.go @@ -107,6 +107,7 @@ func TestSelectAllInt16(t *testing.T) { } } + func TestSelectAllFloat64(t *testing.T) { conn := getSharedConnection() @@ -142,3 +143,4 @@ func TestSelectAllFloat32(t *testing.T) { t.Error("Should have received error on null") } } + diff --git a/connection_select_column_test.go.erb b/connection_select_column_test.go.erb index cdb7d1ac..d048cf97 100644 --- a/connection_select_column_test.go.erb +++ b/connection_select_column_test.go.erb @@ -51,6 +51,7 @@ func TestSelectAllInt<%= size %>(t *testing.T) { t.Error("Should have received error on null") } } + <% end %> <% [64, 32].each do |size| %> @@ -71,4 +72,5 @@ func TestSelectAllFloat<%= size %>(t *testing.T) { t.Error("Should have received error on null") } } + <% end %> diff --git a/connection_select_value_test.go b/connection_select_value_test.go index 66646927..0eb43502 100644 --- a/connection_select_value_test.go +++ b/connection_select_value_test.go @@ -105,6 +105,7 @@ func TestSelectInt16(t *testing.T) { } } + func TestSelectFloat64(t *testing.T) { conn := getSharedConnection() @@ -140,3 +141,4 @@ func TestSelectFloat32(t *testing.T) { t.Error("Should have received error on null") } } + diff --git a/connection_select_value_test.go.erb b/connection_select_value_test.go.erb index 20f8f1de..4c34bcec 100644 --- a/connection_select_value_test.go.erb +++ b/connection_select_value_test.go.erb @@ -49,6 +49,7 @@ func TestSelectInt<%= size %>(t *testing.T) { t.Error("Should have received error on null") } } + <% end %> <% [64, 32].each do |size| %> @@ -69,4 +70,5 @@ func TestSelectFloat<%= size %>(t *testing.T) { t.Error("Should have received error on null") } } + <% end %> diff --git a/data_row_reader_test.go b/data_row_reader_test.go index c4ee6600..8c91d992 100644 --- a/data_row_reader_test.go +++ b/data_row_reader_test.go @@ -22,7 +22,6 @@ func TestDataRowReaderReadString(t *testing.T) { } } - func TestDataRowReaderReadInt64(t *testing.T) { conn := getSharedConnection() @@ -78,7 +77,6 @@ func TestDataRowReaderReadInt16(t *testing.T) { } - func TestDataRowReaderReadFloat64(t *testing.T) { conn := getSharedConnection() diff --git a/data_row_reader_test.go.erb b/data_row_reader_test.go.erb index f5d75a4b..28778660 100644 --- a/data_row_reader_test.go.erb +++ b/data_row_reader_test.go.erb @@ -40,6 +40,7 @@ func TestDataRowReaderReadInt<%= size %>(t *testing.T) { t.Error("Wrong value returned") } } + <% end %> <% [64, 32].each do |size| %> @@ -60,4 +61,5 @@ func TestDataRowReaderReadFloat<%= size %>(t *testing.T) { t.Error("Wrong value returned") } } + <% end %>