Skip to content

Commit c572f8f

Browse files
committed
Deprecate using Sinatra::ApexCharts extension
1 parent 8e7ff26 commit c572f8f

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ All notable changes to this project will be documented in this file.
1616
- Chart options set globally not showing as default options
1717
- Chart height options not overriden by default options
1818

19+
### Deprecated
20+
- Using Sinatra helper name `Sinatra::ApexCharts`. No need to call
21+
anything after requiring 'apexcharts' now.
22+
1923
## [0.2.0] - 2022-02-28
2024
### Added
2125
- Option to render chart with a script whose type is module

docs/web-support/sinatra.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
### Sinatra
22

3-
Require it after you `require 'sinatra/base'` and add helper `Sinatra::ApexCharts` in the
4-
class that inherits from `Sinatra::Base`.
3+
Require it after you `require 'sinatra/base'`.
54

65
```ruby
76
require 'sinatra/base'
87
require 'apexcharts'
9-
10-
class SimpleApp < Sinatra::Base
11-
helpers Sinatra::ApexCharts
12-
end
138
```
149

1510
To add the asset (ApexCharts.JS), include a script tag in your template

lib/apex_charts/support/sinatra.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
# frozen_string_literal: true
22

33
module Sinatra
4-
module ApexCharts
5-
include ::ApexCharts::Helper
4+
def self.const_missing(const_name)
5+
if const_name == :ApexCharts
6+
warn "[DEPRECATION] specifying `Sinatra::#{const_name}` as " \
7+
'helper is deprecated and will raise an error in next ' \
8+
'release. Requiring ApexCharts (`require "apexcharts"`) ' \
9+
'is enough to use its chart helper methods.'
10+
::ApexCharts::SinatraHelper
11+
else
12+
super
13+
end
614
end
15+
end
716

8-
helpers ApexCharts
17+
module ApexCharts
18+
module SinatraHelper
19+
include ::ApexCharts::Helper
20+
end
921
end
22+
23+
Sinatra::Base.helpers ApexCharts::SinatraHelper

0 commit comments

Comments
 (0)