Permalink
Browse files

Merge pull request #25 from guedes/custom-templates

Custom templates
  • Loading branch information...
guedes committed Nov 21, 2011
2 parents 91ae5ef + c8c763f commit 917967d8cc5c5dfa25ea6002aebf731983b59e2a
Showing with 1,343 additions and 54 deletions.
  1. +2 −2 META.json
  2. +89 −25 README.md
  3. +56 −20 Rakefile
  4. +7 −3 lib/pgxn_utils/cli.rb
  5. +14 −0 lib/pgxn_utils/no_tasks.rb
  6. +5 −0 lib/pgxn_utils/templates/c/%extension_name%.control.tt
  7. +8 −0 lib/pgxn_utils/templates/c/.gitignore.tt
  8. +1 −0 lib/pgxn_utils/templates/c/.template
  9. +37 −0 lib/pgxn_utils/templates/c/META.json.tt
  10. +24 −0 lib/pgxn_utils/templates/c/Makefile.tt
  11. +80 −0 lib/pgxn_utils/templates/c/README.md.tt
  12. +33 −0 lib/pgxn_utils/templates/c/doc/%extension_name%.md.tt
  13. +17 −0 lib/pgxn_utils/templates/c/sql/%extension_name%.sql.tt
  14. +1 −0 lib/pgxn_utils/templates/c/sql/uninstall_%extension_name%.sql.tt
  15. +26 −0 lib/pgxn_utils/templates/c/src/%extension_name%.c.tt
  16. +9 −0 lib/pgxn_utils/templates/c/test/expected/base.out.tt
  17. +10 −0 lib/pgxn_utils/templates/c/test/sql/base.sql.tt
  18. +5 −0 lib/pgxn_utils/templates/fdw/%extension_name%.control.tt
  19. +8 −0 lib/pgxn_utils/templates/fdw/.gitignore.tt
  20. +1 −0 lib/pgxn_utils/templates/fdw/.template
  21. +37 −0 lib/pgxn_utils/templates/fdw/META.json.tt
  22. +24 −0 lib/pgxn_utils/templates/fdw/Makefile.tt
  23. +80 −0 lib/pgxn_utils/templates/fdw/README.md.tt
  24. +33 −0 lib/pgxn_utils/templates/fdw/doc/%extension_name%.md.tt
  25. +31 −0 lib/pgxn_utils/templates/fdw/sql/%extension_name%.sql.tt
  26. +14 −0 lib/pgxn_utils/templates/fdw/sql/uninstall_%extension_name%.sql.tt
  27. +323 −0 lib/pgxn_utils/templates/fdw/src/%extension_name%_fdw.c.tt
  28. +4 −0 lib/pgxn_utils/templates/fdw/test/expected/base.out.tt
  29. +8 −0 lib/pgxn_utils/templates/fdw/test/sql/base.sql.tt
  30. +4 −0 lib/pgxn_utils/templates/sql/%extension_name%.control.tt
  31. +8 −0 lib/pgxn_utils/templates/sql/.gitignore.tt
  32. +1 −0 lib/pgxn_utils/templates/sql/.template
  33. +27 −0 lib/pgxn_utils/templates/sql/META.json.tt
  34. +28 −0 lib/pgxn_utils/templates/sql/Makefile.tt
  35. +80 −0 lib/pgxn_utils/templates/sql/README.md.tt
  36. +33 −0 lib/pgxn_utils/templates/sql/doc/%extension_name%.md.tt
  37. +31 −0 lib/pgxn_utils/templates/sql/sql/%extension_name%.sql.tt
  38. +21 −0 lib/pgxn_utils/templates/sql/sql/uninstall_%extension_name%.sql.tt
  39. +49 −0 lib/pgxn_utils/templates/sql/test/expected/base.out.tt
  40. +25 −0 lib/pgxn_utils/templates/sql/test/sql/base.sql.tt
  41. +1 −1 lib/pgxn_utils/version.rb
  42. +48 −3 spec/cli_spec.rb
