mygen 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/.ruby-version +1 -1
- data/README.md +41 -41
- data/bin/console +14 -14
- data/bin/myg +74 -75
- data/bin/setup +8 -8
- data/lib/mygen/generator.rb +107 -107
- data/lib/mygen/plugins/mygen_generator.rb +19 -19
- data/lib/mygen/plugins.rb +23 -23
- data/lib/mygen/version.rb +3 -3
- data/lib/mygen.rb +11 -11
- data/mygen.gemspec +38 -38
- data/templates/mygen_generator/Gemfile +3 -3
- data/templates/mygen_generator/README.md.erb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1301a243f662a069312d093a13e08a6b295a4d0
|
4
|
+
data.tar.gz: ae78b5b58f737cdf0a8fe6ba2a51aeda262448a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8edcb881a266c6d4e8279d24f58afe85182752e1ffe3a0092a8408552000c3c20cea5d9eae6dfe52bfd3e31e88768b2b5b204ac5abf8e35d08c19d1895377de
|
7
|
+
data.tar.gz: 6209a14901eac47276df15ca0185c02766d4a5c4683bf1bc6342fb65eb1a82052794052a934dd01880dc08ad77eb4b63b9392c3024ed40fee2879b3a7623e613
|
data/.gitignore
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
.byebug_history
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
.byebug_history
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.2
|
1
|
+
2.2.2
|
data/README.md
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
# Mygen
|
2
|
-
|
3
|
-
A code generator
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'mygen'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install mygen
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
```
|
24
|
-
myg --help
|
25
|
-
```
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/iamkristian/mygen.
|
36
|
-
|
37
|
-
|
38
|
-
## License
|
39
|
-
|
40
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
1
|
+
# Mygen
|
2
|
+
|
3
|
+
A code generator
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'mygen'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mygen
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```
|
24
|
+
myg --help
|
25
|
+
```
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/iamkristian/mygen.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "mygen"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mygen"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/myg
CHANGED
@@ -1,75 +1,74 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'mygen'
|
4
|
-
require 'gli'
|
5
|
-
require 'mygen'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
c.
|
29
|
-
|
30
|
-
|
31
|
-
plugin
|
32
|
-
c.
|
33
|
-
c.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
plugin.
|
38
|
-
plugin.
|
39
|
-
plugin.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
#
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
exit run(ARGV)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'mygen'
|
4
|
+
require 'gli'
|
5
|
+
require 'mygen'
|
6
|
+
|
7
|
+
include GLI::App
|
8
|
+
|
9
|
+
program_desc 'A simple code generator'
|
10
|
+
|
11
|
+
version Mygen::VERSION
|
12
|
+
|
13
|
+
subcommand_option_handling :normal
|
14
|
+
arguments :strict
|
15
|
+
|
16
|
+
desc "Dry run, doesn't change files"
|
17
|
+
switch :s
|
18
|
+
|
19
|
+
|
20
|
+
desc 'Describe some flag here'
|
21
|
+
default_value 'the default'
|
22
|
+
|
23
|
+
|
24
|
+
desc 'Apply an arbitrary generator'
|
25
|
+
arg_name 'The generator to run'
|
26
|
+
command :generate do |c|
|
27
|
+
c.desc 'Describe a flag to generate'
|
28
|
+
c.flag :f
|
29
|
+
Mygen::Plugins.load.each do |p|
|
30
|
+
plugin = p.new
|
31
|
+
c.desc plugin.description
|
32
|
+
c.arg 'name'
|
33
|
+
c.command plugin.generator_name.to_sym do |s|
|
34
|
+
plugin.plugin_commands(s) if plugin.respond_to?(:plugin_commands)
|
35
|
+
s.action do |global_options, options, args|
|
36
|
+
plugin.dry_run = global_options[:s]
|
37
|
+
plugin.name = args[0]
|
38
|
+
plugin.dest_dir = args[0]
|
39
|
+
plugin.call if plugin.respond_to?(:call)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
c.action do |global_options,options,args|
|
44
|
+
|
45
|
+
# Your command logic here
|
46
|
+
# If you have any errors, just raise them
|
47
|
+
# raise "that command made no sense"
|
48
|
+
|
49
|
+
puts "generate command ran"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
pre do |global,command,options,args|
|
54
|
+
# Pre logic here
|
55
|
+
# Return true to proceed; false to abort and not call the
|
56
|
+
# chosen command
|
57
|
+
# Use skips_pre before a command to skip this block
|
58
|
+
# on that command only
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
post do |global,command,options,args|
|
63
|
+
# Post logic here
|
64
|
+
# Use skips_post before a command to skip this
|
65
|
+
# block on that command only
|
66
|
+
end
|
67
|
+
|
68
|
+
on_error do |exception|
|
69
|
+
# Error logic here
|
70
|
+
# return false to skip default error handling
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
exit run(ARGV)
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
data/lib/mygen/generator.rb
CHANGED
@@ -1,107 +1,107 @@
|
|
1
|
-
module Mygen
|
2
|
-
class Generator
|
3
|
-
attr_accessor :name, :dest_dir, :dry_run, :template_source_dir
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@template_source_dir = File.join(ENV['HOME'], ".mygen", "plugins", generator_name, "templates")
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.descendants
|
10
|
-
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
11
|
-
end
|
12
|
-
|
13
|
-
def description
|
14
|
-
"Plugin has no description"
|
15
|
-
end
|
16
|
-
|
17
|
-
def generator_name
|
18
|
-
self.class.name.gsub(/::/, '/').
|
19
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
20
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
21
|
-
tr("-", "_").
|
22
|
-
split('/').last.
|
23
|
-
downcase
|
24
|
-
end
|
25
|
-
|
26
|
-
def fileutils
|
27
|
-
dry_run ? FileUtils::DryRun : FileUtils::Verbose
|
28
|
-
end
|
29
|
-
|
30
|
-
def template_files(path = template_source_dir)
|
31
|
-
Dir.glob(File.join(path, "**/*")).select { |f| File.file? f }
|
32
|
-
end
|
33
|
-
|
34
|
-
def template_dirs(path = template_source_dir)
|
35
|
-
Dir.glob(File.join(path, "**/*")).select { |f| File.directory? f }
|
36
|
-
end
|
37
|
-
|
38
|
-
def internal_template_files
|
39
|
-
template_files(internal_template_source_dir)
|
40
|
-
end
|
41
|
-
|
42
|
-
def internal_template_source_dir
|
43
|
-
File.join(Mygen.root, "templates", generator_name)
|
44
|
-
end
|
45
|
-
|
46
|
-
def make_template_tree(internal = false)
|
47
|
-
@template_source_dir = internal_template_source_dir if internal
|
48
|
-
fileutils.rm_rf(dest_dir) if File.exist?(dest_dir)
|
49
|
-
fileutils.cp_r(template_source_dir, dest_dir)
|
50
|
-
end
|
51
|
-
|
52
|
-
# rename directories that should be filtered, from __name
|
53
|
-
# files should be from the destination, so no dirs needs to be filtered
|
54
|
-
# and only files need to be processed.
|
55
|
-
#
|
56
|
-
def parse_templates(bindings)
|
57
|
-
template_dirs(File.join(dest_dir)).each do |dir|
|
58
|
-
dest = file_destination(dir, bindings)
|
59
|
-
move_file_in_place(dir, dest)
|
60
|
-
end
|
61
|
-
# Filter files with erb
|
62
|
-
template_files(File.join(dest_dir)).each do |file|
|
63
|
-
dest = file_destination(file, bindings)
|
64
|
-
# This is where you parse the erb files and fill in the contens
|
65
|
-
if file.end_with? 'erb'
|
66
|
-
parse(file, bindings)
|
67
|
-
end
|
68
|
-
move_file_in_place(file, dest)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def parse(file, bindings)
|
73
|
-
erb = ERB.new(File.read(file))
|
74
|
-
result = erb.result bindings
|
75
|
-
File.open(file, "w") { |f| f.write(result) }
|
76
|
-
end
|
77
|
-
|
78
|
-
def move_file_in_place(src, dest)
|
79
|
-
sf = File.absolute_path(src)
|
80
|
-
df = File.absolute_path(dest)
|
81
|
-
fileutils.mv(sf, df) unless sf == df
|
82
|
-
end
|
83
|
-
|
84
|
-
def parse_and_place_file(file, dest, bindings)
|
85
|
-
erb = ERB.new(File.read(file))
|
86
|
-
erb.result bindings
|
87
|
-
end
|
88
|
-
|
89
|
-
def file_destination(file, bindings)
|
90
|
-
# subtract template_source_dir from path, add dest_dir and substitute filenames
|
91
|
-
new_file = file.gsub(template_source_dir, '')
|
92
|
-
replaced_filename(new_file, bindings)
|
93
|
-
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
def replaced_filename(file, bindings)
|
98
|
-
elements = File.basename(file).split('.')
|
99
|
-
elements.pop if elements.last == 'erb'
|
100
|
-
dirname = File.dirname(file)
|
101
|
-
f = elements.map do |element|
|
102
|
-
element.start_with?('__') ? eval( element.sub(/^__/, ''), bindings) : element
|
103
|
-
end.join('.')
|
104
|
-
File.join(dirname, f)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
1
|
+
module Mygen
|
2
|
+
class Generator
|
3
|
+
attr_accessor :name, :dest_dir, :dry_run, :template_source_dir
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@template_source_dir = File.join(ENV['HOME'], ".mygen", "plugins", generator_name, "templates")
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.descendants
|
10
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
11
|
+
end
|
12
|
+
|
13
|
+
def description
|
14
|
+
"Plugin has no description"
|
15
|
+
end
|
16
|
+
|
17
|
+
def generator_name
|
18
|
+
self.class.name.gsub(/::/, '/').
|
19
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
20
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
21
|
+
tr("-", "_").
|
22
|
+
split('/').last.
|
23
|
+
downcase
|
24
|
+
end
|
25
|
+
|
26
|
+
def fileutils
|
27
|
+
dry_run ? FileUtils::DryRun : FileUtils::Verbose
|
28
|
+
end
|
29
|
+
|
30
|
+
def template_files(path = template_source_dir)
|
31
|
+
Dir.glob(File.join(path, "**/*")).select { |f| File.file? f }
|
32
|
+
end
|
33
|
+
|
34
|
+
def template_dirs(path = template_source_dir)
|
35
|
+
Dir.glob(File.join(path, "**/*")).select { |f| File.directory? f }
|
36
|
+
end
|
37
|
+
|
38
|
+
def internal_template_files
|
39
|
+
template_files(internal_template_source_dir)
|
40
|
+
end
|
41
|
+
|
42
|
+
def internal_template_source_dir
|
43
|
+
File.join(Mygen.root, "templates", generator_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
def make_template_tree(internal = false)
|
47
|
+
@template_source_dir = internal_template_source_dir if internal
|
48
|
+
fileutils.rm_rf(dest_dir) if File.exist?(dest_dir)
|
49
|
+
fileutils.cp_r(template_source_dir, dest_dir)
|
50
|
+
end
|
51
|
+
|
52
|
+
# rename directories that should be filtered, from __name
|
53
|
+
# files should be from the destination, so no dirs needs to be filtered
|
54
|
+
# and only files need to be processed.
|
55
|
+
#
|
56
|
+
def parse_templates(bindings)
|
57
|
+
template_dirs(File.join(dest_dir)).each do |dir|
|
58
|
+
dest = file_destination(dir, bindings)
|
59
|
+
move_file_in_place(dir, dest)
|
60
|
+
end
|
61
|
+
# Filter files with erb
|
62
|
+
template_files(File.join(dest_dir)).each do |file|
|
63
|
+
dest = file_destination(file, bindings)
|
64
|
+
# This is where you parse the erb files and fill in the contens
|
65
|
+
if file.end_with? 'erb'
|
66
|
+
parse(file, bindings)
|
67
|
+
end
|
68
|
+
move_file_in_place(file, dest)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse(file, bindings)
|
73
|
+
erb = ERB.new(File.read(file))
|
74
|
+
result = erb.result bindings
|
75
|
+
File.open(file, "w") { |f| f.write(result) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def move_file_in_place(src, dest)
|
79
|
+
sf = File.absolute_path(src)
|
80
|
+
df = File.absolute_path(dest)
|
81
|
+
fileutils.mv(sf, df) unless sf == df
|
82
|
+
end
|
83
|
+
|
84
|
+
def parse_and_place_file(file, dest, bindings)
|
85
|
+
erb = ERB.new(File.read(file))
|
86
|
+
erb.result bindings
|
87
|
+
end
|
88
|
+
|
89
|
+
def file_destination(file, bindings)
|
90
|
+
# subtract template_source_dir from path, add dest_dir and substitute filenames
|
91
|
+
new_file = file.gsub(template_source_dir, '')
|
92
|
+
replaced_filename(new_file, bindings)
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def replaced_filename(file, bindings)
|
98
|
+
elements = File.basename(file).split('.')
|
99
|
+
elements.pop if elements.last == 'erb'
|
100
|
+
dirname = File.dirname(file)
|
101
|
+
f = elements.map do |element|
|
102
|
+
element.start_with?('__') ? eval( element.sub(/^__/, ''), bindings) : element
|
103
|
+
end.join('.')
|
104
|
+
File.join(dirname, f)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'mygen/generator'
|
2
|
-
module Mygen
|
3
|
-
module Plugins
|
4
|
-
class MygenGenerator < Mygen::Generator
|
5
|
-
def description
|
6
|
-
"Generates a new mygen generator"
|
7
|
-
end
|
8
|
-
|
9
|
-
def call
|
10
|
-
puts "create generator named #{name}"
|
11
|
-
make_template_tree(true)
|
12
|
-
@bleh = "fish"
|
13
|
-
@name = name
|
14
|
-
b = binding
|
15
|
-
parse_templates(b)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
1
|
+
require 'mygen/generator'
|
2
|
+
module Mygen
|
3
|
+
module Plugins
|
4
|
+
class MygenGenerator < Mygen::Generator
|
5
|
+
def description
|
6
|
+
"Generates a new mygen generator"
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
puts "create generator named #{name}"
|
11
|
+
make_template_tree(true)
|
12
|
+
@bleh = "fish"
|
13
|
+
@name = name
|
14
|
+
b = binding
|
15
|
+
parse_templates(b)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/mygen/plugins.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
module Mygen
|
2
|
-
#
|
3
|
-
# Load plugins from a dir (default to $HOME/.mygen/plugins)
|
4
|
-
# Add all subdirs to $LOAD_PATH, and get ancestors of the generator class
|
5
|
-
# And register them in the myg shell command
|
6
|
-
#
|
7
|
-
module Plugins
|
8
|
-
def self.load(path = File.join(ENV['HOME'], ".mygen", "plugins"))
|
9
|
-
dirs = Dir.glob(File.join(path, "**/*.rb"))
|
10
|
-
dirs.each do |d|
|
11
|
-
register_plugin(d)
|
12
|
-
end
|
13
|
-
Generator.descendants
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.register_plugin(plugin)
|
17
|
-
dir = File.dirname(plugin)
|
18
|
-
$LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
|
19
|
-
klass = File.basename(plugin, '.rb').downcase
|
20
|
-
require klass
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
1
|
+
module Mygen
|
2
|
+
#
|
3
|
+
# Load plugins from a dir (default to $HOME/.mygen/plugins)
|
4
|
+
# Add all subdirs to $LOAD_PATH, and get ancestors of the generator class
|
5
|
+
# And register them in the myg shell command
|
6
|
+
#
|
7
|
+
module Plugins
|
8
|
+
def self.load(path = File.join(ENV['HOME'], ".mygen", "plugins"))
|
9
|
+
dirs = Dir.glob(File.join(path, "**/*.rb"))
|
10
|
+
dirs.each do |d|
|
11
|
+
register_plugin(d)
|
12
|
+
end
|
13
|
+
Generator.descendants
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.register_plugin(plugin)
|
17
|
+
dir = File.dirname(plugin)
|
18
|
+
$LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
|
19
|
+
klass = File.basename(plugin, '.rb').downcase
|
20
|
+
require klass
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/mygen/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Mygen
|
2
|
-
VERSION = "0.2.
|
3
|
-
end
|
1
|
+
module Mygen
|
2
|
+
VERSION = "0.2.1"
|
3
|
+
end
|
data/lib/mygen.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require "mygen/version"
|
2
|
-
require "mygen/plugins"
|
3
|
-
require "mygen/plugins/mygen_generator"
|
4
|
-
require "mygen/generator"
|
5
|
-
require "erb"
|
6
|
-
|
7
|
-
module Mygen
|
8
|
-
def self.root
|
9
|
-
File.dirname __dir__
|
10
|
-
end
|
11
|
-
end
|
1
|
+
require "mygen/version"
|
2
|
+
require "mygen/plugins"
|
3
|
+
require "mygen/plugins/mygen_generator"
|
4
|
+
require "mygen/generator"
|
5
|
+
require "erb"
|
6
|
+
|
7
|
+
module Mygen
|
8
|
+
def self.root
|
9
|
+
File.dirname __dir__
|
10
|
+
end
|
11
|
+
end
|
data/mygen.gemspec
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'mygen/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "mygen"
|
8
|
-
spec.version = Mygen::VERSION
|
9
|
-
spec.authors = ["Kristian Rasmussen"]
|
10
|
-
spec.email = ["me@krx.io"]
|
11
|
-
|
12
|
-
spec.summary = %q{Code generator for generating project structures,
|
13
|
-
for various languages}
|
14
|
-
spec.description = %q{Code generator that helps you generating project
|
15
|
-
structures, filtering files. Plugable in a git like manner.}
|
16
|
-
spec.homepage = "https://github.com/iamkristian/mygen"
|
17
|
-
spec.license = "MIT"
|
18
|
-
|
19
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
20
|
-
# delete this section to allow pushing this gem to any host.
|
21
|
-
if spec.respond_to?(:metadata)
|
22
|
-
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
23
|
-
else
|
24
|
-
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
-
end
|
26
|
-
|
27
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
-
spec.bindir = "bin"
|
29
|
-
spec.executables = spec.files.grep(%r{^bin/myg}) { |f| File.basename(f) }
|
30
|
-
spec.require_paths = ["lib"]
|
31
|
-
|
32
|
-
spec.add_development_dependency "bundler", "~> 1.11"
|
33
|
-
spec.add_development_dependency "rspec", "~> 3.2"
|
34
|
-
spec.add_development_dependency "gli", "~> 2.13"
|
35
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
-
spec.add_development_dependency "pry", "~> 0.10"
|
37
|
-
spec.add_development_dependency "pry-byebug", "~> 3.3"
|
38
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mygen/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mygen"
|
8
|
+
spec.version = Mygen::VERSION
|
9
|
+
spec.authors = ["Kristian Rasmussen"]
|
10
|
+
spec.email = ["me@krx.io"]
|
11
|
+
|
12
|
+
spec.summary = %q{Code generator for generating project structures,
|
13
|
+
for various languages}
|
14
|
+
spec.description = %q{Code generator that helps you generating project
|
15
|
+
structures, filtering files. Plugable in a git like manner.}
|
16
|
+
spec.homepage = "https://github.com/iamkristian/mygen"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
20
|
+
# delete this section to allow pushing this gem to any host.
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
23
|
+
else
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
spec.bindir = "bin"
|
29
|
+
spec.executables = spec.files.grep(%r{^bin/myg}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
34
|
+
spec.add_development_dependency "gli", "~> 2.13"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
37
|
+
spec.add_development_dependency "pry-byebug", "~> 3.3"
|
38
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gem "mygen"
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem "mygen"
|
@@ -1,3 +1,3 @@
|
|
1
|
-
# <%= name %>
|
2
|
-
|
3
|
-
This describes the generator <%= name %>
|
1
|
+
# <%= name %>
|
2
|
+
|
3
|
+
This describes the generator <%= name %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mygen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristian Rasmussen
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.4.5
|
147
|
+
rubygems_version: 2.4.5
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: Code generator for generating project structures, for various languages
|