diff --git a/app/controllers/admin/communication/websites/pages_controller.rb b/app/controllers/admin/communication/websites/pages_controller.rb index 4d3e9be9919a7c3aa44ef54327a4d706e9e02d07..d4c34e11234b7c96c1704a2366a8c8e276b8d579 100644 --- a/app/controllers/admin/communication/websites/pages_controller.rb +++ b/app/controllers/admin/communication/websites/pages_controller.rb @@ -35,6 +35,11 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We render layout: false end + def preview + @url = @website.url + render layout: 'admin/layouts/preview' + end + def new @page.website = @website breadcrumb diff --git a/app/views/admin/communication/websites/pages/preview.html.erb b/app/views/admin/communication/websites/pages/preview.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..2aaf52e00beb873fd789e0e90f187094565fd955 --- /dev/null +++ b/app/views/admin/communication/websites/pages/preview.html.erb @@ -0,0 +1,4 @@ +<%= @page.text.to_s %> +<% @page.blocks.ordered.each do |block| %> +<%= render 'admin/communication/blocks/preview', block: block %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/layouts/preview.html.erb b/app/views/admin/layouts/preview.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..c0f2336ef7b58a2b1ec3a16f2a394abcfd4ffffe --- /dev/null +++ b/app/views/admin/layouts/preview.html.erb @@ -0,0 +1,31 @@ +<% +@html = Nokogiri::HTML open(@url) +@css_files = @html.xpath '//link[@rel="stylesheet"]/@href' +@css = '' +@css_files.each do |url| + uri = URI.parse url + data = Net::HTTP.get uri + data = data.force_encoding("UTF-8") + data = data.gsub "src:url(../", "src:url(#{@url}/assets/" + data = data.gsub ",url(../", ",url(#{@url}/assets/" + @css << data +end +%> +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> + <title><%= yield :title %></title> + </head> + <body class="is-loaded"> + <style> + <%= @css %> + </style> + <main class="page-with-blocks" id="main" role="main" tabindex="-1"> + <div class="blocks"> + <%= yield %> + </div> + </main> + </body> +</html> diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index a7ee40e9a3fc2a42abc8208162969350f53f783a..a8673cb0287ec5d6151910f32521eda26a6bc28e 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -12,6 +12,7 @@ namespace :communication do member do get :children get :static + get :preview end end resources :categories, controller: 'websites/categories' do