Skip to content

Commit

Permalink
Rake task to add new adapter template
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakriti-nith committed Jul 24, 2018
1 parent 8d4f389 commit 008e73b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -19,7 +19,7 @@ Coveralls::RakeTask.new
import 'lib/tasks/high_charts.rake'
import 'lib/tasks/nyaplot.rake'
import 'lib/tasks/google_charts.rake'
import 'lib/tasks/new_adapter.rake'

# TODO: add Nyaplot
task :update_all => ["googlecharts:update", "highcharts:update"]

47 changes: 47 additions & 0 deletions lib/tasks/new_adapter.rake
@@ -0,0 +1,47 @@
def extract_adapter_template_code(file_name, template_code_str)
template_code_str << "module Daru"
template_code_str << "\n module View"
template_code_str << "\n module Adapter"
template_code_str << "\n module #{file_name.capitalize}Adapter"
template_code_str << "\n extend self # rubocop:disable Style/ModuleFunction"
template_code_str << "\n def init(data, options, _user_options={})"
template_code_str << "\n # TODO"
template_code_str << "\n end"
template_code_str << "\n"
template_code_str << "\n def export_html_file(plot, path='./plot.html')"
template_code_str << "\n # TODO"
template_code_str << "\n end"
template_code_str << "\n"
template_code_str << "\n def show_in_iruby(plot)"
template_code_str << "\n # TODO"
template_code_str << "\n end"
template_code_str << "\n"
template_code_str << "\n def init_script"
template_code_str << "\n # TODO"
template_code_str << "\n end"
template_code_str << "\n"
template_code_str << "\n def init_iruby"
template_code_str << "\n # TODO"
template_code_str << "\n end"
template_code_str << "\n end"
template_code_str << "\n end"
template_code_str << "\n end"
template_code_str << "\nend"
template_code_str << "\n"
end

namespace :new do
desc "Generate a sample template for the new adapter"
task :adapter do
print "Creating new adapter..."
ARGV.each { |a| task a.to_sym do ; end }
file_name = ARGV[1].to_s
path = File.expand_path(
'../daru/view/adapters/' + file_name + '.rb', __dir__
)
template_code_str = ''
extract_adapter_template_code(file_name, template_code_str)
File.write(path, template_code_str)
puts "Done."
end
end
9 changes: 9 additions & 0 deletions spec/new_adapter_spec.rb
@@ -0,0 +1,9 @@
require 'spec_helper'
require 'rake'

describe 'new:adapter' do
it "runs the task new:adapter" do
Rake.application.rake_require 'tasks/new_adapter'
expect { Rake::Task['new:adapter'].invoke }.not_to raise_exception
end
end

0 comments on commit 008e73b

Please sign in to comment.