acgt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +75 -0
- data/acgt.gemspec +18 -0
- data/bin/acgt +17 -0
- data/lib/acgt.rb +92 -0
- metadata +83 -0
data/README
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
acgt(1)
|
2
|
+
|
3
|
+
NAME
|
4
|
+
acgt - Generate using templates
|
5
|
+
|
6
|
+
SYNOPSIS
|
7
|
+
acgt [-h | --help] [-e] [-o path ] <template> [name:value]*
|
8
|
+
|
9
|
+
DESCRIPTION
|
10
|
+
<template>
|
11
|
+
Name of the template to be used as a generator.
|
12
|
+
|
13
|
+
-e
|
14
|
+
Opens the template in $EDITOR for edition.
|
15
|
+
|
16
|
+
-o
|
17
|
+
Path to write generated content. If omitted writes to
|
18
|
+
STDOUT.
|
19
|
+
|
20
|
+
[name:value]*
|
21
|
+
Several variable replacements. If a name is used more than
|
22
|
+
once then the variable is converted to an array of values.
|
23
|
+
|
24
|
+
See section on default values.
|
25
|
+
|
26
|
+
-h, --help
|
27
|
+
Display this help message.
|
28
|
+
|
29
|
+
TEMPLATES STORAGE
|
30
|
+
Templates are searched in ./.acgt and ~/.acgt
|
31
|
+
|
32
|
+
Templates are written using Mote, and should end in .mote
|
33
|
+
extension.
|
34
|
+
|
35
|
+
EXAMPLE USAGE
|
36
|
+
Given a template ~/.acgt/gemspec.mote with the following contents:
|
37
|
+
|
38
|
+
# encoding: utf-8
|
39
|
+
|
40
|
+
Gem::Specification.new do |s|
|
41
|
+
s.name = "{{ name }}"
|
42
|
+
s.version = "{{ version }}"
|
43
|
+
s.summary = "{{ description }}"
|
44
|
+
s.description = "{{ description }}"
|
45
|
+
s.authors = {{ authors.inspect }}
|
46
|
+
s.email = {{ email.inspect }}
|
47
|
+
s.homepage = "{{ homepage }}"
|
48
|
+
s.files = `git ls-files 2> /dev/null`.split("\n")
|
49
|
+
end
|
50
|
+
|
51
|
+
we can issue the following command to generate:
|
52
|
+
|
53
|
+
acgt gemspec name:acgt version:0.0.1 \
|
54
|
+
description:"DNA for simple generators" \
|
55
|
+
authors:"Leandro López" email:"inkel.ar@gmail.com" \
|
56
|
+
homepage:"http://inkel.github.com/acgt" \
|
57
|
+
authors: email:
|
58
|
+
|
59
|
+
generates the following output:
|
60
|
+
|
61
|
+
# encoding: utf-8
|
62
|
+
|
63
|
+
Gem::Specification.new do |s|
|
64
|
+
s.name = "acgt"
|
65
|
+
s.version = "0.0.1"
|
66
|
+
s.summary = "DNA for simple generators"
|
67
|
+
s.description = "DNA for simple generators"
|
68
|
+
s.authors = ["Leandro Lopez"]
|
69
|
+
s.email = ["inkel.ar@gmail.com"]
|
70
|
+
s.homepage = "http://inkel.github.com/acgt"
|
71
|
+
s.files = `git ls-files 2> /dev/null`.split("\n")
|
72
|
+
end
|
73
|
+
|
74
|
+
In this example we've used empty authors and email vars at the
|
75
|
+
end to convert it to an array.
|
data/acgt.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "acgt"
|
5
|
+
s.version = "0.0.1"
|
6
|
+
s.summary = "DNA for simple generators"
|
7
|
+
s.description = "DNA for simple generators"
|
8
|
+
s.authors = ["Leandro Lopez"]
|
9
|
+
s.email = ["inkel.ar@gmail.com"]
|
10
|
+
s.homepage = "http://inkel.github.com/acgt"
|
11
|
+
s.files = `git ls-files 2> /dev/null`.split("\n")
|
12
|
+
s.licenses = ["MIT"]
|
13
|
+
|
14
|
+
s.executables = ["acgt"]
|
15
|
+
|
16
|
+
s.add_dependency "mote"
|
17
|
+
s.add_dependency "clap"
|
18
|
+
end
|
data/bin/acgt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require "clap"
|
4
|
+
require_relative "../lib/acgt"
|
5
|
+
|
6
|
+
rest = Clap.run ARGV, {
|
7
|
+
"-h" => ACGT.method(:help),
|
8
|
+
"--help" => ACGT.method(:help),
|
9
|
+
"--version" => lambda { puts "acgt version #{ ACGT::VERSION }"; exit 0 }
|
10
|
+
}
|
11
|
+
|
12
|
+
template, *params = Clap.run rest, {
|
13
|
+
"-o" => ACGT.method(:output),
|
14
|
+
"-e" => ACGT.method(:edit_template)
|
15
|
+
}
|
16
|
+
|
17
|
+
ACGT.run template, params
|
data/lib/acgt.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require "mote"
|
2
|
+
|
3
|
+
module ACGT
|
4
|
+
VERSION = "0.0.1".freeze
|
5
|
+
|
6
|
+
@options = { output: nil, edit: false }
|
7
|
+
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def help
|
11
|
+
readme = File.expand_path("../README", File.dirname(__FILE__))
|
12
|
+
exec "${PAGER:-less} #{ readme }"
|
13
|
+
end
|
14
|
+
|
15
|
+
def output path
|
16
|
+
@options[:output] = File.absolute_path(path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_templates_dir path
|
20
|
+
@options[:templates].unshift File.absolute_path(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse params
|
24
|
+
{}.tap do |vars|
|
25
|
+
params.each do |param|
|
26
|
+
name, value = param.split(":", 2)
|
27
|
+
name = name.to_sym
|
28
|
+
if vars[name]
|
29
|
+
vars[name] = [vars[name]] unless vars[name].is_a?(Array)
|
30
|
+
vars[name] << value if value && !value.empty?
|
31
|
+
else
|
32
|
+
vars[name] = value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def edit_template
|
39
|
+
@options[:edit] = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_template_file template
|
43
|
+
get_template_file_from_cwd(template) || get_template_file_from_home(template)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_template_file_from_cwd template
|
47
|
+
get_template_file_from File.join(Dir.pwd, ".acgt"), template
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_template_file_from_home template
|
51
|
+
get_template_file_from(File.join(ENV["HOME"], ".acgt"), template)
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_template_file_from dir, template
|
55
|
+
file = File.join(File.absolute_path(dir), "#{ template }.mote")
|
56
|
+
file if File.exists?(file)
|
57
|
+
end
|
58
|
+
|
59
|
+
def render template, params
|
60
|
+
vars = parse params
|
61
|
+
Mote.parse(File.read(template), self, vars.keys).call(vars)
|
62
|
+
end
|
63
|
+
|
64
|
+
def run template, params
|
65
|
+
file = get_template_file template
|
66
|
+
|
67
|
+
if @options[:edit]
|
68
|
+
if file.nil?
|
69
|
+
file = File.join(ENV["HOME"], ".acgt", "#{template}.mote")
|
70
|
+
STDERR.puts "Creating template #{ file }"
|
71
|
+
end
|
72
|
+
exec "$EDITOR #{ file }"
|
73
|
+
end
|
74
|
+
|
75
|
+
if file.nil?
|
76
|
+
STDERR.puts "Template #{template} doesn't exists in #{Dir.pwd}/.acgt or ~/.acgt."
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
|
80
|
+
dna = render file, params
|
81
|
+
|
82
|
+
if @options[:output]
|
83
|
+
output = File.absolute_path(@options[:output])
|
84
|
+
STDOUT.puts "Generating #{output}"
|
85
|
+
File.open(output, "w") do |fp|
|
86
|
+
fp.write dna
|
87
|
+
end
|
88
|
+
else
|
89
|
+
STDOUT.puts dna
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acgt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leandro Lopez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mote
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: clap
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: DNA for simple generators
|
47
|
+
email:
|
48
|
+
- inkel.ar@gmail.com
|
49
|
+
executables:
|
50
|
+
- acgt
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- README
|
55
|
+
- acgt.gemspec
|
56
|
+
- bin/acgt
|
57
|
+
- lib/acgt.rb
|
58
|
+
homepage: http://inkel.github.com/acgt
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.23
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: DNA for simple generators
|
83
|
+
test_files: []
|