Commit 4482d3b1b90d300f13266d7b0695372e3ee29f50

Authored by Andrey Karpikov
1 parent 807a168a

check preview content in admin part

1 1 module Kanjai
2 2 module Admin::PagesHelper
  3 + require 'open-uri'
  4 +
3 5 def get_html_by_json(page_data, client_view = false)
4 6 json_data = page_data.template_content
5 7 html = ''
... ... @@ -18,7 +20,7 @@ module Kanjai
18 20 if client_view == false and row['attributes']['type'] == 'block'
19 21 html_attributes['data-id'] = row['attributes']['id']
20 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 24 end
23 25
24 26 if client_view == false and row['attributes']['type'] == 'row'
... ... @@ -31,7 +33,7 @@ module Kanjai
31 33 ActionController::Base.helpers.concat(row_html.html_safe)
32 34 row["cells"].each do |cell|
33 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 38 cell_class_name = ''
37 39
... ... @@ -160,5 +162,37 @@ module Kanjai
160 162 html.html_safe
161 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 195 end
  196 +
  197 +
164 198 end
\ No newline at end of file
... ...
1 1 module Kanjai
2   - VERSION = "0.0.318"
  2 + VERSION = "0.0.319"
3 3 end
... ...