Skip to content

user support for updating JS #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,26 @@ For now, other applications (Rails/Sinatra) you need to run it locally.

## Update to latest js library. Additional command line

### 1. Users

- To view command usage:

```
daru-view -h (or) --help
```

- To update JS files for google charts:
```
daru-view -g (or) --update-googlecharts
```

- To update JS files for highcharts:
```
daru-view -H (or) --update-highcharts
```

### 2. Developers

To update to the current highcharts.js directly from http://code.highcharts.com/", you can always run

rake highcharts:update
Expand Down
66 changes: 66 additions & 0 deletions bin/daru-view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env ruby

require 'optparse'
require 'rake'

path = File.expand_path('../lib/daru',__dir__)

parser = OptionParser.new do |opts|
opts.banner = "Usage: daru-view [options]"
# TODO add arguments to update only modules/adapters/a particular file

# Update google charts javascript dependent files, from latest Builds
# on the google developers website
opts.on('-g', '--update-googlecharts', 'Update googlecharts.js libraries') do
sh "mkdir -p #{path}/view/adapters/js/googlecharts_js/"

sh "curl -# http://www.google.com/jsapi -L --compressed -o #{path}/view/adapters/js/googlecharts_js/google_visualr.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must create folder and file if it is not present, right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will make that change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if file is also not present or deleted to update it ? touch can be useful here, right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this too. curl downloads the missing/deleted files. I have checked it by manually removing some js files. So it won't be a problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even I tried deleting the files. But it was throwing error. I hope you can write testcases for it. Please write in comment the TODO part as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the travis script to run the executable and added the TODO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length can be reduced,right ?

sh "curl -# http://www.gstatic.com/charts/loader.js -L --compressed -o #{path}/view/adapters/js/googlecharts_js/loader.js"
end

# Update highcharts.js from latest Builds on Highcharts codebase
# http://code.highcharts.com/
opts.on('-H', '--update-highcharts', 'Update highcharts.js libraries') do
sh "mkdir -p #{path}/view/adapters/js/highcharts_js/modules/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must have modularity , to update just modules or just adapters or just particular file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a doubt, why will someone using daru-view care about updating adapters and modules separately or a specific file? I think it is a different issue of having updates in a granular manner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, if someone wants to use new features added in highcharts3d then user may just want to update the file highcharts-3d.js . Let me know if it is little tricky task. We will add it as TODO task .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be better to add it as a TODO task in #47 as it will require a bit of restructuring. This PR will make it easy to atleast update the JS files for now. ☺️

sh "mkdir -p #{path}/view/adapters/js/highcharts_js/adapters/"

sh "curl -# http://code.highcharts.com/highcharts.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/highcharts.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we make them in a loop ?

sh "curl -# http://code.highcharts.com/highcharts-more.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/highcharts-more.js"
sh "curl -# http://code.highcharts.com/highcharts-3d.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/highcharts-3d.js"

# Modules
sh "curl -# http://code.highcharts.com/modules/accessibility.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/accessibility.js"
sh "curl -# http://code.highcharts.com/modules/annotations.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/annotations.js"
sh "curl -# http://code.highcharts.com/modules/boost.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/boost.js"
sh "curl -# http://code.highcharts.com/modules/broken-axis.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/broken-axis.js"
sh "curl -# http://code.highcharts.com/modules/canvas-tools.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/canvas-tools.js"
sh "curl -# http://code.highcharts.com/modules/data.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/data.js"
sh "curl -# http://code.highcharts.com/modules/exporting.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/exporting.js"
sh "curl -# http://code.highcharts.com/modules/drilldown.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/drilldown.js"
sh "curl -# http://code.highcharts.com/modules/funnel.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/funnel.js"
sh "curl -# http://code.highcharts.com/modules/heatmap.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/heatmap.js"
sh "curl -# http://code.highcharts.com/modules/no-data-to-display.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/no-data-to-display.js"
sh "curl -# http://code.highcharts.com/modules/offline-exporting.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/offline-exporting.js"
sh "curl -# http://code.highcharts.com/modules/solid-gauge.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/solid-gauge.js"
sh "curl -# http://code.highcharts.com/modules/treemap.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/modules/treemap.js"

sh "curl -# http://code.highcharts.com/adapters/mootools-adapter.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/adapters/mootools-adapter.js"
sh "curl -# http://code.highcharts.com/adapters/prototype-adapter.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/adapters/prototype-adapter.js"
sh "mkdir -p #{path}/view/adapters/js/highcharts_js/stock/modules/"
sh "mkdir -p #{path}/view/adapters/js/highcharts_js/stock/adapters/"

sh "curl -# http://code.highcharts.com/stock/highstock.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/highstock.js"
sh "curl -# http://code.highcharts.com/stock/highcharts-more.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/stock/highcharts-more.js"
sh "curl -# http://code.highcharts.com/stock/modules/exporting.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/stock/modules/exporting.js"
sh "curl -# http://code.highcharts.com/stock/modules/funnel.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/stock/modules/funnel.js"
sh "curl -# http://code.highcharts.com/stock/adapters/mootools-adapter.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/stock/adapters/mootools-adapter.js"
sh "curl -# http://code.highcharts.com/stock/adapters/prototype-adapter.js -L --compressed -o #{path}/view/adapters/js/highcharts_js/stock/adapters/prototype-adapter.js"
end

