diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2018-02-08 19:14:10 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2018-02-26 17:06:49 +0300 |
commit | b985fe95b6c30bc83725e9b5e18a79a8ceb900d3 (patch) | |
tree | 482f2903a5f3170c5e8c0f763456f4daaad4c2ea /lib/tasks/plugins.rake | |
parent | 9be0c2734ae3e3cc84196cf167a0c327c7cf8570 (diff) |
Add generator for plugins
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib/tasks/plugins.rake')
-rw-r--r-- | lib/tasks/plugins.rake | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/tasks/plugins.rake b/lib/tasks/plugins.rake new file mode 100644 index 00000000000..fac6070ea9b --- /dev/null +++ b/lib/tasks/plugins.rake @@ -0,0 +1,25 @@ +namespace :plugins do + desc 'Generate skeleton for new plugin' + task generate: :environment do + ARGV.each { |a| task a.to_sym { } } + name = ARGV[1] + + unless name.present? + puts 'Error. You need to specify a name for the plugin' + exit 1 + end + + class_name = name.classify + param = name.underscore + file_path = Rails.root.join('plugins', param + '_plugin.rb') + template = File.read(Rails.root.join('generator_templates', 'plugins', 'template.rb')) + template.gsub!('$NAME', class_name) + + if File.write(file_path, template) + puts "Done. Your plugin saved under #{file_path}." + puts 'Feel free to edit it.' + else + puts "Failed to save #{file_path}." + end + end +end |