Commit 4482d3b1b90d300f13266d7b0695372e3ee29f50
1 parent
807a168a
check preview content in admin part
Showing
2 changed files
with
37 additions
and
3 deletions
| 1 | module Kanjai | 1 | module Kanjai |
| 2 | module Admin::PagesHelper | 2 | module Admin::PagesHelper |
| 3 | + require 'open-uri' | ||
| 4 | + | ||
| 3 | def get_html_by_json(page_data, client_view = false) | 5 | def get_html_by_json(page_data, client_view = false) |
| 4 | json_data = page_data.template_content | 6 | json_data = page_data.template_content |
| 5 | html = '' | 7 | html = '' |
| @@ -18,7 +20,7 @@ module Kanjai | @@ -18,7 +20,7 @@ module Kanjai | ||
| 18 | if client_view == false and row['attributes']['type'] == 'block' | 20 | if client_view == false and row['attributes']['type'] == 'block' |
| 19 | html_attributes['data-id'] = row['attributes']['id'] | 21 | html_attributes['data-id'] = row['attributes']['id'] |
| 20 | page_content = page_data.page_contents.where(:structure_id => row['attributes']['id']).first | 22 | page_content = page_data.page_contents.where(:structure_id => row['attributes']['id']).first |
| 21 | - row_html = '<div class="col-html">' + (page_content.nil? ? '' : page_content.get_content_frontend) + '</div>' | 23 | + row_html = '<div class="col-html">' + (page_content.nil? ? '' : wrap_iframe(page_content)) + '</div>' |
| 22 | end | 24 | end |
| 23 | 25 | ||
| 24 | if client_view == false and row['attributes']['type'] == 'row' | 26 | if client_view == false and row['attributes']['type'] == 'row' |
| @@ -31,7 +33,7 @@ module Kanjai | @@ -31,7 +33,7 @@ module Kanjai | ||
| 31 | ActionController::Base.helpers.concat(row_html.html_safe) | 33 | ActionController::Base.helpers.concat(row_html.html_safe) |
| 32 | row["cells"].each do |cell| | 34 | row["cells"].each do |cell| |
| 33 | page_content = page_data.page_contents.where(:structure_id => cell['id']).first | 35 | page_content = page_data.page_contents.where(:structure_id => cell['id']).first |
| 34 | - html = page_content.nil? ? '' : page_content.get_content_frontend | 36 | + html = page_content.nil? ? '' : wrap_iframe(page_content) |
| 35 | 37 | ||
| 36 | cell_class_name = '' | 38 | cell_class_name = '' |
| 37 | 39 | ||
| @@ -160,5 +162,37 @@ module Kanjai | @@ -160,5 +162,37 @@ module Kanjai | ||
| 160 | html.html_safe | 162 | html.html_safe |
| 161 | end | 163 | end |
| 162 | 164 | ||
| 165 | + def wrap_iframe(page_content) | ||
| 166 | + content = page_content.get_content_frontend | ||
| 167 | + layer = page_content.page_datum.page.page_template.get_html_content | ||
| 168 | + | ||
| 169 | + css_files = [].tap do |n| | ||
| 170 | + doc = Nokogiri::HTML(layer, nil, 'UTF-8') | ||
| 171 | + doc.css("link").each do |x| | ||
| 172 | + if x['rel'] == 'stylesheet' | ||
| 173 | + css_link = x['href'] | ||
| 174 | + n << css_link | ||
| 175 | + end | ||
| 176 | + end | ||
| 177 | + end | ||
| 178 | + styles = css_files.collect do |file| | ||
| 179 | + #begin | ||
| 180 | + Net::HTTP.get(URI.parse(file)) | ||
| 181 | + #rescue | ||
| 182 | + | ||
| 183 | + #end | ||
| 184 | + end | ||
| 185 | + | ||
| 186 | + #css_files = css_files.collect{|link| "<link rel='stylesheet' href='#{link}' />".html_safe }.join('') | ||
| 187 | + content += "<style>#{styles.join(' ')}</style>".html_safe | ||
| 188 | + | ||
| 189 | + #<link rel="stylesheet" href="./assets/css/libs.bundle.css" /> | ||
| 190 | + | ||
| 191 | + "<iframe frameBorder='0' src='data:text/html;charset=utf-8,#{ERB::Util.url_encode(content)}'></iframe>" | ||
| 192 | + end | ||
| 193 | + | ||
| 194 | + | ||
| 163 | end | 195 | end |
| 196 | + | ||
| 197 | + | ||
| 164 | end | 198 | end |