opts.on('-h', '--help', 'Displays Help') do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How it will handle if invalid option is given?

puts opts
exit
end
end

parser.parse!
4 changes: 2 additions & 2 deletions daru-view.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8

lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)

$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand All @@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']
spec.files = `git ls-files -z`.split("\x0")
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.executables = ['daru-view']

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rspec'
Expand All @@ -49,4 +50,3 @@ Gem::Specification.new do |spec|
# build gem and release it on rubygems
spec.add_development_dependency 'rubygems-tasks'
end

3 changes: 1 addition & 2 deletions lib/daru/view/adapters/googlecharts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def show_in_iruby(plot)
end

def generate_html(plot)
# TODO: modify code
path = File.expand_path('../../templates/googlecharts/chart_div.erb', __FILE__)
path = File.expand_path('../templates/googlecharts/static_html.erb', __dir__)
template = File.read(path)
initial_script = init_script
chart_script = generate_body(plots)
Expand Down
2 changes: 1 addition & 1 deletion lib/daru/view/adapters/googlecharts/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def show_script(dom=SecureRandom.uuid, options={})
end

def to_html(id=nil, options={})
path = File.expand_path('../../../templates/googlecharts/chart_div.erb', __FILE__)
path = File.expand_path('../../templates/googlecharts/chart_div.erb', __dir__)
template = File.read(path)
id ||= SecureRandom.uuid
chart_script = show_script(id, script_tag: false)
Expand Down
4 changes: 2 additions & 2 deletions lib/daru/view/adapters/googlecharts/iruby_notebook.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module GoogleVisualr
# generate initializing code
def self.generate_init_code(dependent_js)
js_dir = File.expand_path('../../js/googlecharts_js', __FILE__)
path = File.expand_path('../../../templates/googlecharts/init.inline.js.erb', __FILE__)
js_dir = File.expand_path('../js/googlecharts_js', __dir__)
path = File.expand_path('../../templates/googlecharts/init.inline.js.erb', __dir__)
template = File.read(path)
ERB.new(template).result(binding)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/daru/view/adapters/highcharts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def show_in_iruby(plot)
end

def generate_html(plot)
path = File.expand_path('../../templates/highcharts/static_html.erb', __FILE__)
path = File.expand_path('../templates/highcharts/static_html.erb', __dir__)
template = File.read(path)
initial_script = init_script
chart_div = generate_body(plots)
Expand Down
4 changes: 2 additions & 2 deletions lib/daru/view/adapters/highcharts/iruby_notebook.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module LazyHighCharts
# generate initializing code
def self.generate_init_code(dependent_js)
js_dir = File.expand_path('../../js/highcharts_js', __FILE__)
path = File.expand_path('../../../templates/highcharts/init.inline.js.erb', __FILE__)
js_dir = File.expand_path('../js/highcharts_js', __dir__)
path = File.expand_path('../../templates/highcharts/init.inline.js.erb', __dir__)
template = File.read(path)
ERB.new(template).result(binding)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/daru/view/adapters/nyaplot/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Nyaplot
# dependent JS to include in head tag of the web application
def self.init_script
init = Nyaplot.generate_init_code
path = File.expand_path('../../../templates/nyaplot/init_script.erb', __FILE__)
path = File.expand_path('../../templates/nyaplot/init_script.erb', __dir__)
template = File.read(path)
ERB.new(template).result(binding)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/daru/view/adapters/nyaplot/iruby_notebook.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Nyaplot
# generate initializing code
def self.generate_init_code_offline(dependent_js)
js_dir = File.expand_path('../../js/nyaplot_js', __FILE__)
path = File.expand_path('../../../templates/nyaplot/init.inline.js.erb', __FILE__)
js_dir = File.expand_path('../js/nyaplot_js', __dir__)
path = File.expand_path('../../templates/nyaplot/init.inline.js.erb', __dir__)
template = File.read(path)
ERB.new(template).result(binding)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# Configure Rails Environment
# these lines are needed when spec/dummy_rails will be created
# ENV["RAILS_ENV"] = "test"
# require File.expand_path("../dummy_rails/config/environment.rb", __FILE__)
# require File.expand_path("dummy_rails/config/environment.rb", __dir__)

SimpleCov.start
22 changes: 22 additions & 0 deletions spec/update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe Daru::View, "Update JS files" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the tab indent to 2 spaces. 😄

context "command usage" do
it "shows the command usage description" do
flag = system('daru-view -h')
expect(flag).to eq(true)
end
end

context "googlecharts" do
it "updates google charts javascript dependent files" do
flag = system('daru-view -g')
expect(flag).to eq(true)
end
end

context "highcharts" do
it "updates high charts javascript dependent files" do
flag = system('daru-view -H')
expect(flag).to eq(true)
end
end
end