View
@@ -1,7 +1,7 @@
{
"name": "pgxn_utils",
"abstract": "pgxn_utils is a development tool to create PostgreSQL extensions",
- "version": "0.1.3",
+ "version": "0.1.4dev",
"maintainer": "Dickson S. Guedes <guedes@guedesoft.net>",
"license": "postgresql",
"release_status": "stable",
@@ -14,7 +14,7 @@
"provides": {
"pgxn_utils": {
"file": "pgxn_utils",
- "version": "0.1.3"
+ "version": "0.1.4dev"
}
},
"meta-spec": {
View
114 README.md
@@ -4,7 +4,9 @@ pgxn utils
What is it?
--------
-It aims to be a set of task to help PostgreSQL extension's developers to focus more on the problem that they wants to solve than in the structure and files and control files need to PGXS to build the extension.
+It is a set of task that help developers to create PostgreSQL's extensions, putting
+the extension's files in the recomended places and supplying tasks to help bundle
+and release your extension to PGXN.
How to install it?
------------------
@@ -17,7 +19,6 @@ Or you can install it by rubygems:
gem install pgxn_utils
-
How it works?
-------------
@@ -30,6 +31,7 @@ It is all about tasks. Let's see them:
pgxn-utils help [TASK] # Describe available tasks or one specific task
pgxn-utils release filename # Release an extension to PGXN
pgxn-utils skeleton extension_name # Creates an extension skeleton in current directory
+
# Creating a new extension
@@ -38,6 +40,7 @@ It is all about tasks. Let's see them:
create my_cool_extension
create my_cool_extension/my_cool_extension.control
create my_cool_extension/.gitignore
+ create my_cool_extension/.template
create my_cool_extension/META.json
create my_cool_extension/Makefile
create my_cool_extension/README.md
@@ -47,14 +50,20 @@ It is all about tasks. Let's see them:
create my_cool_extension/test/expected/base.out
create my_cool_extension/test/sql/base.sql
-You can start creating an extension with or without version control. By default `pgxn-utils`
-supports [git](http://git-scm.org) but it will not create a repository unless you use `--git`
-option in the skeleton task.
+
+Thats it! Just start coding! ":)
+
+## Git support
+
+You can start a new extension with or without version control. By default `pgxn-utils`
+supports [git](http://git-scm.org) but it will not create a repository unless you
+use `--git` option in the skeleton task.
$ pgxn-utils skeleton my_cool_versioned_extension --git
create my_cool_versioned_extension
create my_cool_versioned_extension/my_cool_versioned_extension.control
create my_cool_versioned_extension/.gitignore
+ create my_cool_versioned_extension/.template
create my_cool_versioned_extension/META.json
create my_cool_versioned_extension/Makefile
create my_cool_versioned_extension/README.md
@@ -66,16 +75,81 @@ option in the skeleton task.
init /tmp/my_cool_versioned_extension
commit initial commit
-Thats it! Just start coding! ":)
+
+
+When you create a new extension with git support in addition to create skeleton,
+`pgxn-utils` will initialize a git repository and create the initial commit.
+
+Once you have your extension in a git repository your `bundle` will use only the
+commited files to create the archive, but if your repository is dirty then `pgxn-utils`
+will hint you to commit or stash your changes, before bundle.
+
+You must be careful with new files not added to repository, because they will NOT
+be archived.
+
+## Default templates
+
+`pgxn-utils` has three templates: `sql`, `c` and `fdw`. If you call `skeleton` without
+specifying a template the `sql` is the default. But if your extension will supply some C
+modules or you will create a FDW, you can create the extension calling `skeleton` with a
+`--template` option.
+
+ $ pgxn-utils skeleton my_cool_c_extension --template=c
+ create my_cool_c_extension
+ create my_cool_c_extension/my_cool_c_extension.control
+ create my_cool_c_extension/.gitignore
+ create my_cool_c_extension/.template
+ create my_cool_c_extension/META.json
+ create my_cool_c_extension/Makefile
+ create my_cool_c_extension/README.md
+ create my_cool_c_extension/doc/my_cool_c_extension.md
+ create my_cool_c_extension/sql/my_cool_c_extension.sql
+ create my_cool_c_extension/sql/uninstall_my_cool_c_extension.sql
+ create my_cool_c_extension/src/my_cool_c_extension.c
+ create my_cool_c_extension/test/expected/base.out
+ create my_cool_c_extension/test/sql/base.sql
+
+
+
+ $ pgxn-utils skeleton my_cool_fdw_extension --template=fdw
+ create my_cool_fdw_extension
+ create my_cool_fdw_extension/my_cool_fdw_extension.control
+ create my_cool_fdw_extension/.gitignore
+ create my_cool_fdw_extension/.template
+ create my_cool_fdw_extension/META.json
+ create my_cool_fdw_extension/Makefile
+ create my_cool_fdw_extension/README.md
+ create my_cool_fdw_extension/doc/my_cool_fdw_extension.md
+ create my_cool_fdw_extension/sql/my_cool_fdw_extension.sql
+ create my_cool_fdw_extension/sql/uninstall_my_cool_fdw_extension.sql
+ create my_cool_fdw_extension/src/my_cool_fdw_extension_fdw.c
+ create my_cool_fdw_extension/test/expected/base.out
+ create my_cool_fdw_extension/test/sql/base.sql
+
+
+The templates contains examples codes and some links to PostgreSQL documentation
+that will try to help you to start coding. SQL and C templates contains some tests
+examples, and the example code will compiles and pass `make installcheck`, but they
+are examples and you must write your own tests and code.
+
+## Custom templates
+
+If you don't like the templates provided by `pgxn-utils` you can create you own
+templates. Just create a directory where you want with at least a META.json or
+META.json.tt file then you can use your directory as argument to the `--template`
+option.
+
+To see how create your own template, you can use, as example, the
+[templates directory](https://github.com/guedes/pgxn-utils/tree/master/lib/pgxn_utils/templates).
# Changing something
-Well suppose you want to change the default maintainer's name and the license, well just do:
+Well suppose you want to change the default maintainer's name and the license, just do:
$ pgxn-utils change my_cool_extension --maintainer "Dickson Guedes" --license bsd
conflict META.json
- Overwrite /tmp/my_cool_extension/META.json? (enter "h" for help) [Ynaqdh] d
- {
+ Overwrite /tmp/my_cool_extension/META.json? (enter "h" for help) [Ynaqdh]
+ {
"name": "my_cool_extension",
"abstract": "A short description",
"description": "A long description",
@@ -103,12 +177,12 @@ Well suppose you want to change the default maintainer's name and the license, w
}
}
Retrying...
- Overwrite /tmp/my_cool_extension/META.json? (enter "h" for help) [Ynaqdh] Y
+ Overwrite /tmp/my_cool_extension/META.json? (enter "h" for help) [Ynaqdh]
force META.json
identical my_cool_extension.control
-It will wait you decide what to do.
+It will wait until you decide what to do.
For all switches that you can use with *change*, type:
@@ -134,8 +208,11 @@ For all switches that you can use with *change*, type:
# Bundling and Releasing!
Well, since you finished your work you can bundle it to send to [PGXN](http://pgxn.org).
+Note that if you have your extension in a git repository `bundle` will use only the
+commited files to create the archive, but if your repository is dirty then `pgxn-utils`
+will hint you to commit or stash your changes, before bundle.
-Bundle it:
+Let's bundle it:
$ pgxn-utils bundle my_cool_extension
create /home/guedes/extensions/my_cool_extension-0.0.1.zip
@@ -151,19 +228,6 @@ and release it:
You can export `PGXN_USER` and `PGXN_PASSWORD` environment variables to avoid
type username and password everytime.
-# Git support
-
-You can start a new extension with git support calling `skeleton` task with
-`--git` flag, then in addition to create skeleton, `pgxn-utils` will initialize
-a git repository and do a initial commit.
-
-Once you have your extension in a git repository your `bundle` will use only the
-commited files to create the archive, but if your repository is dirty then `pgxn-utils`
-will hint you to commit or stash your changes, before bundle.
-
-You must be careful with new files not added to repository, because they will NOT
-be archived.
-
# Working in progress
* improve [git](http://git-scm.org) support
View
@@ -22,6 +22,8 @@ end
desc "Generate README.md"
task :generate_readme do
rm_r "/tmp/my_cool_extension" if File.exist?("/tmp/my_cool_extension")
+ rm_r "/tmp/my_cool_c_extension" if File.exist?("/tmp/my_cool_c_extension")
+ rm_r "/tmp/my_cool_fdw_extension" if File.exist?("/tmp/my_cool_fdw_extension")
rm_r "/tmp/my_cool_versioned_extension" if File.exist?("/tmp/my_cool_versioned_extension")
readme = File.new("README.md.new", 'w')
readme.puts <<-README
@@ -31,7 +33,9 @@ pgxn utils
What is it?
--------
-It aims to be a set of task to help PostgreSQL extension's developers to focus more on the problem that they wants to solve than in all structure and files and control files need to PGXS to build the extension.
+It is a set of task that help developers to create PostgreSQL's extensions, putting
+the extension's files in the recomended places and supplying tasks to help bundle
+and release your extension to PGXN.
How to install it?
------------------
@@ -57,14 +61,56 @@ It is all about tasks. Let's see them:
$ pgxn-utils skeleton my_cool_extension
#{format_cmd_output("skeleton my_cool_extension -p /tmp")}
-You can start creating an extension with or without version control. By default `pgxn-utils`
-supports [git](http://git-scm.org) but it will not create a repository unless you use `--git`
-option in the skeleton task.
+Thats it! Just start coding! ":)
+
+## Git support
+
+You can start a new extension with or without version control. By default `pgxn-utils`
+supports [git](http://git-scm.org) but it will not create a repository unless you
+use `--git` option in the skeleton task.
$ pgxn-utils skeleton my_cool_versioned_extension --git
#{format_cmd_output("skeleton my_cool_versioned_extension --git -p /tmp")}
-Thats it! Just start coding! ":)
+
+When you create a new extension with git support in addition to create skeleton,
+`pgxn-utils` will initialize a git repository and create the initial commit.
+
+Once you have your extension in a git repository your `bundle` will use only the
+commited files to create the archive, but if your repository is dirty then `pgxn-utils`
+will hint you to commit or stash your changes, before bundle.
+
+You must be careful with new files not added to repository, because they will NOT
+be archived.
+
+## Default templates
+
+`pgxn-utils` has three templates: `sql`, `c` and `fdw`. If you call `skeleton` without
+specifying a template the `sql` is the default. But if your extension will supply some C
+modules or you will create a FDW, you can create the extension calling `skeleton` with a
+`--template` option.
+
+ $ pgxn-utils skeleton my_cool_c_extension --template=c
+#{format_cmd_output("skeleton my_cool_c_extension --template=c -p /tmp")}
+
+
+ $ pgxn-utils skeleton my_cool_fdw_extension --template=fdw
+#{format_cmd_output("skeleton my_cool_fdw_extension --template=fdw -p /tmp")}
+
+The templates contains examples codes and some links to PostgreSQL documentation
+that will try to help you to start coding. SQL and C templates contains some tests
+examples, and the example code will compiles and pass `make installcheck`, but they
+are examples and you must write your own tests and code.
+
+## Custom templates
+
+If you don't like the templates provided by `pgxn-utils` you can create you own
+templates. Just create a directory where you want with at least a META.json or
+META.json.tt file then you can use your directory as argument to the `--template`
+option.
+
+To see how create your own template, you can use, as example, the
+[templates directory](https://github.com/guedes/pgxn-utils/tree/master/lib/pgxn_utils/templates).
# Changing something
@@ -73,7 +119,7 @@ Well suppose you want to change the default maintainer's name and the license, j
$ pgxn-utils change my_cool_extension --maintainer "Dickson Guedes" --license bsd
#{format_cmd_output("change my_cool_extension -p /tmp --maintainer 'Dickson Guedes' --license bsd")}
-It will wait you decide what to do.
+It will wait until you decide what to do.
For all switches that you can use with *change*, type:
@@ -83,8 +129,11 @@ For all switches that you can use with *change*, type:
# Bundling and Releasing!
Well, since you finished your work you can bundle it to send to [PGXN](http://pgxn.org).
+Note that if you have your extension in a git repository `bundle` will use only the
+commited files to create the archive, but if your repository is dirty then `pgxn-utils`
+will hint you to commit or stash your changes, before bundle.
-Bundle it:
+Let's bundle it:
$ pgxn-utils bundle my_cool_extension
create /home/guedes/extensions/my_cool_extension-0.0.1.zip
@@ -100,19 +149,6 @@ and release it:
You can export `PGXN_USER` and `PGXN_PASSWORD` environment variables to avoid
type username and password everytime.
-# Git support
-
-You can start a new extension with git support calling `skeleton` task with
-`--git` flag, then in addition to create skeleton, `pgxn-utils` will initialize
-a git repository and do a initial commit.
-
-Once you have your extension in a git repository your `bundle` will use only the
-commited files to create the archive, but if your repository is dirty then `pgxn-utils`
-will hint you to commit or stash your changes, before bundle.
-
-You must be careful with new files not added to repository, because they will NOT
-be archived.
-
# Working in progress
* improve [git](http://git-scm.org) support
View
@@ -24,6 +24,7 @@ class CLI < Thor
method_option :tags, :aliases => "-t", :type => :array, :desc => "Defines extension's tags"
method_option :release_status, :aliases => "-r", :type => :string, :desc => "Initial extension's release status"
method_option :git, :type => :boolean, :default => false, :desc => "Initialize a git repository after create the extension"
+ method_option :template, :type => :string, :default => "sql", :desc => "The template that will be used to create the extension. Expected values are: sql, c, fdw"
def skeleton(extension_name,target=nil)
self.target = options[:target] || target || "."
@@ -36,7 +37,8 @@ def skeleton(extension_name,target=nil)
say "Can't create an extension overwriting an existing directory.", :red
else
self.set_accessors extension_name
- directory "root", extension_name
+
+ directory selected_template, extension_name
init_repository("#{self.target}/#{extension_name}") if options[:git]
end
@@ -61,14 +63,16 @@ def skeleton(extension_name,target=nil)
def change(extension_name=".")
extension_path, extension_name = resolve_extension_path_and_name(extension_name)
+ template_type = File.read("#{extension_path}/.template").chomp
+
self.target = extension_path
self.extension_name = extension_name
set_accessors(extension_name)
if is_extension?(extension_path)
- template "root/META.json.tt", "#{extension_path}/META.json"
- template "root/%extension_name%.control.tt", "#{extension_path}/%extension_name%.control"
+ template "#{template_type}/META.json.tt", "#{extension_path}/META.json"
+ template "#{template_type}/%extension_name%.control.tt", "#{extension_path}/%extension_name%.control"
else
say "'#{extension_name}' doesn't appears to be an extension. Please, supply the extension's name", :red
end
View
@@ -4,6 +4,20 @@ module NoTasks
include PgxnUtils::Constants
include Grit
+ def selected_template
+ template = options[:template]
+
+ unless [ 'sql', 'c', 'fdw' ].include?(template)
+ if Dir["#{template}/*"].include?("#{template}/META.json") or
+ Dir["#{template}/*"].include?("#{template}/META.json.tt")
+ template = File.expand_path(options[:template])
+ else
+ raise "invalid template: #{template}"
+ end
+ end
+ template
+ end
+
def init_repository(extension_dir)
repo = Repo.init(extension_dir)
original_dir = File.expand_path "."
@@ -0,0 +1,5 @@
+# <%= extension_name %> extension
+comment = '<%= abstract %>'
+default_version = '<%= version %>'
+module_pathname = '$libdir/<%= extension_name %>'
+relocatable = true
Oops, something went wrong.

0 comments on commit 917967d

Please sign in to comment.