mirror of https://github.com/jackc/pgx.git
Use rake instead of guard for erb compilation
parent
3fef18bf38
commit
ec460173eb
48
Guardfile
48
Guardfile
|
@ -1,48 +0,0 @@
|
|||
# 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
|
|
@ -14,17 +14,16 @@ 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.
|
||||
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 are automatically automatically processed with [rake](https://github.com/jimweirich/rake).
|
||||
|
||||
Prerequisites:
|
||||
|
||||
* Ruby
|
||||
* guard
|
||||
* guard-tilt
|
||||
* Rake
|
||||
|
||||
To automatically process .go.erb files open a shell in the pgx directory and run:
|
||||
To automatically process .go.erb files and run the tests:
|
||||
|
||||
jack@hk-47~/dev/pgx$ guard
|
||||
jack@hk-47~/dev/pgx$ rake test
|
||||
|
||||
Testing
|
||||
-------
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
require 'rake/clean'
|
||||
|
||||
ERB = FileList['*.go.erb']
|
||||
GO = ERB.ext
|
||||
CLEAN.include(GO)
|
||||
|
||||
rule '.go' => '.go.erb' do |t|
|
||||
sh "erb #{t.source} > #{t.name}"
|
||||
end
|
||||
|
||||
desc "Run tests"
|
||||
task :test => GO do
|
||||
sh "go test"
|
||||
end
|
|
@ -23,6 +23,7 @@ func TestSelectAllString(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func TestSelectAllInt64(t *testing.T) {
|
||||
conn := getSharedConnection()
|
||||
|
||||
|
@ -108,6 +109,7 @@ func TestSelectAllInt16(t *testing.T) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
func TestSelectAllFloat64(t *testing.T) {
|
||||
conn := getSharedConnection()
|
||||
|
||||
|
|
|
@ -51,7 +51,6 @@ func TestSelectAllInt<%= size %>(t *testing.T) {
|
|||
t.Error("Should have received error on null")
|
||||
}
|
||||
}
|
||||
|
||||
<% end %>
|
||||
|
||||
<% [64, 32].each do |size| %>
|
||||
|
@ -72,5 +71,4 @@ func TestSelectAllFloat<%= size %>(t *testing.T) {
|
|||
t.Error("Should have received error on null")
|
||||
}
|
||||
}
|
||||
|
||||
<% end %>
|
||||
|
|
|
@ -21,6 +21,7 @@ func TestSelectString(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func TestSelectInt64(t *testing.T) {
|
||||
conn := getSharedConnection()
|
||||
|
||||
|
@ -106,6 +107,7 @@ func TestSelectInt16(t *testing.T) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
func TestSelectFloat64(t *testing.T) {
|
||||
conn := getSharedConnection()
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ func TestSelectInt<%= size %>(t *testing.T) {
|
|||
t.Error("Should have received error on null")
|
||||
}
|
||||
}
|
||||
|
||||
<% end %>
|
||||
|
||||
<% [64, 32].each do |size| %>
|
||||
|
@ -70,5 +69,4 @@ func TestSelectFloat<%= size %>(t *testing.T) {
|
|||
t.Error("Should have received error on null")
|
||||
}
|
||||
}
|
||||
|
||||
<% end %>
|
||||
|
|
|
@ -22,6 +22,7 @@ func TestDataRowReaderReadString(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func TestDataRowReaderReadInt64(t *testing.T) {
|
||||
conn := getSharedConnection()
|
||||
|
||||
|
@ -77,6 +78,7 @@ func TestDataRowReaderReadInt16(t *testing.T) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
func TestDataRowReaderReadFloat64(t *testing.T) {
|
||||
conn := getSharedConnection()
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ func TestDataRowReaderReadInt<%= size %>(t *testing.T) {
|
|||
t.Error("Wrong value returned")
|
||||
}
|
||||
}
|
||||
|
||||
<% end %>
|
||||
|
||||
<% [64, 32].each do |size| %>
|
||||
|
@ -61,5 +60,4 @@ func TestDataRowReaderReadFloat<%= size %>(t *testing.T) {
|
|||
t.Error("Wrong value returned")
|
||||
}
|
||||
}
|
||||
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue