Skip to content

Commit 6c69e2e

Browse files
committed
rake task to add new adapter template
1 parent 8d4f389 commit 6c69e2e

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Coveralls::RakeTask.new
1919
import 'lib/tasks/high_charts.rake'
2020
import 'lib/tasks/nyaplot.rake'
2121
import 'lib/tasks/google_charts.rake'
22+
import 'lib/tasks/new_adapter.rake'
2223

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

lib/tasks/new_adapter.rake

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
def extract_adapter_template_code(file_name, template_code_str)
2+
template_code_str << "module Daru"
3+
template_code_str << "\n module View"
4+
template_code_str << "\n module Adapter"
5+
template_code_str << "\n module #{file_name.capitalize}Adapter"
6+
template_code_str << "\n extend self # rubocop:disable Style/ModuleFunction"
7+
template_code_str << "\n def init(data, options, _user_options={})"
8+
template_code_str << "\n # TODO"
9+
template_code_str << "\n end"
10+
template_code_str << "\n"
11+
template_code_str << "\n def export_html_file(plot, path='./plot.html')"
12+
template_code_str << "\n # TODO"
13+
template_code_str << "\n end"
14+
template_code_str << "\n"
15+
template_code_str << "\n def show_in_iruby(plot)"
16+
template_code_str << "\n # TODO"
17+
template_code_str << "\n end"
18+
template_code_str << "\n"
19+
template_code_str << "\n def init_script"
20+
template_code_str << "\n # TODO"
21+
template_code_str << "\n end"
22+
template_code_str << "\n"
23+
template_code_str << "\n def init_iruby"
24+
template_code_str << "\n # TODO"
25+
template_code_str << "\n end"
26+
template_code_str << "\n end"
27+
template_code_str << "\n end"
28+
template_code_str << "\n end"
29+
template_code_str << "\nend"
30+
template_code_str << "\n"
31+
end
32+
33+
namespace :new do
34+
desc "Generate a sample template for the new adapter"
35+
task :adapter do
36+
print "Creating new adapter..."
37+
ARGV.each { |a| task a.to_sym do ; end }
38+
file_name = ARGV[1].to_s
39+
path = File.expand_path(
40+
'../daru/view/adapters/' + file_name + '.rb', __dir__
41+
)
42+
template_code_str = ''
43+
extract_adapter_template_code(file_name, template_code_str)
44+
File.write(path, template_code_str)
45+
puts "Done."
46+
end
47+
end

spec/new_adapter_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'spec_helper'
2+
require 'rake'
3+
4+
describe 'new:adapter' do
5+
it "runs the task new:adapter" do
6+
Rake.application.rake_require 'tasks/new_adapter'
7+
expect { Rake::Task['new:adapter'].invoke }.not_to raise_exception
8+
end
9+
end

0 commit comments

Comments
 (0)