pageflow-chart 2.1.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +12 -8
- data/README.md +2 -2
- data/app/assets/javascripts/pageflow/chart/consent.js +16 -0
- data/app/assets/javascripts/pageflow/chart/editor/config.js +7 -0
- data/app/assets/javascripts/pageflow/chart/editor/models/scraped_site.js +11 -50
- data/app/assets/javascripts/pageflow/chart/editor/views/configuration_editor.js +6 -4
- data/app/assets/javascripts/pageflow/chart/editor/views/embedded/iframe_embedded_view.js +32 -16
- data/app/assets/javascripts/pageflow/chart/editor/views/inputs/scraped_url_input_view.js +18 -39
- data/app/assets/javascripts/pageflow/chart/editor.js +4 -3
- data/app/assets/javascripts/pageflow/chart/page_type.js +61 -53
- data/app/assets/javascripts/pageflow/chart.js +2 -3
- data/app/assets/stylesheets/pageflow/chart/editor.scss +3 -20
- data/app/assets/stylesheets/pageflow/chart/themes/default.scss +3 -0
- data/app/assets/stylesheets/pageflow/chart.scss +9 -16
- data/app/helpers/pageflow/chart/scraped_sites_helper.rb +17 -8
- data/app/jobs/pageflow/chart/scrape_site_job.rb +14 -4
- data/app/models/pageflow/chart/scraped_site.rb +37 -4
- data/app/views/pageflow/chart/editor/scraped_sites/_scraped_site.json.jbuilder +1 -0
- data/app/views/pageflow/chart/page.html.erb +9 -2
- data/chart.gemspec +2 -2
- data/config/locales/de.yml +4 -0
- data/config/locales/en.yml +4 -0
- data/db/migrate/20190531141820_add_file_attributes_to_scraped_sites.rb +8 -0
- data/db/migrate/20190531145431_insert_file_usages_for_scraped_sites.rb +59 -0
- data/db/migrate/20200507141608_add_javascript_body_attachment_to_scraped_site.rb +5 -0
- data/lib/pageflow/chart/configuration.rb +6 -3
- data/lib/pageflow/chart/downloader.rb +4 -1
- data/lib/pageflow/chart/page_type.rb +17 -0
- data/lib/pageflow/chart/plugin.rb +10 -0
- data/lib/pageflow/chart/refresh_tag_following_downloader.rb +3 -3
- data/lib/pageflow/chart/scraper.rb +25 -13
- data/lib/pageflow/chart/version.rb +1 -1
- data/lib/pageflow/chart.rb +4 -0
- data/spec/factories/scraped_sites.rb +17 -3
- data/spec/fixtures/all.css +3 -0
- data/spec/fixtures/all.js +1 -0
- data/spec/fixtures/all_body.js +1 -0
- data/spec/fixtures/data.csv +1 -0
- data/spec/fixtures/index.html +7 -0
- data/spec/helpers/pageflow/chart/scraped_sites_helper_spec.rb +59 -0
- data/spec/integration/file_type_spec.rb +10 -0
- data/spec/jobs/pageflow/chart/scrape_site_job_spec.rb +14 -1
- data/spec/models/pageflow/chart/scraped_site_spec.rb +54 -0
- data/spec/pageflow/chart/downloader_spec.rb +13 -3
- data/spec/pageflow/chart/refresh_tag_following_downloader_spec.rb +23 -10
- data/spec/pageflow/chart/scraper_spec.rb +201 -63
- metadata +28 -20
- data/app/assets/javascripts/pageflow/chart/editor/collections/scraped_sites_collection.js +0 -23
- data/app/assets/javascripts/pageflow/chart/editor/initializers/setup_collections.js +0 -1
- data/app/assets/javascripts/pageflow/chart/editor/templates/scraped_site_status.jst.ejs +0 -2
- data/app/assets/javascripts/pageflow/chart/editor/templates/url_input.jst.ejs +0 -7
- data/app/assets/javascripts/pageflow/chart/editor/views/scraped_site_status_view.js +0 -18
- data/app/controllers/pageflow/chart/application_controller.rb +0 -6
- data/app/controllers/pageflow/chart/scraped_sites_controller.rb +0 -25
- data/config/routes.rb +0 -3
- data/spec/controllers/pageflow/chart/scraped_sites_controller_spec.rb +0 -35
- data/spec/requests/scraping_site_spec.rb +0 -23
@@ -8,7 +8,8 @@ module Pageflow
|
|
8
8
|
def perform_with_result(scraped_site,
|
9
9
|
_options = {},
|
10
10
|
downloader: downloader_for(scraped_site))
|
11
|
-
downloader.load_following_refresh_tags(scraped_site.url
|
11
|
+
downloader.load_following_refresh_tags(scraped_site.url,
|
12
|
+
raise_on_http_error: true) do |file|
|
12
13
|
scraper = Scraper.new(file.read, Chart.config.scraper_options)
|
13
14
|
scraped_site.html_file = StringIOWithContentType.new(
|
14
15
|
scraper.html,
|
@@ -16,11 +17,18 @@ module Pageflow
|
|
16
17
|
content_type: 'text/html'
|
17
18
|
)
|
18
19
|
|
19
|
-
downloader.load_all(scraper.
|
20
|
+
downloader.load_all(scraper.javascript_urls_in_head,
|
20
21
|
extension: '.js',
|
21
22
|
before_each: begin_try_catch,
|
22
|
-
after_each: end_try_catch) do |
|
23
|
-
scraped_site.javascript_file =
|
23
|
+
after_each: end_try_catch) do |javascript_head_file|
|
24
|
+
scraped_site.javascript_file = javascript_head_file
|
25
|
+
end
|
26
|
+
|
27
|
+
downloader.load_all(scraper.javascript_urls_in_body,
|
28
|
+
extension: '.js',
|
29
|
+
before_each: begin_try_catch,
|
30
|
+
after_each: end_try_catch) do |javascript_body_file|
|
31
|
+
scraped_site.javascript_body_file = javascript_body_file
|
24
32
|
end
|
25
33
|
|
26
34
|
downloader.load_all(scraper.stylesheet_urls,
|
@@ -35,6 +43,8 @@ module Pageflow
|
|
35
43
|
end
|
36
44
|
|
37
45
|
:ok
|
46
|
+
rescue Downloader::HTTPError
|
47
|
+
:error
|
38
48
|
end
|
39
49
|
|
40
50
|
private
|
@@ -1,12 +1,16 @@
|
|
1
1
|
module Pageflow
|
2
2
|
module Chart
|
3
3
|
class ScrapedSite < ActiveRecord::Base
|
4
|
+
include Pageflow::ReusableFile
|
5
|
+
|
4
6
|
has_attached_file :javascript_file, Chart.config.paperclip_options(extension: 'js')
|
7
|
+
has_attached_file :javascript_body_file, Chart.config.paperclip_options(basename: 'all_body', extension: 'js')
|
5
8
|
has_attached_file :stylesheet_file, Chart.config.paperclip_options(extension: 'css')
|
6
9
|
has_attached_file :html_file, Chart.config.paperclip_options(extension: 'html')
|
7
10
|
has_attached_file :csv_file, Chart.config.paperclip_options(basename: 'data', extension: 'csv')
|
8
11
|
|
9
12
|
do_not_validate_attachment_file_type(:javascript_file)
|
13
|
+
do_not_validate_attachment_file_type(:javascript_body_file)
|
10
14
|
do_not_validate_attachment_file_type(:stylesheet_file)
|
11
15
|
do_not_validate_attachment_file_type(:html_file)
|
12
16
|
do_not_validate_attachment_file_type(:csv_file)
|
@@ -23,6 +27,10 @@ module Pageflow
|
|
23
27
|
transition 'unprocessed' => 'processing'
|
24
28
|
end
|
25
29
|
|
30
|
+
event :skip_reprocessing_imported_site do
|
31
|
+
transition 'unprocessed' => 'processed'
|
32
|
+
end
|
33
|
+
|
26
34
|
event :reprocess do
|
27
35
|
transition 'processed' => 'processing'
|
28
36
|
transition 'processing_failed' => 'processing'
|
@@ -44,10 +52,6 @@ module Pageflow
|
|
44
52
|
URI.join(url, 'data.csv').to_s
|
45
53
|
end
|
46
54
|
|
47
|
-
def as_json(*)
|
48
|
-
super.merge(html_file_url: html_file_url)
|
49
|
-
end
|
50
|
-
|
51
55
|
def html_file_url
|
52
56
|
return unless html_file.try(:path)
|
53
57
|
if Chart.config.scraped_sites_root_url.present?
|
@@ -56,6 +60,35 @@ module Pageflow
|
|
56
60
|
html_file.url
|
57
61
|
end
|
58
62
|
end
|
63
|
+
|
64
|
+
# ReusableFile-overrides:
|
65
|
+
def url
|
66
|
+
read_attribute(:url)
|
67
|
+
end
|
68
|
+
|
69
|
+
def retryable?
|
70
|
+
processing_failed?
|
71
|
+
end
|
72
|
+
|
73
|
+
def ready?
|
74
|
+
processed?
|
75
|
+
end
|
76
|
+
|
77
|
+
def publish!
|
78
|
+
if html_file.present?
|
79
|
+
skip_reprocessing_imported_site!
|
80
|
+
else
|
81
|
+
process!
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def retry!
|
86
|
+
reprocess!
|
87
|
+
end
|
88
|
+
|
89
|
+
def attachments_for_export
|
90
|
+
[javascript_file, javascript_body_file, stylesheet_file, html_file, csv_file]
|
91
|
+
end
|
59
92
|
end
|
60
93
|
end
|
61
94
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
json.call(scraped_site, :url, :html_file_url, :use_custom_theme)
|
@@ -7,9 +7,16 @@
|
|
7
7
|
|
8
8
|
<div class="content">
|
9
9
|
<div class="iframeWrapper">
|
10
|
-
<%= scraped_site_iframe(configuration
|
11
|
-
|
10
|
+
<%= scraped_site_iframe(configuration) %>
|
11
|
+
<%= third_party_embed_opt_in(
|
12
|
+
entry: entry,
|
13
|
+
vendor_name: 'datawrapper',
|
14
|
+
message: t('pageflow.public.chart.opt_in_prompt')
|
15
|
+
) %>
|
12
16
|
<div class="bigscreen_toggler" tabindex="4" title="<%= t('pageflow.public.chart.toggle') %>"><%= t('pageflow.public.chart.toggle') %></div>
|
17
|
+
<div class="opt_out_wrapper">
|
18
|
+
<%= third_party_embed_opt_out_info(entry) %>
|
19
|
+
</div>
|
13
20
|
</div>
|
14
21
|
<div class="scroller">
|
15
22
|
<div>
|
data/chart.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.required_ruby_version = '~> 2.1'
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'pageflow', '~>
|
21
|
+
spec.add_runtime_dependency 'pageflow', '~> 15.7.x'
|
22
22
|
spec.add_runtime_dependency 'nokogiri', '~> 1.0'
|
23
23
|
spec.add_runtime_dependency 'pageflow-public-i18n', '~> 1.0'
|
24
24
|
|
25
|
-
spec.add_development_dependency 'pageflow-support', '~>
|
25
|
+
spec.add_development_dependency 'pageflow-support', '~> 15.x'
|
26
26
|
spec.add_development_dependency 'bundler', ['>= 1.0', '< 3']
|
27
27
|
spec.add_development_dependency 'rake', '~> 12.0'
|
28
28
|
spec.add_development_dependency 'rspec-rails', '~> 3.0'
|
data/config/locales/de.yml
CHANGED
@@ -31,6 +31,8 @@ de:
|
|
31
31
|
|
32
32
|
Typische Anwendungsbeispiele: Statistiken, Diagramme, Zahlen&Fakten
|
33
33
|
page_attributes:
|
34
|
+
chart_url:
|
35
|
+
label: Diagramm URL
|
34
36
|
full_width:
|
35
37
|
inline_help: Verbreitert das Diagramm, so dass es die maximal verfügbare Breite nutzt.
|
36
38
|
label: Gesamte Breite nutzen
|
@@ -39,3 +41,5 @@ de:
|
|
39
41
|
page_type_category_name: Daten und Diagramme
|
40
42
|
page_type_description: Einbindung von Diagrammen, die mit Datawrapper erstellt wurden
|
41
43
|
page_type_name: Diagramm
|
44
|
+
chart_embed_opt_in:
|
45
|
+
feature_name: Opt-In für Datawrapper Embeds
|
data/config/locales/en.yml
CHANGED
@@ -17,6 +17,8 @@ en:
|
|
17
17
|
menu_item: Chart
|
18
18
|
text: "# Chart\n\nIntegration of a Datawrapper-Diagram\n\nHere you can add animated infographics to your Pageflow. The diagram is embedded into a background-picture/video and text. To enlarge the graphic you simply have to click on it. \n\nBut first of all you have to create your graphic externally and generate a link. You can find examples and requirements for this under www.datawrapper.de.\n\nNote that Datawrapper offers a special layout option for charts that shall be embedded into a Pageflow: In the \"Visualize\" step of the chart creation wizard, click the \"Design\" tab and select the \"Pageflow\" layout. That way a color scheme is used which complements Pageflow's look.\n\nExamples of application: statistics, diagrams, numbers & facts"
|
19
19
|
page_attributes:
|
20
|
+
chart_url:
|
21
|
+
label: Chart URL
|
20
22
|
full_width:
|
21
23
|
inline_help: Extends the chart to use the maximum width available.
|
22
24
|
label: Use full width
|
@@ -25,3 +27,5 @@ en:
|
|
25
27
|
page_type_category_name: Data and Charts
|
26
28
|
page_type_description: Embedded Datawrapper chart
|
27
29
|
page_type_name: Chart
|
30
|
+
chart_embed_opt_in:
|
31
|
+
feature_name: Opt-in for Datawrapper embeds
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class AddFileAttributesToScrapedSites < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
add_reference :pageflow_chart_scraped_sites, :entry, index: true
|
4
|
+
add_column :pageflow_chart_scraped_sites, :rights, :string
|
5
|
+
add_column :pageflow_chart_scraped_sites, :parent_file_id, :integer
|
6
|
+
add_column :pageflow_chart_scraped_sites, :parent_file_model_type, :string
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class InsertFileUsagesForScrapedSites < ActiveRecord::Migration[5.2]
|
2
|
+
# Pageflow models might have gotten out of sync with schema at this
|
3
|
+
# point. Use local models instead.
|
4
|
+
class MigratedPage < ActiveRecord::Base
|
5
|
+
self.table_name = 'pageflow_pages'
|
6
|
+
|
7
|
+
belongs_to :chapter, class_name: 'MigratedChapter'
|
8
|
+
|
9
|
+
serialize :configuration, JSON
|
10
|
+
|
11
|
+
def configuration
|
12
|
+
super || {}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MigratedChapter < ActiveRecord::Base
|
17
|
+
self.table_name = 'pageflow_chapters'
|
18
|
+
belongs_to :storyline, class_name: 'MigratedStoryline'
|
19
|
+
end
|
20
|
+
|
21
|
+
class MigratedStoryline < ActiveRecord::Base
|
22
|
+
self.table_name = 'pageflow_storylines'
|
23
|
+
end
|
24
|
+
|
25
|
+
class MigratedFileUsage < ActiveRecord::Base
|
26
|
+
self.table_name = 'pageflow_file_usages'
|
27
|
+
end
|
28
|
+
|
29
|
+
def up
|
30
|
+
MigratedPage.where(template: 'chart').find_each do |page|
|
31
|
+
scraped_site_id = page.configuration['scraped_site_id']
|
32
|
+
next unless scraped_site_id
|
33
|
+
|
34
|
+
scraped_site = Pageflow::Chart::ScrapedSite.find_by_id(scraped_site_id)
|
35
|
+
|
36
|
+
unless scraped_site
|
37
|
+
puts "Scraped site #{scraped_site_id} not found"
|
38
|
+
next
|
39
|
+
end
|
40
|
+
|
41
|
+
revision_id = page&.chapter&.storyline&.revision_id
|
42
|
+
|
43
|
+
unless revision_id
|
44
|
+
puts "No revision_id for page #{page.id}"
|
45
|
+
next
|
46
|
+
end
|
47
|
+
|
48
|
+
MigratedFileUsage.create(file_id: scraped_site.id,
|
49
|
+
file_type: 'Pageflow::Chart::ScrapedSite',
|
50
|
+
revision_id: revision_id)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def down
|
55
|
+
MigratedFileUsage
|
56
|
+
.where(file_type: 'Pageflow::Chart::ScrapedSite')
|
57
|
+
.delete_all
|
58
|
+
end
|
59
|
+
end
|
@@ -22,6 +22,7 @@ module Pageflow
|
|
22
22
|
#
|
23
23
|
# @param [Hash] opts
|
24
24
|
# @option opts [Array<Regexp>] :head_script_blacklist Script tags in page head are ignored if they match any of this list of regexes.
|
25
|
+
# @option opts [Array<Regexp>] :body_script_blacklist Script tags in page body are ignored if they match any of this list of regexes.
|
25
26
|
# @option opts [Array<Regexp>] :inline_script_blacklist Inline script tags are ignored if they match any of this list of regexes.
|
26
27
|
# @option opts [Array<String>] :selector_blacklist HTML-elements matched by selectors in this list will not be scraped.
|
27
28
|
# @return [Hash]
|
@@ -55,6 +56,7 @@ module Pageflow
|
|
55
56
|
def initialize
|
56
57
|
@scraper_options = {
|
57
58
|
head_script_blacklist: [/piwik/],
|
59
|
+
body_script_blacklist: [/piwik/],
|
58
60
|
inline_script_blacklist: [/piwik/],
|
59
61
|
selector_blacklist: ['body .noscript']
|
60
62
|
}
|
@@ -62,9 +64,10 @@ module Pageflow
|
|
62
64
|
@paperclip_base_path = ':pageflow_s3_root'
|
63
65
|
@scraped_sites_root_url = nil
|
64
66
|
@supported_hosts = [
|
65
|
-
'
|
66
|
-
'
|
67
|
-
'
|
67
|
+
'cf.datawrapper.de',
|
68
|
+
'charts.datawrapper.de',
|
69
|
+
'datawrapper.dwcdn.de',
|
70
|
+
'datawrapper.dwcdn.net'
|
68
71
|
]
|
69
72
|
@use_custom_theme = false
|
70
73
|
@datawrapper_themes_with_transparent_background_support = ['pageflow']
|
@@ -6,15 +6,18 @@ module Pageflow
|
|
6
6
|
class Downloader
|
7
7
|
attr_reader :options
|
8
8
|
|
9
|
+
class HTTPError < StandardError; end
|
10
|
+
|
9
11
|
def initialize(options = {})
|
10
12
|
@options = options
|
11
13
|
end
|
12
14
|
|
13
|
-
def load(url)
|
15
|
+
def load(url, raise_on_http_error: false)
|
14
16
|
file = open(make_absolute(url))
|
15
17
|
yield(file)
|
16
18
|
rescue OpenURI::HTTPError => exception
|
17
19
|
Rails.logger.error "Exception loading url #{url}: #{exception.message}"
|
20
|
+
raise(HTTPError) if raise_on_http_error
|
18
21
|
ensure
|
19
22
|
file.close if file
|
20
23
|
end
|
@@ -10,6 +10,23 @@ module Pageflow
|
|
10
10
|
def json_seed_template
|
11
11
|
'pageflow/chart/page_type.json.jbuilder'
|
12
12
|
end
|
13
|
+
|
14
|
+
def file_types
|
15
|
+
[Chart.scraped_site_file_type]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.scraped_site_file_type
|
20
|
+
FileType.new(model: ScrapedSite,
|
21
|
+
editor_partial: 'pageflow/chart/editor/scraped_sites/scraped_site',
|
22
|
+
custom_attributes: {
|
23
|
+
url: {
|
24
|
+
permitted_create_param: true
|
25
|
+
},
|
26
|
+
use_custom_theme: {
|
27
|
+
permitted_create_param: false
|
28
|
+
}
|
29
|
+
})
|
13
30
|
end
|
14
31
|
end
|
15
32
|
end
|
@@ -9,15 +9,15 @@ module Pageflow
|
|
9
9
|
class TooManyRedirects < StandardError; end
|
10
10
|
class NoUrlInRefreshMetaTag < StandardError; end
|
11
11
|
|
12
|
-
def load_following_refresh_tags(url, redirect_count = 0, &block)
|
13
|
-
load(url) do |file|
|
12
|
+
def load_following_refresh_tags(url, options = {}, redirect_count = 0, &block)
|
13
|
+
load(url, options) do |file|
|
14
14
|
if (redirect_url = find_refresh_meta_tag_url(file.read))
|
15
15
|
if redirect_count >= MAX_REDIRECT_COUNT
|
16
16
|
raise TooManyRedirects, 'Too many redirects via refresh meta tags.'
|
17
17
|
end
|
18
18
|
|
19
19
|
redirect_url = ensure_absolute(redirect_url, url)
|
20
|
-
return load_following_refresh_tags(redirect_url, redirect_count + 1, &block)
|
20
|
+
return load_following_refresh_tags(redirect_url, options, redirect_count + 1, &block)
|
21
21
|
end
|
22
22
|
|
23
23
|
file.rewind
|
@@ -3,7 +3,11 @@ require 'nokogiri'
|
|
3
3
|
module Pageflow
|
4
4
|
module Chart
|
5
5
|
class Scraper
|
6
|
-
attr_reader :document,
|
6
|
+
attr_reader :document,
|
7
|
+
:options,
|
8
|
+
:javascript_urls_in_head,
|
9
|
+
:javascript_urls_in_body,
|
10
|
+
:stylesheet_urls
|
7
11
|
|
8
12
|
def initialize(html, options = {})
|
9
13
|
@document = Nokogiri::HTML(html)
|
@@ -23,14 +27,21 @@ module Pageflow
|
|
23
27
|
private
|
24
28
|
|
25
29
|
def parse
|
26
|
-
parse_javascript_urls
|
30
|
+
parse_javascript_urls(:head)
|
31
|
+
parse_javascript_urls(:body)
|
27
32
|
parse_stylesheet_urls
|
28
33
|
end
|
29
34
|
|
30
|
-
def parse_javascript_urls
|
31
|
-
|
35
|
+
def parse_javascript_urls(container)
|
36
|
+
script_tags = filtered_script_tags_in(container).map do |tag|
|
32
37
|
tag[:src]
|
33
38
|
end
|
39
|
+
|
40
|
+
if container.eql?(:head)
|
41
|
+
@javascript_urls_in_head = script_tags
|
42
|
+
else
|
43
|
+
@javascript_urls_in_body = script_tags
|
44
|
+
end
|
34
45
|
end
|
35
46
|
|
36
47
|
def parse_stylesheet_urls
|
@@ -42,7 +53,8 @@ module Pageflow
|
|
42
53
|
def rewrite
|
43
54
|
filter_inline_scripts
|
44
55
|
filter_by_selectors
|
45
|
-
|
56
|
+
combine_script_tags_in(:head)
|
57
|
+
combine_script_tags_in(:body)
|
46
58
|
combine_css_link_tags
|
47
59
|
end
|
48
60
|
|
@@ -66,12 +78,12 @@ module Pageflow
|
|
66
78
|
end
|
67
79
|
end
|
68
80
|
|
69
|
-
def
|
70
|
-
script_tags_to_remove =
|
81
|
+
def combine_script_tags_in(container)
|
82
|
+
script_tags_to_remove = script_src_tags_in(container)
|
71
83
|
return if script_tags_to_remove.empty?
|
72
84
|
|
73
85
|
all_script_src_tag = Nokogiri::XML::Node.new('script', document)
|
74
|
-
all_script_src_tag[:src] = 'all.js'
|
86
|
+
all_script_src_tag[:src] = container.eql?(:head) ? 'all.js' : 'all_body.js'
|
75
87
|
all_script_src_tag[:type] = 'text/javascript'
|
76
88
|
|
77
89
|
script_tags_to_remove
|
@@ -91,16 +103,16 @@ module Pageflow
|
|
91
103
|
document.at_css('head') << all_css_link_tag
|
92
104
|
end
|
93
105
|
|
94
|
-
def
|
95
|
-
|
96
|
-
options.fetch(
|
106
|
+
def filtered_script_tags_in(container)
|
107
|
+
script_src_tags_in(container).reject do |tag|
|
108
|
+
options.fetch("#{container}_script_blacklist".to_sym, []).any? do |regexp|
|
97
109
|
tag[:src] =~ regexp
|
98
110
|
end
|
99
111
|
end
|
100
112
|
end
|
101
113
|
|
102
|
-
def
|
103
|
-
document.css(
|
114
|
+
def script_src_tags_in(container)
|
115
|
+
document.css("#{container} script[src]")
|
104
116
|
end
|
105
117
|
|
106
118
|
def css_link_tags
|
data/lib/pageflow/chart.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module Pageflow
|
2
|
+
module Chart
|
3
|
+
FactoryBot.define do
|
4
|
+
factory :scraped_site, class: 'Pageflow::Chart::ScrapedSite' do
|
5
|
+
url { 'MyString' }
|
6
|
+
|
7
|
+
trait :processed do
|
8
|
+
state { 'processed' }
|
9
|
+
|
10
|
+
javascript_file { File.open(Engine.root.join('spec', 'fixtures', 'all.js')) }
|
11
|
+
javascript_body_file { File.open(Engine.root.join('spec', 'fixtures', 'all_body.js')) }
|
12
|
+
stylesheet_file { File.open(Engine.root.join('spec', 'fixtures', 'all.css')) }
|
13
|
+
html_file { File.open(Engine.root.join('spec', 'fixtures', 'index.html')) }
|
14
|
+
csv_file { File.open(Engine.root.join('spec', 'fixtures', 'data.csv')) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
4
18
|
end
|
5
19
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
var chart = {};
|
@@ -0,0 +1 @@
|
|
1
|
+
var chart_body = {};
|
@@ -0,0 +1 @@
|
|
1
|
+
some,values
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'pageflow/used_file_test_helper'
|
4
|
+
|
5
|
+
module Pageflow
|
6
|
+
module Chart
|
7
|
+
describe ScrapedSitesHelper do
|
8
|
+
include UsedFileTestHelper
|
9
|
+
|
10
|
+
before { Pageflow::Chart.config.use_custom_theme = false }
|
11
|
+
|
12
|
+
it 'renders iframe with data-src attribute for scraped site' do
|
13
|
+
scraped_site = create_used_file(:scraped_site, :processed)
|
14
|
+
|
15
|
+
html = scraped_site_iframe('scraped_site_id' => scraped_site.perma_id)
|
16
|
+
|
17
|
+
iframe = Capybara.string(html).find('iframe')
|
18
|
+
expect(iframe['data-src']).to match(%r{original/index\.html})
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'renders no data-custom-theme attribute by default' do
|
22
|
+
scraped_site = create_used_file(:scraped_site, :processed)
|
23
|
+
|
24
|
+
html = scraped_site_iframe('scraped_site_id' => scraped_site.perma_id)
|
25
|
+
|
26
|
+
iframe = Capybara.string(html).find('iframe')
|
27
|
+
expect(iframe['data-use-custom-theme']).to be_blank
|
28
|
+
expect(iframe['data-customize-layout']).to eq('true')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'renders data-custom-theme if site has custom theme' do
|
32
|
+
Pageflow::Chart.config.use_custom_theme = true
|
33
|
+
scraped_site = create_used_file(:scraped_site, :processed)
|
34
|
+
|
35
|
+
html = scraped_site_iframe('scraped_site_id' => scraped_site.perma_id)
|
36
|
+
|
37
|
+
iframe = Capybara.string(html).find('iframe')
|
38
|
+
expect(iframe['data-use-custom-theme']).to eq('true')
|
39
|
+
expect(iframe['data-customize-layout']).to eq('true')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'renders iframe with data-src attribute for chart_url' do
|
43
|
+
html = scraped_site_iframe('chart_url' => 'https://example.com/chart')
|
44
|
+
|
45
|
+
iframe = Capybara.string(html).find('iframe')
|
46
|
+
expect(iframe['data-src']).to eq('//example.com/chart')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'renders no data-custom-theme attribute for chart_url' do
|
50
|
+
html = scraped_site_iframe('chart_url' => 'https://example.com/chart')
|
51
|
+
|
52
|
+
iframe = Capybara.string(html).find('iframe')
|
53
|
+
|
54
|
+
expect(iframe['data-customize-layout']).to be_blank
|
55
|
+
expect(iframe['data-use-custom-theme']).to be_blank
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -12,10 +12,23 @@ module Pageflow
|
|
12
12
|
|
13
13
|
allow(Scraper).to receive(:new).and_return(scraper)
|
14
14
|
|
15
|
-
expect(downloader).to receive(:load_following_refresh_tags)
|
15
|
+
expect(downloader).to receive(:load_following_refresh_tags)
|
16
|
+
.with('http://example.com',
|
17
|
+
raise_on_http_error: true)
|
16
18
|
|
17
19
|
job.perform_with_result(scraped_site, {}, downloader: downloader)
|
18
20
|
end
|
21
|
+
|
22
|
+
it 'returns :error on HTTP error' do
|
23
|
+
job = ScrapeSiteJob.new
|
24
|
+
scraped_site = create(:scraped_site, url: 'http://example.com/a')
|
25
|
+
|
26
|
+
stub_request(:get, 'http://example.com/a').to_return(status: 404, body: '')
|
27
|
+
|
28
|
+
result = job.perform_with_result(scraped_site)
|
29
|
+
|
30
|
+
expect(result).to eq(:error)
|
31
|
+
end
|
19
32
|
end
|
20
33
|
end
|
21
34
|
end
|