Skip to content
Browse files

allow the creation of custom templates, #18

  • Loading branch information...
1 parent 496a09a commit 33d631a3890a0e079b1248d2a9e4d2f933c573e4 @guedes guedes committed Nov 21, 2011
Showing with 48 additions and 11 deletions.
  1. +17 −7 README.md
  2. +15 −3 Rakefile
  3. +2 −1 lib/pgxn_utils/cli.rb
  4. +14 −0 lib/pgxn_utils/no_tasks.rb
View
24 README.md
@@ -4,7 +4,9 @@ pgxn utils
What is it?
--------
-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.
+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?
------------------
@@ -54,8 +56,8 @@ 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.
+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
@@ -130,14 +132,23 @@ that will try to help you to start coding. SQL and C templates contains some tes
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, 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",
@@ -165,8 +176,7 @@ Well suppose you want to change the default maintainer's name and the license, j
}
}
Retrying...
- Overwrite /tmp/my_cool_extension/META.json? (enter "h" for help) [Ynaqdh] Y
- force META.json
+ Overwrite /tmp/my_cool_extension/META.json? (enter "h" for help) [Ynaqdh] force META.json
identical my_cool_extension.control
View
18 Rakefile
@@ -33,7 +33,9 @@ pgxn utils
What is it?
--------
-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.
+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?
------------------
@@ -64,8 +66,8 @@ 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.
+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")}
@@ -100,6 +102,16 @@ that will try to help you to start coding. SQL and C templates contains some tes
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, just do:
View
3 lib/pgxn_utils/cli.rb
@@ -37,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 options[:template], extension_name
+
+ directory selected_template, extension_name
init_repository("#{self.target}/#{extension_name}") if options[:git]
end
View
14 lib/pgxn_utils/no_tasks.rb
@@ -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 comments on commit 33d631a

Please sign in to comment.
Something went wrong with that request. Please try again.